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