Skip to content

Commit 64a3e6c

Browse files
committed
SSLEngineTest should not depend on OpenSsl* class.
Motivation: 6152990 introduced a test-case in SSLEngineTest which used OpenSsl.* which should not be done as this is am abstract bass class that is also used for non OpenSsl tests. Modifications: Move the protocol definations into SslUtils. Result: Cleaner code.
1 parent 0ad9931 commit 64a3e6c

File tree

6 files changed

+181
-162
lines changed

6 files changed

+181
-162
lines changed

handler/src/main/java/io/netty/handler/ssl/OpenSsl.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@
4242
import static io.netty.handler.ssl.SslUtils.DEFAULT_CIPHER_SUITES;
4343
import static io.netty.handler.ssl.SslUtils.addIfSupported;
4444
import static io.netty.handler.ssl.SslUtils.useFallbackCiphersIfDefaultIsEmpty;
45+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_SSL_V2;
46+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_SSL_V2_HELLO;
47+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_SSL_V3;
48+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1;
49+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1_1;
50+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1_2;
4551

4652
/**
4753
* Tells if <a href="http://netty.io/wiki/forked-tomcat-native.html">{@code netty-tcnative}</a> and its OpenSSL support
@@ -63,14 +69,6 @@ public final class OpenSsl {
6369
private static final boolean USE_KEYMANAGER_FACTORY;
6470
private static final boolean SUPPORTS_OCSP;
6571

66-
// Protocols
67-
static final String PROTOCOL_SSL_V2_HELLO = "SSLv2Hello";
68-
static final String PROTOCOL_SSL_V2 = "SSLv2";
69-
static final String PROTOCOL_SSL_V3 = "SSLv3";
70-
static final String PROTOCOL_TLS_V1 = "TLSv1";
71-
static final String PROTOCOL_TLS_V1_1 = "TLSv1.1";
72-
static final String PROTOCOL_TLS_V1_2 = "TLSv1.2";
73-
7472
static final Set<String> SUPPORTED_PROTOCOLS_SET;
7573

7674
static {

handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
import static io.netty.util.internal.EmptyArrays.EMPTY_CERTIFICATES;
6262
import static io.netty.util.internal.EmptyArrays.EMPTY_JAVAX_X509_CERTIFICATES;
6363
import static io.netty.util.internal.ObjectUtil.checkNotNull;
64+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_SSL_V2;
65+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_SSL_V2_HELLO;
66+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_SSL_V3;
67+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1;
68+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1_1;
69+
import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1_2;
6470
import static java.lang.Integer.MAX_VALUE;
6571
import static java.lang.Math.min;
6672
import static javax.net.ssl.SSLEngineResult.HandshakeStatus.FINISHED;
@@ -1341,7 +1347,7 @@ public final String[] getSupportedProtocols() {
13411347
public final String[] getEnabledProtocols() {
13421348
List<String> enabled = new ArrayList<String>(6);
13431349
// Seems like there is no way to explicit disable SSLv2Hello in openssl so it is always enabled
1344-
enabled.add(OpenSsl.PROTOCOL_SSL_V2_HELLO);
1350+
enabled.add(PROTOCOL_SSL_V2_HELLO);
13451351

13461352
int opts;
13471353
synchronized (this) {
@@ -1351,20 +1357,20 @@ public final String[] getEnabledProtocols() {
13511357
return enabled.toArray(new String[1]);
13521358
}
13531359
}
1354-
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_TLSv1, OpenSsl.PROTOCOL_TLS_V1)) {
1355-
enabled.add(OpenSsl.PROTOCOL_TLS_V1);
1360+
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_TLSv1, PROTOCOL_TLS_V1)) {
1361+
enabled.add(PROTOCOL_TLS_V1);
13561362
}
1357-
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_TLSv1_1, OpenSsl.PROTOCOL_TLS_V1_1)) {
1358-
enabled.add(OpenSsl.PROTOCOL_TLS_V1_1);
1363+
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_TLSv1_1, PROTOCOL_TLS_V1_1)) {
1364+
enabled.add(PROTOCOL_TLS_V1_1);
13591365
}
1360-
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_TLSv1_2, OpenSsl.PROTOCOL_TLS_V1_2)) {
1361-
enabled.add(OpenSsl.PROTOCOL_TLS_V1_2);
1366+
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_TLSv1_2, PROTOCOL_TLS_V1_2)) {
1367+
enabled.add(PROTOCOL_TLS_V1_2);
13621368
}
1363-
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_SSLv2, OpenSsl.PROTOCOL_SSL_V2)) {
1364-
enabled.add(OpenSsl.PROTOCOL_SSL_V2);
1369+
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_SSLv2, PROTOCOL_SSL_V2)) {
1370+
enabled.add(PROTOCOL_SSL_V2);
13651371
}
1366-
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_SSLv3, OpenSsl.PROTOCOL_SSL_V3)) {
1367-
enabled.add(OpenSsl.PROTOCOL_SSL_V3);
1372+
if (isProtocolEnabled(opts, SSL.SSL_OP_NO_SSLv3, PROTOCOL_SSL_V3)) {
1373+
enabled.add(PROTOCOL_SSL_V3);
13681374
}
13691375
return enabled.toArray(new String[enabled.size()]);
13701376
}
@@ -1396,35 +1402,35 @@ public final void setEnabledProtocols(String[] protocols) {
13961402
if (!OpenSsl.SUPPORTED_PROTOCOLS_SET.contains(p)) {
13971403
throw new IllegalArgumentException("Protocol " + p + " is not supported.");
13981404
}
1399-
if (p.equals(OpenSsl.PROTOCOL_SSL_V2)) {
1405+
if (p.equals(PROTOCOL_SSL_V2)) {
14001406
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2) {
14011407
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2;
14021408
}
14031409
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2) {
14041410
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV2;
14051411
}
1406-
} else if (p.equals(OpenSsl.PROTOCOL_SSL_V3)) {
1412+
} else if (p.equals(PROTOCOL_SSL_V3)) {
14071413
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3) {
14081414
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3;
14091415
}
14101416
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3) {
14111417
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_SSLV3;
14121418
}
1413-
} else if (p.equals(OpenSsl.PROTOCOL_TLS_V1)) {
1419+
} else if (p.equals(PROTOCOL_TLS_V1)) {
14141420
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1) {
14151421
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1;
14161422
}
14171423
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1) {
14181424
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1;
14191425
}
1420-
} else if (p.equals(OpenSsl.PROTOCOL_TLS_V1_1)) {
1426+
} else if (p.equals(PROTOCOL_TLS_V1_1)) {
14211427
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1) {
14221428
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1;
14231429
}
14241430
if (maxProtocolIndex < OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1) {
14251431
maxProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_1;
14261432
}
1427-
} else if (p.equals(OpenSsl.PROTOCOL_TLS_V1_2)) {
1433+
} else if (p.equals(PROTOCOL_TLS_V1_2)) {
14281434
if (minProtocolIndex > OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2) {
14291435
minProtocolIndex = OPENSSL_OP_NO_PROTOCOL_INDEX_TLSv1_2;
14301436
}

handler/src/main/java/io/netty/handler/ssl/SslUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
*/
3737
final class SslUtils {
3838

39+
// Protocols
40+
static final String PROTOCOL_SSL_V2_HELLO = "SSLv2Hello";
41+
static final String PROTOCOL_SSL_V2 = "SSLv2";
42+
static final String PROTOCOL_SSL_V3 = "SSLv3";
43+
static final String PROTOCOL_TLS_V1 = "TLSv1";
44+
static final String PROTOCOL_TLS_V1_1 = "TLSv1.1";
45+
static final String PROTOCOL_TLS_V1_2 = "TLSv1.2";
46+
3947
/**
4048
* change cipher spec
4149
*/

handler/src/test/java/io/netty/handler/ssl/JdkSslEngineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ public void testAlpnCompatibleProtocolsDifferentClientOrder() throws Exception {
271271

272272
@Test
273273
public void testEnablingAnAlreadyDisabledSslProtocol() throws Exception {
274-
testEnablingAnAlreadyDisabledSslProtocol(new String[]{}, new String[]{PROTOCOL_TLS_V1_2});
274+
testEnablingAnAlreadyDisabledSslProtocol(new String[]{}, new String[]{ SslUtils.PROTOCOL_TLS_V1_2 });
275275
}
276276

277277
@Ignore /* Does the JDK support a "max certificate chain length"? */

0 commit comments

Comments
 (0)