mysql icon indicating copy to clipboard operation
mysql copied to clipboard

Registered TLS config cannot be reused between servers

Open jfhamlin opened this issue 9 years ago • 1 comments

Issue description

Follow these steps:

  1. Create an x509.CertPool and add a CA cert valid for two mysql servers (A and B).
  2. Register a TLS config using this cert pool as the root CAs: mysql.RegisterTLSConfig("custom", &tls.Config{ RootCAs: rootCertPool })
  3. Open a connection to a mysql server at hostname A with tls=custom.
  4. Open a connection to a mysql server at hostname B with tls=custom.

Expected: The connection to server B succeeds. Actual: The connection to server B fails with error: x509: certificate is valid for A, not B

See https://github.com/go-sql-driver/mysql/blob/master/dsn.go#L513 for the root cause. The registered config is mutated by the first connection (to A), and thereafter it can only be used to connect to A.

Configuration

Driver version (or git SHA): 2e00b5cd70399450106cec6431c2e2ce3cae5034

Go version: 1.7.1

Server version: MySQL 5.7

Server OS: Ubuntu 15.10

jfhamlin avatar Jan 07 '17 20:01 jfhamlin

Cf. https://github.com/golang/go/blob/master/src/net/http/server.go#L2841

jfhamlin avatar Jan 07 '17 21:01 jfhamlin