1 // tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
2 // manager, WARC/geminispace browser
3 // Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, version 3 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
26 "go.stargrave.org/tofuproxy/caches"
29 func list(l *sync.RWMutex, m map[string]string, p string) {
31 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
36 for host, hsh := range m {
37 if _, err = fmt.Fprintf(fd, "%s\t%s\n", host, hsh); err != nil {
46 func listAccepted(p string) {
47 list(&caches.AcceptedM, caches.Accepted, p)
50 func listRejected(p string) {
51 list(&caches.RejectedM, caches.Rejected, p)
54 func listHTTPAuth(p string) {
56 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
60 caches.HTTPAuthCacheM.RLock()
61 for host, creds := range caches.HTTPAuthCache {
62 if _, err = fmt.Fprintf(fd, "%s\t%s\n", host, creds[0]); err != nil {
66 caches.HTTPAuthCacheM.RUnlock()
71 func listTLSAuth(p string) {
73 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
77 caches.TLSAuthCacheM.RLock()
78 for host, tlsCert := range caches.TLSAuthCache {
80 if len(tlsCert.Certificate) != 0 {
81 cert, err := x509.ParseCertificate(tlsCert.Certificate[0])
85 subj = cert.Subject.String()
87 if _, err = fmt.Fprintf(fd, "%s\t%s\n", host, subj); err != nil {
91 caches.TLSAuthCacheM.RUnlock()