diff options
author | Alex Klyubin <klyubin@google.com> | 2015-04-13 10:54:53 -0700 |
---|---|---|
committer | Alex Klyubin <klyubin@google.com> | 2015-04-13 10:54:53 -0700 |
commit | fbf1472d613572d991bc9d68ded4c9e937f13586 (patch) | |
tree | c401bc8005739b23f27f108274ba03b8b714069b /keystore/java/android/security/KeyStoreParameter.java | |
parent | 62d1d9efe72752fd00c791f596163856708beac2 (diff) | |
parent | a978a3d6e9586af8cc7191cde83dcf2742ea5269 (diff) |
resolved conflicts for merge of a978a3d6 to master
Change-Id: Ifd7ca9e1dfa0d50a87f2bafef377fcaeb5d9f6d5
Diffstat (limited to 'keystore/java/android/security/KeyStoreParameter.java')
-rw-r--r-- | keystore/java/android/security/KeyStoreParameter.java | 139 |
1 files changed, 86 insertions, 53 deletions
diff --git a/keystore/java/android/security/KeyStoreParameter.java b/keystore/java/android/security/KeyStoreParameter.java index 751eef5b42e8..a04bc6c882a3 100644 --- a/keystore/java/android/security/KeyStoreParameter.java +++ b/keystore/java/android/security/KeyStoreParameter.java @@ -43,12 +43,13 @@ public final class KeyStoreParameter implements ProtectionParameter { private final Date mKeyValidityStart; private final Date mKeyValidityForOriginationEnd; private final Date mKeyValidityForConsumptionEnd; - private final @KeyStoreKeyConstraints.PurposeEnum int mPurposes; - private final @KeyStoreKeyConstraints.PaddingEnum int mPaddings; - private final @KeyStoreKeyConstraints.DigestEnum Integer mDigests; - private final @KeyStoreKeyConstraints.BlockModeEnum int mBlockModes; + private final @KeyStoreKeyProperties.PurposeEnum int mPurposes; + private final String[] mEncryptionPaddings; + private final String[] mSignaturePaddings; + private final String[] mDigests; + private final String[] mBlockModes; private final boolean mRandomizedEncryptionRequired; - private final @KeyStoreKeyConstraints.UserAuthenticatorEnum int mUserAuthenticators; + private final @KeyStoreKeyProperties.UserAuthenticatorEnum int mUserAuthenticators; private final int mUserAuthenticationValidityDurationSeconds; private final boolean mInvalidatedOnNewFingerprintEnrolled; @@ -56,12 +57,13 @@ public final class KeyStoreParameter implements ProtectionParameter { Date keyValidityStart, Date keyValidityForOriginationEnd, Date keyValidityForConsumptionEnd, - @KeyStoreKeyConstraints.PurposeEnum int purposes, - @KeyStoreKeyConstraints.PaddingEnum int paddings, - @KeyStoreKeyConstraints.DigestEnum Integer digests, - @KeyStoreKeyConstraints.BlockModeEnum int blockModes, + @KeyStoreKeyProperties.PurposeEnum int purposes, + String[] encryptionPaddings, + String[] signaturePaddings, + String[] digests, + String[] blockModes, boolean randomizedEncryptionRequired, - @KeyStoreKeyConstraints.UserAuthenticatorEnum int userAuthenticators, + @KeyStoreKeyProperties.UserAuthenticatorEnum int userAuthenticators, int userAuthenticationValidityDurationSeconds, boolean invalidatedOnNewFingerprintEnrolled) { if ((userAuthenticationValidityDurationSeconds < 0) @@ -75,9 +77,12 @@ public final class KeyStoreParameter implements ProtectionParameter { mKeyValidityForOriginationEnd = keyValidityForOriginationEnd; mKeyValidityForConsumptionEnd = keyValidityForConsumptionEnd; mPurposes = purposes; - mPaddings = paddings; - mDigests = digests; - mBlockModes = blockModes; + mEncryptionPaddings = + ArrayUtils.cloneIfNotEmpty(ArrayUtils.nullToEmpty(encryptionPaddings)); + mSignaturePaddings = + ArrayUtils.cloneIfNotEmpty(ArrayUtils.nullToEmpty(signaturePaddings)); + mDigests = ArrayUtils.cloneIfNotEmpty(digests); + mBlockModes = ArrayUtils.cloneIfNotEmpty(ArrayUtils.nullToEmpty(blockModes)); mRandomizedEncryptionRequired = randomizedEncryptionRequired; mUserAuthenticators = userAuthenticators; mUserAuthenticationValidityDurationSeconds = userAuthenticationValidityDurationSeconds; @@ -136,37 +141,48 @@ public final class KeyStoreParameter implements ProtectionParameter { * * @hide */ - public @KeyStoreKeyConstraints.PurposeEnum int getPurposes() { + public @KeyStoreKeyProperties.PurposeEnum int getPurposes() { return mPurposes; } /** - * Gets the set of padding schemes to which the key is restricted. + * Gets the set of padding schemes with which the key can be used when encrypting/decrypting. * * @hide */ - public @KeyStoreKeyConstraints.PaddingEnum int getPaddings() { - return mPaddings; + public String[] getEncryptionPaddings() { + return ArrayUtils.cloneIfNotEmpty(mEncryptionPaddings); } /** - * Gets the set of digests to which the key is restricted. + * Gets the set of padding schemes with which the key can be used when signing or verifying + * signatures. * - * @throws IllegalStateException if this restriction has not been specified. + * @hide + */ + public String[] getSignaturePaddings() { + return ArrayUtils.cloneIfNotEmpty(mSignaturePaddings); + } + + /** + * Gets the set of digest algorithms with which the key can be used. + * + * @throws IllegalStateException if this set has not been specified. * * @see #isDigestsSpecified() * * @hide */ - public @KeyStoreKeyConstraints.DigestEnum int getDigests() { + public String[] getDigests() { if (mDigests == null) { throw new IllegalStateException("Digests not specified"); } - return mDigests; + return ArrayUtils.cloneIfNotEmpty(mDigests); } /** - * Returns {@code true} if digest restrictions have been specified. + * Returns {@code true} if the set of digest algorithms with which the key can be used has been + * specified. * * @see #getDigests() * @@ -177,12 +193,12 @@ public final class KeyStoreParameter implements ProtectionParameter { } /** - * Gets the set of block modes to which the key is restricted. + * Gets the set of block modes with which the key can be used. * * @hide */ - public @KeyStoreKeyConstraints.BlockModeEnum int getBlockModes() { - return mBlockModes; + public String[] getBlockModes() { + return ArrayUtils.cloneIfNotEmpty(mBlockModes); } /** @@ -208,7 +224,7 @@ public final class KeyStoreParameter implements ProtectionParameter { * * @hide */ - public @KeyStoreKeyConstraints.UserAuthenticatorEnum int getUserAuthenticators() { + public @KeyStoreKeyProperties.UserAuthenticatorEnum int getUserAuthenticators() { return mUserAuthenticators; } @@ -260,12 +276,13 @@ public final class KeyStoreParameter implements ProtectionParameter { private Date mKeyValidityStart; private Date mKeyValidityForOriginationEnd; private Date mKeyValidityForConsumptionEnd; - private @KeyStoreKeyConstraints.PurposeEnum int mPurposes; - private @KeyStoreKeyConstraints.PaddingEnum int mPaddings; - private @KeyStoreKeyConstraints.DigestEnum Integer mDigests; - private @KeyStoreKeyConstraints.BlockModeEnum int mBlockModes; + private @KeyStoreKeyProperties.PurposeEnum int mPurposes; + private String[] mEncryptionPaddings; + private String[] mSignaturePaddings; + private String[] mDigests; + private String[] mBlockModes; private boolean mRandomizedEncryptionRequired = true; - private @KeyStoreKeyConstraints.UserAuthenticatorEnum int mUserAuthenticators; + private @KeyStoreKeyProperties.UserAuthenticatorEnum int mUserAuthenticators; private int mUserAuthenticationValidityDurationSeconds = -1; private boolean mInvalidatedOnNewFingerprintEnrolled; @@ -359,55 +376,70 @@ public final class KeyStoreParameter implements ProtectionParameter { } /** - * Restricts the key to being used only for the provided set of purposes. + * Sets the set of purposes for which the key can be used. * - * <p>This restriction must be specified. There is no default. + * <p>This must be specified for all keys. There is no default. * * @hide */ - public Builder setPurposes(@KeyStoreKeyConstraints.PurposeEnum int purposes) { + public Builder setPurposes(@KeyStoreKeyProperties.PurposeEnum int purposes) { mPurposes = purposes; return this; } /** - * Restricts the key to being used only with the provided padding schemes. Attempts to use - * the key with any other padding will be rejected. + * Sets the set of padding schemes with which the key can be used when + * encrypting/decrypting. Attempts to use the key with any other padding scheme will be + * rejected. * - * <p>This restriction must be specified for keys which are used for encryption/decryption. + * <p>This must be specified for keys which are used for encryption/decryption. * * @hide */ - public Builder setPaddings(@KeyStoreKeyConstraints.PaddingEnum int paddings) { - mPaddings = paddings; + public Builder setEncryptionPaddings(String... paddings) { + mEncryptionPaddings = ArrayUtils.cloneIfNotEmpty(paddings); return this; } /** - * Restricts the key to being used only with the provided digests when generating signatures - * or HMACs. Attempts to use the key with any other digest will be rejected. + * Sets the set of padding schemes with which the key can be used when + * signing/verifying. Attempts to use the key with any other padding scheme will be + * rejected. + * + * <p>This must be specified for RSA keys which are used for signing/verification. + * + * @hide + */ + public Builder setSignaturePaddings(String... paddings) { + mSignaturePaddings = ArrayUtils.cloneIfNotEmpty(paddings); + return this; + } + + + /** + * Sets the set of digests with which the key can be used when signing/verifying or + * generating MACs. Attempts to use the key with any other digest will be rejected. * - * <p>For HMAC keys, the default is to restrict to the digest specified in - * {@link Key#getAlgorithm()}. For asymmetric signing keys this constraint must be specified - * because there is no default. + * <p>For HMAC keys, the default is the digest specified in {@link Key#getAlgorithm()}. For + * asymmetric signing keys this constraint must be specified. * * @hide */ - public Builder setDigests(@KeyStoreKeyConstraints.DigestEnum int digests) { - mDigests = digests; + public Builder setDigests(String... digests) { + mDigests = ArrayUtils.cloneIfNotEmpty(digests); return this; } /** - * Restricts the key to being used only with the provided block modes. Attempts to use the - * key with any other block modes will be rejected. + * Sets the set of block modes with which the key can be used when encrypting/decrypting. + * Attempts to use the key with any other block modes will be rejected. * - * <p>This restriction must be specified for symmetric encryption/decryption keys. + * <p>This must be specified for encryption/decryption keys. * * @hide */ - public Builder setBlockModes(@KeyStoreKeyConstraints.BlockModeEnum int blockModes) { - mBlockModes = blockModes; + public Builder setBlockModes(String... blockModes) { + mBlockModes = ArrayUtils.cloneIfNotEmpty(blockModes); return this; } @@ -466,7 +498,7 @@ public final class KeyStoreParameter implements ProtectionParameter { * @hide */ public Builder setUserAuthenticators( - @KeyStoreKeyConstraints.UserAuthenticatorEnum int userAuthenticators) { + @KeyStoreKeyProperties.UserAuthenticatorEnum int userAuthenticators) { mUserAuthenticators = userAuthenticators; return this; } @@ -517,7 +549,8 @@ public final class KeyStoreParameter implements ProtectionParameter { mKeyValidityForOriginationEnd, mKeyValidityForConsumptionEnd, mPurposes, - mPaddings, + mEncryptionPaddings, + mSignaturePaddings, mDigests, mBlockModes, mRandomizedEncryptionRequired, |