Correctly handle task offloading when using BoringSSL / OpenSSL (#9575)
Motivation: We did not correctly handle taskoffloading when using BoringSSL / OpenSSL. This could lead to the situation that we did not write the SSL alert out for the remote peer before closing the connection. Modifications: - Correctly handle exceptions when we resume processing on the EventLoop after the task was offloadded - Ensure we call SSL.doHandshake(...) to flush the alert out to the outboundbuffer when an handshake exception was detected - Correctly signal back the need to call WRAP again when a handshake exception is pending. This will ensure we flush out the alert in all cases. Result: No more failures when task offloading is used.
This commit is contained in:
parent
72716be648
commit
57e048147b
@ -541,6 +541,17 @@ public abstract class ReferenceCountedOpenSslContext extends SslContext implemen
|
||||
}
|
||||
}
|
||||
|
||||
// Exposed for testing only
|
||||
final void setUseTasks(boolean useTasks) {
|
||||
Lock writerLock = ctxLock.writeLock();
|
||||
writerLock.lock();
|
||||
try {
|
||||
SSLContext.setUseTasks(ctx, useTasks);
|
||||
} finally {
|
||||
writerLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
// IMPORTANT: This method must only be called from either the constructor or the finalizer as a user MUST never
|
||||
// get access to an OpenSslSessionContext after this method was called to prevent the user from
|
||||
// producing a segfault.
|
||||
|
@ -759,8 +759,15 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
||||
// If there is a handshake exception and we have produced data, we should send the data before
|
||||
// we allow handshake() to throw the handshake exception.
|
||||
//
|
||||
// unwrap(...) will then ensure we propagate the handshake error back to the user.
|
||||
return newResult(NEED_UNWRAP, 0, bytesProduced);
|
||||
// When the user calls wrap() again we will propagate the handshake error back to the user as
|
||||
// soon as there is no more data to was produced (as part of an alert etc).
|
||||
if (bytesProduced > 0) {
|
||||
return newResult(NEED_WRAP, 0, bytesProduced);
|
||||
}
|
||||
// Nothing was produced see if there is a handshakeException that needs to be propagated
|
||||
// to the caller by calling handshakeException() which will return the right HandshakeStatus
|
||||
// if it can "recover" from the exception for now.
|
||||
return newResult(handshakeException(), 0, 0);
|
||||
}
|
||||
|
||||
status = handshake();
|
||||
@ -1743,6 +1750,12 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
||||
checkEngineClosed();
|
||||
|
||||
if (handshakeException != null) {
|
||||
// Let's call SSL.doHandshake(...) again in case there is some async operation pending that would fill the
|
||||
// outbound buffer.
|
||||
if (SSL.doHandshake(ssl) <= 0) {
|
||||
// Clear any error that was put on the stack by the handshake
|
||||
SSL.clearError();
|
||||
}
|
||||
return handshakeException();
|
||||
}
|
||||
|
||||
|
@ -1639,7 +1639,12 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
||||
// We need more data so lets try to unwrap first and then call decode again which will feed us
|
||||
// with buffered data (if there is any).
|
||||
case NEED_UNWRAP:
|
||||
unwrapNonAppData(ctx);
|
||||
try {
|
||||
unwrapNonAppData(ctx);
|
||||
} catch (SSLException e) {
|
||||
handleUnwrapThrowable(ctx, e);
|
||||
return;
|
||||
}
|
||||
tryDecodeAgain();
|
||||
break;
|
||||
|
||||
|
@ -34,18 +34,25 @@ import static org.junit.Assume.assumeTrue;
|
||||
@RunWith(Parameterized.class)
|
||||
public class ConscryptOpenSslEngineInteropTest extends ConscryptSslEngineTest {
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}")
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}, useTasks = {3}")
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> params = new ArrayList<Object[]>();
|
||||
for (BufferType type: BufferType.values()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, true });
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public ConscryptOpenSslEngineInteropTest(BufferType type, ProtocolCipherCombo combo, boolean delegate) {
|
||||
private final boolean useTasks;
|
||||
|
||||
public ConscryptOpenSslEngineInteropTest(BufferType type, ProtocolCipherCombo combo,
|
||||
boolean delegate, boolean useTasks) {
|
||||
super(type, combo, delegate);
|
||||
this.useTasks = useTasks;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@ -140,4 +147,12 @@ public class ConscryptOpenSslEngineInteropTest extends ConscryptSslEngineTest {
|
||||
protected SSLEngine wrapEngine(SSLEngine engine) {
|
||||
return Java8SslTestUtils.wrapSSLEngineForTesting(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SslContext wrapContext(SslContext context) {
|
||||
if (context instanceof OpenSslContext) {
|
||||
((OpenSslContext) context).setUseTasks(useTasks);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@ -33,23 +33,33 @@ import static org.junit.Assume.assumeTrue;
|
||||
@RunWith(Parameterized.class)
|
||||
public class JdkOpenSslEngineInteroptTest extends SSLEngineTest {
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}")
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}, useTasks = {3}")
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> params = new ArrayList<Object[]>();
|
||||
for (BufferType type: BufferType.values()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, true });
|
||||
|
||||
if (PlatformDependent.javaVersion() >= 11 && OpenSsl.isTlsv13Supported()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true, true });
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public JdkOpenSslEngineInteroptTest(BufferType type, ProtocolCipherCombo protocolCipherCombo, boolean delegate) {
|
||||
private final boolean useTasks;
|
||||
|
||||
public JdkOpenSslEngineInteroptTest(BufferType type, ProtocolCipherCombo protocolCipherCombo,
|
||||
boolean delegate, boolean useTasks) {
|
||||
super(type, protocolCipherCombo, delegate);
|
||||
this.useTasks = useTasks;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@ -145,4 +155,12 @@ public class JdkOpenSslEngineInteroptTest extends SSLEngineTest {
|
||||
protected SSLEngine wrapEngine(SSLEngine engine) {
|
||||
return Java8SslTestUtils.wrapSSLEngineForTesting(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SslContext wrapContext(SslContext context) {
|
||||
if (context instanceof OpenSslContext) {
|
||||
((OpenSslContext) context).setUseTasks(useTasks);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@ -33,18 +33,25 @@ import static org.junit.Assume.assumeTrue;
|
||||
@RunWith(Parameterized.class)
|
||||
public class OpenSslConscryptSslEngineInteropTest extends ConscryptSslEngineTest {
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}")
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}, useTasks = {3}")
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> params = new ArrayList<Object[]>();
|
||||
for (BufferType type: BufferType.values()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, true });
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public OpenSslConscryptSslEngineInteropTest(BufferType type, ProtocolCipherCombo combo, boolean delegate) {
|
||||
private final boolean useTasks;
|
||||
|
||||
public OpenSslConscryptSslEngineInteropTest(BufferType type, ProtocolCipherCombo combo,
|
||||
boolean delegate, boolean useTasks) {
|
||||
super(type, combo, delegate);
|
||||
this.useTasks = useTasks;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@ -132,4 +139,12 @@ public class OpenSslConscryptSslEngineInteropTest extends ConscryptSslEngineTest
|
||||
protected SSLEngine wrapEngine(SSLEngine engine) {
|
||||
return Java8SslTestUtils.wrapSSLEngineForTesting(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SslContext wrapContext(SslContext context) {
|
||||
if (context instanceof OpenSslContext) {
|
||||
((OpenSslContext) context).setUseTasks(useTasks);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@ -66,29 +66,37 @@ import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class OpenSslEngineTest extends SSLEngineTest {
|
||||
private static final String PREFERRED_APPLICATION_LEVEL_PROTOCOL = "my-protocol-http2";
|
||||
private static final String FALLBACK_APPLICATION_LEVEL_PROTOCOL = "my-protocol-http1_1";
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}")
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}, useTasks = {3}")
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> params = new ArrayList<Object[]>();
|
||||
for (BufferType type: BufferType.values()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, true });
|
||||
|
||||
if (OpenSsl.isTlsv13Supported()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true, true });
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public OpenSslEngineTest(BufferType type, ProtocolCipherCombo cipherCombo, boolean delegate) {
|
||||
protected final boolean useTasks;
|
||||
|
||||
public OpenSslEngineTest(BufferType type, ProtocolCipherCombo cipherCombo, boolean delegate, boolean useTasks) {
|
||||
super(type, cipherCombo, delegate);
|
||||
this.useTasks = useTasks;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@ -229,18 +237,18 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
}
|
||||
@Test
|
||||
public void testWrapBuffersNoWritePendingError() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -267,18 +275,18 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testOnlySmallBufferNeededForWrap() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -322,18 +330,18 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testNeededDstCapacityIsCorrectlyCalculated() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -362,18 +370,18 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testSrcsLenOverFlowCorrectlyHandled() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -413,12 +421,12 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testCalculateOutNetBufSizeOverflow() throws SSLException {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
try {
|
||||
clientEngine = clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
|
||||
@ -431,12 +439,12 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testCalculateOutNetBufSize0() throws SSLException {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
try {
|
||||
clientEngine = clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
|
||||
@ -458,18 +466,18 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
private void testCorrectlyCalculateSpaceForAlert(boolean jdkCompatabilityMode) throws Exception {
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -520,14 +528,14 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testWrapWithDifferentSizesTLSv1() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
testWrapWithDifferentSizes(PROTOCOL_TLS_V1, "AES128-SHA");
|
||||
testWrapWithDifferentSizes(PROTOCOL_TLS_V1, "ECDHE-RSA-AES128-SHA");
|
||||
@ -551,14 +559,14 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testWrapWithDifferentSizesTLSv1_1() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
testWrapWithDifferentSizes(PROTOCOL_TLS_V1_1, "ECDHE-RSA-AES256-SHA");
|
||||
testWrapWithDifferentSizes(PROTOCOL_TLS_V1_1, "AES256-SHA");
|
||||
@ -579,14 +587,14 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testWrapWithDifferentSizesTLSv1_2() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
testWrapWithDifferentSizes(PROTOCOL_TLS_V1_2, "AES128-SHA");
|
||||
testWrapWithDifferentSizes(PROTOCOL_TLS_V1_2, "ECDHE-RSA-AES128-SHA");
|
||||
@ -617,14 +625,14 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testWrapWithDifferentSizesSSLv3() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
testWrapWithDifferentSizes(PROTOCOL_SSL_V3, "ADH-AES128-SHA");
|
||||
testWrapWithDifferentSizes(PROTOCOL_SSL_V3, "ADH-CAMELLIA128-SHA");
|
||||
@ -657,21 +665,21 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
public void testMultipleRecordsInOneBufferWithNonZeroPositionJDKCompatabilityModeOff() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
try {
|
||||
@ -738,21 +746,21 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
public void testInputTooBigAndFillsUpBuffersJDKCompatabilityModeOff() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
try {
|
||||
@ -826,21 +834,21 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
public void testPartialPacketUnwrapJDKCompatabilityModeOff() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
try {
|
||||
@ -905,21 +913,21 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
public void testBufferUnderFlowAvoidedIfJDKCompatabilityModeOff() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newHandler(UnpooledByteBufAllocator.DEFAULT).engine());
|
||||
|
||||
try {
|
||||
@ -1045,11 +1053,11 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
public void testSNIMatchersDoesNotThrow() throws Exception {
|
||||
assumeTrue(PlatformDependent.javaVersion() >= 8);
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
SSLEngine engine = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
try {
|
||||
@ -1067,11 +1075,11 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
assumeTrue(PlatformDependent.javaVersion() >= 8);
|
||||
byte[] name = "rb8hx3pww30y3tvw0mwy.v1_1".getBytes(CharsetUtil.UTF_8);
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
SSLEngine engine = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
try {
|
||||
@ -1089,11 +1097,11 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAlgorithmConstraintsThrows() throws Exception {
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
SSLEngine engine = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
try {
|
||||
@ -1126,15 +1134,15 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
@Test
|
||||
public void testExtractMasterkeyWorksCorrectly() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(cert.key(), cert.cert())
|
||||
.sslProvider(SslProvider.OPENSSL).build();
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(cert.key(), cert.cert())
|
||||
.sslProvider(SslProvider.OPENSSL).build());
|
||||
final SSLEngine serverEngine =
|
||||
serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(cert.certificate())
|
||||
.sslProvider(SslProvider.OPENSSL).build();
|
||||
.sslProvider(SslProvider.OPENSSL).build());
|
||||
final SSLEngine clientEngine =
|
||||
clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT);
|
||||
wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
//lets set the cipher suite to a specific one with DHE
|
||||
@ -1307,4 +1315,10 @@ public class OpenSslEngineTest extends SSLEngineTest {
|
||||
}
|
||||
return (ReferenceCountedOpenSslEngine) engine;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SslContext wrapContext(SslContext context) {
|
||||
((OpenSslContext) context).setUseTasks(useTasks);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@ -35,23 +35,33 @@ import static org.junit.Assume.assumeTrue;
|
||||
@RunWith(Parameterized.class)
|
||||
public class OpenSslJdkSslEngineInteroptTest extends SSLEngineTest {
|
||||
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}")
|
||||
@Parameterized.Parameters(name = "{index}: bufferType = {0}, combo = {1}, delegate = {2}, useTasks = {3}")
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> params = new ArrayList<Object[]>();
|
||||
for (BufferType type: BufferType.values()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, false});
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv12(), true, true });
|
||||
|
||||
if (PlatformDependent.javaVersion() >= 11 && OpenSsl.isTlsv13Supported()) {
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), false, true });
|
||||
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true, false });
|
||||
params.add(new Object[] { type, ProtocolCipherCombo.tlsv13(), true, true });
|
||||
}
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public OpenSslJdkSslEngineInteroptTest(BufferType type, ProtocolCipherCombo combo, boolean delegate) {
|
||||
private final boolean useTasks;
|
||||
|
||||
public OpenSslJdkSslEngineInteroptTest(BufferType type, ProtocolCipherCombo combo,
|
||||
boolean delegate, boolean useTasks) {
|
||||
super(type, combo, delegate);
|
||||
this.useTasks = useTasks;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@ -130,4 +140,12 @@ public class OpenSslJdkSslEngineInteroptTest extends SSLEngineTest {
|
||||
protected SSLEngine wrapEngine(SSLEngine engine) {
|
||||
return Java8SslTestUtils.wrapSSLEngineForTesting(engine);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SslContext wrapContext(SslContext context) {
|
||||
if (context instanceof OpenSslContext) {
|
||||
((OpenSslContext) context).setUseTasks(useTasks);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,9 @@ import javax.net.ssl.SSLEngine;
|
||||
|
||||
public class ReferenceCountedOpenSslEngineTest extends OpenSslEngineTest {
|
||||
|
||||
public ReferenceCountedOpenSslEngineTest(BufferType type, ProtocolCipherCombo combo, boolean delegate) {
|
||||
super(type, combo, delegate);
|
||||
public ReferenceCountedOpenSslEngineTest(BufferType type, ProtocolCipherCombo combo, boolean delegate,
|
||||
boolean useTasks) {
|
||||
super(type, combo, delegate, useTasks);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,13 +60,19 @@ public class ReferenceCountedOpenSslEngineTest extends OpenSslEngineTest {
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testNotLeakOnException() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
clientSslCtx.newEngine(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SslContext wrapContext(SslContext context) {
|
||||
((ReferenceCountedOpenSslContext) context).setUseTasks(useTasks);
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@ -698,7 +698,7 @@ public abstract class SSLEngineTest {
|
||||
final boolean serverInitEngine)
|
||||
throws SSLException, InterruptedException {
|
||||
serverSslCtx =
|
||||
SslContextBuilder.forServer(serverKMF)
|
||||
wrapContext(SslContextBuilder.forServer(serverKMF)
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.sslProvider(sslServerProvider())
|
||||
@ -707,10 +707,10 @@ public abstract class SSLEngineTest {
|
||||
.clientAuth(clientAuth)
|
||||
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
|
||||
.sessionCacheSize(0)
|
||||
.sessionTimeout(0).build();
|
||||
.sessionTimeout(0).build());
|
||||
|
||||
clientSslCtx =
|
||||
SslContextBuilder.forClient()
|
||||
wrapContext(SslContextBuilder.forClient()
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.sslProvider(sslClientProvider())
|
||||
@ -719,7 +719,7 @@ public abstract class SSLEngineTest {
|
||||
.keyManager(clientKMF)
|
||||
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
|
||||
.sessionCacheSize(0)
|
||||
.sessionTimeout(0).build();
|
||||
.sessionTimeout(0).build());
|
||||
|
||||
serverConnectedChannel = null;
|
||||
sb = new ServerBootstrap();
|
||||
@ -850,7 +850,7 @@ public abstract class SSLEngineTest {
|
||||
final boolean failureExpected)
|
||||
throws SSLException, InterruptedException {
|
||||
final String expectedHost = "localhost";
|
||||
serverSslCtx = SslContextBuilder.forServer(serverCrtFile, serverKeyFile, null)
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(serverCrtFile, serverKeyFile, null)
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
@ -859,9 +859,9 @@ public abstract class SSLEngineTest {
|
||||
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
|
||||
.sessionCacheSize(0)
|
||||
.sessionTimeout(0)
|
||||
.build();
|
||||
.build());
|
||||
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
@ -870,7 +870,7 @@ public abstract class SSLEngineTest {
|
||||
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
|
||||
.sessionCacheSize(0)
|
||||
.sessionTimeout(0)
|
||||
.build();
|
||||
.build());
|
||||
|
||||
serverConnectedChannel = null;
|
||||
sb = new ServerBootstrap();
|
||||
@ -1020,7 +1020,7 @@ public abstract class SSLEngineTest {
|
||||
File clientTrustCrtFile, File clientKeyFile, final File clientCrtFile, String clientKeyPassword)
|
||||
throws InterruptedException, SSLException {
|
||||
serverSslCtx =
|
||||
SslContextBuilder.forServer(serverCrtFile, serverKeyFile, serverKeyPassword)
|
||||
wrapContext(SslContextBuilder.forServer(serverCrtFile, serverKeyFile, serverKeyPassword)
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
@ -1028,9 +1028,9 @@ public abstract class SSLEngineTest {
|
||||
.trustManager(servertTrustCrtFile)
|
||||
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
|
||||
.sessionCacheSize(0)
|
||||
.sessionTimeout(0).build();
|
||||
.sessionTimeout(0).build());
|
||||
clientSslCtx =
|
||||
SslContextBuilder.forClient()
|
||||
wrapContext(SslContextBuilder.forClient()
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols())
|
||||
@ -1039,7 +1039,7 @@ public abstract class SSLEngineTest {
|
||||
.keyManager(clientCrtFile, clientKeyFile, clientKeyPassword)
|
||||
.ciphers(null, IdentityCipherSuiteFilter.INSTANCE)
|
||||
.sessionCacheSize(0)
|
||||
.sessionTimeout(0).build();
|
||||
.sessionTimeout(0).build());
|
||||
|
||||
serverConnectedChannel = null;
|
||||
sb = new ServerBootstrap();
|
||||
@ -1187,9 +1187,9 @@ public abstract class SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testGetCreationTime() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider()).build();
|
||||
.sslContextProvider(clientSslContextProvider()).build());
|
||||
SSLEngine engine = null;
|
||||
try {
|
||||
engine = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
@ -1201,20 +1201,20 @@ public abstract class SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testSessionInvalidate() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -1235,20 +1235,20 @@ public abstract class SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testSSLSessionId() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
// This test only works for non TLSv1.3 for now
|
||||
.protocols(PROTOCOL_TLS_V1_2)
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
// This test only works for non TLSv1.3 for now
|
||||
.protocols(PROTOCOL_TLS_V1_2)
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -1277,12 +1277,12 @@ public abstract class SSLEngineTest {
|
||||
throws CertificateException, SSLException, InterruptedException, ExecutionException {
|
||||
Assume.assumeTrue(PlatformDependent.javaVersion() >= 11);
|
||||
final SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
sb = new ServerBootstrap()
|
||||
.group(new NioEventLoopGroup(1))
|
||||
.channel(NioServerSocketChannel.class)
|
||||
@ -1336,13 +1336,13 @@ public abstract class SSLEngineTest {
|
||||
|
||||
serverChannel = sb.bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
|
||||
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
// OpenSslEngine doesn't support renegotiation on client side
|
||||
.sslProvider(SslProvider.JDK)
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
cb = new Bootstrap();
|
||||
cb.group(new NioEventLoopGroup(1))
|
||||
@ -1405,12 +1405,12 @@ public abstract class SSLEngineTest {
|
||||
try {
|
||||
File serverKeyFile = ResourcesUtil.getFile(getClass(), "test_unencrypted.pem");
|
||||
File serverCrtFile = ResourcesUtil.getFile(getClass(), "test.crt");
|
||||
serverSslCtx = SslContextBuilder.forServer(serverCrtFile, serverKeyFile)
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(serverCrtFile, serverKeyFile)
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
sslEngine = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
@ -1619,7 +1619,7 @@ public abstract class SSLEngineTest {
|
||||
clientCtxBuilder.protocols(PROTOCOL_TLS_V1_2);
|
||||
}
|
||||
|
||||
setupHandlers(serverCtxBuilder.build(), clientCtxBuilder.build());
|
||||
setupHandlers(wrapContext(serverCtxBuilder.build()), wrapContext(clientCtxBuilder.build()));
|
||||
} finally {
|
||||
ssc.delete();
|
||||
}
|
||||
@ -1709,14 +1709,14 @@ public abstract class SSLEngineTest {
|
||||
@Test(timeout = 30000)
|
||||
public void testMutualAuthSameCertChain() throws Exception {
|
||||
serverSslCtx =
|
||||
SslContextBuilder.forServer(
|
||||
wrapContext(SslContextBuilder.forServer(
|
||||
new ByteArrayInputStream(X509_CERT_PEM.getBytes(CharsetUtil.UTF_8)),
|
||||
new ByteArrayInputStream(PRIVATE_KEY_PEM.getBytes(CharsetUtil.UTF_8)))
|
||||
.trustManager(new ByteArrayInputStream(X509_CERT_PEM.getBytes(CharsetUtil.UTF_8)))
|
||||
.clientAuth(ClientAuth.REQUIRE).sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers()).build();
|
||||
.ciphers(ciphers()).build());
|
||||
|
||||
sb = new ServerBootstrap();
|
||||
sb.group(new NioEventLoopGroup(), new NioEventLoopGroup());
|
||||
@ -1772,13 +1772,13 @@ public abstract class SSLEngineTest {
|
||||
}).bind(new InetSocketAddress(0)).syncUninterruptibly().channel();
|
||||
|
||||
clientSslCtx =
|
||||
SslContextBuilder.forClient().keyManager(
|
||||
wrapContext(SslContextBuilder.forClient().keyManager(
|
||||
new ByteArrayInputStream(CLIENT_X509_CERT_CHAIN_PEM.getBytes(CharsetUtil.UTF_8)),
|
||||
new ByteArrayInputStream(CLIENT_PRIVATE_KEY_PEM.getBytes(CharsetUtil.UTF_8)))
|
||||
.trustManager(new ByteArrayInputStream(X509_CERT_PEM.getBytes(CharsetUtil.UTF_8)))
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols()).ciphers(ciphers()).build();
|
||||
.protocols(protocols()).ciphers(ciphers()).build());
|
||||
cb = new Bootstrap();
|
||||
cb.group(new NioEventLoopGroup());
|
||||
cb.channel(NioSocketChannel.class);
|
||||
@ -1798,21 +1798,21 @@ public abstract class SSLEngineTest {
|
||||
public void testUnwrapBehavior() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
byte[] bytes = "Hello World".getBytes(CharsetUtil.US_ASCII);
|
||||
@ -1892,19 +1892,19 @@ public abstract class SSLEngineTest {
|
||||
private void testProtocol(String[] clientProtocols, String[] serverProtocols) throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(clientProtocols)
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(serverProtocols)
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -1922,18 +1922,18 @@ public abstract class SSLEngineTest {
|
||||
// Select a mandatory cipher from the TLSv1.2 RFC https://www.ietf.org/rfc/rfc5246.txt so handshakes won't fail
|
||||
// due to no shared/supported cipher.
|
||||
final String sharedCipher = "TLS_RSA_WITH_AES_128_CBC_SHA";
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.ciphers(Collections.singletonList(sharedCipher))
|
||||
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.ciphers(Collections.singletonList(sharedCipher))
|
||||
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
|
||||
.sslProvider(sslServerProvider())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -1953,18 +1953,18 @@ public abstract class SSLEngineTest {
|
||||
// Select a mandatory cipher from the TLSv1.2 RFC https://www.ietf.org/rfc/rfc5246.txt so handshakes won't fail
|
||||
// due to no shared/supported cipher.
|
||||
final String sharedCipher = "TLS_RSA_WITH_AES_128_CBC_SHA";
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.ciphers(Collections.singletonList(sharedCipher), SupportedCipherSuiteFilter.INSTANCE)
|
||||
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.ciphers(Collections.singletonList(sharedCipher), SupportedCipherSuiteFilter.INSTANCE)
|
||||
.protocols(PROTOCOL_TLS_V1_2, PROTOCOL_TLS_V1)
|
||||
.sslProvider(sslServerProvider())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -1982,21 +1982,21 @@ public abstract class SSLEngineTest {
|
||||
public void testPacketBufferSizeLimit() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2026,12 +2026,12 @@ public abstract class SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testSSLEngineUnwrapNoSslRecord() throws Exception {
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2056,12 +2056,12 @@ public abstract class SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testBeginHandshakeAfterEngineClosed() throws SSLException {
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2082,20 +2082,20 @@ public abstract class SSLEngineTest {
|
||||
public void testBeginHandshakeCloseOutbound() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2133,20 +2133,20 @@ public abstract class SSLEngineTest {
|
||||
public void testCloseInboundAfterBeginHandshake() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2173,21 +2173,21 @@ public abstract class SSLEngineTest {
|
||||
public void testCloseNotifySequence() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
// This test only works for non TLSv1.3 for now
|
||||
.protocols(PROTOCOL_TLS_V1_2)
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
// This test only works for non TLSv1.3 for now
|
||||
.protocols(PROTOCOL_TLS_V1_2)
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2327,21 +2327,21 @@ public abstract class SSLEngineTest {
|
||||
public void testWrapAfterCloseOutbound() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2370,21 +2370,21 @@ public abstract class SSLEngineTest {
|
||||
public void testMultipleRecordsInOneBufferWithNonZeroPosition() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2449,21 +2449,21 @@ public abstract class SSLEngineTest {
|
||||
public void testMultipleRecordsInOneBufferBiggerThenPacketBufferSize() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2517,21 +2517,21 @@ public abstract class SSLEngineTest {
|
||||
public void testBufferUnderFlow() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2592,21 +2592,21 @@ public abstract class SSLEngineTest {
|
||||
public void testWrapDoesNotZeroOutSrc() throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2649,12 +2649,12 @@ public abstract class SSLEngineTest {
|
||||
private void testDisableProtocols(String protocol, String... disabledProtocols) throws Exception {
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
|
||||
SslContext ctx = SslContextBuilder
|
||||
SslContext ctx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine server = wrapEngine(ctx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
|
||||
try {
|
||||
@ -2685,7 +2685,7 @@ public abstract class SSLEngineTest {
|
||||
public void testUsingX509TrustManagerVerifiesHostname() throws Exception {
|
||||
SslProvider clientProvider = sslClientProvider();
|
||||
SelfSignedCertificate cert = new SelfSignedCertificate();
|
||||
clientSslCtx = SslContextBuilder
|
||||
clientSslCtx = wrapContext(SslContextBuilder
|
||||
.forClient()
|
||||
.trustManager(new TrustManagerFactory(new TrustManagerFactorySpi() {
|
||||
@Override
|
||||
@ -2723,17 +2723,17 @@ public abstract class SSLEngineTest {
|
||||
}, null, TrustManagerFactory.getDefaultAlgorithm()) {
|
||||
})
|
||||
.sslProvider(sslClientProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
SSLEngine client = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT, "netty.io", 1234));
|
||||
SSLParameters sslParameters = client.getSSLParameters();
|
||||
sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
|
||||
client.setSSLParameters(sslParameters);
|
||||
|
||||
serverSslCtx = SslContextBuilder
|
||||
serverSslCtx = wrapContext(SslContextBuilder
|
||||
.forServer(cert.certificate(), cert.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
SSLEngine server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
try {
|
||||
@ -2756,8 +2756,9 @@ public abstract class SSLEngineTest {
|
||||
cipherList.add("InvalidCipher");
|
||||
SSLEngine server = null;
|
||||
try {
|
||||
serverSslCtx = SslContextBuilder.forServer(cert.key(), cert.cert()).sslProvider(sslClientProvider())
|
||||
.ciphers(cipherList).build();
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(cert.key(), cert.cert())
|
||||
.sslProvider(sslClientProvider())
|
||||
.ciphers(cipherList).build());
|
||||
server = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT));
|
||||
fail();
|
||||
} catch (IllegalArgumentException expected) {
|
||||
@ -2772,20 +2773,20 @@ public abstract class SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testGetCiphersuite() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -2807,20 +2808,20 @@ public abstract class SSLEngineTest {
|
||||
|
||||
@Test
|
||||
public void testSessionBindingEvent() throws Exception {
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -2919,13 +2920,13 @@ public abstract class SSLEngineTest {
|
||||
clientContextBuilder.keyManager(ssc.key(), ssc.cert());
|
||||
}
|
||||
}
|
||||
clientSslCtx = clientContextBuilder
|
||||
clientSslCtx = wrapContext(clientContextBuilder
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
SslContextBuilder serverContextBuilder = kmf != null ?
|
||||
SslContextBuilder.forServer(kmf) :
|
||||
@ -2933,12 +2934,12 @@ public abstract class SSLEngineTest {
|
||||
if (mutualAuth) {
|
||||
serverContextBuilder.clientAuth(ClientAuth.REQUIRE);
|
||||
}
|
||||
serverSslCtx = serverContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
serverSslCtx = wrapContext(serverContextBuilder.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -3153,22 +3154,23 @@ public abstract class SSLEngineTest {
|
||||
}
|
||||
}
|
||||
|
||||
clientSslCtx = SslContextBuilder.forClient().keyManager(new TestKeyManagerFactory(newKeyManagerFactory(ssc)))
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.keyManager(new TestKeyManagerFactory(newKeyManagerFactory(ssc)))
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslProvider(sslClientProvider())
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
.build());
|
||||
|
||||
serverSslCtx = SslContextBuilder.forServer(new TestKeyManagerFactory(newKeyManagerFactory(ssc)))
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(new TestKeyManagerFactory(newKeyManagerFactory(ssc)))
|
||||
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.sslProvider(sslServerProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.clientAuth(ClientAuth.REQUIRE)
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -3189,7 +3191,7 @@ public abstract class SSLEngineTest {
|
||||
final TestTrustManagerFactory clientTmf = new TestTrustManagerFactory(ssc.cert());
|
||||
final TestTrustManagerFactory serverTmf = new TestTrustManagerFactory(ssc.cert());
|
||||
|
||||
clientSslCtx = SslContextBuilder.forClient()
|
||||
clientSslCtx = wrapContext(SslContextBuilder.forClient()
|
||||
.trustManager(new SimpleTrustManagerFactory() {
|
||||
@Override
|
||||
protected void engineInit(KeyStore keyStore) {
|
||||
@ -3211,8 +3213,8 @@ public abstract class SSLEngineTest {
|
||||
.sslContextProvider(clientSslContextProvider())
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.build();
|
||||
serverSslCtx = SslContextBuilder.forServer(newKeyManagerFactory(ssc))
|
||||
.build());
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(newKeyManagerFactory(ssc))
|
||||
.trustManager(new SimpleTrustManagerFactory() {
|
||||
@Override
|
||||
protected void engineInit(KeyStore keyStore) {
|
||||
@ -3234,7 +3236,7 @@ public abstract class SSLEngineTest {
|
||||
.protocols(protocols())
|
||||
.ciphers(ciphers())
|
||||
.clientAuth(ClientAuth.REQUIRE)
|
||||
.build();
|
||||
.build());
|
||||
SSLEngine clientEngine = null;
|
||||
SSLEngine serverEngine = null;
|
||||
try {
|
||||
@ -3269,10 +3271,10 @@ public abstract class SSLEngineTest {
|
||||
System.setProperty(SslMasterKeyHandler.SYSTEM_PROP_KEY, Boolean.TRUE.toString());
|
||||
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate();
|
||||
serverSslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
serverSslCtx = wrapContext(SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
|
||||
.sslProvider(sslServerProvider())
|
||||
.sslContextProvider(serverSslContextProvider())
|
||||
.build();
|
||||
.build());
|
||||
Socket socket = null;
|
||||
|
||||
try {
|
||||
@ -3412,6 +3414,10 @@ public abstract class SSLEngineTest {
|
||||
return engine;
|
||||
}
|
||||
|
||||
protected SslContext wrapContext(SslContext context) {
|
||||
return context;
|
||||
}
|
||||
|
||||
protected List<String> ciphers() {
|
||||
return Collections.singletonList(protocolCipherCombo.cipher);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user