summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2012-03-27 20:42:00 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-03-27 20:42:00 -0700
commitb9bae2cd234ed07d72cf73616d15774860eac023 (patch)
tree17ea66e1c2a69d42c4b9366d6391ac77e41003cd /src
parent9c2b71c70b3086784f6d26d601dc3e9212c228b3 (diff)
parent6f1f03bcae70792bbd8bc0aecb90c7b9c43b76b5 (diff)
downloadandroid_packages_apps_KeyChain-b9bae2cd234ed07d72cf73616d15774860eac023.tar.gz
android_packages_apps_KeyChain-b9bae2cd234ed07d72cf73616d15774860eac023.tar.bz2
android_packages_apps_KeyChain-b9bae2cd234ed07d72cf73616d15774860eac023.zip
Merge "Convert to new KeyStore format"
Diffstat (limited to 'src')
-rw-r--r--src/com/android/keychain/KeyChainService.java31
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() {