]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/cmd/govpn-verifier/main.go
No need in constant time comparison in CLI utility
[govpn.git] / src / govpn / cmd / govpn-verifier / main.go
index 1757e1e183976a6e16b36dbb3c6cf21373689b0e..876d9a53cedb37e36e59f846d1a6a9edc208c650 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
@@ -20,8 +20,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 package main
 
 import (
-       "crypto/rand"
-       "crypto/subtle"
+       "bytes"
        "flag"
        "fmt"
        "log"
@@ -35,13 +34,17 @@ var (
        mOpt     = flag.Int("m", govpn.DefaultM, "Argon2d memory parameter (KiBs)")
        tOpt     = flag.Int("t", govpn.DefaultT, "Argon2d iteration parameter")
        pOpt     = flag.Int("p", govpn.DefaultP, "Argon2d parallelizm parameter")
+       egdPath  = flag.String("egd", "", "Optional path to EGD socket")
 )
 
 func main() {
        flag.Parse()
+       if *egdPath != "" {
+               govpn.EGDInit(*egdPath)
+       }
        if *verifier == "" {
                id := new([govpn.IDSize]byte)
-               if _, err := rand.Read(id[:]); err != nil {
+               if _, err := govpn.Rand.Read(id[:]); err != nil {
                        log.Fatalln(err)
                }
                pid := govpn.PeerId(*id)
@@ -55,7 +58,10 @@ func main() {
        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(govpn.StringFromFile(*keyPath))
-       fmt.Println(subtle.ConstantTimeCompare(v.Pub[:], pub[:]) == 1)
+       fmt.Println(bytes.Equal(v.Pub[:], pub[:]))
 }