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/>.
25 "go.cypherpunks.ru/ucspi"
26 "go.stargrave.org/tofuproxy"
27 "go.stargrave.org/tofuproxy/fifos"
28 "go.stargrave.org/tofuproxy/rounds"
29 ttls "go.stargrave.org/tofuproxy/tls"
30 "go.stargrave.org/tofuproxy/warc"
34 ai := flag.String("ai", "eddsa", "ecdsa|eddsa (ECDSA-256 or EdDSA algorithm)")
35 crtPath := flag.String("cert", "cert.pem", "Path to server X.509 certificate")
36 prvPath := flag.String("key", "cert.pem", "Path to server PKCS#8 private key")
37 bind := flag.String("bind", "[::1]:8080", "Bind address")
38 certs := flag.String("certs", "./certs", "Directory with pinned certificates")
39 ccerts := flag.String("ccerts", "./ccerts", "Directory with client certificates")
40 dnsSrv := flag.String("dns", "[::1]:53", "DNS server")
41 fifosDir := flag.String("fifos", "fifos", "Directory with FIFOs")
42 notai := flag.Bool("notai", false, "Do not prepend TAI64N to logs")
43 warcOnly := flag.Bool("warc-only", false, "Server only WARC URIs")
44 unzstdPath := flag.String("unzstd", "cmd/zstd/unzstd", "Path to unzstd utility")
46 log.SetFlags(log.Lshortfile)
49 _, caCert, err := ucspi.CertificateFromFile(*crtPath)
53 caPrv, err := ucspi.PrivateKeyFromFile(*prvPath)
59 fifos.Start(*fifosDir)
63 tofuproxy.CACert = caCert
64 tofuproxy.CAPrv = caPrv
65 tofuproxy.X509Algo = *ai
66 rounds.WARCOnly = *warcOnly
67 warc.UnZSTDPath = *unzstdPath
69 ln, err := net.Listen("tcp", *bind)
74 Handler: &tofuproxy.Handler{},
75 TLSNextProto: tofuproxy.TLSNextProtoS,
77 log.Println("listening:", *bind, "dns:", *dnsSrv, "certs:", *certs, "ccerts:", *ccerts)
78 if err := srv.Serve(ln); err != nil {