2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2017 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/>.
26 "github.com/flynn/noise"
27 "github.com/gorhill/cronexpr"
28 "golang.org/x/crypto/blake2b"
29 "golang.org/x/crypto/ed25519"
30 "golang.org/x/crypto/nacl/box"
33 type NodeId [blake2b.Size256]byte
35 func (id NodeId) String() string {
36 return ToBase32(id[:])
43 SignPub ed25519.PublicKey
51 Addrs map[string]string
64 SignPub ed25519.PublicKey
65 SignPrv ed25519.PrivateKey
71 Cron *cronexpr.Expression
79 func NewNodeGenerate() (*NodeOur, error) {
80 exchPub, exchPrv, err := box.GenerateKey(rand.Reader)
84 signPub, signPrv, err := ed25519.GenerateKey(rand.Reader)
88 noiseKey := noise.DH25519.GenerateKeypair(rand.Reader)
89 noisePub := new([32]byte)
90 noisePrv := new([32]byte)
91 copy(noisePrv[:], noiseKey.Private)
92 copy(noisePub[:], noiseKey.Public)
94 id := NodeId(blake2b.Sum256([]byte(signPub)))
107 func (nodeOur *NodeOur) Their() *Node {
111 ExchPub: nodeOur.ExchPub,
112 SignPub: nodeOur.SignPub,
116 func NodeIdFromString(raw string) (*NodeId, error) {
117 decoded, err := FromBase32(raw)
121 if len(decoded) != blake2b.Size256 {
122 return nil, errors.New("Invalid node id size")
124 buf := new([blake2b.Size256]byte)
125 copy(buf[:], decoded)
126 nodeId := NodeId(*buf)