Skip to content

Commit 522cb5f

Browse files
author
Karthikeyan
authored
Secure information stored in SharedPreferences (#771)
* 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
1 parent 92f0048 commit 522cb5f

File tree

57 files changed

+6434
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+6434
-200
lines changed

.circleci/config.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,16 @@ commands:
153153
echo "title:$title"
154154
echo "content:$content"
155155
python3 ../CircleciScripts/create_pullrequest.py "${GITHUB_BUMPVERSION_USER}" "${GITHUB_BUMPVERSION_TOKEN}" "$title" "$content" "master" "${GITHUB_BUMPVERSION_USER}:bump_version" ${bumpversion_repo_user} ${bumpversion_repo_name}
156-
156+
setup_android_platform23:
157+
description: >-
158+
setup android platform 23
159+
steps:
160+
- run:
161+
name: download android platform 23
162+
command: |
163+
# This is required becaused AWSCore has a compileOnly
164+
# dependency on API Level 23.
165+
sudo yes | sdkmanager "platforms;android-23"
157166
158167
jobs:
159168
build:
@@ -165,6 +174,7 @@ jobs:
165174
steps:
166175
- checkout
167176
- generate_gradle_wrapper
177+
- setup_android_platform23
168178
- run:
169179
name: build the whole project
170180
command: |
@@ -188,6 +198,7 @@ jobs:
188198
steps:
189199
- checkout
190200
- generate_gradle_wrapper
201+
- setup_android_platform23
191202
- run:
192203
name: run unit tests
193204
command: |
@@ -320,7 +331,7 @@ jobs:
320331
- run:
321332
name: Install Android build tools
322333
command: |
323-
sudo yes | /usr/local/bin/sdkmanager "platforms;android-21" "platforms;android-27" "build-tools;27.0.1" "extras;google;m2repository" "extras;android;m2repository"
334+
sudo yes | /usr/local/bin/sdkmanager "platforms;android-21" "platforms;android-23" "platforms;android-27" "build-tools;27.0.1" "extras;google;m2repository" "extras;android;m2repository"
324335
/usr/local/bin/sdkmanager --update
325336
- run:
326337
name: Install GPG
@@ -438,6 +449,7 @@ jobs:
438449
steps:
439450
- checkout
440451
- configure_aws
452+
- setup_android_platform23
441453
- run:
442454
name: install python3-pip
443455
command: |
@@ -487,6 +499,7 @@ jobs:
487499
steps:
488500
- checkout
489501
- configure_aws
502+
- setup_android_platform23
490503
- run:
491504
name: checkout sample applications
492505
command: |

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ __pycache__/
7676
# Credentials
7777
**/testconfiguration.json
7878
**/awsconfiguration.json
79+
80+
# AWSCoreRuntime libs
81+
aws-android-sdk-core/libs

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Change Log - AWS SDK for Android
22

3+
## [Release 2.12.3](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.12.3)
4+
5+
### Enhancements
6+
7+
* **AWS Core**
8+
* The `SharedPreferences` used by `CognitoCachingCredentialsProvider` is now encrypted.
9+
* Added a method `CognitoCachingCredentialsProvider.setPersistenceEnabled(boolean)`, which is enabled (set to true) by default therefore the information is persisted in SharedPreferences. When disabled (set to false), the information will only be kept in memory.
10+
11+
* **Amazon CognitoIdentityProvider**
12+
* The `SharedPreferences` used by `CognitoUserPool` is now encrypted.
13+
* Added a method `CognitoUserPool.setPersistenceEnabled(boolean)`, which is enabled (set to true) by default therefore the information is persisted in SharedPreferences. When disabled (set to false), the information will only be kept in memory.
14+
15+
* **Amazon CognitoAuth**
16+
* The `SharedPreferences` used by `Auth` is now encrypted.
17+
* Added a method `Auth.setPersistenceEnabled(boolean)`, which is enabled (set to true) by default therefore the information is persisted in SharedPreferences. When disabled (set to false), the information will only be kept in memory.
18+
19+
* **AWSMobileClient**
20+
* The `SharedPreferences` used by `AWSMobileClient` is now encrypted.
21+
322
## [Release 2.12.2](https://github.com/aws/aws-sdk-android/releases/tag/release_v2.12.2)
423

524
### Misc. Updates

CircleciScripts/run_integrationtest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
root = sys.argv[2]
77
credentials = sys.argv[3]
88

9-
testmodules = ["aws-android-sdk-apigateway-test",
9+
testmodules = ["aws-android-sdk-core-test",
10+
"aws-android-sdk-apigateway-test",
1011
"aws-android-sdk-autoscaling-test",
12+
"aws-android-sdk-cognitoidentityprovider-test",
13+
"aws-android-sdk-cognitoauth",
1114
"aws-android-sdk-cloudwatch-test",
1215
"aws-android-sdk-elb-test",
1316
"aws-android-sdk-ddb-test",

aws-android-sdk-auth-core/src/main/java/com/amazonaws/mobile/auth/core/IdentityManager.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import android.app.Activity;
2121
import android.content.Context;
22-
import android.content.Intent;
2322
import android.util.Log;
2423

2524
import com.amazonaws.ClientConfiguration;
@@ -30,6 +29,7 @@
3029
import com.amazonaws.auth.AWSCredentialsProvider;
3130
import com.amazonaws.auth.CognitoCachingCredentialsProvider;
3231

32+
import com.amazonaws.internal.keyvaluestore.AWSKeyValueStore;
3333
import com.amazonaws.mobile.auth.core.signin.AuthException;
3434
import com.amazonaws.mobile.auth.core.signin.CognitoAuthException;
3535
import com.amazonaws.mobile.auth.core.signin.ProviderAuthException;
@@ -42,9 +42,6 @@
4242
import com.amazonaws.regions.Region;
4343
import com.amazonaws.regions.Regions;
4444

45-
import java.io.IOException;
46-
import java.lang.reflect.Method;
47-
import java.util.Arrays;
4845
import java.util.Collection;
4946
import java.util.Date;
5047
import java.util.HashMap;
@@ -56,7 +53,6 @@
5653
import java.util.concurrent.ExecutorService;
5754
import java.util.concurrent.Executors;
5855

59-
import org.json.JSONArray;
6056
import org.json.JSONException;
6157
import org.json.JSONObject;
6258

@@ -157,6 +153,19 @@ private void setUnderlyingProvider(final CognitoCachingCredentialsProvider under
157153
*/
158154
private static final String EXPIRATION_KEY = "expirationDate";
159155

156+
/**
157+
* Instance of AWSKeyValueStorageUtility that provides access
158+
* to secure storage of credentials in SharedPreferences.
159+
*/
160+
private AWSKeyValueStore awsKeyValueStore;
161+
162+
/**
163+
* Flag if true indicates that secure storage is used to
164+
* access information. Flag if false keeps the information
165+
* in memory.
166+
*/
167+
private boolean isPersistenceEnabled = true;
168+
160169
boolean shouldFederate = true;
161170

162171
/**
@@ -199,6 +208,7 @@ public IdentityManager(final Context context) {
199208
this.awsConfiguration = null;
200209
this.clientConfiguration = null;
201210
this.credentialsProviderHolder = null;
211+
this.awsKeyValueStore = new AWSKeyValueStore(appContext, SHARED_PREF_NAME, isPersistenceEnabled);
202212
}
203213

204214
/**
@@ -216,6 +226,7 @@ public IdentityManager(final Context context,
216226
this.clientConfiguration = new ClientConfiguration().withUserAgent(awsConfiguration.getUserAgent());
217227
this.credentialsProviderHolder = new AWSCredentialsProviderHolder();
218228
createCredentialsProvider(this.appContext, this.clientConfiguration);
229+
this.awsKeyValueStore = new AWSKeyValueStore(appContext, SHARED_PREF_NAME, isPersistenceEnabled);
219230
}
220231

221232
/**
@@ -245,6 +256,7 @@ public IdentityManager(final Context context,
245256

246257
this.credentialsProviderHolder = new AWSCredentialsProviderHolder();
247258
createCredentialsProvider(this.appContext, this.clientConfiguration);
259+
this.awsKeyValueStore = new AWSKeyValueStore(appContext, SHARED_PREF_NAME, isPersistenceEnabled);
248260
}
249261

250262
/**
@@ -260,8 +272,24 @@ public IdentityManager(final Context context,
260272
this.clientConfiguration = clientConfiguration;
261273
this.credentialsProviderHolder = new AWSCredentialsProviderHolder();
262274
credentialsProviderHolder.setUnderlyingProvider(credentialsProvider);
275+
this.awsKeyValueStore = new AWSKeyValueStore(appContext, SHARED_PREF_NAME, isPersistenceEnabled);
263276
}
264277

278+
/**
279+
* Set the flag that indicates if persistence is enabled or not.
280+
* @param persistenceEnabled the flag that indicates if persistence is enabled or not.
281+
*/
282+
public void setPersistenceEnabled(boolean persistenceEnabled) {
283+
isPersistenceEnabled = persistenceEnabled;
284+
this.awsKeyValueStore.setPersistenceEnabled(isPersistenceEnabled);
285+
}
286+
287+
/**
288+
* Set the flag that indicates if tokens will be
289+
* federated into Cognito Identity pool
290+
* @param enabled Flag that indicates if tokens will
291+
* be federated into Cognito Identity pool
292+
*/
265293
public void enableFederation(final boolean enabled) {
266294
shouldFederate = enabled;
267295
}
@@ -544,11 +572,8 @@ private void refreshCredentialWithLogins(final Map<String, String> loginMap) {
544572
credentialsProvider.refresh();
545573

546574
// Set the expiration key of the Credentials Provider to 8 minutes, 30 seconds.
547-
appContext.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE)
548-
.edit()
549-
.putLong(credentialsProvider.getIdentityPoolId() + "." + EXPIRATION_KEY,
550-
System.currentTimeMillis() + (510 * 1000))
551-
.apply();
575+
awsKeyValueStore.put(credentialsProvider.getIdentityPoolId() + "." + EXPIRATION_KEY,
576+
String.valueOf(System.currentTimeMillis() + (510 * 1000)));
552577
}
553578

554579
/**
@@ -904,9 +929,10 @@ private void createCredentialsProvider(final Context context,
904929
new AWSRefreshingCognitoIdentityProvider(null, poolId,
905930
clientConfiguration, cognitoIdentityRegion);
906931

907-
credentialsProviderHolder.setUnderlyingProvider(
908-
new CognitoCachingCredentialsProvider(context, refreshingCredentialsProvider,
909-
cognitoIdentityRegion, clientConfiguration));
932+
final CognitoCachingCredentialsProvider cognitoCachingCredentialsProvider = new CognitoCachingCredentialsProvider(context, refreshingCredentialsProvider,
933+
cognitoIdentityRegion, clientConfiguration);
934+
cognitoCachingCredentialsProvider.setPersistenceEnabled(isPersistenceEnabled);
935+
credentialsProviderHolder.setUnderlyingProvider(cognitoCachingCredentialsProvider);
910936
}
911937

912938
/**

aws-android-sdk-cognitoauth/build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apply plugin: 'com.android.library'
2+
apply plugin: 'devicefarm'
23

34
android {
45
compileSdkVersion 27
@@ -31,9 +32,28 @@ dependencies {
3132

3233
implementation "com.amazonaws:aws-android-sdk-cognitoidentityprovider-asf:1.0.0"
3334
implementation "com.android.support:customtabs:25.4.0"
35+
api (project(':aws-android-sdk-core')) {
36+
exclude group: "com.google.android", module: "android"
37+
}
3438

3539
testImplementation 'junit:junit:4.12'
3640

3741
androidTestImplementation 'com.android.support.test:runner:1.0.2'
3842
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
43+
androidTestImplementation project(':aws-android-sdk-testutils')
44+
}
45+
46+
devicefarm {
47+
48+
// Required. The Project must already exist. You can create a project in the AWS console.
49+
projectName "AWSAndroidKeyStoreTester"
50+
51+
// Required. You must specify either accessKey and secretKey OR roleArn. roleArn takes precedence.
52+
authentication {
53+
accessKey "$System.env.DEVICEFARM_ACCESS_KEY"
54+
secretKey "$System.env.DEVICEFARM_SECRET_KEY"
55+
}
56+
57+
devicePool "AWSAndroidKeyStoreTesterPool"
3958
}
59+

aws-android-sdk-cognitoauth/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
<optional>false</optional>
5050
<version>1.0.0</version>
5151
</dependency>
52+
<dependency>
53+
<groupId>com.amazonaws</groupId>
54+
<artifactId>aws-android-sdk-core</artifactId>
55+
<optional>false</optional>
56+
<version>2.12.2</version>
57+
</dependency>
5258
<dependency>
5359
<groupId>com.android.support</groupId>
5460
<artifactId>customtabs</artifactId>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2019-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amazonaws.mobileconnectors.cognitoauth;
17+
18+
import com.amazonaws.testutils.AWSTestBase;
19+
20+
import org.json.JSONObject;
21+
22+
public abstract class CognitoAuthIntegrationTestBase extends AWSTestBase {
23+
public static JSONObject getPackageConfigure() {
24+
return getPackageConfigure("cognitoauth");
25+
}
26+
}

0 commit comments

Comments
 (0)