List of usage examples for android.security KeyChain getCertificateChain
@Nullable @WorkerThread public static X509Certificate[] getCertificateChain(@NonNull Context context, @NonNull String alias) throws KeyChainException, InterruptedException
From source file:org.strongswan.android.logic.CharonVpnService.java
/** * Function called via JNI to get a list containing the DER encoded certificates * of the user selected certificate chain (beginning with the user certificate). * * Since this method is called from a thread of charon's thread pool we are safe * to call methods on KeyChain directly. * * @return list containing the certificates (first element is the user certificate) * @throws InterruptedException/* w ww .j av a 2 s. co m*/ * @throws KeyChainException * @throws CertificateEncodingException */ private byte[][] getUserCertificate() throws KeyChainException, InterruptedException, CertificateEncodingException { ArrayList<byte[]> encodings = new ArrayList<byte[]>(); X509Certificate[] chain = KeyChain.getCertificateChain(getApplicationContext(), mCurrentUserCertificateAlias); if (chain == null || chain.length == 0) { return null; } for (X509Certificate cert : chain) { encodings.add(cert.getEncoded()); } return encodings.toArray(new byte[encodings.size()][]); }