/*
GoVPN -- simple secure free software virtual private network daemon
-Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2020 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
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
+the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
package main
import (
- "crypto/subtle"
- "encoding/hex"
+ "bytes"
"flag"
"fmt"
+ "io"
+ "log"
- "govpn"
+ "go.cypherpunks.ru/govpn/v7"
)
var (
- IDRaw = flag.String("id", "", "Client identification")
- keyPath = flag.String("key", "", "Path to passphrase file")
- verifierPath = flag.String("verifier", "", "Optional path to verifier")
+ keyPath = flag.String("key", "", "Path to passphrase file")
+ verifier = flag.String("verifier", "", "Optional verifier")
+ sOpt = flag.Int("s", govpn.DefaultS, "Balloon space cost")
+ tOpt = flag.Int("t", govpn.DefaultT, "Balloon time cost")
+ pOpt = flag.Int("p", govpn.DefaultP, "Balloon parallel jobs")
+ egdPath = flag.String("egd", "", "Optional path to EGD socket")
+ version = flag.Bool("version", false, "Print version information")
+ warranty = flag.Bool("warranty", false, "Print warranty information")
)
func main() {
flag.Parse()
- id := govpn.IDDecode(*IDRaw)
- if id == nil {
- panic("ID is not specified")
+ if *warranty {
+ fmt.Println(govpn.Warranty)
+ return
}
- pub, _ := govpn.NewVerifier(id, govpn.StringFromFile(*keyPath))
- if *verifierPath == "" {
- fmt.Println(hex.EncodeToString(pub[:]))
- } else {
- verifier, err := hex.DecodeString(govpn.StringFromFile(*verifierPath))
- if err != nil {
- panic("Can not decode verifier")
+ if *version {
+ fmt.Println(govpn.VersionGet())
+ return
+ }
+ if *egdPath != "" {
+ govpn.EGDInit(*egdPath)
+ }
+ key, err := govpn.KeyRead(*keyPath)
+ if err != nil {
+ log.Fatalln("Unable to read the key", err)
+ }
+ if *verifier == "" {
+ id := new([govpn.IDSize]byte)
+ if _, err = io.ReadFull(govpn.Rand, id[:]); err != nil {
+ log.Fatalln(err)
}
- fmt.Println(subtle.ConstantTimeCompare(verifier[:], pub[:]) == 1)
+ pid := govpn.PeerID(*id)
+ v := govpn.VerifierNew(*sOpt, *tOpt, *pOpt, &pid)
+ v.PasswordApply(key)
+ fmt.Println(v.LongForm())
+ fmt.Println(v.ShortForm())
+ return
+ }
+ v, err := govpn.VerifierFromString(*verifier)
+ if err != nil {
+ log.Fatalln("Can not decode verifier", err)
+ }
+ if v.Pub == nil {
+ log.Fatalln("Verifier does not contain public key")
}
+ pub := *v.Pub
+ v.PasswordApply(key)
+ fmt.Println(bytes.Equal(v.Pub[:], pub[:]))
}