title: Android ICS: how to choose a self-installed user Certificate from KeyStore properly
body: <p>we are developping a client for android.  at first the user has to decide which Certificate gets used for the connection (ikev2). is there a propper way to do this? </p>
  
  <p>all i found is a loop over all installed certificates, if the typed alias (through user input==very bad) is matching the certificate alias "CN=foobar CA,O=foobar,C=CH" we take it, but its taking ages as you can imagine and the fact that the user has to type in the alias is not applicable...</p>
  
  <pre><code>public X509Certificate getCACert(String caName){
      ks = KeyStore.getInstance("AndroidCAStore");
      Enumeration&lt;?&gt; aliases = ks.aliases();
      while (aliases.hasMoreElements()) {
          String alias = (String) aliases.nextElement();
          cert = null;
          try {
              cert = (X509Certificate) ks.getCertificate(alias);
          } catch (KeyStoreException e) {
              e.printStackTrace();
          }
  
          if (cert.getSubjectDN().getName().equalsIgnoreCase(caName)) {
              break;
          }
      }
  return cert;
  }
  </code></pre>
  
  <p>is there maybe a prebuild callback for selecting user certs, maybe a type for keystore.getInstance("type4userCA") which returns only the user CA's without the preinstalled CA's or has anybody an idea how to filter it another way?</p>
  
  <p>i saw that the android-vpn setting is able of displaying only the userCA's in a spinner, but they are using the keystore.saw() method which i cant use on my java.security.keystore...</p>
  
  <p>thx</p>