diff options
author | Chad Brubaker <cbrubaker@google.com> | 2015-02-24 04:54:41 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-02-24 04:54:41 +0000 |
commit | 39fee05ea25c68f6e5156483cc5e5cc44e9b09d9 (patch) | |
tree | 92c7c399418aa6caa56c2ff4fd580cca04cbb06d /keystore | |
parent | 7d0c22e21b00b339204f0004f5075f088b19cbaa (diff) | |
parent | f271fa33f148b0c410e8ee06aceb1f2b57cd62c7 (diff) | |
download | frameworks_base-39fee05ea25c68f6e5156483cc5e5cc44e9b09d9.zip frameworks_base-39fee05ea25c68f6e5156483cc5e5cc44e9b09d9.tar.gz frameworks_base-39fee05ea25c68f6e5156483cc5e5cc44e9b09d9.tar.bz2 |
am f271fa33: am cdc70256: am f3c117ca: Merge "Add new IKeystoreService methods to KeyStore"
* commit 'f271fa33f148b0c410e8ee06aceb1f2b57cd62c7':
Add new IKeystoreService methods to KeyStore
Diffstat (limited to 'keystore')
-rw-r--r-- | keystore/java/android/security/KeyStore.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index e753a7c..bfbf028 100644 --- a/keystore/java/android/security/KeyStore.java +++ b/keystore/java/android/security/KeyStore.java @@ -18,8 +18,14 @@ package android.security; import com.android.org.conscrypt.NativeCrypto; +import android.os.Binder; +import android.os.IBinder; import android.os.RemoteException; import android.os.ServiceManager; +import android.security.keymaster.ExportResult; +import android.security.keymaster.KeyCharacteristics; +import android.security.keymaster.KeymasterArguments; +import android.security.keymaster.OperationResult; import android.util.Log; import java.util.Locale; @@ -58,6 +64,8 @@ public class KeyStore { private final IKeystoreService mBinder; + private IBinder mToken; + private KeyStore(IKeystoreService binder) { mBinder = binder; } @@ -68,6 +76,13 @@ public class KeyStore { return new KeyStore(keystore); } + private synchronized IBinder getToken() { + if (mToken == null) { + mToken = new Binder(); + } + return mToken; + } + static int getKeyTypeForAlgorithm(String keyType) { if ("RSA".equalsIgnoreCase(keyType)) { return NativeCrypto.EVP_PKEY_RSA; @@ -363,4 +378,100 @@ public class KeyStore { public int getLastError() { return mError; } + + public boolean addRngEntropy(byte[] data) { + try { + return mBinder.addRngEntropy(data) == NO_ERROR; + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return false; + } + } + + public int generateKey(String alias, KeymasterArguments args, int uid, int flags, + KeyCharacteristics outCharacteristics) { + try { + return mBinder.generateKey(alias, args, uid, flags, outCharacteristics); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return SYSTEM_ERROR; + } + } + + public int generateKey(String alias, KeymasterArguments args, int flags, + KeyCharacteristics outCharacteristics) { + return generateKey(alias, args, UID_SELF, flags, outCharacteristics); + } + + public int getKeyCharacteristics(String alias, byte[] clientId, byte[] appId, + KeyCharacteristics outCharacteristics) { + try { + return mBinder.getKeyCharacteristics(alias, clientId, appId, outCharacteristics); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return SYSTEM_ERROR; + } + } + + public int importKey(String alias, KeymasterArguments args, int format, byte[] keyData, + int uid, int flags, KeyCharacteristics outCharacteristics) { + try { + return mBinder.importKey(alias, args, format, keyData, uid, flags, + outCharacteristics); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return SYSTEM_ERROR; + } + } + + public int importKey(String alias, KeymasterArguments args, int format, byte[] keyData, + int flags, KeyCharacteristics outCharacteristics) { + return importKey(alias, args, format, keyData, UID_SELF, flags, outCharacteristics); + } + + public ExportResult exportKey(String alias, int format, byte[] clientId, byte[] appId) { + try { + return mBinder.exportKey(alias, format, clientId, appId); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return null; + } + } + + public OperationResult begin(String alias, int purpose, boolean pruneable, + KeymasterArguments args, KeymasterArguments outArgs) { + try { + return mBinder.begin(getToken(), alias, purpose, pruneable, args, outArgs); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return null; + } + } + + public OperationResult update(IBinder token, KeymasterArguments arguments, byte[] input) { + try { + return mBinder.update(token, arguments, input); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return null; + } + } + + public OperationResult finish(IBinder token, KeymasterArguments arguments, byte[] signature) { + try { + return mBinder.finish(token, arguments, signature); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return null; + } + } + + public int abort(IBinder token) { + try { + return mBinder.abort(token); + } catch (RemoteException e) { + Log.w(TAG, "Cannot connect to keystore", e); + return SYSTEM_ERROR; + } + } } |