]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - tls/tlsauth.go
Modern rand.Read never fails
[tofuproxy.git] / tls / tlsauth.go
index 131dff2ad3926643ca4c4ca9ab7aef6c74389ded..98780e66f48e6e51bd131cb1378404bb7515d819 100644 (file)
@@ -1,20 +1,18 @@
-/*
-tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
-             manager, WARC/geminispace browser
-Copyright (C) 2021-2022 Sergey Matveev <stargrave@stargrave.org>
-
-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
-the Free Software Foundation, version 3 of the License.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
+// tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
+//              manager, WARC/geminispace browser
+// Copyright (C) 2021-2025 Sergey Matveev <stargrave@stargrave.org>
+//
+// 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
+// the Free Software Foundation, version 3 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 package tofuproxy
 
@@ -31,7 +29,7 @@ import (
        "strconv"
        "strings"
 
-       "go.cypherpunks.ru/ucspi"
+       "go.cypherpunks.su/ucspi/v2"
        "go.stargrave.org/tofuproxy/caches"
        "go.stargrave.org/tofuproxy/fifos"
 )
@@ -57,8 +55,7 @@ func (g *ClientCertificateGetter) get(
                sigSchemes = append(sigSchemes, ss.String())
        }
        var b bytes.Buffer
-       b.WriteString(fmt.Sprintf(`
-tk_setPalette grey
+       fmt.Fprintf(&b, `
 wm title . "TLS client authentication: %s"
 
 set lb [listbox .lb]
@@ -94,7 +91,7 @@ foreach sigScheme {%s} {
                g.host,
                ucspi.TLSVersion(cri.Version),
                strings.Join(sigSchemes, " "),
-       ))
+       )
 
        ents, err := os.ReadDir(CCerts)
        if err != nil {
@@ -107,11 +104,13 @@ foreach sigScheme {%s} {
        tlsCerts = append(tlsCerts, nil)
        for i, ent := range ents {
                p := filepath.Join(CCerts, ent.Name())
-               _, cert, err := ucspi.CertificateFromFile(p)
+               var cert *x509.Certificate
+               _, cert, err = ucspi.CertificateFromFile(p)
                if err != nil {
                        log.Fatalln(err)
                }
-               prv, err := ucspi.PrivateKeyFromFile(p)
+               var prv any
+               prv, err = ucspi.PrivateKeyFromFile(p)
                if err != nil {
                        log.Fatalln(err)
                }
@@ -120,7 +119,7 @@ foreach sigScheme {%s} {
                        Certificate: [][]byte{cert.Raw},
                        PrivateKey:  prv,
                })
-               b.WriteString(fmt.Sprintf(".lb insert end \"%d: %s\"\n", i+1, cert.Subject))
+               fmt.Fprintf(&b, ".lb insert end \"%d: %s\"\n", i+1, cert.Subject)
        }
        // os.WriteFile("/tmp/tls-auth-dialog.tcl", b.Bytes(), 0666)
        cmd := exec.Command(CmdWish)