2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2016 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, either version 3 of the License, or
8 (at your option) any later version.
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.
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/>.
19 // Simple secure, DPI/censorship-resistant free software VPN daemon client.
31 "cypherpunks.ru/govpn"
35 remoteAddr = flag.String("remote", "", "Remote server address")
36 proto = flag.String("proto", "udp", "Protocol to use: udp or tcp")
37 ifaceName = flag.String("iface", "tap0", "TAP network interface")
38 verifierRaw = flag.String("verifier", "", "Verifier")
39 keyPath = flag.String("key", "", "Path to passphrase file")
40 upPath = flag.String("up", "", "Path to up-script")
41 downPath = flag.String("down", "", "Path to down-script")
42 stats = flag.String("stats", "", "Enable stats retrieving on host:port")
43 proxyAddr = flag.String("proxy", "", "Use HTTP proxy on host:port")
44 proxyAuth = flag.String("proxy-auth", "", "user:password Basic proxy auth")
45 mtu = flag.Int("mtu", govpn.MTUDefault, "MTU of TAP interface")
46 timeoutP = flag.Int("timeout", 60, "Timeout seconds")
47 timeSync = flag.Int("timesync", 0, "Time synchronization requirement")
48 noisy = flag.Bool("noise", false, "Enable noise appending")
49 encless = flag.Bool("encless", false, "Encryptionless mode")
50 cpr = flag.Int("cpr", 0, "Enable constant KiB/sec out traffic rate")
51 egdPath = flag.String("egd", "", "Optional path to EGD socket")
52 warranty = flag.Bool("warranty", false, "Print warranty information")
57 firstUpCall bool = true
58 knownPeers govpn.KnownPeers
59 idsCache *govpn.CipherCache
65 fmt.Println(govpn.Warranty)
70 log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
72 if *mtu > govpn.MTUMax {
73 log.Fatalln("Maximum allowable MTU is", govpn.MTUMax)
76 log.Println("Using", *egdPath, "EGD")
77 govpn.EGDInit(*egdPath)
80 if *verifierRaw == "" {
81 log.Fatalln("No verifier specified")
83 verifier, err := govpn.VerifierFromString(*verifierRaw)
87 key, err := govpn.KeyRead(*keyPath)
89 log.Fatalln("Unable to read the key", err)
91 priv := verifier.PasswordApply(key)
94 log.Fatalln("Currently encryptionless mode works only with TCP")
98 conf = &govpn.PeerConf{
102 Timeout: time.Second * time.Duration(timeout),
110 idsCache = govpn.NewCipherCache()
111 confs := map[govpn.PeerId]*govpn.PeerConf{*verifier.Id: conf}
112 idsCache.Update(&confs)
113 log.Println(govpn.VersionGet())
115 tap, err = govpn.TAPListen(*ifaceName, *mtu)
117 log.Fatalln("Can not listen on TAP interface:", err)
121 log.Println("Stats are going to listen on", *stats)
122 statsPort, err := net.Listen("tcp", *stats)
124 log.Fatalln("Can not listen on stats port:", err)
126 go govpn.StatsProcessor(statsPort, &knownPeers)
129 termSignal := make(chan os.Signal, 1)
130 signal.Notify(termSignal, os.Interrupt, os.Kill)
134 timeouted := make(chan struct{})
135 rehandshaking := make(chan struct{})
136 termination := make(chan struct{})
137 if *proxyAddr != "" {
142 go startUDP(timeouted, rehandshaking, termination)
144 if *proxyAddr != "" {
145 go proxyTCP(timeouted, rehandshaking, termination)
147 go startTCP(timeouted, rehandshaking, termination)
150 log.Fatalln("Unknown protocol specified")
154 log.Fatalln("Finishing")
155 termination <- struct{}{}
159 case <-rehandshaking:
165 govpn.ScriptCall(*downPath, *ifaceName, *remoteAddr)