2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2023 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.Fprintln(os.Stderr, "nncp-cfgnew -- generate new configuration and keys\nOptions:")
45 areaName = flag.String("area", "", "Generate area's keypairs")
46 yggdrasil = flag.Bool("yggdrasil", false, "Generate Yggdrasil keypair")
47 noComments = flag.Bool("nocomments", false, "Do not include descriptive comments")
48 version = flag.Bool("version", false, "Print version information")
49 warranty = flag.Bool("warranty", false, "Print warranty information")
51 log.SetFlags(log.Lshortfile)
55 fmt.Println(nncp.Warranty)
59 fmt.Println(nncp.VersionGet())
64 pub, prv, err := ed25519.GenerateKey(rand.Reader)
68 fmt.Println("Public:", hex.EncodeToString(pub))
69 fmt.Println("Private:", hex.EncodeToString(prv))
74 pub, prv, err := box.GenerateKey(rand.Reader)
78 areaId := nncp.AreaId(blake2b.Sum256(pub[:]))
81 cfgRaw = fmt.Sprintf(`areas: {
84 # KEEP AWAY keypair from the nodes you want only participate in multicast
91 nncp.Base32Codec.EncodeToString(pub[:]),
92 nncp.Base32Codec.EncodeToString(prv[:]),
95 cfgRaw = fmt.Sprintf(`areas: {
99 # KEEP AWAY keypair from the nodes you want only participate in multicast
103 # List of subscribers you should multicast area messages to
106 # Allow incoming files (from the area) saving in that directory
107 # incoming: /home/areas/%s/incoming
109 # Allow incoming area commands execution
110 # exec: {sendmail: ["%s"]}
112 # Allow unknown sender's message tossing (relaying will be made anyway)
113 # allow-unknown: true
118 nncp.Base32Codec.EncodeToString(pub[:]),
119 nncp.Base32Codec.EncodeToString(prv[:]),
121 nncp.DefaultSendmailPath,
124 var cfgGeneral map[string]interface{}
125 if err = hjson.Unmarshal([]byte(cfgRaw), &cfgGeneral); err != nil {
128 marshaled, err := json.Marshal(cfgGeneral)
132 var areas map[string]nncp.AreaJSON
133 if err = json.Unmarshal(marshaled, &areas); err != nil {
140 nodeOur, err := nncp.NewNodeGenerate()
146 cfgRaw = fmt.Sprintf(`{
151 # DO NOT show anyone your private keys!!!
167 exec: {sendmail: ["%s"]}
171 nncp.DefaultSpoolPath,
174 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
175 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
176 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
177 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
178 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
179 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
181 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
182 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
183 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
184 nncp.DefaultSendmailPath,
187 cfgRaw = fmt.Sprintf(`{
188 # Path to encrypted packets spool directory
192 # Enforce specified umask usage
194 # Omit progress showing by default
196 # Do not use hdr/ files
199 # MultiCast Discovery:
200 # List of interface regular expressions where to listen for MCD announcements
202 # Interfaces regular expressions and intervals (in seconds) where to send
206 # Yggdrasil related aliases:
207 # yggdrasil-aliases: {
209 # bob-pub: 98de...ac19d
210 # alice-endpoint: tcp://example.com:1234?key=689c...13fb
211 # default-endpoints: tcp://[::1]:2345,alice-endpoint
214 # Enable notification email sending
217 # from: nncp@localhost
218 # to: user+file@example.com
221 # from: nncp@localhost
222 # to: user+freq@example.com
224 # # Send some exec commands execution notifications
226 # # bob neighbour's "somehandle" notification
228 # from: nncp+bob@localhost
229 # to: user+somehandle@example.com
231 # # Any neighboor's "anotherhandle"
233 # from: nncp@localhost
234 # to: user+anotherhandle@example.com
240 # DO NOT show anyone your private keys!!!
252 # You should give public keys below to your neighbours
259 # Default self's sendmail command is used for email notifications sending
264 # Example neighbour, most of fields are optional
267 # exchpub: MJACJ...FAI6A
268 # signpub: T4AFC...N2FRQ
269 # noisepub: UBM5K...VI42A
271 # # He is allowed to send email
272 # # exec: {sendmail: ["%s"]}
274 # # Allow incoming files saving in that directory
275 # # incoming: "/home/alice/incoming"
277 # # Transitional nodes path
278 # # via: ["bob", "eve"]
280 # # Inactivity timeout when session with remote peer should be terminated
281 # # onlinedeadline: 1800
283 # # Maximal online session lifetime
284 # # maxonlinetime: 3600
286 # # If neither freq section, nor freq.path exist, then no freqing allowed
288 # # # Allow freqing from that directory
289 # # path: "/home/bob/pub"
290 # # # Send freqed files with chunks
292 # # # Send freqed files with minumal chunk size
294 # # # Maximal allowable freqing file size
298 # # Set maximal packets per second receive and transmit rates
304 # # lan: "[fe80::1234%%igb0]:5400"
305 # # internet: alice.com:3389
308 # # Calls configuration
311 # # cron: "*/2 * * * *"
312 # # onlinedeadline: 1800
313 # # maxonlinetime: 1750
314 # # nice: PRIORITY+10
319 # # when-tx-exists: true
324 # # autotoss-doseen: true
325 # # autotoss-nofile: true
326 # # autotoss-nofreq: true
327 # # autotoss-noexec: true
328 # # autotoss-notrns: true
334 nncp.DefaultSpoolPath,
337 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
338 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
339 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
340 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
341 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
342 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
344 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
345 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
346 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
347 nncp.DefaultSendmailPath,
348 nncp.DefaultSendmailPath,
351 if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {