- log.Println("root:", *root, "bind:", *bind)
+ tlsConfig := tls.Config{
+ ClientSessionCache: tls.NewLRUClientSessionCache(16),
+ NextProtos: []string{"h2", "http/1.1"},
+ }
+ pypiHTTPTransport = http.Transport{
+ ForceAttemptHTTP2: true,
+ TLSClientConfig: &tlsConfig,
+ }
+ if *pypiCertHash != "" {
+ ourDgst, err := hex.DecodeString(*pypiCertHash)
+ if err != nil {
+ log.Fatalln(err)
+ }
+ tlsConfig.VerifyConnection = func(s tls.ConnectionState) error {
+ spki := s.VerifiedChains[0][0].RawSubjectPublicKeyInfo
+ theirDgst := sha256.Sum256(spki)
+ if bytes.Compare(ourDgst, theirDgst[:]) != 0 {
+ return errors.New("certificate's SPKI digest mismatch")
+ }
+ return nil
+ }
+ }