Skip to content

Commit 7784bf9

Browse files
committed
Added new test case for corner case of iv length
1 parent b5cda34 commit 7784bf9

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ public byte[] decrypt(byte[] encryptedInput) throws CryptoException, Incompatibl
469469
* @param encryptedInput the encrypted data to check
470470
* @return true if new format, false if legacy format
471471
*/
472-
@VisibleForTesting
473-
private boolean isNewFormat(byte[] encryptedInput) {
472+
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
473+
boolean isNewFormat(byte[] encryptedInput) {
474474

475475
// Boundary check
476476
if (encryptedInput == null || encryptedInput.length < 2) {

auth0/src/test/java/com/auth0/android/authentication/storage/CryptoUtilTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,34 @@ public void shouldVerifyMinimumLengthRequirements() {
12451245
assertThat(cryptoUtil.isNewFormat(tooShort16), is(false));
12461246
}
12471247

1248+
@Test
1249+
public void shouldRejectInvalidIVLengthsInNewFormat() {
1250+
byte[] ivLength0 = new byte[19];
1251+
ivLength0[0] = 0x01;
1252+
ivLength0[1] = 0;
1253+
assertThat(cryptoUtil.isNewFormat(ivLength0), is(false));
1254+
1255+
byte[] ivLength13 = new byte[32];
1256+
ivLength13[0] = 0x01;
1257+
ivLength13[1] = 13;
1258+
assertThat(cryptoUtil.isNewFormat(ivLength13), is(false));
1259+
1260+
byte[] ivLength14 = new byte[33];
1261+
ivLength14[0] = 0x01;
1262+
ivLength14[1] = 14;
1263+
assertThat(cryptoUtil.isNewFormat(ivLength14), is(false));
1264+
1265+
byte[] ivLength15 = new byte[34];
1266+
ivLength15[0] = 0x01;
1267+
ivLength15[1] = 15;
1268+
assertThat(cryptoUtil.isNewFormat(ivLength15), is(false));
1269+
1270+
byte[] ivLength255 = new byte[274];
1271+
ivLength255[0] = 0x01;
1272+
ivLength255[1] = (byte) 255;
1273+
assertThat(cryptoUtil.isNewFormat(ivLength255), is(false));
1274+
}
1275+
12481276
/*
12491277
* MIGRATION SCENARIO tests - Testing backward compatibility and format coexistence
12501278
*/

0 commit comments

Comments
 (0)