Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1520 upgrade TLS version to minimum 1.2 #1521

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -868,11 +868,7 @@ private static SSLContext createSSLContext(final KeyStore keyStore, final KeySto

SSLContext sslContext;
try {
if(!client) {
sslContext = SSLContext.getInstance("TLS");
} else {
sslContext = SSLContext.getInstance("TLS");
}
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Unable to create and initialise the SSLContext", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,7 @@ private static SSLContext createSSLContext(final KeyStore keyStore, final KeySto

SSLContext sslContext;
try {
if(!client) {
sslContext = SSLContext.getInstance("TLS");
} else {
sslContext = SSLContext.getInstance("TLS");
}
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Unable to create and initialise the SSLContext", e);
Expand Down
5 changes: 4 additions & 1 deletion client/src/main/java/com/networknt/client/Http2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class Http2Client {
static final String KEY_STORE = "keyStore";
static final String KEY_STORE_PASS = "keyStorePass";
static final String KEY_PASS = "keyPass";
static final String TLS_VERSION = "tlsVersion";
static final String KEY_STORE_PROPERTY = "javax.net.ssl.keyStore";
static final String KEY_STORE_PASSWORD_PROPERTY = "javax.net.ssl.keyStorePassword";
static final String TRUST_STORE_PROPERTY = "javax.net.ssl.trustStore";
Expand Down Expand Up @@ -697,7 +698,9 @@ public static SSLContext createSSLContext(String trustedNamesGroupKey) throws IO
}

try {
sslContext = SSLContext.getInstance("TLS");
String tlsVersion = (String)tlsMap.get(TLS_VERSION);
if(tlsVersion == null) tlsVersion = "TLSv1.2";
sslContext = SSLContext.getInstance(tlsVersion);
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Unable to create and initialise the SSLContext", e);
Expand Down
3 changes: 3 additions & 0 deletions client/src/main/resources/config/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tls:
keyStorePass: ${client.keyStorePass:password}
# private key password
keyPass: ${client.keyPass:password}
# TLS version. Default is TSLv1.2, and you can downgrade to TLSv1 to support some internal old servers that support only TLSv1.1(deprecated
# and risky). You can also upgrade to TSLv1.3 for maximum security if all your servers support it.
tlsVersion: ${client.tlsVersion:TLSv1.2}
# settings for OAuth2 server communication
oauth:
# OAuth 2.0 token endpoint configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ protected static SSLContext createSSLContext(final KeyStore keyStore, final KeyS

SSLContext sslContext;
try {
if(!client) {
sslContext = SSLContext.getInstance("TLS");
} else {
sslContext = SSLContext.getInstance("TLS");
}
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Unable to create and initialise the SSLContext", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,7 @@ private static SSLContext createSSLContext(final KeyStore keyStore, final KeySto

SSLContext sslContext;
try {
if(!client) {
sslContext = SSLContext.getInstance("TLS");
} else {
sslContext = SSLContext.getInstance("TLS");
}
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Unable to create and initialise the SSLContext", e);
Expand Down Expand Up @@ -613,7 +609,7 @@ private static SSLContext createTestSSLContext(boolean verifyHostName, String tr
}

try {
sslContext = SSLContext.getInstance("TLS");
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);

} catch (NoSuchAlgorithmException | KeyManagementException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;

import static com.networknt.client.Http2Client.TLS_VERSION;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -873,7 +874,7 @@ private static SSLContext createTestSSLContext(boolean verifyHostName, String tr
}

try {
sslContext = SSLContext.getInstance("TLS");
sslContext = SSLContext.getInstance((String)tlsMap.get(TLS_VERSION));
sslContext.init(keyManagers, trustManagers, null);

} catch (NoSuchAlgorithmException | KeyManagementException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,7 @@ private static SSLContext createSSLContext(final KeyStore keyStore, final KeySto

SSLContext sslContext;
try {
if(!client) {
sslContext = SSLContext.getInstance("TLS");
} else {
sslContext = SSLContext.getInstance("TLS");
}
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Unable to create and initialise the SSLContext", e);
Expand Down
3 changes: 3 additions & 0 deletions client/src/test/resources/config/client-multiple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tls:
keyStorePass: ${client.keyStorePass:password}
# private key password
keyPass: ${client.keyPass:password}
# TLS version. Default is TSLv1.2, and you can downgrade to TLSv1 to support some internal old servers that support only TLSv1.1(deprecated
# and risky). You can also upgrade to TSLv1.3 for maximum security if all your servers support it.
tlsVersion: ${client.tlsVersion:TLSv1.2}
# settings for OAuth2 server communication
oauth:
# OAuth 2.0 token endpoint configuration
Expand Down
3 changes: 3 additions & 0 deletions client/src/test/resources/config/client-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tls:
keyStorePass: ${client.keyStorePass:password}
# private key password
keyPass: ${client.keyPass:password}
# TLS version. Default is TSLv1.2, and you can downgrade to TLSv1 to support some internal old servers that support only TLSv1.1(deprecated
# and risky). You can also upgrade to TSLv1.3 for maximum security if all your servers support it.
tlsVersion: ${client.tlsVersion:TLSv1.2}
# settings for OAuth2 server communication
oauth:
# OAuth 2.0 token endpoint configuration
Expand Down
3 changes: 3 additions & 0 deletions client/src/test/resources/config/client-single.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tls:
keyStorePass: ${client.keyStorePass:password}
# private key password
keyPass: ${client.keyPass:password}
# TLS version. Default is TSLv1.2, and you can downgrade to TLSv1 to support some internal old servers that support only TLSv1.1(deprecated
# and risky). You can also upgrade to TSLv1.3 for maximum security if all your servers support it.
tlsVersion: ${client.tlsVersion:TLSv1.2}
# settings for OAuth2 server communication
oauth:
# OAuth 2.0 token endpoint configuration
Expand Down
3 changes: 3 additions & 0 deletions client/src/test/resources/config/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ tls:
keyStorePass: password
# private key password
keyPass: password
# TLS version. Default is TSLv1.2, and you can downgrade to TLSv1 to support some internal old servers that support only TLSv1.1(deprecated
# and risky). You can also upgrade to TSLv1.3 for maximum security if all your servers support it.
tlsVersion: ${client.tlsVersion:TLSv1.2}
# settings for OAuth2 server communication
oauth:
# OAuth 2.0 token endpoint configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private SSLContext createSSLContext() throws IOException {
}

try {
sslContext = SSLContext.getInstance("TLS");
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
logger.error("Exception:", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ protected static SSLContext createSSLContext(final KeyStore keyStore, final KeyS

SSLContext sslContext;
try {
if(!client) {
sslContext = SSLContext.getInstance("TLS");
} else {
sslContext = SSLContext.getInstance("TLS");
}
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new IOException("Unable to create and initialise the SSLContext", e);
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/com/networknt/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ private static SSLContext createSSLContext() throws RuntimeException {
}

SSLContext sslContext;
sslContext = SSLContext.getInstance("TLSv1");
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(keyManagers, trustManagers, null);
return sslContext;
} catch (Exception e) {
Expand Down