Skip to content

Commit 793a9f2

Browse files
Karthikeyanminbi
authored andcommitted
[Core] Remove call to setKeySize in KeyProvider18 (#967)
1 parent 8149b96 commit 793a9f2

File tree

9 files changed

+163
-27
lines changed

9 files changed

+163
-27
lines changed

.circleci/config.yml

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,16 @@ commands:
182182
# This is required becaused AWSCore has a compileOnly
183183
# dependency on API Level 23.
184184
sudo yes | sdkmanager "platforms;android-23"
185+
setup_android_platform18:
186+
description: >-
187+
setup android platform 18
188+
steps:
189+
- run:
190+
name: download android platform 18
191+
command: |
192+
# This is required becaused AWSCore has a compileOnly
193+
# dependency on API Level 18.
194+
sudo yes | sdkmanager "platforms;android-18"
185195
skip_test_job:
186196
description: >-
187197
check if the test job can be skipped
@@ -288,6 +298,7 @@ jobs:
288298
- checkout
289299
- generate_gradle_wrapper
290300
- setup_android_platform23
301+
- setup_android_platform18
291302
- run:
292303
name: build the whole project
293304
command: |
@@ -334,7 +345,40 @@ jobs:
334345
- run:
335346
name: build the whole project
336347
command: |
337-
bash gradlew :aws-android-sdk-core:build -x test
348+
bash gradlew :aws-android-sdk-core:build -x test
349+
350+
build_api18:
351+
working_directory: ~/code
352+
docker:
353+
- image: circleci/android:api-27-alpha
354+
environment:
355+
JVM_OPTS: -Xmx3200m
356+
steps:
357+
- skip_job_if_required
358+
- checkout
359+
- generate_gradle_wrapper
360+
- run:
361+
name: download android-18
362+
command:
363+
sudo yes | sdkmanager "platforms;android-18"
364+
- run:
365+
name: install python3-pip
366+
command: |
367+
sudo apt-get update
368+
sudo apt-get -y install python3-pip
369+
- run:
370+
name: install json parser
371+
command: sudo pip3 install demjson
372+
- run:
373+
name: update code for API 18
374+
command: |
375+
python3 CircleciScripts/replace_android18.py "$(pwd)"
376+
rm aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/KeyProvider23.java
377+
cat aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java
378+
- run:
379+
name: build the whole project
380+
command: |
381+
export ANDROID_API_LEVEL=18; bash gradlew :aws-android-sdk-core:build -x test
338382
339383
unittest:
340384
working_directory: ~/code
@@ -350,6 +394,7 @@ jobs:
350394
- skip_test_job
351395
- generate_gradle_wrapper
352396
- setup_android_platform23
397+
- setup_android_platform18
353398
- run:
354399
name: run unit tests
355400
command: |
@@ -485,7 +530,7 @@ jobs:
485530
- run:
486531
name: Install Android build tools
487532
command: |
488-
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"
533+
sudo yes | /usr/local/bin/sdkmanager "platforms;android-18" "platforms;android-21" "platforms;android-23" "platforms;android-27" "build-tools;27.0.1" "extras;google;m2repository" "extras;android;m2repository"
489534
/usr/local/bin/sdkmanager --update
490535
- run:
491536
name: Install GPG
@@ -660,6 +705,7 @@ jobs:
660705
- skip_test_job
661706
- configure_aws
662707
- setup_android_platform23
708+
- setup_android_platform18
663709
- run:
664710
name: install python3-pip
665711
command: |
@@ -717,6 +763,7 @@ jobs:
717763
- skip_test_job
718764
- configure_aws
719765
- setup_android_platform23
766+
- setup_android_platform18
720767
- run:
721768
name: checkout sample applications
722769
command: |
@@ -1019,6 +1066,7 @@ jobs:
10191066
- skip_test_job
10201067
- configure_aws
10211068
- setup_android_platform23
1069+
- setup_android_platform18
10221070
- run:
10231071
name: install python3-pip
10241072
command: |
@@ -1150,7 +1198,11 @@ workflows:
11501198
- build_api10:
11511199
filters:
11521200
branches:
1153-
ignore: bump_sdk_version
1201+
ignore: bump_sdk_version
1202+
- build_api18:
1203+
filters:
1204+
branches:
1205+
ignore: bump_sdk_version
11541206
- unittest:
11551207
filters:
11561208
branches:
@@ -1466,6 +1518,7 @@ workflows:
14661518
- merge_to_master:
14671519
requires:
14681520
- build_api10
1521+
- build_api18
14691522
- build
14701523
- unittest
14711524
- post_integrationtest
@@ -1476,6 +1529,7 @@ workflows:
14761529
- prepare_release_sdk:
14771530
requires:
14781531
- build_api10
1532+
- build_api18
14791533
- build
14801534
- unittest
14811535
- post_integrationtest
@@ -1496,7 +1550,13 @@ workflows:
14961550
branches:
14971551
ignore: /.*/
14981552
tags:
1499-
only: /^(release|beta)_v[0-9]+.[0-9]+.[0-9]+$/
1553+
only: /^(release|beta)_v[0-9]+.[0-9]+.[0-9]+$/
1554+
- build_api18:
1555+
filters:
1556+
branches:
1557+
ignore: /.*/
1558+
tags:
1559+
only: /^(release|beta)_v[0-9]+.[0-9]+.[0-9]+$/
15001560
- unittest:
15011561
filters:
15021562
branches:
@@ -1809,6 +1869,7 @@ workflows:
18091869
- unittest
18101870
- post_integrationtest
18111871
- build_api10
1872+
- build_api18
18121873
filters:
18131874
branches:
18141875
ignore: /.*/

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Bug Fixes
66

7+
* **AWS Core Runtime**
8+
* Fixed a bug where generating RSA keys for encryption of the credentials failed due to `setKeySize(int)` method not available in Android API level 18. See [issue #964](https://github.com/aws-amplify/aws-sdk-android/issues/964) for details.
9+
710
* **Amazon Kinesis Video Streams**
811
* Removed trailing zeroes from encoder output that caused 0x3200000d errors when frames contained more than 3 trailing zeroes. See AnnexB sepcification.
912

CircleciScripts/replace_android10.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,10 @@
1212
"files" : [
1313
"aws-android-sdk-core/build.gradle"
1414
]
15-
} ,
16-
{
17-
"match" : 'android-23.jar',
18-
"replace" : 'android-10.jar',
19-
"files" : [
20-
"aws-android-sdk-core/build.gradle"
21-
]
22-
} ,
15+
}
2316
]
2417
replacefiles(root, replaces)
2518

26-
27-
28-
2919
AWSKeyValueStoreFile = os.path.join(root,"aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java")
3020
newcontent = ""
3121
with open(AWSKeyValueStoreFile, 'r') as myfile:
@@ -40,5 +30,3 @@
4030
newcontent = re.sub(pattern, repl, newcontent)
4131
with open(AWSKeyValueStoreFile,"w") as myfile:
4232
myfile.write(newcontent)
43-
44-
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from utils import replacefiles
2+
import demjson
3+
import sys
4+
import re
5+
import os
6+
root = sys.argv[1]
7+
8+
replaces = [
9+
{
10+
"match" : 'android-23',
11+
"replace" : 'android-18',
12+
"files" : [
13+
"aws-android-sdk-core/build.gradle"
14+
]
15+
}
16+
]
17+
replacefiles(root, replaces)
18+
19+
AWSKeyValueStoreFile = os.path.join(root,"aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/AWSKeyValueStore.java")
20+
newcontent = ""
21+
with open(AWSKeyValueStoreFile, 'r') as myfile:
22+
content = myfile.read()
23+
pattern = r'//@apiLevel23Start[\s\S]*?//@apiLevel23End'
24+
repl = r""
25+
newcontent = re.sub(pattern, repl, content)
26+
27+
with open(AWSKeyValueStoreFile,"w") as myfile:
28+
myfile.write(newcontent)

aws-android-sdk-core/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ dependencies {
2626
// The following command (is idempotent)
2727
// removes the libs folder, creates libs folder and
2828
// creates a symbolic link to android-23.jar.
29-
task myTask(type:Exec) {
29+
task getApi23(type:Exec) {
30+
print 'Creating a symlink for Android API Level 23.'
3031
workingDir '.'
3132
commandLine 'sh', '-c', "rm -rf libs && mkdir libs && ln -s $System.env.ANDROID_HOME/platforms/android-23/android.jar libs/android-23.jar"
3233
}
3334

34-
compileJava.dependsOn(myTask)
35+
36+
compileJava.dependsOn(getApi23)
3537

3638
sourceCompatibility = "1.7"
3739
targetCompatibility = "1.7"

aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/KeyProvider.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
* You may obtain a copy of the License at:
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11+
* OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
116
package com.amazonaws.internal.keyvaluestore;
217

318
import android.content.Context;

aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/KeyProvider10.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
* You may obtain a copy of the License at:
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11+
* OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
116
package com.amazonaws.internal.keyvaluestore;
217

318
import android.content.Context;

aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/KeyProvider18.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
* You may obtain a copy of the License at:
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11+
* OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
116
package com.amazonaws.internal.keyvaluestore;
217

318
import android.content.Context;
@@ -8,19 +23,14 @@
823
import com.amazonaws.logging.LogFactory;
924
import com.amazonaws.util.Base64;
1025

11-
import java.io.ByteArrayInputStream;
12-
import java.io.ByteArrayOutputStream;
1326
import java.math.BigInteger;
1427
import java.security.Key;
1528
import java.security.KeyPairGenerator;
1629
import java.security.KeyStore;
1730
import java.security.SecureRandom;
18-
import java.util.ArrayList;
1931
import java.util.Calendar;
2032

2133
import javax.crypto.Cipher;
22-
import javax.crypto.CipherInputStream;
23-
import javax.crypto.CipherOutputStream;
2434
import javax.crypto.KeyGenerator;
2535
import javax.crypto.SecretKey;
2636
import javax.crypto.spec.SecretKeySpec;
@@ -31,7 +41,8 @@
3141
* It generates a AES 256-bit symmetric key which is
3242
* used to encrypt the data. It also generates a master
3343
* key using RSA provided by AndroidKeyStore and uses
34-
* the RSA key to encrypt the AES key.
44+
* the RSA key to encrypt the AES key. The size of the
45+
* RSA key is 2048 bits by default.
3546
*
3647
* Once the AES key is encrypted with the RSA key, the
3748
* encrypted AES key is stored in SharedPreferences.
@@ -52,7 +63,6 @@ public class KeyProvider18 implements KeyProvider {
5263
static final String KEY_ALGORITHM_RSA = "RSA";
5364
static final String CIPHER_RSA_MODE = "RSA/ECB/PKCS1Padding";
5465
static final String CIPHER_PROVIDER_NAME_FOR_RSA = "AndroidOpenSSL";
55-
static final int RSA_KEY_SIZE = 2048;
5666

5767
static final String ENCRYPTED_AES_KEY = "AesGcmNoPadding18-encrypted-encryption-key";
5868

@@ -151,7 +161,6 @@ private void initializeRSAKeyFromKeyStore(Context context,
151161
.setSerialNumber(BigInteger.TEN)
152162
.setStartDate(start.getTime())
153163
.setEndDate(end.getTime())
154-
.setKeySize(RSA_KEY_SIZE)
155164
.build();
156165
KeyPairGenerator kpg = KeyPairGenerator.getInstance(
157166
KEY_ALGORITHM_RSA,

aws-android-sdk-core/src/main/java/com/amazonaws/internal/keyvaluestore/KeyProvider23.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
* You may obtain a copy of the License at:
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11+
* OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
116
package com.amazonaws.internal.keyvaluestore;
217

318
import android.content.Context;

0 commit comments

Comments
 (0)