2 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
3 manager, WARC/geminispace browser
4 Copyright (C) 2021-2022 Sergey Matveev <stargrave@stargrave.org>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3 of the License.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 "go.stargrave.org/tofuproxy/caches"
31 func list(l *sync.RWMutex, m map[string]string, p string) {
33 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
38 for host, hsh := range m {
39 if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, hsh)); err != nil {
48 func listAccepted(p string) {
49 list(&caches.AcceptedM, caches.Accepted, p)
52 func listRejected(p string) {
53 list(&caches.RejectedM, caches.Rejected, p)
56 func listHTTPAuth(p string) {
58 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
62 caches.HTTPAuthCacheM.RLock()
63 for host, creds := range caches.HTTPAuthCache {
64 if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, creds[0])); err != nil {
68 caches.HTTPAuthCacheM.RUnlock()
73 func listTLSAuth(p string) {
75 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
79 caches.TLSAuthCacheM.RLock()
80 for host, tlsCert := range caches.TLSAuthCache {
82 if len(tlsCert.Certificate) != 0 {
83 cert, err := x509.ParseCertificate(tlsCert.Certificate[0])
87 subj = cert.Subject.String()
89 if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, subj)); err != nil {
93 caches.TLSAuthCacheM.RUnlock()