]> Sergey Matveev's repositories - tofuproxy.git/blob - cmd/tofuproxy/main.go
ddfa4771d74b910cd82e38855300311b866a7f3c
[tofuproxy.git] / cmd / tofuproxy / main.go
1 /*
2 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
3              manager, WARC/geminispace browser
4 Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
5
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.
9
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.
14
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/>.
17 */
18
19 package main
20
21 import (
22         "flag"
23         "log"
24         "net"
25         "net/http"
26
27         "go.cypherpunks.ru/ucspi"
28         "go.stargrave.org/tofuproxy"
29         "go.stargrave.org/tofuproxy/fifos"
30         "go.stargrave.org/tofuproxy/rounds"
31         ttls "go.stargrave.org/tofuproxy/tls"
32         "go.stargrave.org/tofuproxy/warc"
33 )
34
35 func main() {
36         ai := flag.String("ai", "eddsa", "ecdsa|eddsa (ECDSA-256 or EdDSA algorithm)")
37         crtPath := flag.String("cert", "cert.pem", "Path to server X.509 certificate")
38         prvPath := flag.String("key", "cert.pem", "Path to server PKCS#8 private key")
39         bind := flag.String("bind", "[::1]:8080", "Bind address")
40         certs := flag.String("certs", "./certs", "Directory with pinned certificates")
41         ccerts := flag.String("ccerts", "./ccerts", "Directory with client certificates")
42         dnsSrv := flag.String("dns", "[::1]:53", "DNS server")
43         fifosDir := flag.String("fifos", "fifos", "Directory with FIFOs")
44         notai := flag.Bool("notai", false, "Do not prepend TAI64N to logs")
45         warcOnly := flag.Bool("warc-only", false, "Server only WARC URIs")
46         unzstdPath := flag.String("unzstd", "cmd/zstd/unzstd", "Path to unzstd utility")
47         flag.Parse()
48         log.SetFlags(log.Lshortfile)
49
50         var err error
51         _, caCert, err := ucspi.CertificateFromFile(*crtPath)
52         if err != nil {
53                 log.Fatalln(err)
54         }
55         caPrv, err := ucspi.PrivateKeyFromFile(*prvPath)
56         if err != nil {
57                 log.Fatalln(err)
58         }
59
60         fifos.NoTAI = *notai
61         fifos.Start(*fifosDir)
62         ttls.Certs = *certs
63         ttls.CCerts = *ccerts
64         ttls.DNSSrv = *dnsSrv
65         tofuproxy.CACert = caCert
66         tofuproxy.CAPrv = caPrv
67         tofuproxy.X509Algo = *ai
68         rounds.WARCOnly = *warcOnly
69         warc.UnZSTDPath = *unzstdPath
70
71         ln, err := net.Listen("tcp", *bind)
72         if err != nil {
73                 log.Fatalln(err)
74         }
75         srv := http.Server{
76                 Handler:      &tofuproxy.Handler{},
77                 TLSNextProto: tofuproxy.TLSNextProtoS,
78         }
79         log.Println("listening:", *bind, "dns:", *dnsSrv, "certs:", *certs, "ccerts:", *ccerts)
80         if err := srv.Serve(ln); err != nil {
81                 log.Fatalln(err)
82         }
83 }