Skip to content

Commit 1f41eb3

Browse files
authored
fix: replace sha1prng secure random with recommended algorithm (#3314)
1 parent 79e42d1 commit 1f41eb3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

aws-android-sdk-cognitoidentityprovider/src/main/java/com/amazonaws/mobileconnectors/cognitoidentityprovider/CognitoUser.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.amazonaws.mobileconnectors.cognitoidentityprovider;
1919

2020
import android.content.Context;
21+
import android.os.Build;
2122
import android.os.Handler;
2223
import android.os.Looper;
2324

@@ -4040,7 +4041,11 @@ protected MessageDigest initialValue() {
40404041

40414042
static {
40424043
try {
4043-
SECURE_RANDOM = SecureRandom.getInstance("SHA1PRNG");
4044+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
4045+
SECURE_RANDOM = SecureRandom.getInstanceStrong();
4046+
} else {
4047+
SECURE_RANDOM = new SecureRandom();
4048+
}
40444049

40454050
final MessageDigest messageDigest = THREAD_MESSAGE_DIGEST.get();
40464051
messageDigest.reset();

aws-android-sdk-cognitoidentityprovider/src/main/java/com/amazonaws/mobileconnectors/cognitoidentityprovider/util/CognitoDeviceHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,11 @@ protected MessageDigest initialValue() {
334334

335335
static {
336336
try {
337-
SECURE_RANDOM = SecureRandom.getInstance("SHA1PRNG");
337+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
338+
SECURE_RANDOM = SecureRandom.getInstanceStrong();
339+
} else {
340+
SECURE_RANDOM = new SecureRandom();
341+
}
338342
} catch (final NoSuchAlgorithmException e) {
339343
throw new ExceptionInInitializerError(e);
340344
}
@@ -360,7 +364,7 @@ public BigInteger getVerifier() {
360364
/**
361365
* Helps to start the SRP validation of the device.
362366
* @param deviceGroupKey REQUIRED: Group assigned to the device.
363-
* @param deviceKey REQUIRED: Unique identifier assigned to the device.
367+
* @param deviceKey REQUIRED: Unique identifier assigned to the device.
364368
* @param password REQUIRED: The device password.
365369
*/
366370
public deviceSRP(String deviceGroupKey, String deviceKey, String password) {

0 commit comments

Comments
 (0)