@@ -133,6 +133,16 @@ public void testServerHandshakeTimeout() throws Exception {
133
133
testHandshakeTimeout (false );
134
134
}
135
135
136
+ private static SSLEngine newServerModeSSLEngine () throws NoSuchAlgorithmException {
137
+ SSLEngine engine = SSLContext .getDefault ().createSSLEngine ();
138
+ // Set the mode before we try to do the handshake as otherwise it may throw an IllegalStateException.
139
+ // See:
140
+ // - https://docs.oracle.com/javase/10/docs/api/javax/net/ssl/SSLEngine.html#beginHandshake()
141
+ // - http://mail.openjdk.java.net/pipermail/security-dev/2018-July/017715.html
142
+ engine .setUseClientMode (false );
143
+ return engine ;
144
+ }
145
+
136
146
private static void testHandshakeTimeout (boolean client ) throws Exception {
137
147
SSLEngine engine = SSLContext .getDefault ().createSSLEngine ();
138
148
engine .setUseClientMode (client );
@@ -155,9 +165,7 @@ private static void testHandshakeTimeout(boolean client) throws Exception {
155
165
156
166
@ Test
157
167
public void testTruncatedPacket () throws Exception {
158
- SSLEngine engine = SSLContext .getDefault ().createSSLEngine ();
159
- engine .setUseClientMode (false );
160
-
168
+ SSLEngine engine = newServerModeSSLEngine ();
161
169
EmbeddedChannel ch = new EmbeddedChannel (new SslHandler (engine ));
162
170
163
171
// Push the first part of a 5-byte handshake message.
@@ -183,9 +191,7 @@ public void testTruncatedPacket() throws Exception {
183
191
184
192
@ Test
185
193
public void testNonByteBufWriteIsReleased () throws Exception {
186
- SSLEngine engine = SSLContext .getDefault ().createSSLEngine ();
187
- engine .setUseClientMode (false );
188
-
194
+ SSLEngine engine = newServerModeSSLEngine ();
189
195
EmbeddedChannel ch = new EmbeddedChannel (new SslHandler (engine ));
190
196
191
197
AbstractReferenceCounted referenceCounted = new AbstractReferenceCounted () {
@@ -210,9 +216,7 @@ protected void deallocate() {
210
216
211
217
@ Test (expected = UnsupportedMessageTypeException .class )
212
218
public void testNonByteBufNotPassThrough () throws Exception {
213
- SSLEngine engine = SSLContext .getDefault ().createSSLEngine ();
214
- engine .setUseClientMode (false );
215
-
219
+ SSLEngine engine = newServerModeSSLEngine ();
216
220
EmbeddedChannel ch = new EmbeddedChannel (new SslHandler (engine ));
217
221
218
222
try {
@@ -224,9 +228,7 @@ public void testNonByteBufNotPassThrough() throws Exception {
224
228
225
229
@ Test
226
230
public void testIncompleteWriteDoesNotCompletePromisePrematurely () throws NoSuchAlgorithmException {
227
- SSLEngine engine = SSLContext .getDefault ().createSSLEngine ();
228
- engine .setUseClientMode (false );
229
-
231
+ SSLEngine engine = newServerModeSSLEngine ();
230
232
EmbeddedChannel ch = new EmbeddedChannel (new SslHandler (engine ));
231
233
232
234
ChannelPromise promise = ch .newPromise ();
@@ -398,7 +400,8 @@ public void channelInactive(ChannelHandlerContext ctx) {
398
400
399
401
@ Test
400
402
public void testCloseFutureNotified () throws Exception {
401
- SslHandler handler = new SslHandler (SSLContext .getDefault ().createSSLEngine ());
403
+ SSLEngine engine = newServerModeSSLEngine ();
404
+ SslHandler handler = new SslHandler (engine );
402
405
EmbeddedChannel ch = new EmbeddedChannel (handler );
403
406
404
407
ch .close ();
@@ -416,7 +419,7 @@ public void testCloseFutureNotified() throws Exception {
416
419
417
420
@ Test (timeout = 5000 )
418
421
public void testEventsFired () throws Exception {
419
- SSLEngine engine = SSLContext . getDefault (). createSSLEngine ();
422
+ SSLEngine engine = newServerModeSSLEngine ();
420
423
final BlockingQueue <SslCompletionEvent > events = new LinkedBlockingQueue <SslCompletionEvent >();
421
424
EmbeddedChannel channel = new EmbeddedChannel (new SslHandler (engine ), new ChannelInboundHandlerAdapter () {
422
425
@ Override
0 commit comments