diff options
author | Kenny Root <kroot@google.com> | 2012-03-08 10:30:39 -0800 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2012-03-15 20:51:22 -0700 |
commit | 6f1f03bcae70792bbd8bc0aecb90c7b9c43b76b5 (patch) | |
tree | f605963317802514eccf0a68ba3bc6da9d8d012a /src/com/android/keychain/KeyChainService.java | |
parent | db6218b771e86f77740532fc86c6ae4081eacd75 (diff) | |
download | android_packages_apps_KeyChain-6f1f03bcae70792bbd8bc0aecb90c7b9c43b76b5.tar.gz android_packages_apps_KeyChain-6f1f03bcae70792bbd8bc0aecb90c7b9c43b76b5.tar.bz2 android_packages_apps_KeyChain-6f1f03bcae70792bbd8bc0aecb90c7b9c43b76b5.zip |
Convert to new KeyStore format
Change-Id: I531ca8fbf8c7008383488cba1dd73f59537edb01
Diffstat (limited to 'src/com/android/keychain/KeyChainService.java')
-rw-r--r-- | src/com/android/keychain/KeyChainService.java | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/com/android/keychain/KeyChainService.java b/src/com/android/keychain/KeyChainService.java index 1ab3ad3..8d26643 100644 --- a/src/com/android/keychain/KeyChainService.java +++ b/src/com/android/keychain/KeyChainService.java @@ -25,7 +25,9 @@ import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.os.Binder; import android.os.IBinder; +import android.os.Process; import android.security.Credentials; import android.security.IKeyChainService; import android.security.KeyChain; @@ -82,15 +84,30 @@ public class KeyChainService extends IntentService { private final TrustedCertificateStore mTrustedCertificateStore = new TrustedCertificateStore(); - @Override public byte[] getPrivateKey(String alias) { - return getKeyStoreEntry(Credentials.USER_PRIVATE_KEY, alias); + @Override + public String requestPrivateKey(String alias) { + checkArgs(alias); + + final String keystoreAlias = Credentials.USER_PRIVATE_KEY + alias; + final int uid = Binder.getCallingUid(); + if (!mKeyStore.grant(keystoreAlias, uid)) { + return null; + } + + final StringBuilder sb = new StringBuilder(); + sb.append(Process.SYSTEM_UID); + sb.append('_'); + sb.append(keystoreAlias); + + return sb.toString(); } @Override public byte[] getCertificate(String alias) { - return getKeyStoreEntry(Credentials.USER_CERTIFICATE, alias); + checkArgs(alias); + return mKeyStore.get(Credentials.USER_CERTIFICATE + alias); } - private byte[] getKeyStoreEntry(String type, String alias) { + private void checkArgs(String alias) { if (alias == null) { throw new NullPointerException("alias == null"); } @@ -102,12 +119,6 @@ public class KeyChainService extends IntentService { throw new IllegalStateException("uid " + callingUid + " doesn't have permission to access the requested alias"); } - String key = type + alias; - byte[] bytes = mKeyStore.get(key); - if (bytes == null) { - return null; - } - return bytes; } private boolean isKeyStoreUnlocked() { |