2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 "github.com/agl/ed25519"
34 RefreshRate = time.Minute
38 confs map[govpn.PeerId]*govpn.PeerConf
39 idsCache govpn.CipherCache
42 func confRead() map[govpn.PeerId]*govpn.PeerConf {
43 data, err := ioutil.ReadFile(*confPath)
45 log.Fatalln("Unable to read configuration:", err)
47 confsRaw := new(map[string]govpn.PeerConf)
48 err = json.Unmarshal(data, confsRaw)
50 log.Fatalln("Unable to parse configuration:", err)
53 confs := make(map[govpn.PeerId]*govpn.PeerConf, len(*confsRaw))
54 for peerIdRaw, pc := range *confsRaw {
55 peerId, err := govpn.IDDecode(peerIdRaw)
57 log.Fatalln("Invalid peer ID:", peerIdRaw, err)
59 conf := govpn.PeerConf{
67 if pc.TimeoutInt <= 0 {
68 pc.TimeoutInt = govpn.TimeoutDefault
70 conf.Timeout = time.Second * time.Duration(pc.TimeoutInt)
72 if len(pc.Verifier) != ed25519.PublicKeySize*2 {
73 log.Fatalln("Verifier must be 64 hex characters long")
75 keyDecoded, err := hex.DecodeString(string(pc.Verifier))
77 log.Fatalln("Unable to decode the key:", err.Error(), pc.Verifier)
79 conf.DSAPub = new([ed25519.PublicKeySize]byte)
80 copy(conf.DSAPub[:], keyDecoded)
82 confs[*peerId] = &conf
89 ids := make([]govpn.PeerId, 0, len(confs))
90 for peerId, _ := range confs {
91 ids = append(ids, peerId)
97 idsCache = govpn.NewCipherCache(nil)
101 time.Sleep(RefreshRate)