Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version gating to some tests #128

Merged
merged 1 commit into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
*.ipr
*.iws
*.iml
*.orig
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ method.
### Improvements
* Stricter guarantees about which curves are used for EC key generation. [PR #127](https://github.com/corretto/amazon-corretto-crypto-provider/pull/127)

### Patches
* Add version gating to some tests introduced in 1.5.0 [PR #128](https://github.com/corretto/amazon-corretto-crypto-provider/pull/128)

## 1.5.0
### Breaking Change Warning
In accordance with our [versioning policy](https://github.com/corretto/amazon-corretto-crypto-provider/blob/master/VERSIONING.rst),
Expand Down
4 changes: 4 additions & 0 deletions tst/com/amazon/corretto/crypto/provider/test/AesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ public void testBadAEADTagException() throws Throwable {

@Test
public void testBadAEADTagException_noRelease() throws Throwable {
assumeMinimumVersion("1.5.0", AmazonCorrettoCryptoProvider.INSTANCE);

final SecureRandom rnd = TestUtil.MISC_SECURE_RANDOM.get();

Cipher c = Cipher.getInstance(ALGO_NAME, PROVIDER_SUN);
Expand All @@ -664,6 +666,8 @@ public void testBadAEADTagException_noRelease() throws Throwable {

@Test
public void testBadAEADTagException_noReleaseByteBuffer() throws Throwable {
assumeMinimumVersion("1.5.0", AmazonCorrettoCryptoProvider.INSTANCE);

final SecureRandom rnd = TestUtil.MISC_SECURE_RANDOM.get();

Cipher c = Cipher.getInstance(ALGO_NAME, PROVIDER_SUN);
Expand Down
4 changes: 3 additions & 1 deletion tst/com/amazon/corretto/crypto/provider/test/HmacTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ public byte[] getEncoded() {
assertThrows(InvalidAlgorithmParameterException.class, () -> mac.init(validKey, new IvParameterSpec(new byte[0])));
assertThrows(InvalidKeyException.class, () -> mac.init(pubKey));
assertThrows(InvalidKeyException.class, () -> mac.init(badFormat));
assertThrows(InvalidKeyException.class, () -> mac.init(nullFormat));
assertThrows(InvalidKeyException.class, () -> mac.init(nullEncoding));

TestUtil.assumeMinimumVersion("1.5.0", AmazonCorrettoCryptoProvider.INSTANCE);
assertThrows(InvalidKeyException.class, () -> mac.init(nullFormat));
}
}

Expand Down
51 changes: 32 additions & 19 deletions tst/com/amazon/corretto/crypto/provider/test/RsaCipherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ public void jce2nativeNoPadding1024() throws GeneralSecurityException {
testJce2Native(NO_PADDING, 1024);
}

private void assertProperWrongInputSizeException(GeneralSecurityException ex) throws GeneralSecurityException {
// Behavior changed as of version 1.5.0 and sometimes we need tests to run
// against older versions.
if (TestUtil.versionCompare("1.5.0", NATIVE_PROVIDER) <= 0) {
if (!(ex instanceof IllegalBlockSizeException)) {
throw ex;
}
} else {
if (!(ex instanceof BadPaddingException)) {
throw ex;
}
}
}

@Test
public void noPaddingSizes() throws GeneralSecurityException {
final Cipher nativeEncrypt = Cipher.getInstance(NO_PADDING, NATIVE_PROVIDER);
Expand All @@ -146,8 +160,8 @@ public void noPaddingSizes() throws GeneralSecurityException {
try {
nativeEncrypt.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}

plaintext = new byte[1024 / 8];
Expand All @@ -165,8 +179,8 @@ public void noPaddingSizes() throws GeneralSecurityException {
try {
nativeEncrypt.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}

plaintext = new byte[2048 / 8];
Expand All @@ -184,8 +198,8 @@ public void noPaddingSizes() throws GeneralSecurityException {
try {
nativeEncrypt.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}

plaintext = new byte[4096 / 8];
Expand Down Expand Up @@ -355,18 +369,17 @@ public void Pkcs1PaddingSizes() throws GeneralSecurityException {
try {
nativeC.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}

nativeC.init(Cipher.ENCRYPT_MODE, PAIR_2048.getPublic());

plaintext = getPlaintext(2048 / 8 - 10);
try {
nativeC.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}

nativeC.init(Cipher.ENCRYPT_MODE, PAIR_4096.getPublic());
Expand All @@ -375,8 +388,8 @@ public void Pkcs1PaddingSizes() throws GeneralSecurityException {
try {
nativeC.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}
}

Expand Down Expand Up @@ -419,8 +432,8 @@ public void OaepSha1PaddingSizes() throws GeneralSecurityException {
try {
nativeC.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}

nativeC.init(Cipher.ENCRYPT_MODE, PAIR_2048.getPublic());
Expand All @@ -429,8 +442,8 @@ public void OaepSha1PaddingSizes() throws GeneralSecurityException {
try {
nativeC.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}

nativeC.init(Cipher.ENCRYPT_MODE, PAIR_4096.getPublic());
Expand All @@ -439,8 +452,8 @@ public void OaepSha1PaddingSizes() throws GeneralSecurityException {
try {
nativeC.doFinal(plaintext);
fail("Expected IllegalBlockSizeException");
} catch (final IllegalBlockSizeException ex) {
// expected
} catch (final GeneralSecurityException ex) {
assertProperWrongInputSizeException(ex);
}
}

Expand Down