]> Cypherpunks.ru repositories - gocheese.git/blobdiff - main.go
Drop PGP signatures support
[gocheese.git] / main.go
diff --git a/main.go b/main.go
index 08c75535c1491feb8ac230f754cb37b63086e4c2..89aa5a62b6e59aa4e6a6174d5315a406ba24383a 100644 (file)
--- a/main.go
+++ b/main.go
@@ -1,7 +1,7 @@
 /*
 GoCheese -- Python private package repository and caching proxy
-Copyright (C) 2019-2022 Sergey Matveev <stargrave@stargrave.org>
-              2019-2022 Elena Balakhonova <balakhonova_e@riseup.net>
+Copyright (C) 2019-2023 Sergey Matveev <stargrave@stargrave.org>
+              2019-2023 Elena Balakhonova <balakhonova_e@riseup.net>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@ import (
 )
 
 const (
-       Version   = "3.5.0"
+       Version   = "4.0.0"
        UserAgent = "GoCheese/" + Version
 )
 
@@ -59,7 +59,6 @@ var (
 
        NoRefreshURLPath = flag.String("norefresh", DefaultNoRefreshURLPath, "")
        RefreshURLPath   = flag.String("refresh", DefaultRefreshURLPath, "")
-       GPGUpdateURLPath = flag.String("gpgupdate", DefaultGPGUpdateURLPath, "")
        JSONURLPath      = flag.String("json", DefaultJSONURLPath, "")
 
        PyPIURL      = flag.String("pypi", DefaultPyPIURL, "")
@@ -82,7 +81,7 @@ func servePkg(w http.ResponseWriter, r *http.Request, pkgName, filename string)
        log.Println(r.RemoteAddr, "get", filename)
        path := filepath.Join(Root, pkgName, filename)
        if _, err := os.Stat(path); os.IsNotExist(err) {
-               if !refreshDir(w, r, pkgName, filename, false) {
+               if !refreshDir(w, r, pkgName, filename) {
                        return
                }
        }
@@ -95,16 +94,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
        case "GET":
                var path string
                var autorefresh bool
-               var gpgUpdate bool
                if strings.HasPrefix(r.URL.Path, *NoRefreshURLPath) {
                        path = strings.TrimPrefix(r.URL.Path, *NoRefreshURLPath)
                } else if strings.HasPrefix(r.URL.Path, *RefreshURLPath) {
                        path = strings.TrimPrefix(r.URL.Path, *RefreshURLPath)
                        autorefresh = true
-               } else if strings.HasPrefix(r.URL.Path, *GPGUpdateURLPath) {
-                       path = strings.TrimPrefix(r.URL.Path, *GPGUpdateURLPath)
-                       autorefresh = true
-                       gpgUpdate = true
                } else {
                        http.Error(w, "unknown action", http.StatusBadRequest)
                        return
@@ -118,7 +112,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
                        if parts[0] == "" {
                                listRoot(w, r)
                        } else {
-                               serveListDir(w, r, parts[0], autorefresh, gpgUpdate)
+                               serveListDir(w, r, parts[0], autorefresh)
                        }
                } else {
                        servePkg(w, r, parts[0], parts[1])
@@ -212,6 +206,9 @@ func main() {
                log.Fatalln("Both -tls-cert and -tls-key are required")
        }
 
+       UmaskCur = syscall.Umask(0)
+       syscall.Umask(UmaskCur)
+
        var err error
        PyPIURLParsed, err = url.Parse(*PyPIURL)
        if err != nil {
@@ -233,7 +230,7 @@ func main() {
                tlsConfig.VerifyConnection = func(s tls.ConnectionState) error {
                        spki := s.VerifiedChains[0][0].RawSubjectPublicKeyInfo
                        theirDgst := sha256.Sum256(spki)
-                       if bytes.Compare(ourDgst, theirDgst[:]) != 0 {
+                       if !bytes.Equal(ourDgst, theirDgst[:]) {
                                return errors.New("certificate's SPKI digest mismatch")
                        }
                        return nil
@@ -249,9 +246,6 @@ func main() {
        http.HandleFunc(*JSONURLPath, serveJSON)
        http.HandleFunc(*NoRefreshURLPath, handler)
        http.HandleFunc(*RefreshURLPath, handler)
-       if *GPGUpdateURLPath != "" {
-               http.HandleFunc(*GPGUpdateURLPath, handler)
-       }
 
        if *DoUCSPI {
                server.SetKeepAlivesEnabled(false)
@@ -271,8 +265,8 @@ func main() {
        }
        ln = netutil.LimitListener(ln, *MaxClients)
 
-       needsShutdown := make(chan os.Signal, 0)
-       exitErr := make(chan error, 0)
+       needsShutdown := make(chan os.Signal, 1)
+       exitErr := make(chan error)
        signal.Notify(needsShutdown, syscall.SIGTERM, syscall.SIGINT)
        go func(s *http.Server) {
                <-needsShutdown