-
Notifications
You must be signed in to change notification settings - Fork 18k
crypto/tls: should apply default NextProtos to the result of GetConfigForClient #70214
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
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Comments
Please show a reproducer. package main
import (
"crypto/tls"
"fmt"
"net/http"
)
func main() {
crt, err := tls.LoadX509KeyPair("localhost.pem", "localhost-key.pem")
if err != nil {
panic(err)
}
svr := &http.Server{
Addr: ":8443",
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello world")
}),
TLSConfig: &tls.Config{
GetCertificate: func(chi *tls.ClientHelloInfo) (*tls.Certificate, error) {
return &crt, nil
},
},
}
panic(svr.ListenAndServeTLS("", ""))
} curl: $ curl -v https://localhost:8443/hello
* Couldn't find host localhost in the .netrc file; using defaults
* Host localhost:8443 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
* Trying [::1]:8443...
* ALPN: curl offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: none
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256 / x25519 / RSASSA-PSS
* ALPN: server accepted h2
* Server certificate:
* subject: O=mkcert development certificate; OU=user@hwaryun
* start date: Nov 6 17:36:49 2024 GMT
* expire date: Feb 6 17:36:49 2027 GMT
* subjectAltName: host "localhost" matched cert's "localhost"
* issuer: O=mkcert development CA; OU=user@hwaryun; CN=mkcert user@hwaryun
* SSL certificate verify ok.
* Certificate level 0: Public key type RSA (2048/112 Bits/secBits), signed using sha256WithRSAEncryption
* Certificate level 1: Public key type RSA (3072/128 Bits/secBits), signed using sha256WithRSAEncryption
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* Connected to localhost (::1) port 8443
* using HTTP/2
* [HTTP/2] [1] OPENED stream for https://localhost:8443/hello
* [HTTP/2] [1] [:method: GET]
* [HTTP/2] [1] [:scheme: https]
* [HTTP/2] [1] [:authority: localhost:8443]
* [HTTP/2] [1] [:path: /hello]
* [HTTP/2] [1] [user-agent: curl/8.10.1]
* [HTTP/2] [1] [accept: */*]
> GET /hello HTTP/2
> Host: localhost:8443
> User-Agent: curl/8.10.1
> Accept: */*
>
* Request completely sent off
< HTTP/2 200
< content-type: text/plain; charset=utf-8
< content-length: 12
< date: Wed, 06 Nov 2024 17:41:15 GMT
<
hello world
* Connection #0 to host localhost left intact |
sorry for misleading, the callback function is GetConfigForClient package main
import (
"crypto/tls"
"fmt"
"net/http"
)
var gTlsCfg = &tls.Config{
ClientAuth: tls.RequireAndVerifyClientCert,
Certificates: tlsCertArr,
RootCAs: pool,
ClientCAs: pool,
InsecureSkipVerify: false,
MinVersion: tls.VersionTLS12,
}
func getTlsConfigForClient(chi *tls.ClientHelloInfo) (*tls.Config, error) {
if chi.ServerName == "example.com" {
tlsCfg := &tls.Config{
ClientAuth: tls.RequireAndVerifyClientCert,
Certificates: tlsCertArr,
RootCAs: pool,
ClientCAs: pool,
InsecureSkipVerify: false,
MinVersion: tls.VersionTLS13,
}
return tlsCfg, nil
}
return gTlsCfg
}
func main() {
svr := &http.Server{
Addr: ":8443",
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "hello world")
}),
TLSConfig: gTlsCfg,
}
svr.TLSConfig.GetConfigForClient = getTlsConfigForClient
panic(svr.ListenAndServeTLS("", ""))
} |
cc @golang/security |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
go version go1.22.8 darwin/amd64
Output of
go env
in your module/workspace:What did you do?
I start a service with multiple domains, use GetConfigForClient function for providing TLS certificates dynamically depends on the request's servername. Start go1.6 has enable http2 by default, and it will add supported application level protocols,such as "h2","http/1.1", but the tls.Config from GetConfigForClient did not do this.
this leads to the client request offers h2,http/1.1, but server only accepted http/1.1 only
What did you see happen?
What did you expect to see?
if the NextProtos of tls.Config is empty, should copy from originalConfig, It should be consistent with the default
The text was updated successfully, but these errors were encountered: