8207250: setUseClientMode post handshake with the same value as before does not throw IAE

Reviewed-by: xuelei
This commit is contained in:
Weijun Wang 2018-07-19 00:14:29 +08:00
parent 8818f46285
commit a825fe0a2d
2 changed files with 20 additions and 16 deletions

View file

@ -393,13 +393,6 @@ class TransportContext implements ConnectionContext, Closeable {
} }
void setUseClientMode(boolean useClientMode) { void setUseClientMode(boolean useClientMode) {
/*
* If we need to change the client mode and the enabled
* protocols and cipher suites haven't specifically been
* set by the user, change them to the corresponding
* default ones.
*/
if (sslConfig.isClientMode != useClientMode) {
// Once handshaking has begun, the mode can not be reset for the // Once handshaking has begun, the mode can not be reset for the
// life of this engine. // life of this engine.
if (handshakeContext != null || isNegotiated) { if (handshakeContext != null || isNegotiated) {
@ -407,6 +400,13 @@ class TransportContext implements ConnectionContext, Closeable {
"Cannot change mode after SSL traffic has started"); "Cannot change mode after SSL traffic has started");
} }
/*
* If we need to change the client mode and the enabled
* protocols and cipher suites haven't specifically been
* set by the user, change them to the corresponding
* default ones.
*/
if (sslConfig.isClientMode != useClientMode) {
if (sslContext.isDefaultProtocolVesions( if (sslContext.isDefaultProtocolVesions(
sslConfig.enabledProtocols)) { sslConfig.enabledProtocols)) {
sslConfig.enabledProtocols = sslConfig.enabledProtocols =

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,7 @@
/* /*
* @test * @test
* @bug 4980882 * @bug 4980882 8207250
* @summary SSLEngine should enforce setUseClientMode * @summary SSLEngine should enforce setUseClientMode
* @run main/othervm EngineEnforceUseClientMode * @run main/othervm EngineEnforceUseClientMode
* @author Brad R. Wetmore * @author Brad R. Wetmore
@ -190,15 +190,19 @@ public class EngineEnforceUseClientMode {
checkTransfer(appOut1, appIn2); checkTransfer(appOut1, appIn2);
checkTransfer(appOut2, appIn1); checkTransfer(appOut2, appIn1);
// Should not be able to set mode now, no matter if
// it is the same of different.
System.out.println("Try changing modes..."); System.out.println("Try changing modes...");
for (boolean b : new Boolean[] {true, false}) {
try { try {
ssle2.setUseClientMode(true); ssle2.setUseClientMode(b);
throw new RuntimeException( throw new RuntimeException(
"setUseClientMode(): " + "setUseClientMode(" + b + "): " +
"Didn't catch the exception properly"); "Didn't catch the exception properly");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
System.out.println("Caught the correct exception."); System.out.println("Caught the correct exception.");
} }
}
return; return;
} }