]> Sergey Matveev's repositories - tofuproxy.git/blobdiff - fifos/list.go
Unify copyright comment format
[tofuproxy.git] / fifos / list.go
index b06a4cce2a1a587d28b9fba756a14eee9604e7fe..f571d04c067c9db36afc0a5ae5f9d2750ba78399 100644 (file)
@@ -1,19 +1,18 @@
-/*
-tofuproxy -- HTTP proxy with TLS certificates management
-Copyright (C) 2021 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-2024 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 fifos
 
@@ -35,7 +34,7 @@ func list(l *sync.RWMutex, m map[string]string, p string) {
                }
                l.RLock()
                for host, hsh := range m {
-                       if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, hsh)); err != nil {
+                       if _, err = fmt.Fprintf(fd, "%s\t%s\n", host, hsh); err != nil {
                                break
                        }
                }
@@ -60,7 +59,7 @@ func listHTTPAuth(p string) {
                }
                caches.HTTPAuthCacheM.RLock()
                for host, creds := range caches.HTTPAuthCache {
-                       if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, creds[0])); err != nil {
+                       if _, err = fmt.Fprintf(fd, "%s\t%s\n", host, creds[0]); err != nil {
                                break
                        }
                }
@@ -77,11 +76,15 @@ func listTLSAuth(p string) {
                }
                caches.TLSAuthCacheM.RLock()
                for host, tlsCert := range caches.TLSAuthCache {
-                       cert, err := x509.ParseCertificate(tlsCert.Certificate[0])
-                       if err != nil {
-                               log.Fatalln(err)
+                       subj := "NONE"
+                       if len(tlsCert.Certificate) != 0 {
+                               cert, err := x509.ParseCertificate(tlsCert.Certificate[0])
+                               if err != nil {
+                                       log.Fatalln(err)
+                               }
+                               subj = cert.Subject.String()
                        }
-                       if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, cert.Subject)); err != nil {
+                       if _, err = fmt.Fprintf(fd, "%s\t%s\n", host, subj); err != nil {
                                break
                        }
                }