android.security.KeyChainException: java.lang.IllegalStateException: uid
Asked Answered
M

1

1

Error:

android.security.KeyChainException: java.lang.IllegalStateException: uid 10111 doesn't have permission to access the requested alias

Code:

new Thread(new Runnable() {

        public void run() {
            try {
                X509Certificate[] myCertificates=KeyChain.getCertificateChain(MainActivity.this, "ServerCertificate");
                if(myCertificates!=null)
                {
                    System.out.println("myCertificates size "+myCertificates.length);

                    for(int i=0;i<myCertificates.length;i++)
                    {
                        System.out.println("myCertificates i= "+i+"    "+myCertificates[i]);
                    }
                }
            } catch (KeyChainException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }).start();
Melodramatic answered 25/8, 2012 at 12:57 Comment(1)
Did you ever figure this one out?Bourgeon
G
6

The KeyChain class requires the application to call choosePrivateKeyAlias() at least once after the application is installed before calling getPrivateKey() or getCertificateChain(). So even if one knows the alias beforehand, the choosePrivateKeyAlias() must be called at least once, otherwise there is no trust established between the app and the internal database that KeyChain uses.

Gyre answered 10/12, 2012 at 16:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.