"flag"
"fmt"
"io"
+ "io/ioutil"
"log"
"net"
"time"
remoteAddr = flag.String("remote", "", "Remote server address")
bindAddr = flag.String("bind", "", "Bind to address")
ifaceName = flag.String("iface", "tap0", "TAP network interface")
- keyHex = flag.String("key", "", "Authentication key")
+ keyPath = flag.String("key", "", "Path to authentication key file")
mtu = flag.Int("mtu", 1500, "MTU")
timeout = flag.Int("timeout", 60, "Timeout seconds")
verbose = flag.Bool("v", false, "Increase verbosity")
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
// Key decoding
- if len(*keyHex) != 64 {
- panic("Key is required argument (64 hex characters)")
+ keyData, err := ioutil.ReadFile(*keyPath)
+ if err != nil {
+ panic("Unable to read keyfile: " + err.Error())
+ }
+ if len(keyData) < 64 {
+ panic("Key must be 64 hex characters long")
}
- keyDecoded, err := hex.DecodeString(*keyHex)
+ keyDecoded, err := hex.DecodeString(string(keyData[0:64]))
if err != nil {
- panic(err)
+ panic("Unable to decode the key: " + err.Error())
}
key := new([KeySize]byte)
copy(key[:], keyDecoded)
+ keyDecoded = nil
+ keyData = nil
// Interface listening
maxIfacePktSize := *mtu - poly1305.TagSize - NonceSize