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

HostNameInCertificate Fix #644

Merged
merged 7 commits into from
May 29, 2018
Merged
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 @@ -116,6 +116,8 @@ public class SQLServerConnection implements ISQLServerConnection {
private byte[] accessTokenInByte = null;

private SqlFedAuthToken fedAuthToken = null;

private String originalHostNameInCertificate = null;

static class Sha1HashKey {
private byte[] bytes;
Expand Down Expand Up @@ -401,7 +403,7 @@ private enum State {
ServerPortPlaceHolder getRoutingInfo() {
return routingInfo;
}

// Permission targets
private static final String callAbortPerm = "callAbort";

Expand Down Expand Up @@ -1198,6 +1200,23 @@ Connection connectInternal(Properties propsIn,
activeConnectionProperties = (Properties) propsIn.clone();

pooledConnectionParent = pooledConnection;

String hostNameInCertificate = activeConnectionProperties.
getProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString());

// hostNameInCertificate property can change when redirection is involved, so maintain this value
// for every instance of SQLServerConnection.
if (null == originalHostNameInCertificate && null != hostNameInCertificate && !hostNameInCertificate.isEmpty()) {
originalHostNameInCertificate = activeConnectionProperties.
getProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString());
}

if (null != originalHostNameInCertificate && !originalHostNameInCertificate.isEmpty()) {
// if hostNameInCertificate has a legitimate value (and not empty or null),
// reset hostNameInCertificate to the original value every time we connect (or re-connect).
activeConnectionProperties.setProperty(SQLServerDriverStringProperty.HOSTNAME_IN_CERTIFICATE.toString(),
originalHostNameInCertificate);
}

String sPropKey;
String sPropValue;
Expand Down Expand Up @@ -3680,7 +3699,6 @@ final void processEnvChange(TDSReader tdsReader) throws SQLServerException {

isRoutedInCurrentAttempt = true;
routingInfo = new ServerPortPlaceHolder(routingServerName, routingPortNumber, null, integratedSecurity);

break;

// Error on unrecognized, unused ENVCHANGES
Expand Down