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

Check tls protocol version and throw warning #1322

Merged
merged 3 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.security.Security;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.sql.SQLWarning;
import java.sql.Timestamp;
import java.text.MessageFormat;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -1593,6 +1594,9 @@ enum SSLHandhsakeState {
SSL_HANDHSAKE_COMPLETE
}

static final String TLS_1 = "TLSv1";
rene-ye marked this conversation as resolved.
Show resolved Hide resolved
static final String TLS_1_1 = "TLSv1.1";

/**
* Enables SSL Handshake.
*
Expand Down Expand Up @@ -1797,6 +1801,15 @@ else if (con.getTrustManagerClass() != null) {
// don't close proxy when SSL socket is closed
sslSocket = (SSLSocket) sslContext.getSocketFactory().createSocket(proxySocket, host, port, false);

// Check the TLS version
String tlsProtocol = sslSocket.getSession().getProtocol();
if (TLS_1.equalsIgnoreCase(tlsProtocol) || TLS_1_1.equalsIgnoreCase(tlsProtocol)) {
String warningMsg = tlsProtocol
+ " was negotiated. Please update server and client to use TLSv1.2 at minimum.";
logger.warning(warningMsg);
con.addWarning(warningMsg);
}

// At long last, start the SSL handshake ...
if (logger.isLoggable(Level.FINER))
logger.finer(toString() + " Starting SSL handshake");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3572,7 +3572,7 @@ public SQLWarning getWarnings() throws SQLServerException {
}

// Any changes to SQLWarnings should be synchronized.
private void addWarning(String warningString) {
void addWarning(String warningString) {
synchronized (warningSynchronization) {
SQLWarning warning = new SQLWarning(warningString);

Expand Down