2 tofuproxy -- flexible HTTP/WARC proxy with TLS certificates management
3 Copyright (C) 2021 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/>.
27 "go.stargrave.org/tofuproxy/caches"
30 func list(l *sync.RWMutex, m map[string]string, p string) {
32 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
37 for host, hsh := range m {
38 if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, hsh)); err != nil {
47 func listAccepted(p string) {
48 list(&caches.AcceptedM, caches.Accepted, p)
51 func listRejected(p string) {
52 list(&caches.RejectedM, caches.Rejected, p)
55 func listHTTPAuth(p string) {
57 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
61 caches.HTTPAuthCacheM.RLock()
62 for host, creds := range caches.HTTPAuthCache {
63 if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, creds[0])); err != nil {
67 caches.HTTPAuthCacheM.RUnlock()
72 func listTLSAuth(p string) {
74 fd, err := os.OpenFile(p, os.O_WRONLY|os.O_APPEND, os.FileMode(0666))
78 caches.TLSAuthCacheM.RLock()
79 for host, tlsCert := range caches.TLSAuthCache {
80 cert, err := x509.ParseCertificate(tlsCert.Certificate[0])
84 if _, err = fd.WriteString(fmt.Sprintf("%s\t%s\n", host, cert.Subject)); err != nil {
88 caches.TLSAuthCacheM.RUnlock()