You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add serverCertificate parameter for byte-comparison validation with backward compatibility (#305)
* Initial plan
* Implement certificate hostname validation skip for strict encryption
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Fix certificate verification logic to use Roots instead of Intermediates
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Add nil checks for PeerCertificates and fix duplicate comment
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Remove InsecureSkipVerify from setupTLSCertificateOnly, use VerifyPeerCertificate in setupTLSCommonName
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Fix intermediate certificate handling in setupTLSCommonName
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Improve comments and optimize intermediate cert handling
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Fix TLS handshake error by using InsecureSkipVerify with VerifyPeerCertificate callback
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Add security documentation explaining InsecureSkipVerify usage
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Use VerifyConnection instead of InsecureSkipVerify for hostname validation skip
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Update msdsn/conn_str.go
avoid duplicate RootCAs assignment
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update msdsn/conn_str_go115pre.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Skip hostname validation for all encryption modes when certificate is provided
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Fix: Use VerifyPeerCertificate instead of VerifyConnection for hostname skip
VerifyConnection runs AFTER standard TLS verification (including hostname check),
so it cannot be used to skip hostname validation. Changed back to using
InsecureSkipVerify=true with VerifyPeerCertificate callback, which is the correct
pattern for custom certificate verification that skips hostname checks.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Change certificate validation to byte comparison like Microsoft.Data.SqlClient
Instead of validating certificate chain/expiry/subject, now simply compares
the raw bytes of the server certificate with the provided certificate file.
This matches the behavior of Microsoft.Data.SqlClient and eliminates the
need for complete certificate chains.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Consolidate setupTLSCertificateOnly into conn_str.go
Moved setupTLSCertificateOnly from build-tag-specific files to conn_str.go
since the implementation is identical for all Go versions. This reduces code
duplication and makes the codebase easier to maintain.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Replace fmt.Errorf with errors.New for simple error messages
Changed fmt.Errorf() to errors.New() for error messages without format
specifiers, following Go best practices. This is more idiomatic and efficient.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Update README, CHANGELOG, and version for certificate validation feature
- Added documentation in README.md explaining certificate-based server validation
- Included OpenSSL command example for obtaining server certificates
- Added connection string examples for using certificates with encryption
- Updated CHANGELOG.md with new feature description for v1.9.6
- Incremented version to v1.9.6 in version.go
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Fix CHANGELOG.md: only prepend v1.9.6 without renumbering earlier versions
Reverted the inadvertent renumbering of earlier changelog entries. Now only
v1.9.6 is added at the top while preserving the original version numbers
(1.9.3, 1.9.2, 1.9.1, etc.) for all previous entries.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Add serverCertificate parameter for backward compatibility
To preserve backward compatibility with the existing 'certificate' parameter:
- Added new 'serverCertificate' parameter for byte-comparison validation
- Reverted 'certificate' parameter to traditional X.509 chain validation
- serverCertificate cannot be used with certificate or hostnameincertificate
- Updated README.md with clear documentation of both parameters
- Updated CHANGELOG.md to reflect the new parameter and compatibility
- Updated tests to verify both validation methods
- All msdsn tests pass successfully
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Revert setupTLSCommonName to original implementation for backward compatibility
Restored the original setupTLSCommonName implementation that uses VerifyConnection
instead of VerifyPeerCertificate. This maintains backward compatibility since:
- setupTLSCommonName is only used for the 'certificate' parameter path
- It is not needed for the new 'serverCertificate' parameter functionality
- The original implementation has been in production and should not change unnecessarily
All msdsn tests pass successfully.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Fix SetupTLS function call parameters in tds.go
Fixed parameter order in msdsn.SetupTLS calls to match the updated function
signature that includes both certificate and serverCertificate parameters.
The function signature is:
SetupTLS(certificate, serverCertificate, insecureSkipVerify, hostInCertificate, minTLSVersion)
This resolves the AppVeyor build errors.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
* Address code review feedback: remove trailing whitespace and fix issue reference
- Removed trailing whitespace from lines 257, 265, 271, 279, 321, and 331 in conn_str.go
- Updated CHANGELOG.md to reference issue #304 instead of placeholder #xxx
- Ran go fmt to ensure proper code formatting
All msdsn tests pass successfully.
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: shueybubbles <2224906+shueybubbles@users.noreply.github.com>
Co-authored-by: David Shiflet <david.shiflet@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,12 @@
1
1
# Changelog
2
+
## 1.9.6
3
+
4
+
### Features
5
+
6
+
* Added new `serverCertificate` connection parameter for byte-for-byte certificate validation, matching Microsoft.Data.SqlClient behavior. This parameter skips hostname validation, chain validation, and expiry checks, only verifying that the server's certificate exactly matches the provided file. This is useful when the server's hostname doesn't match the certificate CN/SAN. (#304)
7
+
* The existing `certificate` parameter maintains backward compatibility with traditional X.509 chain validation including hostname checks, expiry validation, and chain-of-trust verification.
8
+
*`serverCertificate` cannot be used with `certificate` or `hostnameincertificate` parameters to prevent conflicting validation methods.
Copy file name to clipboardExpand all lines: README.md
+63-2Lines changed: 63 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,8 +58,9 @@ Other supported formats are listed below.
58
58
*`TrustServerCertificate`
59
59
* false - Server certificate is checked. Default is false if encrypt is specified.
60
60
* true - Server certificate is not checked. Default is true if encrypt is not specified. If trust server certificate is true, driver accepts any certificate presented by the server and any host name in that certificate. In this mode, TLS is susceptible to man-in-the-middle attacks. This should be used only for testing.
61
-
*`certificate` - The file that contains the public key certificate of the CA that signed the SQL Server certificate. The specified certificate overrides the go platform specific CA certificates. Currently, certificates of PEM type are supported.
62
-
*`hostNameInCertificate` - Specifies the Common Name (CN) in the server certificate. Default value is the server host.
61
+
*`certificate` - The file path to a certificate authority (CA) certificate or server certificate for traditional X.509 chain validation. The specified certificate overrides the go platform specific CA certificates. The driver validates the certificate chain, expiry, and hostname. Supports PEM and DER formats.
62
+
*`serverCertificate` - The file path to a server certificate for byte-for-byte comparison validation (new in v1.9.6). The driver validates that the server's certificate exactly matches this file, skipping chain validation, expiry checks, and hostname validation. This matches Microsoft.Data.SqlClient behavior. Cannot be used with `certificate` or `hostnameincertificate`. Supports PEM and DER formats.
63
+
*`hostNameInCertificate` - Specifies the Common Name (CN) in the server certificate. Default value is the server host. Used with the `certificate` parameter, not applicable for `serverCertificate`.
63
64
*`tlsmin` - Specifies the minimum TLS version for negotiating encryption with the server. Recognized values are `1.0`, `1.1`, `1.2`, `1.3`. If not set to a recognized value the default value for the `tls` package will be used. The default is currently `1.2`.
64
65
*`ServerSPN` - The kerberos SPN (Service Principal Name) for the server. Default is MSSQLSvc/host:port.
65
66
*`Workstation ID` - The workstation name (default is the host name)
@@ -204,6 +205,66 @@ For further information on usage:
The driver supports two ways to validate server certificates:
211
+
212
+
#### 1. `serverCertificate` - Byte-for-byte certificate comparison (New in v1.9.6)
213
+
214
+
When you provide a `serverCertificate` parameter, the driver validates the server by comparing the certificate bytes exactly with the provided file. This:
0 commit comments