MockWebServer を使用して Android InstrumentedTest を作成し、SSL を有効にしたいと考えています。Portecle を使用して「BKS」証明書を作成しました。
SSLSocketFactory を作成するために、次のコードを使用します。
private SSLSocketFactory getSSLSocketFactory_KeyStore(Context context, String keyStoreType, int keystoreResId, String keyPassword)
throws CertificateException, KeyStoreException, IOException, NoSuchAlgorithmException, KeyManagementException {
InputStream caInput = context.getResources().openRawResource(keystoreResId);
if (keyStoreType == null || keyStoreType.length() == 0) {
keyStoreType = KeyStore.getDefaultType();
}
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(caInput, keyPassword.toCharArray());
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
TrustManager[] wrappedTrustManagers = getWrappedTrustManagers(tmf.getTrustManagers());
SSLContext sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, wrappedTrustManagers, null);
return new NoSSLv3SocketFactory(sslContext.getSocketFactory());
}
その後:
final MockWebServer server = new MockWebServer();
server.useHttps(getSSLSocketFactory_KeyStore(appContext, "BKS", R.raw.mykeystore, "mypassword"), false);
次の例外が発生し続けます。
Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted:
ssl=0xdfca3778: Failure in SSL library, usually a protocol error
error:10000410:SSL routines:OPENSSL_internal:SSLV3_ALERT_HANDSHAKE_FAILURE (third_party/openssl/boringssl/src/ssl/tls_record.cc:586 0xc718d288:0x00000001)
error:1000009a:SSL routines:OPENSSL_internal:HANDSHAKE_FAILURE_ON_CLIENT_HELLO (third_party/openssl/boringssl/src/ssl/handshake.cc:542 0xc7800f0d:0x00000000)
at com.google.android.gms.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
at com.google.android.gms.org.conscrypt.NativeSsl.doHandshake(:com.google.android.gms@12862026@12.8.62 (040700-199405334):3)
at com.google.android.gms.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(:com.google.android.gms@12862026@12.8.62 (040700-199405334):15)
何がうまくいかないのですか?