Skip to content

Commit

Permalink
Fix | Validate Certificate expiry date when creating encrypted connec…
Browse files Browse the repository at this point in the history
…tion (#1394)
  • Loading branch information
rene-ye authored Jul 29, 2020
1 parent 0db30ad commit 3ba5e89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1486,12 +1486,20 @@ public void checkClientTrusted(X509Certificate[] chain, String authType) throws
if (logger.isLoggable(Level.FINEST))
logger.finest(logContext + " Forwarding ClientTrusted.");
defaultTrustManager.checkClientTrusted(chain, authType);
// Explicitly validate the expiry dates
for (X509Certificate cert : chain) {
cert.checkValidity();
}
}

public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
if (logger.isLoggable(Level.FINEST))
logger.finest(logContext + " Forwarding Trusting server certificate");
defaultTrustManager.checkServerTrusted(chain, authType);
// Explicitly validate the expiry dates
for (X509Certificate cert : chain) {
cert.checkValidity();
}
if (logger.isLoggable(Level.FINEST))
logger.finest(logContext + " default serverTrusted succeeded proceeding with server name validation");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.security.NoSuchAlgorithmException;
import java.security.Signature;
import java.security.SignatureException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.text.MessageFormat;

Expand All @@ -34,11 +32,6 @@ class CertificateDetails {

CertificateDetails(X509Certificate certificate, Key privateKey) throws SQLServerException {
this.certificate = certificate;
try {
certificate.checkValidity();
} catch (CertificateExpiredException | CertificateNotYetValidException e) {
SQLServerException.makeFromDriverError(null, this, e.getLocalizedMessage(), "", false);
}
this.privateKey = privateKey;
}
}
Expand Down

0 comments on commit 3ba5e89

Please sign in to comment.