Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Version 0.3.2 with HTTPS throws exception on API Level 28 #97

Closed
LUwaisA opened this issue Feb 10, 2019 · 3 comments
Closed

Version 0.3.2 with HTTPS throws exception on API Level 28 #97

LUwaisA opened this issue Feb 10, 2019 · 3 comments

Comments

@LUwaisA
Copy link

LUwaisA commented Feb 10, 2019

We have set up RESTMockServer using https by calling the following function in the Runner for our Android instrumented tests:

    private fun provisionMockServer() {
        RESTMockServer.enableLogging(LaundrappRESTMockLogger())
        val builder = RESTMockOptions.Builder().useHttps(true).build()
        RESTMockServerStarter.startSync(AndroidAssetsFileParser(context), AndroidLogger(), builder)
    }

We also then pass the SSLSocketFactory into our production app as shown in the example app. Using this method works well with Android versions up to Android Oreo (API 27) but running tests fails with the following exception on an emulator running API 28:

E/AndroidRuntime: FATAL EXCEPTION: pool-4-thread-1
    Process: com.company.ourapp, PID: 6114
    java.lang.AssertionError: java.security.NoSuchAlgorithmException: The BC provider no longer provides an implementation for KeyPairGenerator.RSA.  Please see https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html for more details.
        at okhttp3.tls.HeldCertificate$Builder.generateKeyPair(HeldCertificate.java:429)
        at okhttp3.tls.HeldCertificate$Builder.build(HeldCertificate.java:353)
        at io.appflate.restmock.SslUtils.localhost(SslUtils.java:44)
        at io.appflate.restmock.RESTMockServer.setUpHttps(RESTMockServer.java:91)
        at io.appflate.restmock.RESTMockServer.init(RESTMockServer.java:74)
        at io.appflate.restmock.RESTMockServerStarter$1.run(RESTMockServerStarter.java:56)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.security.NoSuchAlgorithmException: The BC provider no longer provides an implementation for KeyPairGenerator.RSA.  Please see https://android-developers.googleblog.com/2018/03/cryptography-changes-in-android-p.html for more details.
        at sun.security.jca.Providers.checkBouncyCastleDeprecation(Providers.java:563)
        at sun.security.jca.Providers.checkBouncyCastleDeprecation(Providers.java:330)
        at java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:303)
        at okhttp3.tls.HeldCertificate$Builder.generateKeyPair(HeldCertificate.java:425)
        at okhttp3.tls.HeldCertificate$Builder.build(HeldCertificate.java:353) 
        at io.appflate.restmock.SslUtils.localhost(SslUtils.java:44) 
        at io.appflate.restmock.RESTMockServer.setUpHttps(RESTMockServer.java:91) 
        at io.appflate.restmock.RESTMockServer.init(RESTMockServer.java:74) 
        at io.appflate.restmock.RESTMockServerStarter$1.run(RESTMockServerStarter.java:56) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:764) 

Running the production app works fine so this has to be an issue with our testing setup - most likely RESTMockServer's usage of OkHttp looking at the stacktrace.

@LUwaisA LUwaisA changed the title Version 0.3.2 needs OkHttp update to work with API Level 28 Version 0.3.2 with HTTPS throws exception on API Level 28 Feb 10, 2019
@LUwaisA
Copy link
Author

LUwaisA commented Feb 10, 2019

Adding:

configurations.all {
    resolutionStrategy {
        force "com.squareup.okhttp3:okhttp:3.13.1"
        force "com.squareup.okhttp3:okhttp-tls:3.13.1"
        force "com.squareup.okhttp3:mockwebserver:3.13.1"
        force "com.squareup.okhttp3:logging-interceptor:3.13.1"
    }
}

to our app's build.gradle seems to avoid the issue above on API Level 28 (Android P) but runs into other issues because other dependencies are not expecting these forced dependencies. Regardless of that - it looks like just updating to okhttp 3.13.1 would solve this issue. Hopefully this isn't too much of a change.

@andrzejchm
Copy link
Owner

I've just released 0.3.3 version that should solve the issue by updating OkHttp to the latest version

@LUwaisA
Copy link
Author

LUwaisA commented Feb 12, 2019

Awesome thanks for the quick response - we're having the conflicts mentioned above but this update has definitely helped 👍

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants