W/CryptoUpcalls: Could not find provider for algorithm: RSA/ECB/PKCS1Padding
- Dominant language
- Java
- Stars
- 1.4k
- Forks
- 326
- Avg merge
- 16h 22m
- Merged PRs (30d)
- 17
Description
I'm developing a kotlin android app, but I get this
```
W/CryptoUpcalls: Could not find provider for algorithm: RSA/ECB/PKCS1Padding
I/okhttp.OkHttpClient: <-- HTTP FAILED: javax.net.ssl.SSLHandshakeException: Read error: ssl=0x6fde49c498: Failure in SSL library, usually a protocol error
error:04000044:RSA routines:OPENSSL_internal:internal error (external/conscrypt/common/src/jni/main/cpp/conscrypt/native_crypto.cc:741 0x6f395ae05a:0x00000000)
```
I am using android 11
Here is some code that maybe can help better understanding my problem
Create OkHttpClient
```
Security.removeProvider("ProviderName")
val provider = GenerateProvider()
Security.insertProviderAt(provider , 1)
val builder = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS)
.writeTimeout(15, TimeUnit.SECONDS)
val keyStore: KeyStore = KeyStore.getInstance("ProviderName")
keyStore.load(ByteArrayInputStream(certificate), null)
val kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm())
kmf.init(keyStore, null)
val keyManagers = kmf.keyManagers
val trustManagerFactory =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.init(null as KeyStore?)
val trustManagers = trustManagerFactory.trustManagers
if (trustManagers.size != 1 || trustManagers[0] !is X509TrustManager) {
throw IllegalStateException(
"Unexpected default trust managers:" + Arrays.toString(
trustManagers
)
)
}
val trustManager = trustManagers[0] as X509TrustManager
val sslContext = SSLContext.getInstance("TLSv1.2")
sslContext.init(keyManagers, null, null)
val spec: ConnectionSpec = ConnectionSpec.Builder(ConnectionSpec.COMPATIBLE_TLS)
.supportsTlsExtensions(true)
.tlsVersions(TlsVersion.TLS_1_2, TlsVersion.TLS_1_1, TlsVersion.TLS_1_0)
.cipherSuites(
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
TLS_DHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
TLS_AES_128_CCM_8_SHA256,
TLS_AES_256_GCM_SHA384,
TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
TLS_ECDHE_RSA_WITH_RC4_128_SHA,
TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
TLS_DHE_DSS_WITH_AES_128_CBC_SHA,
TLS_DHE_RSA_WITH_AES_256_CBC_SHA
)
.build()
return builder.sslSocketFactory(sslContext.socketFactory, trustManager)
.connectionSpecs(Collections.singletonList(spec)).build()
```
Create Retrofit
```
Retrofit.Builder().baseUrl(BuildConfig.URL)
.client(okHttpClient)
.addConverterFactory(ScalarsConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
```
And then I do an http post
```
postInterface = createRetrofit()
(postInterface?: return).DoPost(mapValues).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(object :
DisposableSingleObserver>() {
override fun onSuccess(idpResponse: Response) {
//....
}
override fun onError(e: Throwable) {
//....
}
})
```
And this is the postInterface
```
interface PostInterface {
@Headers("User-Agent: Mozilla/5.0")
@FormUrlEncoded
@POST(Endpoints.URL)
fun DoPost(@FieldMap(encoded = true) values: Map): Single>
}
```
Thanks in advance
Contributor guide
Assessment
This issue has not been assessed yet.