2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2019 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, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 "github.com/flynn/noise"
26 "golang.org/x/crypto/blake2b"
27 "golang.org/x/crypto/ed25519"
28 "golang.org/x/crypto/nacl/box"
31 type NodeId [blake2b.Size256]byte
33 func (id NodeId) String() string {
34 return ToBase32(id[:])
41 SignPub ed25519.PublicKey
43 Exec map[string][]string
50 Addrs map[string]string
65 SignPub ed25519.PublicKey
66 SignPrv ed25519.PrivateKey
71 func NewNodeGenerate() (*NodeOur, error) {
72 exchPub, exchPrv, err := box.GenerateKey(rand.Reader)
76 signPub, signPrv, err := ed25519.GenerateKey(rand.Reader)
80 noiseKey, err := noise.DH25519.GenerateKeypair(rand.Reader)
84 noisePub := new([32]byte)
85 noisePrv := new([32]byte)
86 copy(noisePrv[:], noiseKey.Private)
87 copy(noisePub[:], noiseKey.Public)
89 id := NodeId(blake2b.Sum256([]byte(signPub)))
102 func (nodeOur *NodeOur) Their() *Node {
106 ExchPub: nodeOur.ExchPub,
107 SignPub: nodeOur.SignPub,
108 FreqChunked: MaxFileSize,
109 FreqMaxSize: MaxFileSize,
113 func NodeIdFromString(raw string) (*NodeId, error) {
114 decoded, err := FromBase32(raw)
118 if len(decoded) != blake2b.Size256 {
119 return nil, errors.New("Invalid node id size")
121 buf := new([blake2b.Size256]byte)
122 copy(buf[:], decoded)
123 nodeId := NodeId(*buf)