forked from quic-go/quic-go
copy VerifyPeerCertificate from the tls.Config to the mint.Config
This commit is contained in:
@@ -76,6 +76,7 @@ func tlsToMintConfig(tlsConf *tls.Config, pers protocol.Perspective) (*mint.Conf
|
||||
mconf.ServerName = tlsConf.ServerName
|
||||
mconf.InsecureSkipVerify = tlsConf.InsecureSkipVerify
|
||||
mconf.Certificates = make([]*mint.Certificate, len(tlsConf.Certificates))
|
||||
mconf.VerifyPeerCertificate = tlsConf.VerifyPeerCertificate
|
||||
for i, certChain := range tlsConf.Certificates {
|
||||
mconf.Certificates[i] = &mint.Certificate{
|
||||
Chain: make([]*x509.Certificate, len(certChain.Certificate)),
|
||||
|
||||
@@ -3,6 +3,8 @@ package quic
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"errors"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/internal/crypto"
|
||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||
@@ -42,20 +44,6 @@ var _ = Describe("Packing and unpacking Initial packets", func() {
|
||||
Expect(mintConf.NonBlocking).To(BeTrue())
|
||||
})
|
||||
|
||||
It("sets the server name", func() {
|
||||
conf := &tls.Config{ServerName: "www.example.com"}
|
||||
mintConf, err := tlsToMintConfig(conf, protocol.PerspectiveClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mintConf.ServerName).To(Equal("www.example.com"))
|
||||
})
|
||||
|
||||
It("sets InsecureSkipVerify", func() {
|
||||
conf := &tls.Config{InsecureSkipVerify: true}
|
||||
mintConf, err := tlsToMintConfig(conf, protocol.PerspectiveClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mintConf.InsecureSkipVerify).To(BeTrue())
|
||||
})
|
||||
|
||||
It("sets the certificate chain", func() {
|
||||
tlsConf := testdata.GetTLSConfig()
|
||||
mintConf, err := tlsToMintConfig(tlsConf, protocol.PerspectiveClient)
|
||||
@@ -64,6 +52,22 @@ var _ = Describe("Packing and unpacking Initial packets", func() {
|
||||
Expect(mintConf.Certificates).To(HaveLen(len(tlsConf.Certificates)))
|
||||
})
|
||||
|
||||
It("copies values from the tls.Config", func() {
|
||||
verifyErr := errors.New("test err")
|
||||
tlsConf := &tls.Config{
|
||||
ServerName: "www.example.com",
|
||||
InsecureSkipVerify: true,
|
||||
VerifyPeerCertificate: func(_ [][]byte, _ [][]*x509.Certificate) error {
|
||||
return verifyErr
|
||||
},
|
||||
}
|
||||
mintConf, err := tlsToMintConfig(tlsConf, protocol.PerspectiveClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(mintConf.ServerName).To(Equal("www.example.com"))
|
||||
Expect(mintConf.InsecureSkipVerify).To(BeTrue())
|
||||
Expect(mintConf.VerifyPeerCertificate(nil, nil)).To(MatchError(verifyErr))
|
||||
})
|
||||
|
||||
It("requires client authentication", func() {
|
||||
mintConf, err := tlsToMintConfig(nil, protocol.PerspectiveClient)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Reference in New Issue
Block a user