How start an Android application only if there is a specific certificate installed on device?

108 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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;
                    }
                }
            }