2 tofuproxy -- HTTP 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/>.
26 "go.cypherpunks.ru/ucspi"
27 "go.stargrave.org/tofuproxy"
28 "go.stargrave.org/tofuproxy/fifos"
32 crtPath := flag.String("cert", "cert.pem", "Path to server X.509 certificate")
33 prvPath := flag.String("key", "prv.pem", "Path to server PKCS#8 private key")
34 bind := flag.String("bind", "[::1]:8080", "Bind address")
35 certs := flag.String("certs", "./certs", "Directory with pinned certificates")
36 ccerts := flag.String("ccerts", "./ccerts", "Directory with client certificates")
37 dnsSrv := flag.String("dns", "[::1]:53", "DNS server")
38 fifosDir := flag.String("fifos", "fifos", "Directory with FIFOs")
39 notai := flag.Bool("notai", false, "Do not prepend TAI64N to logs")
41 log.SetFlags(log.Lshortfile)
44 _, caCert, err := ucspi.CertificateFromFile(*crtPath)
48 caPrv, err := ucspi.PrivateKeyFromFile(*prvPath)
54 fifos.FIFOs = *fifosDir
56 tofuproxy.Certs = *certs
57 tofuproxy.CCerts = *ccerts
58 tofuproxy.DNSSrv = *dnsSrv
59 tofuproxy.CACert = caCert
60 tofuproxy.CAPrv = caPrv
62 ln, err := net.Listen("tcp", *bind)
67 Handler: &tofuproxy.Handler{},
68 TLSNextProto: tofuproxy.TLSNextProtoS,
70 log.Println("listening:", *bind, "dns:", *dnsSrv, "certs:", *certs, "ccerts:", *ccerts)
71 if err := srv.Serve(ln); err != nil {