]> Cypherpunks.ru repositories - govpn.git/blobdiff - src/govpn/identify.go
Replace -noncediff with the hash keeping up to 256 seen nonces
[govpn.git] / src / govpn / identify.go
index 4363c58d39fd9bd001b8aaae73cab6c8e2b93e81..c7675b6368b48cc62e7eef3180e8515ac1421e1b 100644 (file)
@@ -21,6 +21,7 @@ package govpn
 import (
        "crypto/subtle"
        "encoding/hex"
+       "errors"
        "io/ioutil"
        "log"
        "os"
@@ -58,7 +59,6 @@ func (id PeerId) MarshalJSON() ([]byte, error) {
 type PeerConf struct {
        Id          *PeerId
        Timeout     time.Duration
-       Noncediff   int
        NoiseEnable bool
        CPR         int
        // This is passphrase verifier
@@ -112,8 +112,8 @@ func (cc cipherCache) refresh() {
        }
        available := make(map[PeerId]bool)
        for _, peerId := range peerIds {
-               id := IDDecode(peerId)
-               if id == nil {
+               id, err := IDDecode(peerId)
+               if err != nil {
                        continue
                }
                available[*id] = true
@@ -179,7 +179,7 @@ func (id *PeerId) Conf() *PeerConf {
        if dummyConf != nil {
                return dummyConf
        }
-       conf := PeerConf{Id: id, Noncediff: 1, NoiseEnable: false, CPR: 0}
+       conf := PeerConf{Id: id, NoiseEnable: false, CPR: 0}
        peerPath := path.Join(PeersPath, id.String())
 
        verPath := path.Join(peerPath, "verifier")
@@ -206,9 +206,6 @@ func (id *PeerId) Conf() *PeerConf {
        }
        conf.Timeout = time.Second * time.Duration(timeout)
 
-       if val, err := readIntFromFile(path.Join(peerPath, "noncediff")); err == nil {
-               conf.Noncediff = val
-       }
        if val, err := readIntFromFile(path.Join(peerPath, "noise")); err == nil && val == 1 {
                conf.NoiseEnable = true
        }
@@ -220,17 +217,16 @@ func (id *PeerId) Conf() *PeerConf {
 
 // Decode identification string.
 // It must be 32 hexadecimal characters long.
-// If it is not the valid one, then return nil.
-func IDDecode(raw string) *PeerId {
+func IDDecode(raw string) (*PeerId, error) {
        if len(raw) != IDSize*2 {
-               return nil
+               return nil, errors.New("ID must be 32 characters long")
        }
        idDecoded, err := hex.DecodeString(raw)
        if err != nil {
-               return nil
+               return nil, errors.New("ID must contain hexadecimal characters only")
        }
        idP := new([IDSize]byte)
        copy(idP[:], idDecoded)
        id := PeerId(*idP)
-       return &id
+       return &id, nil
 }