-
Notifications
You must be signed in to change notification settings - Fork 79
Implement -J flag for server certificate pinning with strict encryption #615
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements the -J flag to enable server certificate pinning for encrypted SQL Server connections. The feature allows users to specify a path to a certificate file (PEM, DER, or CER format) that will be matched exactly against the server's TLS certificate, bypassing standard certificate validation.
Changes:
- Added
ServerCertificatefield toSQLCmdArgumentsandConnectSettingsstructs - Registered
-J/--server-certificateflag with validation requiring encryption to be enabled - Updated go-mssqldb dependency from v1.9.2 to v1.9.6 to support the certificate pinning feature
- Added comprehensive test coverage for valid and invalid flag combinations
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/sqlcmd/sqlcmd.go | Added ServerCertificate field, validation logic, flag registration, and helper function to check encryption modes |
| cmd/sqlcmd/sqlcmd_test.go | Added test cases for valid -J flag usage with different encryption modes and invalid combinations |
| pkg/sqlcmd/connect.go | Added ServerCertificate field to ConnectSettings and passed it to connection string via msdsn.ServerCertificate |
| go.mod | Updated go-mssqldb dependency from v1.9.2 to v1.9.6 |
| go.sum | Updated checksums for go-mssqldb v1.9.6 and added shopspring/decimal v1.4.0 (transitive dependency) |
| .gitignore | Added patterns to ignore certificate files and build artifacts |
Comments suppressed due to low confidence (1)
cmd/sqlcmd/sqlcmd_test.go:1
- The test case on line 123-125 doesn't verify the EncryptConnection value. The validation function should check both fields are set correctly, similar to line 120-122. Add
&& args.EncryptConnection == \"true\"to the return statement.
// Copyright (c) Microsoft Corporation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case a.UseAad && len(a.AuthenticationMethod) > 0: | ||
| err = mutuallyExclusiveError("-G", "--authentication-method") | ||
| case len(a.HostNameInCertificate) > 0 && len(a.ServerCertificate) > 0: | ||
| err = mutuallyExclusiveError("-F", "-J") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is -F here still Format? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hostnameincertificate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I look at sqlcmd -? it has
-F,--format
Specifies the formatting for results
Adds the
-Jflag to specify a server certificate file (PEM, DER, or CER) for certificate pinning when using strict encryption mode. The certificate is matched exactly against the server's TLS certificate, bypassing standard validation (expiry, hostname, trust chain).Changes
ServerCertificatestring field to store certificate path-J/--server-certificateflag with help textmsdsn.Certificateparameter to go-mssqldb driver-Jrequires strict encryption (-N sor-N strict)Usage
The implementation follows the existing pattern for connection flags like
-F(HostNameInCertificate).Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.