-
Notifications
You must be signed in to change notification settings - Fork 285
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
Managed SNI (TCP) doesn't handle localhost for Certificate validation, fails during pre-login #2112
Comments
I figured this is due to HostName in certificate being set to Machine name as I use Mitigation: Specify |
@cheenamalhotra alias name could be added to SANs, but for instances of of SQL server I found this article. I can do some testing to validate it. On some other note for managed SNI we can also test with this PR to see more info and check at what part it fails. I will do more testing to get an answer to the question and will get back to you on this. If you test with Net7.0 all the SANs will be validated. |
After investigating the issue it seems that if you provide Read access to private key for the instance name it works fine. for example if the user name for default instance is |
here is how I created a self-signed certificate # Get FQDN of the machine
$fqdn = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName
Write-Host $fqdn
# Create a self-signed certificate
$params = @{
Type = "SSLServerAuthentication"
Subject = "CN=$fqdn"
KeyAlgorithm = "RSA"
KeyLength = 2048
HashAlgorithm = "SHA256"
TextExtension = "2.5.29.37={text}1.3.6.1.5.5.7.3.1", "2.5.29.17={text}DNS=$fqdn&DNS=localhost&IPAddress=127.0.0.1&IPAddress=::1"
NotAfter = (Get-Date).AddMonths(36)
KeySpec = "KeyExchange"
Provider = "Microsoft RSA SChannel Cryptographic Provider"
CertStoreLocation = "Cert:\LocalMachine\My"
}
$certificate = New-SelfSignedCertificate @params
Write-Host "Certificate created successfully"
Write-Host "Certificate Thumbprint: $($certificate.Thumbprint)" This part $fqdn = [System.Net.Dns]::GetHostByName(($env:computerName)).HostName will get the full name if there is a domain instead of computer name. |
This issue may be related to #2115. Currently, Native SNI requires the computer name as SAN in the certificate while managed SNI requires |
@cheenamalhotra can you provide server setup and certificate setup process please? |
SQL Server is below, running in a managed instance:
I created self signed certificate using $cert = New-SelfSignedCertificate -Subject {machine name}
$cert | Format-List -Property * Attach this certificate to the SQL instance running and attempt connection. |
@cheenamalhotra can you test with the latest SNI hotfix release to see if the behavior identical for managed and native code? |
Closing the issue as SNI hotfix has addressed the issue. |
Describe the bug
Managed SNI fails to validate remote certificate for some reason, even though I am able to make connection successfully with Native SNI.
Actual error
To reproduce
Console app targeting .NET 6/7
Expected behavior
Connect.
Further technical details
Microsoft.Data.SqlClient version: 5.1.1, main
.NET target: .NET 6/7
Microsoft SQL Server 2022 (RTM-GDR) (KB5021522) - 16.0.1050.5 (X64)
Jan 23 2023 17:02:42
Copyright (C) 2022 Microsoft Corporation
Developer Edition (64-bit) on Windows 10 Pro 10.0 (Build 22621: ) (Hypervisor)
Operating system: Windows 11
The text was updated successfully, but these errors were encountered: