Many years ago I set up an IIS web server and created an Android application that had no issues communicating with the server. Today the hardware hosting the web server failed and I set up the web-site on a different machine.
The Android up uses the following code:
public static void allowSelfSignedCertificates(Context context)
{
final KeyStore ks;
try {
ks = KeyStore.getInstance("BKS");
final InputStream in = context.getResources().openRawResource( R.raw.mykeystore);
try {
ks.load(in, context.getString( R.string.keystorepass).toCharArray());
} catch ( Exception e ) {
e.printStackTrace();
} finally {
in.close();
}
final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory
.getDefaultAlgorithm());
kmf.init(ks, "password".toCharArray());
final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory
.getDefaultAlgorithm());
tmf.init(ks);
final SSLContext sc=SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new java.security.SecureRandom());
socketFactory = sc.getSocketFactory();
} catch (Exception ex) {
ex.printStackTrace();
}
}
I do not have access to the self-signed certificate used by the the IIS on the failed machine but I have access to the .jks keystore used by the Android app. Can I somehow make the application work?
The Android app code cannot change since the devices using the app gets updates from the server and now they cannot connect to it.