]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/cmd/govpn-client/main.go
Ability to explicitly specify TAP interface, without up-script using
[govpn.git] / src / govpn / cmd / govpn-client / main.go
index 467bec6545645ac9bde4f06d734d884eeb78dd51..9b5bf1891ad6fa00f110c5dec8987bd0c8046a78 100644 (file)
@@ -1,6 +1,6 @@
 /*
 GoVPN -- simple secure free software virtual private network daemon
-Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2016 Sergey Matveev <stargrave@stargrave.org>
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
@@ -31,27 +31,29 @@ import (
 )
 
 var (
-       remoteAddr = flag.String("remote", "", "Remote server address")
-       proto      = flag.String("proto", "udp", "Protocol to use: udp or tcp")
-       ifaceName  = flag.String("iface", "tap0", "TAP network interface")
-       IDRaw      = flag.String("id", "", "Client identification")
-       keyPath    = flag.String("key", "", "Path to passphrase file")
-       upPath     = flag.String("up", "", "Path to up-script")
-       downPath   = flag.String("down", "", "Path to down-script")
-       stats      = flag.String("stats", "", "Enable stats retrieving on host:port")
-       proxyAddr  = flag.String("proxy", "", "Use HTTP proxy on host:port")
-       proxyAuth  = flag.String("proxy-auth", "", "user:password Basic proxy auth")
-       mtu        = flag.Int("mtu", 1452, "MTU for outgoing packets")
-       timeoutP   = flag.Int("timeout", 60, "Timeout seconds")
-       noisy      = flag.Bool("noise", false, "Enable noise appending")
-       cpr        = flag.Int("cpr", 0, "Enable constant KiB/sec out traffic rate")
-       egdPath    = flag.String("egd", "", "Optional path to EGD socket")
+       remoteAddr  = flag.String("remote", "", "Remote server address")
+       proto       = flag.String("proto", "udp", "Protocol to use: udp or tcp")
+       ifaceName   = flag.String("iface", "tap0", "TAP network interface")
+       verifierRaw = flag.String("verifier", "", "Verifier")
+       keyPath     = flag.String("key", "", "Path to passphrase file")
+       upPath      = flag.String("up", "", "Path to up-script")
+       downPath    = flag.String("down", "", "Path to down-script")
+       stats       = flag.String("stats", "", "Enable stats retrieving on host:port")
+       proxyAddr   = flag.String("proxy", "", "Use HTTP proxy on host:port")
+       proxyAuth   = flag.String("proxy-auth", "", "user:password Basic proxy auth")
+       mtu         = flag.Int("mtu", 1452, "MTU for outgoing packets")
+       timeoutP    = flag.Int("timeout", 60, "Timeout seconds")
+       noisy       = flag.Bool("noise", false, "Enable noise appending")
+       encless     = flag.Bool("encless", false, "Encryptionless mode")
+       cpr         = flag.Int("cpr", 0, "Enable constant KiB/sec out traffic rate")
+       egdPath     = flag.String("egd", "", "Optional path to EGD socket")
 
        conf        *govpn.PeerConf
        tap         *govpn.TAP
        timeout     int
        firstUpCall bool = true
        knownPeers  govpn.KnownPeers
+       idsCache    govpn.CipherCache
 )
 
 func main() {
@@ -62,26 +64,33 @@ func main() {
 
        govpn.MTU = *mtu
 
-       id, err := govpn.IDDecode(*IDRaw)
-       if err != nil {
-               log.Fatalln(err)
-       }
-
        if *egdPath != "" {
                log.Println("Using", *egdPath, "EGD")
                govpn.EGDInit(*egdPath)
        }
 
-       pub, priv := govpn.NewVerifier(id, govpn.StringFromFile(*keyPath))
+       verifier, err := govpn.VerifierFromString(*verifierRaw)
+       if err != nil {
+               log.Fatalln(err)
+       }
+       priv := verifier.PasswordApply(govpn.StringFromFile(*keyPath))
+       if *encless {
+               if *proto != "tcp" {
+                       log.Fatalln("Currently encryptionless mode works only with TCP")
+               }
+               *noisy = true
+       }
        conf = &govpn.PeerConf{
-               Id:      id,
-               Timeout: time.Second * time.Duration(timeout),
-               Noise:   *noisy,
-               CPR:     *cpr,
-               DSAPub:  pub,
-               DSAPriv: priv,
+               Id:       verifier.Id,
+               Iface:    *ifaceName,
+               Timeout:  time.Second * time.Duration(timeout),
+               Noise:    *noisy,
+               CPR:      *cpr,
+               EncLess:  *encless,
+               Verifier: verifier,
+               DSAPriv:  priv,
        }
-       govpn.PeersInitDummy(id, conf)
+       idsCache = govpn.NewCipherCache([]govpn.PeerId{*verifier.Id})
        log.Println(govpn.VersionGet())
 
        tap, err = govpn.TAPListen(*ifaceName)
@@ -107,6 +116,9 @@ MainCycle:
                timeouted := make(chan struct{})
                rehandshaking := make(chan struct{})
                termination := make(chan struct{})
+               if *proxyAddr != "" {
+                       *proto = "tcp"
+               }
                switch *proto {
                case "udp":
                        go startUDP(timeouted, rehandshaking, termination)