diff options
author | Robin Lee <rgl@google.com> | 2016-02-12 13:57:09 +0000 |
---|---|---|
committer | Robin Lee <rgl@google.com> | 2016-02-12 15:32:44 +0000 |
commit | 69f2f0bd44b702debf8503236fcf3dc1a9eb26c5 (patch) | |
tree | 1d03efe26e0718fe30bcb48e39160196a72f3ec9 | |
parent | 97910a20c5114215e04151d228aefbfde1e52be0 (diff) | |
download | android_packages_apps_CertInstaller-69f2f0bd44b702debf8503236fcf3dc1a9eb26c5.tar.gz android_packages_apps_CertInstaller-69f2f0bd44b702debf8503236fcf3dc1a9eb26c5.tar.bz2 android_packages_apps_CertInstaller-69f2f0bd44b702debf8503236fcf3dc1a9eb26c5.zip |
Skip password dialog if PKCS#12 has no password
Just an extra unnecessary step for the user, eg. in the case of a file
generated locally just as an interchange format.
Bug: 27155157
Change-Id: Iafb948172e6a8d33b1742a06e5d0c69dc0658d78
-rw-r--r-- | src/com/android/certinstaller/CertInstaller.java | 6 | ||||
-rw-r--r-- | src/com/android/certinstaller/CredentialHelper.java | 30 |
2 files changed, 28 insertions, 8 deletions
diff --git a/src/com/android/certinstaller/CertInstaller.java b/src/com/android/certinstaller/CertInstaller.java index 0a6049e..6299abd 100644 --- a/src/com/android/certinstaller/CertInstaller.java +++ b/src/com/android/certinstaller/CertInstaller.java @@ -102,7 +102,11 @@ public class CertInstaller extends Activity { toastErrorAndFinish(R.string.no_cert_to_saved); finish(); } else if (mCredentials.hasPkcs12KeyStore()) { - showDialog(PKCS12_PASSWORD_DIALOG); + if (mCredentials.hasPassword()) { + showDialog(PKCS12_PASSWORD_DIALOG); + } else { + new Pkcs12ExtractAction("").run(this); + } } else { MyAction action = new InstallOthersAction(); if (needsKeyStoreAccess()) { diff --git a/src/com/android/certinstaller/CredentialHelper.java b/src/com/android/certinstaller/CredentialHelper.java index a3e2e27..beea8f6 100644 --- a/src/com/android/certinstaller/CredentialHelper.java +++ b/src/com/android/certinstaller/CredentialHelper.java @@ -317,22 +317,30 @@ class CredentialHelper { return true; } + boolean hasPassword() { + if (!hasPkcs12KeyStore()) { + return false; + } + try { + return loadPkcs12Internal(new PasswordProtection(new char[] {})) == null; + } catch (Exception e) { + return true; + } + } + boolean extractPkcs12(String password) { try { - return extractPkcs12Internal(password); + return extractPkcs12Internal(new PasswordProtection(password.toCharArray())); } catch (Exception e) { Log.w(TAG, "extractPkcs12(): " + e, e); return false; } } - private boolean extractPkcs12Internal(String password) + private boolean extractPkcs12Internal(PasswordProtection password) throws Exception { // TODO: add test about this - java.security.KeyStore keystore = java.security.KeyStore.getInstance("PKCS12"); - PasswordProtection passwordProtection = new PasswordProtection(password.toCharArray()); - keystore.load(new ByteArrayInputStream(getData(KeyChain.EXTRA_PKCS12)), - passwordProtection.getPassword()); + java.security.KeyStore keystore = loadPkcs12Internal(password); Enumeration<String> aliases = keystore.aliases(); if (!aliases.hasMoreElements()) { @@ -341,7 +349,7 @@ class CredentialHelper { while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); - KeyStore.Entry entry = keystore.getEntry(alias, passwordProtection); + KeyStore.Entry entry = keystore.getEntry(alias, password); Log.d(TAG, "extracted alias = " + alias + ", entry=" + entry.getClass()); if (entry instanceof PrivateKeyEntry) { @@ -354,6 +362,14 @@ class CredentialHelper { return true; } + private java.security.KeyStore loadPkcs12Internal(PasswordProtection password) + throws Exception { + java.security.KeyStore keystore = java.security.KeyStore.getInstance("PKCS12"); + keystore.load(new ByteArrayInputStream(getData(KeyChain.EXTRA_PKCS12)), + password.getPassword()); + return keystore; + } + private synchronized boolean installFrom(PrivateKeyEntry entry) { mUserKey = entry.getPrivateKey(); mUserCert = (X509Certificate) entry.getCertificate(); |