From 50311c38f9bd3d85a84e41ab7c32164ea100bd07 Mon Sep 17 00:00:00 2001 From: Karthikeyan Date: Wed, 13 Mar 2019 14:40:29 -0700 Subject: [PATCH] Annotate code specific to API Level 23 and above in AWSKeyValueStore (#786) * Secure information stored in SharedPreferences * Lower aws-android-sdk-core-test compile and target sdk version to 27 * Add a symlink to android-23.jar for core * Add a gradle task that creates a symlink to android-23.jar for AWS Core * Fix the gradle task that creates symbolic link to android-23.jar * Change config.yml to setup android-23 * Enable core, cognitoidentityprovider and cognitoauth integration tests on CircleCI * Enable core, cognitoidentityprovider and cognitoauth integration tests on CircleCI * Fix pom.xml * Improve exception handling in AWSKeyValueStore * [2.12.3] Bump the patch version of 2.12.z * Update 2.12.3 CHANGELOG * Add the missing bucket prefixes to CleanupBucketIntegrationTests * Fix a bug where migrating expirationDate in CognitoCachingCredentialsProvider crashes * [2.12.4] Update changelog and bump version * Annotate code specific to API Level 23 and above in AWSKeyValueStore --- .../internal/keyvaluestore/AWSKeyValueStore.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java b/aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java index 98808baf54..941d7a75c2 100644 --- a/aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java +++ b/aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java @@ -196,9 +196,11 @@ public synchronized String get(String key) { // Read from store -> Base64 decode -> decrypt -> convert to string final String encryptedData = sharedPreferences.getString(actualKey, null); byte[] iv = getInitializationVector(actualKey); - String decryptedDataInString = decrypt(apiLevel >= ANDROID_API_LEVEL_23 - ? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv) - : new IvParameterSpec(iv), encryptedData); + String decryptedDataInString = decrypt( + //@apiLevel23Start + apiLevel >= ANDROID_API_LEVEL_23 ? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv) : + //@apiLevel23End + new IvParameterSpec(iv), encryptedData); cache.put(key, decryptedDataInString); return decryptedDataInString; } catch (Exception ex) { @@ -233,9 +235,11 @@ public void put(String key, String value) { try { // Encrypt byte[] iv = generateInitializationVector(); - String encryptedData = encrypt(apiLevel >= ANDROID_API_LEVEL_23 - ? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv) - : new IvParameterSpec(iv), value); + String encryptedData = encrypt( + //@apiLevel23Start + apiLevel >= ANDROID_API_LEVEL_23 ? new GCMParameterSpec(CIPHER_AES_GCM_NOPADDING_TAG_LENGTH_LENGTH_IN_BITS, iv) : + //@apiLevel23End + new IvParameterSpec(iv), value); // Persist sharedPreferences