Вот подробности -
Я использую эту функцию, чтобы установить HTTP-соединение в Android -
public static HurlStack setUpHttpsConnection(Context appContext) {
try {
// Load CAs from an InputStream
// (could be from a resource or ByteArrayInputStream or ...)
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// // My CRT file that I put in the assets folder
// // I got this file by following these steps:
// // * Go to https://littlesvr.ca using Firefox
// // * Click the padlock/More/Security/View Certificate/Details/Export
// // * Saved the file as littlesvr.crt (type X.509 Certificate (PEM))
// // public static Context context;
// InputStream caInput = new BufferedInputStream(appContext.getAssets().open("COMODO RSA Domain Validation Secure Server CA.cer")); //app.geoconnect.io.cer
InputStream caInput = new BufferedInputStream(appContext.getAssets().open("app.testing.io.cer"));
Certificate ca = cf.generateCertificate(caInput);
//System.out.println("ca=" + ((X509Certificate) ca).getSubjectDN());
// Create a KeyStore containing our trusted CAs
InputStream keystoreInput = new BufferedInputStream(appContext.getAssets().open("TestingSSLKeyStore.cer"));
String keystorePassword = "testing";
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
// keyStore.load(keystoreInput, keystorePassword.toCharArray());
keyStore.load(null, null);
keyStore.setCertificateEntry("cer", ca);
// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
// Create an SSLContext that uses our TrustManager
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, tmf.getTrustManagers(), null);
// SSLContext sslContext = SSLContexts.createDefault();
// SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(context,
// new String[]{"TLSv1.1", "TLSv1.2"},
// null,
// new NoopHostnameVerifier());
// CloseableHttpClient client = HttpClientBuilder.create()
// .setDefaultCookieStore(cookieStore)
// .setSSLSocketFactory(sslConnectionSocketFactory)
// .build();
// Tell the URLConnection to use a SocketFactory from our SSLContext
// URL url = new URL(urlString);
// HttpsURLConnection urlConnection = (HttpsURLConnection)url.openConnection();
// urlConnection.setSSLSocketFactory(context.getSocketFactory());
HurlStack hurlStack = new HurlStack(null, context.getSocketFactory());
return hurlStack;
} catch (Exception ex) {
Log.e("SSL Issue ", "Failed to establish SSL connection to server: " + ex.toString());
return null;
}
}
Проблема в том, что я не знаю, откуда мне взять эти файл сертификата. Мой код развернут на AWS и настроен SSL. Пожалуйста, кто-нибудь, помогите мне.