forked from denisenkom/go-mssqldb
-
Notifications
You must be signed in to change notification settings - Fork 91
Validate server certificate by byte comparison when certificate is provided #305
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
Open
Copilot
wants to merge
16
commits into
main
Choose a base branch
from
copilot/ignore-host-name-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
244a007
Initial plan
Copilot c0a2a2e
Implement certificate hostname validation skip for strict encryption
Copilot 8b0692d
Fix certificate verification logic to use Roots instead of Intermediates
Copilot c6eb984
Add nil checks for PeerCertificates and fix duplicate comment
Copilot afa3e49
Remove InsecureSkipVerify from setupTLSCertificateOnly, use VerifyPee…
Copilot edfd563
Fix intermediate certificate handling in setupTLSCommonName
Copilot 1c8901e
Improve comments and optimize intermediate cert handling
Copilot 688fe04
Fix TLS handshake error by using InsecureSkipVerify with VerifyPeerCe…
Copilot dc5d261
Add security documentation explaining InsecureSkipVerify usage
Copilot cce0e41
Use VerifyConnection instead of InsecureSkipVerify for hostname valid…
Copilot 4fa15a5
Update msdsn/conn_str.go
shueybubbles fac055e
Update msdsn/conn_str_go115pre.go
shueybubbles 415045c
Skip hostname validation for all encryption modes when certificate is…
Copilot 99b21d1
Fix: Use VerifyPeerCertificate instead of VerifyConnection for hostna…
Copilot 768525c
Change certificate validation to byte comparison like Microsoft.Data.…
Copilot b1647fd
Consolidate setupTLSCertificateOnly into conn_str.go
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Disabled TLS certificate check High
Copilot Autofix
AI 1 day ago
In general, the fix is to avoid setting
InsecureSkipVerify = trueand instead rely on Go’s normal TLS verification pipeline, adding a custom verification step that enforces the “certificate only” semantics while keeping hostname and chain validation. This is best accomplished by configuring aVerifyConnectioncallback ontls.Config, which runs after the standard verification has been performed, or by usingVerifyPeerCertificatewithout disabling verification and performing full parsing/validation of the certs yourself.For this specific function, the minimal change that preserves existing behavior while removing
InsecureSkipVerifyis to stop disabling verification and adjust the custom verification to work with the standard flow. The current comment that “VerifyConnection runs AFTER standard verification (including hostname check)” is correct, but we don’t need to mimic that by disabling verification; we can simply rely on the default verification and then enforce the raw‑byte equality. A clean approach is:config.InsecureSkipVerify = true.VerifyPeerCertificatein place, but note that whenInsecureSkipVerifyis false, Go’s docs state that ifVerifyPeerCertificateis set, it is called instead of the default verification, not in addition. To both keep default verification and add our check, we should instead useVerifyConnection.config.VerifyConnection = func(cs tls.ConnectionState) error { ... }, obtain the peer certificate fromcs.PeerCertificates[0], compare itsRawbytes toexpectedCertBytes, and then (optionally) callcs.VerifiedChainsto ensure that standard verification succeeded. However, standard verification has already run, and if it failed, the handshake would not reachVerifyConnection, so we only need to perform the equality check.Because you asked to only change shown code in
msdsn/conn_str.go, the concrete edits will:config.InsecureSkipVerify = true.VerifyPeerCertificateassignment with aVerifyConnectionassignment that comparescs.PeerCertificates[0].RawtoexpectedCertBytes.No new imports are required; we already import
crypto/tls,crypto/x509,bytes, andfmt.