2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2022 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/>.
18 // Generate new NNCP node keys and configuration file
31 "github.com/hjson/hjson-go"
32 "golang.org/x/crypto/blake2b"
33 "golang.org/x/crypto/nacl/box"
35 "go.cypherpunks.ru/nncp/v8"
39 fmt.Fprintf(os.Stderr, nncp.UsageHeader())
40 fmt.Fprintln(os.Stderr, "nncp-cfgnew -- generate new configuration and keys\nOptions:")
46 areaName = flag.String("area", "", "Generate area's keypairs")
47 yggdrasil = flag.Bool("yggdrasil", false, "Generate Yggdrasil keypair")
48 noComments = flag.Bool("nocomments", false, "Do not include descriptive comments")
49 version = flag.Bool("version", false, "Print version information")
50 warranty = flag.Bool("warranty", false, "Print warranty information")
52 log.SetFlags(log.Lshortfile)
56 fmt.Println(nncp.Warranty)
60 fmt.Println(nncp.VersionGet())
65 pub, prv, err := ed25519.GenerateKey(rand.Reader)
69 fmt.Println("Public:", hex.EncodeToString(pub))
70 fmt.Println("Private:", hex.EncodeToString(prv))
75 pub, prv, err := box.GenerateKey(rand.Reader)
79 areaId := nncp.AreaId(blake2b.Sum256(pub[:]))
82 cfgRaw = fmt.Sprintf(`areas: {
85 # KEEP AWAY keypair from the nodes you want only participate in multicast
92 nncp.Base32Codec.EncodeToString(pub[:]),
93 nncp.Base32Codec.EncodeToString(prv[:]),
96 cfgRaw = fmt.Sprintf(`areas: {
100 # KEEP AWAY keypair from the nodes you want only participate in multicast
104 # List of subscribers you should multicast area messages to
107 # Allow incoming files (from the area) saving in that directory
108 # incoming: /home/areas/%s/incoming
110 # Allow incoming area commands execution
111 # exec: {sendmail: ["%s"]}
113 # Allow unknown sender's message tossing (relaying will be made anyway)
114 # allow-unknown: true
119 nncp.Base32Codec.EncodeToString(pub[:]),
120 nncp.Base32Codec.EncodeToString(prv[:]),
122 nncp.DefaultSendmailPath,
125 var cfgGeneral map[string]interface{}
126 if err = hjson.Unmarshal([]byte(cfgRaw), &cfgGeneral); err != nil {
129 marshaled, err := json.Marshal(cfgGeneral)
133 var areas map[string]nncp.AreaJSON
134 if err = json.Unmarshal(marshaled, &areas); err != nil {
141 nodeOur, err := nncp.NewNodeGenerate()
147 cfgRaw = fmt.Sprintf(`{
152 # DO NOT show anyone your private keys!!!
168 exec: {sendmail: ["%s"]}
172 nncp.DefaultSpoolPath,
175 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
176 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
177 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
178 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
179 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
180 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
182 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
183 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
184 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
185 nncp.DefaultSendmailPath,
188 cfgRaw = fmt.Sprintf(`{
189 # Path to encrypted packets spool directory
193 # Enforce specified umask usage
195 # Omit progress showing by default
197 # Do not use hdr/ files
200 # MultiCast Discovery:
201 # List of interface regular expressions where to listen for MCD announcements
203 # Interfaces regular expressions and intervals (in seconds) where to send
207 # Yggdrasil related aliases:
208 # yggdrasil-aliases: {
210 # bob-pub: 98de...ac19d
211 # alice-endpoint: tcp://example.com:1234?key=689c...13fb
212 # default-endpoints: tcp://[::1]:2345,alice-endpoint
215 # Enable notification email sending
218 # from: nncp@localhost
219 # to: user+file@example.com
222 # from: nncp@localhost
223 # to: user+freq@example.com
225 # # Send some exec commands execution notifications
227 # # bob neighbour's "somehandle" notification
229 # from: nncp+bob@localhost
230 # to: user+somehandle@example.com
232 # # Any neighboor's "anotherhandle"
234 # from: nncp@localhost
235 # to: user+anotherhandle@example.com
241 # DO NOT show anyone your private keys!!!
253 # You should give public keys below to your neighbours
260 # Default self's sendmail command is used for email notifications sending
265 # Example neighbour, most of fields are optional
268 # exchpub: MJACJ...FAI6A
269 # signpub: T4AFC...N2FRQ
270 # noisepub: UBM5K...VI42A
272 # # He is allowed to send email
273 # # exec: {sendmail: ["%s"]}
275 # # Allow incoming files saving in that directory
276 # # incoming: "/home/alice/incoming"
278 # # Transitional nodes path
279 # # via: ["bob", "eve"]
281 # # Inactivity timeout when session with remote peer should be terminated
282 # # onlinedeadline: 1800
284 # # Maximal online session lifetime
285 # # maxonlinetime: 3600
287 # # If neither freq section, nor freq.path exist, then no freqing allowed
289 # # # Allow freqing from that directory
290 # # path: "/home/bob/pub"
291 # # # Send freqed files with chunks
293 # # # Send freqed files with minumal chunk size
295 # # # Maximal allowable freqing file size
299 # # Set maximal packets per second receive and transmit rates
305 # # lan: "[fe80::1234%%igb0]:5400"
306 # # internet: alice.com:3389
309 # # Calls configuration
312 # # cron: "*/2 * * * *"
313 # # onlinedeadline: 1800
314 # # maxonlinetime: 1750
315 # # nice: PRIORITY+10
320 # # when-tx-exists: true
325 # # autotoss-doseen: true
326 # # autotoss-nofile: true
327 # # autotoss-nofreq: true
328 # # autotoss-noexec: true
329 # # autotoss-notrns: true
335 nncp.DefaultSpoolPath,
338 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
339 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
340 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
341 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
342 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
343 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
345 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
346 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
347 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
348 nncp.DefaultSendmailPath,
349 nncp.DefaultSendmailPath,
352 if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {