Skip to content

Commit 967376e

Browse files
committed
added comment lines as per co pilot review
1 parent e641aa1 commit 967376e

File tree

1 file changed

+10
-1
lines changed
  • auth0/src/main/java/com/auth0/android/authentication/storage

1 file changed

+10
-1
lines changed

auth0/src/main/java/com/auth0/android/authentication/storage/CryptoUtil.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class CryptoUtil {
5454
// Transformations available since API 18
5555
// https://developer.android.com/training/articles/keystore.html#SupportedCiphers
5656
private static final String RSA_TRANSFORMATION = "RSA/ECB/OAEPWithSHA-256AndMGF1Padding";
57+
/**
58+
* !!! WARNING !!!
59+
* "RSA/ECB/PKCS1Padding" is deprecated due to vulnerabilities (see Bleichenbacher attacks, etc),
60+
* and should only be used here for *legacy key migration only*. All new data must use OAEP padding.
61+
* REMOVE SUPPORT FOR THIS AS SOON AS ALL DATA IS MIGRATED.
62+
*/
5763
private static final String OLD_PKCS1_RSA_TRANSFORMATION = "RSA/ECB/PKCS1Padding";
5864
// https://developer.android.com/reference/javax/crypto/Cipher.html
5965
@SuppressWarnings("SpellCheckingInspection")
@@ -404,7 +410,8 @@ byte[] getAESKey() throws IncompatibleDeviceException, CryptoException {
404410
}
405411

406412
if (rsaKey != null && keyAliasUsed != null) {
407-
// Decrypt using OLD PKCS1 padding
413+
// WARNING: Using PKCS1 padding here is intentional and ONLY for decrypting legacy data
414+
// Do NOT use PKCS1 padding for encryption in new code; always use OAEP padding instead.
408415
Cipher rsaPkcs1Cipher = Cipher.getInstance(OLD_PKCS1_RSA_TRANSFORMATION);
409416
rsaPkcs1Cipher.init(Cipher.DECRYPT_MODE, rsaKey.getPrivateKey());
410417
byte[] decryptedAESKey = rsaPkcs1Cipher.doFinal(encryptedAESBytes);
@@ -443,6 +450,8 @@ byte[] getAESKey() throws IncompatibleDeviceException, CryptoException {
443450
try {
444451
byte[] encryptedOldAESBytes = Base64.decode(encodedOldAES, Base64.DEFAULT);
445452
KeyStore.PrivateKeyEntry rsaKeyEntry = getRSAKeyEntry();
453+
// WARNING: Using PKCS1 padding here is intentional and ONLY for decrypting legacy data
454+
// Do NOT use PKCS1 padding for encryption in new code; always use OAEP padding instead.
446455
Cipher rsaPkcs1Cipher = Cipher.getInstance(OLD_PKCS1_RSA_TRANSFORMATION);
447456
rsaPkcs1Cipher.init(Cipher.DECRYPT_MODE, rsaKeyEntry.getPrivateKey());
448457
byte[] decryptedAESKey = rsaPkcs1Cipher.doFinal(encryptedOldAESBytes);

0 commit comments

Comments
 (0)