]> Cypherpunks.ru repositories - gocheese.git/commitdiff
Use TLS session tickets cache
authorSergey Matveev <stargrave@stargrave.org>
Thu, 23 Sep 2021 18:41:53 +0000 (21:41 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 23 Sep 2021 19:38:43 +0000 (22:38 +0300)
gocheese.go

index ed7e55d4646d93ab7530388d7810c9185adff1a4..67bc1c1c40ff157a9fec2edf033689106ef700c8 100644 (file)
@@ -302,23 +302,26 @@ func main() {
                log.Fatalln(err)
        }
        refreshPasswd()
-       if *pypiCertHash == "" {
-               pypiHTTPTransport = http.Transport{}
-       } else {
+       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)
                }
-               pypiHTTPTransport = http.Transport{
-                       TLSClientConfig: &tls.Config{
-                               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 digest mismatch")
-                                       }
-                                       return nil
-                               }},
+               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
                }
        }