Skip to content

Commit

Permalink
Java 17 workarounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
prbprbprb committed Oct 12, 2024
1 parent ae92c50 commit fd38829
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions common/src/test/java/org/conscrypt/javax/crypto/CipherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.ProviderException;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
Expand Down Expand Up @@ -3907,6 +3908,14 @@ private void checkCipher(CipherTestParam p, String provider) throws Exception {
if (!isAEAD(p.transformation)) {
throw maybe;
}
} catch (ProviderException maybe) {
boolean isShortBufferException
= maybe.getCause() instanceof ShortBufferException;
if (!isAEAD(p.transformation)
|| !isBuggyProvider(provider)
|| !isShortBufferException) {
throw maybe;
}
}
try {
c.update(new byte[0]);
Expand All @@ -3920,6 +3929,14 @@ private void checkCipher(CipherTestParam p, String provider) throws Exception {
if (!isAEAD(p.transformation)) {
throw maybe;
}
} catch (ProviderException maybe) {
boolean isShortBufferException
= maybe.getCause() instanceof ShortBufferException;
if (!isAEAD(p.transformation)
|| !isBuggyProvider(provider)
|| !isShortBufferException) {
throw maybe;
}
}
} else {
throw new AssertionError("Define your behavior here for " + provider);
Expand Down Expand Up @@ -4014,6 +4031,13 @@ private void checkCipher(CipherTestParam p, String provider) throws Exception {
}
}

// SunJSSE has known issues between 17 and 21
private boolean isBuggyProvider(String providerName) {
return providerName.equals("SunJCE")
&& TestUtils.isJavaVersion(17)
&& !TestUtils.isJavaVersion(21);
}

/**
* Gets the Cipher transformation with the same algorithm and mode as the provided one but
* which uses no padding.
Expand Down Expand Up @@ -4514,6 +4538,9 @@ public void testRC4_MultipleKeySizes() throws Exception {
public void testAES_keyConstrained() throws Exception {
Provider[] providers = Security.getProviders();
for (Provider p : providers) {
if (isBuggyProvider(p.getName())) {
continue;
}
for (Provider.Service s : p.getServices()) {
if (s.getType().equals("Cipher")) {
if (s.getAlgorithm().startsWith("AES_128/")) {
Expand Down

0 comments on commit fd38829

Please sign in to comment.