diff options
author | Brian Carlstrom <bdc@google.com> | 2012-03-30 16:07:58 -0700 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2012-03-30 22:59:44 -0700 |
commit | f4616bf8c0b3bff8863d627c3c003fa9234cb225 (patch) | |
tree | 50efa81803d39df3ca7df271289ee61e873f6045 /src | |
parent | 7d99ba835013491e9d3d540a937e5e0a742b1ab4 (diff) | |
download | android_packages_apps_CertInstaller-f4616bf8c0b3bff8863d627c3c003fa9234cb225.tar.gz android_packages_apps_CertInstaller-f4616bf8c0b3bff8863d627c3c003fa9234cb225.tar.bz2 android_packages_apps_CertInstaller-f4616bf8c0b3bff8863d627c3c003fa9234cb225.zip |
Broader support for KeyChain.EXTRA_NAME
Previously EXTRA_NAME only supplied the default name when used with
KeyChain.EXTRA_CERTIFICATE. It now also provides the default name with
KeyChain.EXTRA_PKCS12, overriding the value found within the PKCS#12
file. In addition, will be used as the default alias name when
credentials are installed from external storage as opposed to via
an extra.
Bug: 6129421
Change-Id: I63c06a866fc62bfa56636011b766d3dcae7764bd
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/certinstaller/CertFile.java | 11 | ||||
-rw-r--r-- | src/com/android/certinstaller/CertInstallerMain.java | 13 | ||||
-rw-r--r-- | src/com/android/certinstaller/CredentialHelper.java | 14 |
3 files changed, 25 insertions, 13 deletions
diff --git a/src/com/android/certinstaller/CertFile.java b/src/com/android/certinstaller/CertFile.java index 5c75517..401c1a3 100644 --- a/src/com/android/certinstaller/CertFile.java +++ b/src/com/android/certinstaller/CertFile.java @@ -129,6 +129,11 @@ public class CertFile extends PreferenceActivity implements FileFilter { protected void installFromFile(File file) { Log.d(TAG, "install cert from " + file); + String fileName = file.getName(); + Bundle bundle = getIntent().getExtras(); + String name = ((bundle == null) + ? fileName + : bundle.getString(KeyChain.EXTRA_NAME, fileName)); if (file.exists()) { if (file.length() < MAX_FILE_SIZE) { byte[] data = Util.readFile(file); @@ -138,7 +143,7 @@ public class CertFile extends PreferenceActivity implements FileFilter { return; } mCertFile = file; - install(file.getName(), data); + install(fileName, name, data); } else { Log.w(TAG, "cert file is too large: " + file.length()); toastError(CERT_TOO_LARGE_ERROR); @@ -171,9 +176,9 @@ public class CertFile extends PreferenceActivity implements FileFilter { Environment.MEDIA_MOUNTED); } - private void install(String fileName, byte[] value) { + private void install(String fileName, String name, byte[] value) { Intent intent = new Intent(this, CertInstaller.class); - intent.putExtra(CredentialHelper.CERT_NAME_KEY, fileName); + intent.putExtra(KeyChain.EXTRA_NAME, name); if (fileName.endsWith(Credentials.EXTENSION_PFX) || fileName.endsWith(Credentials.EXTENSION_P12)) { intent.putExtra(KeyChain.EXTRA_PKCS12, value); diff --git a/src/com/android/certinstaller/CertInstallerMain.java b/src/com/android/certinstaller/CertInstallerMain.java index 02bcc66..7d7ed6e 100644 --- a/src/com/android/certinstaller/CertInstallerMain.java +++ b/src/com/android/certinstaller/CertInstallerMain.java @@ -62,8 +62,12 @@ public class CertInstallerMain extends CertFile implements Runnable { if (Credentials.INSTALL_ACTION.equals(action)) { Bundle bundle = intent.getExtras(); - - if ((bundle == null) || bundle.isEmpty()) { + // If bundle is empty of any actual credentials, install from external storage. + // Otherwise, pass extras to CertInstaller to install those credentials. + // Either way, we use KeyChain.EXTRA_NAME as the default name if available. + if (bundle == null + || bundle.isEmpty() + || (bundle.size() == 1 && bundle.containsKey(KeyChain.EXTRA_NAME))) { if (!isSdCardPresent()) { Toast.makeText(this, R.string.sdcard_not_present, Toast.LENGTH_SHORT).show(); @@ -76,8 +80,9 @@ public class CertInstallerMain extends CertFile implements Runnable { installFromFile(allFiles.get(0)); return; } else { - startActivityForResult(new Intent(this, CertFileList.class), - REQUEST_INSTALL_CODE); + Intent newIntent = new Intent(this, CertFileList.class); + newIntent.putExtras(intent); + startActivityForResult(newIntent, REQUEST_INSTALL_CODE); return; } } diff --git a/src/com/android/certinstaller/CredentialHelper.java b/src/com/android/certinstaller/CredentialHelper.java index 87b2148..09e78eb 100644 --- a/src/com/android/certinstaller/CredentialHelper.java +++ b/src/com/android/certinstaller/CredentialHelper.java @@ -24,6 +24,7 @@ import android.security.Credentials; import android.security.KeyChain; import android.security.IKeyChainService; import android.text.Html; +import android.text.TextUtils; import android.util.Log; import com.android.org.bouncycastle.asn1.ASN1InputStream; import com.android.org.bouncycastle.asn1.ASN1Sequence; @@ -54,7 +55,6 @@ import java.util.List; * certificates. */ class CredentialHelper { - static final String CERT_NAME_KEY = "name"; private static final String DATA_KEY = "data"; private static final String CERTS_KEY = "crts"; @@ -77,8 +77,8 @@ class CredentialHelper { return; } - String name = bundle.getString(CERT_NAME_KEY); - bundle.remove(CERT_NAME_KEY); + String name = bundle.getString(KeyChain.EXTRA_NAME); + bundle.remove(KeyChain.EXTRA_NAME); if (name != null) { mName = name; } @@ -95,7 +95,7 @@ class CredentialHelper { synchronized void onSaveStates(Bundle outStates) { try { outStates.putSerializable(DATA_KEY, mBundle); - outStates.putString(CERT_NAME_KEY, mName); + outStates.putString(KeyChain.EXTRA_NAME, mName); if (mUserKey != null) { outStates.putByteArray(Credentials.USER_PRIVATE_KEY, mUserKey.getEncoded()); @@ -115,7 +115,7 @@ class CredentialHelper { void onRestoreStates(Bundle savedStates) { mBundle = (HashMap) savedStates.getSerializable(DATA_KEY); - mName = savedStates.getString(CERT_NAME_KEY); + mName = savedStates.getString(KeyChain.EXTRA_NAME); byte[] bytes = savedStates.getByteArray(Credentials.USER_PRIVATE_KEY); if (bytes != null) { setPrivateKey(bytes); @@ -324,7 +324,9 @@ class CredentialHelper { Log.d(TAG, "extracted alias = " + alias + ", entry=" + entry.getClass()); if (entry instanceof PrivateKeyEntry) { - mName = alias; + if (TextUtils.isEmpty(mName)) { + mName = alias; + } return installFrom((PrivateKeyEntry) entry); } } |