Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

Adds the -J flag 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

  • SQLCmdArguments & ConnectSettings: Added ServerCertificate string field to store certificate path
  • Flag registration: Added -J/--server-certificate flag with help text
  • Connection string: Pass certificate path via msdsn.Certificate parameter to go-mssqldb driver
  • Validation: Enforce -J requires strict encryption (-N s or -N strict)
  • Tests: Coverage for valid combinations and invalid usage with non-strict modes

Usage

# Valid: certificate pinning with strict encryption
sqlcmd -S myserver -N s -J /path/to/server.pem

# Invalid: certificate requires strict mode
sqlcmd -S myserver -J /path/to/server.pem
# Error: The -J parameter can only be used with strict encryption mode (-N s or -N strict).

The implementation follows the existing pattern for connection flags like -F (HostNameInCertificate).

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement -J flag to allow a specific server certificate be used to encrypt the connection</issue_title>
<issue_description>-J takes a server certificate. This option can be used with the strict encryption mode (-Ys). This option specifies the path to a certificate file to match against the server's connection encryption certificate. The match is done instead of standard certificate validation (expiry, host name, trust chain, etc.) The accepted certificate formats are PEM, DER, and CER. If specified, the server's certificate is checked by seeing if the server certificate provided is an exact match.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 8, 2026 22:22
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement -J flag to specify server certificate for encryption Implement -J flag for server certificate pinning with strict encryption Jan 8, 2026
Copilot AI requested a review from shueybubbles January 8, 2026 22:30
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

Successfully merging this pull request may close these issues.

Implement -J flag to allow a specific server certificate be used to encrypt the connection

2 participants