forked from quic-go/quic-go
Call GetConfigForClient in tls.Config if present
This commit is contained in:
@@ -57,6 +57,15 @@ func (c *certChain) GetLeafCert(sni string) ([]byte, error) {
|
||||
|
||||
func (cc *certChain) getCertForSNI(sni string) (*tls.Certificate, error) {
|
||||
c := cc.config
|
||||
if c.GetConfigForClient != nil {
|
||||
var err error
|
||||
c, err = c.GetConfigForClient(&tls.ClientHelloInfo{
|
||||
ServerName: sni,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// The rest of this function is mostly copied from crypto/tls.getCertificate
|
||||
|
||||
if c.GetCertificate != nil {
|
||||
|
||||
@@ -127,5 +127,16 @@ var _ = Describe("Proof", func() {
|
||||
_, err := cc.GetLeafCert("invalid domain")
|
||||
Expect(err).To(MatchError(errNoMatchingCertificate))
|
||||
})
|
||||
|
||||
It("respects GetConfigForClient", func() {
|
||||
nestedConfig := &tls.Config{Certificates: []tls.Certificate{cert}}
|
||||
config.GetConfigForClient = func(chi *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
Expect(chi.ServerName).To(Equal("quic.clemente.io"))
|
||||
return nestedConfig, nil
|
||||
}
|
||||
resultCert, err := cc.getCertForSNI("quic.clemente.io")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(*resultCert).To(Equal(cert))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user