I created three certificate by using openssl
- Root CA certificate
- Server certificate
- Client certificate
Server side configuration :
I installed server.cer(peronal folder) and RootCA(trust root certification authority folder) on server machine.Then i attached the server certificate to MSSSQL(SQL Configuration manager->MSSQL properties->certificate dropdown). Made the Force Encryption to No and restarted the service.
Client side configuration:
I installed client.cer(peronal folder) and RootCA(trust root certification authority folder).
Below are the steps to create RootCA(CertAuthority) and server.cert and client.crt :
openssl genrsa -des3 -out CertAuthority.key 4096
openssl req -new -x509 -days 3650 -key CertAuthority.key -out CertAuthority.crt
openssl req -new -sha256 -key CertAuthority.key -out server.csr
openssl x509 -req -days 3650 -in server.csr -CA CertAuthority.crt -CAkey CertAuthority.key -set_serial 01 -out server.crt
openssl req -new -sha256 -key CertAuthority.key -out client.csr
openssl x509 -req -days 3650 -in client.csr -CA CertAuthority.crt -CAkey CertAuthority.key -set_serial 01 -out client.crt
Details given at the time of CertAuthority.crt creation
Common Name : asia.com
Country : IN
remaining fields are left blank
Details given at the time of server.crt creation
Common Name : Myserver.asia.com
Country : IN
remaining fields are left blank
Details given at the time of Client.crt creation
Common Name : Myclient.asia.com
Country : IN
remaining fields are left blank
Here is the connection string i am using for sqlclient
Data Source=Myserver;Initial Catalog=MyDB;User ID=sa;Password=;Connect Timeout=30;Encrypt=True;TrustServerCertificate=False
Whenever i am trying to connect via SQLOLEDB provider by using "Use Encryption For Data=True" as an alternate of Encrypt and TrustServerCertificate property, I am able to establish SSL connection successfully.
But by using SqlConnection i am getting following error: A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.)
Can somebody help me out in this regard. Thanks