(name string, roots *x509.CertPool)
| 13 | ) |
| 14 | |
| 15 | func ExpectPeerName(name string, roots *x509.CertPool) func(cs tls.ConnectionState) error { |
| 16 | return func(cs tls.ConnectionState) error { |
| 17 | opts := x509.VerifyOptions{ |
| 18 | Roots: roots, |
| 19 | DNSName: name, |
| 20 | Intermediates: x509.NewCertPool(), |
| 21 | } |
| 22 | for _, cert := range cs.PeerCertificates[1:] { |
| 23 | opts.Intermediates.AddCert(cert) |
| 24 | } |
| 25 | _, err := cs.PeerCertificates[0].Verify(opts) |
| 26 | return err |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func LoadCAfile(filename string) (*x509.CertPool, error) { |
| 31 | roots := x509.NewCertPool() |