Skip to content

Commit

Permalink
8223482: Unsupported ciphersuites may be offered by a TLS client
Browse files Browse the repository at this point in the history
Reviewed-by: xuelei, andrew
  • Loading branch information
martinuy committed May 28, 2019
1 parent c4c43e3 commit 78e47c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
26 changes: 21 additions & 5 deletions src/java.base/share/classes/sun/security/ssl/SSLCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.PrivilegedAction;
import java.security.SecureRandom;
import java.security.Security;
Expand Down Expand Up @@ -465,16 +466,31 @@ private SSLCipher(String transformation,

// availability of this bulk cipher
//
// We assume all supported ciphers are always available since they are
// shipped with the SunJCE provider. However, AES/256 is unavailable
// when the default JCE policy jurisdiction files are installed because
// of key length restrictions.
this.isAvailable = allowed && isUnlimited(keySize, transformation);
// AES/256 is unavailable when the default JCE policy jurisdiction files
// are installed because of key length restrictions.
this.isAvailable = allowed && isUnlimited(keySize, transformation) &&
isTransformationAvailable(transformation);

this.readCipherGenerators = readCipherGenerators;
this.writeCipherGenerators = writeCipherGenerators;
}

private static boolean isTransformationAvailable(String transformation) {
if (transformation.equals("NULL")) {
return true;
}
try {
JsseJce.getCipher(transformation);
return true;
} catch (NoSuchAlgorithmException e) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl")) {
SSLLogger.fine("Transformation " + transformation + " is" +
" not available.");
}
}
return false;
}

SSLReadCipher createReadCipher(Authenticator authenticator,
ProtocolVersion protocolVersion,
SecretKey key, IvParameterSpec iv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ private static List<CipherSuite> getApplicableCipherSuites(

boolean isSupported = false;
for (ProtocolVersion protocol : protocols) {
if (!suite.supports(protocol)) {
if (!suite.supports(protocol) ||
!suite.bulkCipher.isAvailable()) {
continue;
}

Expand Down
7 changes: 6 additions & 1 deletion test/jdk/sun/security/pkcs11/fips/TestTLS12.java
Original file line number Diff line number Diff line change
Expand Up @@ -376,15 +376,20 @@ private static void runDelegatedTasks(SSLEngineResult result,

private static SSLEngine[][] getSSLEnginesToTest() throws Exception {
SSLEngine[][] enginesToTest = new SSLEngine[2][2];
// TLS_RSA_WITH_AES_128_GCM_SHA256 ciphersuite is available but
// must not be chosen for the TLS connection if not supported.
// See JDK-8222937.
String[][] preferredSuites = new String[][]{ new String[] {
"TLS_RSA_WITH_AES_128_GCM_SHA256",
"TLS_RSA_WITH_AES_128_CBC_SHA256"
}, new String[] {
"TLS_RSA_WITH_AES_128_GCM_SHA256",
"TLS_DHE_RSA_WITH_AES_128_CBC_SHA256"
}};
for (int i = 0; i < enginesToTest.length; i++) {
enginesToTest[i][0] = createSSLEngine(true);
enginesToTest[i][1] = createSSLEngine(false);
enginesToTest[i][0].setEnabledCipherSuites(preferredSuites[i]);
// All CipherSuites enabled for the client.
enginesToTest[i][1].setEnabledCipherSuites(preferredSuites[i]);
}
return enginesToTest;
Expand Down

0 comments on commit 78e47c6

Please sign in to comment.