diff options
author | Alex Klyubin <klyubin@google.com> | 2015-04-02 21:06:27 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-04-02 21:06:28 +0000 |
commit | 3cc9e5d68d89ea1ffa79ad6981585bc46362c4a7 (patch) | |
tree | 21e20b6daf4d13db0b0236d1971cc063870dc899 /keystore/java/android/security | |
parent | 9635a56acfe3318d9ae5020727090a2dc8c118d0 (diff) | |
parent | a80eee052dd729c2898829fab42a5584d6f5eaf0 (diff) | |
download | frameworks_base-3cc9e5d68d89ea1ffa79ad6981585bc46362c4a7.zip frameworks_base-3cc9e5d68d89ea1ffa79ad6981585bc46362c4a7.tar.gz frameworks_base-3cc9e5d68d89ea1ffa79ad6981585bc46362c4a7.tar.bz2 |
Merge "Improve the AndroidKeyStore-backed HMAC state machine."
Diffstat (limited to 'keystore/java/android/security')
-rw-r--r-- | keystore/java/android/security/KeyStoreCipherSpi.java | 2 | ||||
-rw-r--r-- | keystore/java/android/security/KeyStoreHmacSpi.java | 26 |
2 files changed, 18 insertions, 10 deletions
diff --git a/keystore/java/android/security/KeyStoreCipherSpi.java b/keystore/java/android/security/KeyStoreCipherSpi.java index 5219086..afb5e36 100644 --- a/keystore/java/android/security/KeyStoreCipherSpi.java +++ b/keystore/java/android/security/KeyStoreCipherSpi.java @@ -264,8 +264,6 @@ public abstract class KeyStoreCipherSpi extends CipherSpi implements KeyStoreCry @Override protected int engineUpdate(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset) throws ShortBufferException { - ensureKeystoreOperationInitialized(); - byte[] outputCopy = engineUpdate(input, inputOffset, inputLen); if (outputCopy == null) { return 0; diff --git a/keystore/java/android/security/KeyStoreHmacSpi.java b/keystore/java/android/security/KeyStoreHmacSpi.java index 1297cc2..6d0e1ae 100644 --- a/keystore/java/android/security/KeyStoreHmacSpi.java +++ b/keystore/java/android/security/KeyStoreHmacSpi.java @@ -78,7 +78,11 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp } mKeyAliasInKeyStore = ((KeyStoreSecretKey) key).getAlias(); + if (mKeyAliasInKeyStore == null) { + throw new InvalidKeyException("Key's KeyStore alias not known"); + } engineReset(); + ensureKeystoreOperationInitialized(); } @Override @@ -90,8 +94,18 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp } mOperationHandle = null; mChunkedStreamer = null; + } + + private void ensureKeystoreOperationInitialized() { + if (mChunkedStreamer != null) { + return; + } + if (mKeyAliasInKeyStore == null) { + throw new IllegalStateException("Not initialized"); + } KeymasterArguments keymasterArgs = new KeymasterArguments(); + keymasterArgs.addInt(KeymasterDefs.KM_TAG_ALGORITHM, KeyStoreKeyConstraints.Algorithm.HMAC); keymasterArgs.addInt(KeymasterDefs.KM_TAG_DIGEST, mDigest); OperationResult opResult = mKeyStore.begin(mKeyAliasInKeyStore, @@ -105,10 +119,10 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp } else if (opResult.resultCode != KeyStore.NO_ERROR) { throw KeymasterUtils.getCryptoOperationException(opResult.resultCode); } - mOperationToken = opResult.token; - if (mOperationToken == null) { + if (opResult.token == null) { throw new CryptoOperationException("Keystore returned null operation token"); } + mOperationToken = opResult.token; mOperationHandle = opResult.operationHandle; mChunkedStreamer = new KeyStoreCryptoOperationChunkedStreamer( new KeyStoreCryptoOperationChunkedStreamer.MainDataStream( @@ -122,9 +136,7 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp @Override protected void engineUpdate(byte[] input, int offset, int len) { - if (mChunkedStreamer == null) { - throw new IllegalStateException("Not initialized"); - } + ensureKeystoreOperationInitialized(); byte[] output; try { @@ -139,9 +151,7 @@ public abstract class KeyStoreHmacSpi extends MacSpi implements KeyStoreCryptoOp @Override protected byte[] engineDoFinal() { - if (mChunkedStreamer == null) { - throw new IllegalStateException("Not initialized"); - } + ensureKeystoreOperationInitialized(); byte[] result; try { |