]> Sergey Matveev's repositories - tofuproxy.git/blob - cmd/tofuproxy/main.go
Unify copyright comment format
[tofuproxy.git] / cmd / tofuproxy / main.go
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>
4 //
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.
8 //
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.
13 //
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/>.
16
17 package main
18
19 import (
20         "flag"
21         "log"
22         "net"
23         "net/http"
24
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"
31 )
32
33 func main() {
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")
45         flag.Parse()
46         log.SetFlags(log.Lshortfile)
47
48         var err error
49         _, caCert, err := ucspi.CertificateFromFile(*crtPath)
50         if err != nil {
51                 log.Fatalln(err)
52         }
53         caPrv, err := ucspi.PrivateKeyFromFile(*prvPath)
54         if err != nil {
55                 log.Fatalln(err)
56         }
57
58         fifos.NoTAI = *notai
59         fifos.Start(*fifosDir)
60         ttls.Certs = *certs
61         ttls.CCerts = *ccerts
62         ttls.DNSSrv = *dnsSrv
63         tofuproxy.CACert = caCert
64         tofuproxy.CAPrv = caPrv
65         tofuproxy.X509Algo = *ai
66         rounds.WARCOnly = *warcOnly
67         warc.UnZSTDPath = *unzstdPath
68
69         ln, err := net.Listen("tcp", *bind)
70         if err != nil {
71                 log.Fatalln(err)
72         }
73         srv := http.Server{
74                 Handler:      &tofuproxy.Handler{},
75                 TLSNextProto: tofuproxy.TLSNextProtoS,
76         }
77         log.Println("listening:", *bind, "dns:", *dnsSrv, "certs:", *certs, "ccerts:", *ccerts)
78         if err := srv.Serve(ln); err != nil {
79                 log.Fatalln(err)
80         }
81 }