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.
30 "cypherpunks.ru/govpn"
34 remoteAddr = flag.String("remote", "", "Remote server address")
35 proto = flag.String("proto", "udp", "Protocol to use: udp or tcp")
36 ifaceName = flag.String("iface", "tap0", "TAP network interface")
37 verifierRaw = flag.String("verifier", "", "Verifier")
38 keyPath = flag.String("key", "", "Path to passphrase file")
39 upPath = flag.String("up", "", "Path to up-script")
40 downPath = flag.String("down", "", "Path to down-script")
41 stats = flag.String("stats", "", "Enable stats retrieving on host:port")
42 proxyAddr = flag.String("proxy", "", "Use HTTP proxy on host:port")
43 proxyAuth = flag.String("proxy-auth", "", "user:password Basic proxy auth")
44 mtu = flag.Int("mtu", govpn.MTUDefault, "MTU of TAP interface")
45 timeoutP = flag.Int("timeout", 60, "Timeout seconds")
46 timeSync = flag.Int("timesync", 0, "Time synchronization requirement")
47 noisy = flag.Bool("noise", false, "Enable noise appending")
48 encless = flag.Bool("encless", false, "Encryptionless mode")
49 cpr = flag.Int("cpr", 0, "Enable constant KiB/sec out traffic rate")
50 egdPath = flag.String("egd", "", "Optional path to EGD socket")
55 firstUpCall bool = true
56 knownPeers govpn.KnownPeers
57 idsCache *govpn.CipherCache
64 log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
66 if *mtu > govpn.MTUMax {
67 log.Fatalln("Maximum allowable MTU is", govpn.MTUMax)
70 log.Println("Using", *egdPath, "EGD")
71 govpn.EGDInit(*egdPath)
74 if *verifierRaw == "" {
75 log.Fatalln("No verifier specified")
77 verifier, err := govpn.VerifierFromString(*verifierRaw)
81 key, err := govpn.KeyRead(*keyPath)
83 log.Fatalln("Unable to read the key", err)
85 priv := verifier.PasswordApply(key)
88 log.Fatalln("Currently encryptionless mode works only with TCP")
92 conf = &govpn.PeerConf{
96 Timeout: time.Second * time.Duration(timeout),
104 idsCache = govpn.NewCipherCache()
105 confs := map[govpn.PeerId]*govpn.PeerConf{*verifier.Id: conf}
106 idsCache.Update(&confs)
107 log.Println(govpn.VersionGet())
109 tap, err = govpn.TAPListen(*ifaceName, *mtu)
111 log.Fatalln("Can not listen on TAP interface:", err)
115 log.Println("Stats are going to listen on", *stats)
116 statsPort, err := net.Listen("tcp", *stats)
118 log.Fatalln("Can not listen on stats port:", err)
120 go govpn.StatsProcessor(statsPort, &knownPeers)
123 termSignal := make(chan os.Signal, 1)
124 signal.Notify(termSignal, os.Interrupt, os.Kill)
128 timeouted := make(chan struct{})
129 rehandshaking := make(chan struct{})
130 termination := make(chan struct{})
131 if *proxyAddr != "" {
136 go startUDP(timeouted, rehandshaking, termination)
138 if *proxyAddr != "" {
139 go proxyTCP(timeouted, rehandshaking, termination)
141 go startTCP(timeouted, rehandshaking, termination)
144 log.Fatalln("Unknown protocol specified")
148 log.Fatalln("Finishing")
149 termination <- struct{}{}
153 case <-rehandshaking:
159 govpn.ScriptCall(*downPath, *ifaceName, *remoteAddr)