]> Cypherpunks.ru repositories - gocheese.git/blobdiff - gocheese.go
Move documentation to doc/
[gocheese.git] / gocheese.go
index 63854169f549e0e301fd72a2af488b74e77196a7..67bc1c1c40ff157a9fec2edf033689106ef700c8 100644 (file)
@@ -97,8 +97,8 @@ var (
        norefreshURLPath = flag.String("norefresh", "/norefresh/", "Non-refreshing URL path")
        refreshURLPath   = flag.String("refresh", "/simple/", "Auto-refreshing URL path")
        gpgUpdateURLPath = flag.String("gpgupdate", "/gpgupdate/", "GPG forceful refreshing URL path")
-       pypiURL          = flag.String("pypi", "https://pypi.org/simple/", "Upstream PyPI URL")
-       pypiCertHash     = flag.String("pypi-cert-hash", "", "Authenticate PyPI by its X.509 certificate's SHA256 hash")
+       pypiURL          = flag.String("pypi", "https://pypi.org/simple/", "Upstream (PyPI) URL")
+       pypiCertHash     = flag.String("pypi-cert-hash", "", "Authenticate upstream by its X.509 certificate's SPKI SHA256 hash")
        passwdPath       = flag.String("passwd", "passwd", "Path to file with authenticators")
        logTimestamped   = flag.Bool("log-timestamped", false, "Prepend timestmap to log messages")
        passwdCheck      = flag.Bool("passwd-check", false, "Test the -passwd file for syntax errors and exit")
@@ -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
                }
        }