0

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.

Saloom
  • 163
  • 10
  • could you please share what is your iis SSL setting? you could dtry to use the custom trust manager that trusts this server certificate or it suggests to the server to include the intermediate CA in the server chain.https://stackoverflow.com/questions/39264056/android-java-security-cert-certpathvalidatorexception-trust-anchor-for-certific – Jalpa Panchal Mar 09 '21 at 12:12
  • @JalpaPanchal I wanted to avoid updating the application with a new Trust Manager. Unfortunately the issue cannot be solved since only the old server contained the key-pair whose certificate is trusted. – Saloom Mar 10 '21 at 05:27

0 Answers0