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

[Azure] Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization #623

Closed
dspereira004 opened this issue Feb 7, 2018 · 15 comments
Assignees

Comments

@dspereira004
Copy link

Driver version or jar name

6.3.6

SQL Server version

Microsoft SQL Azure (RTM) - 12.0.2000.8

Client operating system

Ubuntu 16.04

Java/JVM version

java version "1.8.0_161"

Table schema

N/A

Problem description

Using the mentioned version of the mssql-jdbc, and connecting to SQL Server on
Azure with a jdbc string provided by Azure, which includes the following
properties:

  • sqlserver
  • database
  • user
  • password
  • encrypt (with value 'true')
  • trustServerCertificate (with value 'false')
  • hostNameInCertificate (with value '*.database.windows.net')
  • loginTimeout (with value '30')

We are getting sometimes the following stacktrace:

com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization.". ClientConnectionId:d5e13b9e-546d-417c-be63-abfece6929fe
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2675)
	at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1837)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:2262)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1927)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1768)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:1076)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.checkClosed(SQLServerConnection.java:1011)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.createStatement(SQLServerConnection.java:3161)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.createStatement(SQLServerConnection.java:2843)
	at com.feedzai.commons.sql.abstraction.engine.impl.SqlServerEngine.checkConnection(SqlServerEngine.java:743)
	at com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine.getConnection(AbstractDatabaseEngine.java:273)
	at com.feedzai.commons.sql.abstraction.engine.AbstractDatabaseEngine.beginTransaction(AbstractDatabaseEngine.java:416)
	at com.feedzai.pulse.service.apps.util.ThreadScopeTransactionFun.beginTx(ThreadScopeTransactionFun.java:331)
	at com.feedzai.pulse.service.apps.util.ThreadScopeTransactionFun.transaction(ThreadScopeTransactionFun.java:280)
	at com.feedzai.pulse.service.apps.util.ThreadScopeTransactionFun.call(ThreadScopeTransactionFun.java:257)
	at com.feedzai.pulse.service.apps.database.TransactionInterceptor.invoke(TransactionInterceptor.java:91)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:77)
	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:55)
	at com.feedzai.pulse.service.apps.manager.RoleManagerImpl$$EnhancerByGuice$$eba0945d.list(<generated>)
	at com.feedzai.pulse.service.security.projection.Projection.reload(Projection.java:72)
	at com.feedzai.pulse.service.security.PulseSecurityImpl.doReloadSecurity(PulseSecurityImpl.java:287)
	at com.feedzai.pulse.service.security.PulseSecurityImpl.lambda$reloadSecurityLocally$2(PulseSecurityImpl.java:349)
	at com.feedzai.pulse.service.security.PulseSecurityUtils.lambda$doAsSystemUser$0(PulseSecurityUtils.java:268)
	at com.feedzai.pulse.service.security.PulseSecurityUtils.getAsSystemUser(PulseSecurityUtils.java:286)
	at com.feedzai.pulse.service.security.PulseSecurityUtils.doAsSystemUser(PulseSecurityUtils.java:267)
	at com.feedzai.pulse.service.security.PulseSecurityImpl.reloadSecurityLocally(PulseSecurityImpl.java:341)
	at com.feedzai.pulse.service.security.PulseSecurityImpl.reloadSecurityInCluster(PulseSecurityImpl.java:506)
	at com.feedzai.pulse.service.security.PulseSecurityImpl.reloadSecurity(PulseSecurityImpl.java:272)
	at com.feedzai.pulse.service.apps.util.ThreadScopeTransactionFun.reloadSecurity(ThreadScopeTransactionFun.java:460)
	at com.feedzai.pulse.service.apps.util.ThreadScopeTransactionFun.commitTx(ThreadScopeTransactionFun.java:413)
	at com.feedzai.pulse.service.apps.util.ThreadScopeTransactionFun.transaction(ThreadScopeTransactionFun.java:294)
	at com.feedzai.pulse.service.apps.util.ThreadScopeTransactionFun.call(ThreadScopeTransactionFun.java:257)
	at com.feedzai.pulse.service.apps.database.TransactionInterceptor.invoke(TransactionInterceptor.java:91)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:77)
	at com.feedzai.pulse.service.security.guice.EnforcePermissionsInterceptor.invoke(EnforcePermissionsInterceptor.java:55)
	at com.google.inject.internal.InterceptorStackCallback$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:77)
	at com.google.inject.internal.InterceptorStackCallback.intercept(InterceptorStackCallback.java:55)
	at com.feedzai.pulse.service.apps.manager.datascience.AppDataScienceTagGroupManagerImpl$$EnhancerByGuice$$2b7a2b98.ensureTags(<generated>)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.feedzai.remote.autowire.remote.RemoteWrapperImpl.invokeRemotely(RemoteWrapperImpl.java:102)
	at sun.reflect.GeneratedMethodAccessor60.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:361)
	at sun.rmi.transport.Transport$1.run(Transport.java:200)
	at sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
	at java.security.AccessController.doPrivileged(Native Method)
	at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization.
	at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
	at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1959)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:328)
	at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:322)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1614)
	at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216)
	at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
	at sun.security.ssl.Handshaker.process_record(Handshaker.java:987)
	at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
	at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
	at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1767)
	... 57 common frames omitted
Caused by: java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization.
	at com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager.validateServerNameInCertificate(IOBuffer.java:1547)
	at com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager.checkServerTrusted(IOBuffer.java:1462)
	at sun.security.ssl.AbstractTrustManagerWrapper.checkServerTrusted(SSLContextImpl.java:985)
	at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1596)
	... 65 common frames omitted
    

This problem happens when the "hostNameInCertificate" property is changed by the driver on the SQLServerConnection class (because of a ENVCHANGE_ROUTING).

In that case, the original "hostNameInCertificate" (which comes from the jdbc string provided by Azure) is replaced by the routing server name.

This will trigger an exception on the method validateServerNameInCertificate since the routing server name does not exist on the certificate.

Expected behavior and actual behavior

Probably, the "hostNameInCertificate" property shouldn't be changed the way it is currently being done, because there are no guarantees that afterward, we will validate the server name in the certificate successfully.

The expected behavior is that this error shouldn't happen since we are providing a correct "hostNameInCertificate" (and which works fine until we have that ENVCHANGE_ROUTING event).

Repro code

Setup on an Azure account both a SQL Server/Database and a VM with a client that uses the mssql-jdbc lib and perform operations with it.

As said previously, this happens from time to time so it may take a little bit to reproduce this behavior.

@peterbae
Copy link
Contributor

peterbae commented Feb 9, 2018

Hi @dspereira004, the processEnvChange method from SQLServerConnection is called when the server has detected an environment change (database context, language setting, etc) as part of the login response. Specifically, the ENVCHANGE_ROUTING token is sent from the server to the driver if the server wants to route the client to an alternate server. I believe the JDBC Driver is changing the "hostNameInCertificate" property because the server has requested to change it, and we need to find out why. (I ran some basic queries against SQL database on azure for a while, but I was not able to reproduce the issue).

Do you have some ideas as to why this might be happening? If you could let me know what the server is trying to set the new host name to, that would help too. (by enabling the logger and setting it to level "finer" or higher in your application).

@dspereira004
Copy link
Author

Hi, unfortunately, I don't have any idea as I haven't taken a deeper look on this.

I forgot to mention, but this is happening when we are executing batches.

I don't have the logs yet, but I took a screenshot when I was debugging to understand what was happening. There you can see the actual (current) hostname and the new one, before crashing on the validateServerNameInCertificate method.
image

In the meantime, I will try to get those logs.

@jschrap
Copy link

jschrap commented Feb 27, 2018

We're experiencing a similar issue. Also intermittently.

@peterbae
Copy link
Contributor

peterbae commented Mar 5, 2018

Hi @dspereira004, @jschrap, I've made a fix in this branch, and the PR #644 is currently in review. In the meantime, you can test the changes by forking that branch.

@peterbae
Copy link
Contributor

Hi @dspereira004, @jschrap, have you had a chance to test out my fixes for this issue? Thanks!

@jschrap
Copy link

jschrap commented Mar 14, 2018 via email

@dspereira004
Copy link
Author

@peterbae I haven't tried with your branch yet. However, I did try to reproduce the problem that I reported to get those logs but didn't succeed anymore. I'm not sure why, but perhaps something changed on the routing side?

@aaronswebs
Copy link

@peterbae I am having a similar issue and have just compiled your branch. I am still getting the same issue with 'failed to validate the server name in certificate' with your branch. This was working three days ago using mssql-jdbc-6.4.0.jre9 on jdk 9 then stopped for no reason or change to codebase / libs.

INER: TDSChannel (ConnectionID:1) Starting SSL handshake
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): Validating the server name:*.database.windows.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The DN name in certificate:cn=datasec-wus2-2-a3.cloudapp.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate datasec-wus2-2-a3.cloudapp.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager):Key: 2; KeyClass:class java.lang.Integer;value: *.database.secure.windows.net; valueClass:class java.lang.String
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate *.database.secure.windows.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): the following name in certificate does not match the serverName: *.database.secure.windows.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager):Key: 2; KeyClass:class java.lang.Integer;value: datasec-wus2-2-a3.cloudapp.net; valueClass:class java.lang.String
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate datasec-wus2-2-a3.cloudapp.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): the following name in certificate does not match the serverName: datasec-wus2-2-a3.cloudapp.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$ProxySocket close
F

@peterbae
Copy link
Contributor

peterbae commented Mar 21, 2018

Hi @rangala, thanks for the detailed information. The response from multiple customers over the past week and their inability to reproduce the issue all of a sudden leads me to believe that this problem might've been coming from the server's (Azure) end. That said, I can see that your SSL certificate has the entry *.database.secure.windows, instead of *.database.windows.net. this page as well as other resources suggest to me that your server might have security/auditing features on, in which case could try putting *.database.secure.windows in your hostNameInCertificate connecting string. Could you let me know if this solves your problem?

@aaronswebs
Copy link

Thanks @peterbae you are correct that auditing was enabled. I have provided another driver trace below. it actually makes two SSL handshakes. First SSL handshake is successful, then the second is with *.database.secure.windows.net as per the trace. Turning off auditing solves the problem and connects.

I can't find reference on inserting multiple hostNameCertificates entries into the connection properties, so the only work around is to set trustServerCertificate = true.

FINER: TDSChannel (ConnectionID:1) Starting SSL handshake
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): Validating the server name:*.database.windows.net
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The DN name in certificate:cn=westus2-a.control.database.windows.net
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate westus2-a.control.database.windows.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager):Key: 2; KeyClass:class java.lang.Integer;value: management.westus2-a.control.database.windows.net; valueClass:class java.lang.String
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate management.westus2-a.control.database.windows.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): the following name in certificate does not match the serverName: management.westus2-a.control.database.windows.net
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager):Key: 2; KeyClass:class java.lang.Integer;value: management.westus2.control.database.windows.net; valueClass:class java.lang.String
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate management.westus2.control.database.windows.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): the following name in certificate does not match the serverName: management.westus2.control.database.windows.net
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager):Key: 2; KeyClass:class java.lang.Integer;value: .database.windows.net; valueClass:class java.lang.String
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate:
.database.windows.net validated against server name *.database.windows.net.
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): found a valid name in certificate: .database.windows.net
Mar. 21, 2018 12:14:58 PM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) SSL enabled
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection processEnvChange
FINER: ConnectionID:1 ClientConnectionId: 77d3c977-a60d-4c31-ba90-5819357025fa Received routing ENVCHANGE with the following values. routingDataValueLength:75 protocol:0 portNumber:1433 serverNameLength:35 serverName:aarondw.database.secure.windows.net
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection processEnvChange
FINER: ConnectionID:1 ClientConnectionId: 77d3c977-a60d-4c31-ba90-5819357025fa Network packet size is 8000 bytes
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.TDSChannel disableSSL
FINER: TDSChannel (ConnectionID:1) Disabling SSL...
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.TDSChannel disableSSL
FINER: TDSChannel (ConnectionID:1) Closing SSL socket
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.TDSChannel disableSSL
FINER: TDSChannel (ConnectionID:1) SSL disabled
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.TDSChannel close
FINER: TDSChannel (ConnectionID:1): Closing TCP socket...
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection login
FINE: ConnectionID:1 This attempt server name: aarondw.database.secure.windows.net port: 1433 InstanceName: null useParallel: false
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection login
FINE: ConnectionID:1 This attempt endtime: 1521594908909
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection login
FINE: ConnectionID:1 This attempt No: 1
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection connectHelper
FINE: ConnectionID:1 Connecting with server: aarondw.database.secure.windows.net port: 1433 Timeout slice: 9855 Timeout Full: 15
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.TDSChannel open
FINER: TDSChannel (ConnectionID:1): Opening TCP socket...
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 Requesting encryption level:ON
Mar. 21, 2018 12:14:59 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 ActivityId 8c79d302-2efe-465d-b1aa-ba22f5320bcb-2
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINE: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 Server returned major version:12
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 Negotiated encryption level:REQUIRED
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 Ignoring prelogin response option:2
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 Ignoring prelogin response option:3
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 Ignoring prelogin response option:4
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.SQLServerConnection Prelogin
FINER: ConnectionID:1 ClientConnectionId: b30621bd-d9fe-4793-a449-f9655433f431 Ignoring prelogin response option:5
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) Enabling SSL...
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) SSL handshake will validate server certificate
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) Using system default trust store and password
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: TDSChannel (ConnectionID:1) Starting SSL handshake
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): Validating the server name:
.database.windows.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The DN name in certificate:cn=datasec-wus2-2-a3.cloudapp.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate datasec-wus2-2-a3.cloudapp.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager):Key: 2; KeyClass:class java.lang.Integer;value: *.database.secure.windows.net; valueClass:class java.lang.String
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate *.database.secure.windows.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): the following name in certificate does not match the serverName: *.database.secure.windows.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager):Key: 2; KeyClass:class java.lang.Integer;value: datasec-wus2-2-a3.cloudapp.net; valueClass:class java.lang.String
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerName
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): The name in certificate datasec-wus2-2-a3.cloudapp.net does not match with the server name *.database.windows.net.
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$HostNameOverrideX509TrustManager validateServerNameInCertificate
FINER: TDSChannel (ConnectionID:1) (HostNameOverrideX509TrustManager): the following name in certificate does not match the serverName: datasec-wus2-2-a3.cloudapp.net
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel$ProxySocket close
FINER: TDSChannel (ConnectionID:1) (ProxySocket): Ignoring close
Mar. 21, 2018 12:15:00 PM com.microsoft.sqlserver.jdbc.TDSChannel enableSSL
FINER: java.security.cert.CertificateException: Failed to validate the server name in a certificate during Secure Sockets Layer (SSL) initialization.

@peterbae
Copy link
Contributor

Hi @rangala, thanks for the detailed information. Did you produce the most recent log with mssql-jdbc-6.4.0.jre9 or with my own branch? (I don't think my branch should be used if the problem was solved on Azure's end) If you haven't already, could you try using hostNameInCertificate=*.database.secure.windows with mssql-jdbc-6.4.0.jre9 driver, and see if the error still persists? Thanks in advance.

@peterbae
Copy link
Contributor

peterbae commented Apr 3, 2018

Hi @rangala, were you able to try out my previous suggestion, or has the problem been solved on your end?

@peterbae
Copy link
Contributor

peterbae commented Apr 6, 2018

I believe the underlying issue (coming from Azure) has been solved, and there's no action due on the driver's end. Closing due to inactivity & problem solved - but please feel free to open this issue if more assistance is required.

@peterbae peterbae closed this as completed Apr 6, 2018
@peterbae
Copy link
Contributor

Looks like the problem is still here. Opening the issue again.

@peterbae peterbae reopened this May 14, 2018
@peterbae
Copy link
Contributor

Merged #644, closing issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants