0

I've create a hybrid web application using SAP Mobile Services.

This application (.apk) must run only if there is a specific certificate installed on the Android device. Otherwise, it should not run.

Any ideas how to solve this?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
Umberto
  • 41
  • 6

1 Answers1

0

in MainActivity.java add this code:

boolean isCertExist = false;
        try
        {
            KeyStore ks = KeyStore.getInstance("AndroidCAStore");
            if (ks != null)
            {
                ks.load(null, null);
                Enumeration aliases = ks.aliases();
                while (aliases.hasMoreElements())
                {
                    String alias = (String) aliases.nextElement();
                    java.security.cert.X509Certificate cert = (java.security.cert.X509Certificate) ks.getCertificate(alias);

                    System.out.println(cert.getIssuerDN().getName());
                    if (cert.getIssuerDN().getName().contains("<STRING CERT>"))
                    {
                        isCertExist = true;
                        break;
                    }
                }
            }
Umberto
  • 41
  • 6