1 // NNCP -- Node to Node copy, utilities for store-and-forward data exchange
2 // Copyright (C) 2016-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // Generate new NNCP node keys and configuration file
29 "github.com/hjson/hjson-go/v4"
30 "golang.org/x/crypto/blake2b"
31 "golang.org/x/crypto/nacl/box"
33 "go.cypherpunks.ru/nncp/v8"
37 fmt.Fprintln(os.Stderr, "nncp-cfgnew -- generate new configuration and keys\nOptions:")
43 areaName = flag.String("area", "", "Generate area's keypairs")
44 yggdrasil = flag.Bool("yggdrasil", false, "Generate Yggdrasil keypair")
45 noComments = flag.Bool("nocomments", false, "Do not include descriptive comments")
46 version = flag.Bool("version", false, "Print version information")
47 warranty = flag.Bool("warranty", false, "Print warranty information")
49 log.SetFlags(log.Lshortfile)
53 fmt.Println(nncp.Warranty)
57 fmt.Println(nncp.VersionGet())
62 pub, prv, err := ed25519.GenerateKey(rand.Reader)
66 fmt.Println("Public:", hex.EncodeToString(pub))
67 fmt.Println("Private:", hex.EncodeToString(prv))
72 pub, prv, err := box.GenerateKey(rand.Reader)
76 areaId := nncp.AreaId(blake2b.Sum256(pub[:]))
79 cfgRaw = fmt.Sprintf(`areas: {
82 # KEEP AWAY keypair from the nodes you want only participate in multicast
89 nncp.Base32Codec.EncodeToString(pub[:]),
90 nncp.Base32Codec.EncodeToString(prv[:]),
93 cfgRaw = fmt.Sprintf(`areas: {
97 # KEEP AWAY keypair from the nodes you want only participate in multicast
101 # List of subscribers you should multicast area messages to
104 # Allow incoming files (from the area) saving in that directory
105 # incoming: /home/areas/%s/incoming
107 # Allow incoming area commands execution
108 # exec: {sendmail: ["%s"]}
110 # Allow unknown sender's message tossing (relaying will be made anyway)
111 # allow-unknown: true
116 nncp.Base32Codec.EncodeToString(pub[:]),
117 nncp.Base32Codec.EncodeToString(prv[:]),
119 nncp.DefaultSendmailPath,
122 var cfgGeneral map[string]interface{}
123 if err = hjson.Unmarshal([]byte(cfgRaw), &cfgGeneral); err != nil {
126 marshaled, err := json.Marshal(cfgGeneral)
130 var areas map[string]nncp.AreaJSON
131 if err = json.Unmarshal(marshaled, &areas); err != nil {
138 nodeOur, err := nncp.NewNodeGenerate()
144 cfgRaw = fmt.Sprintf(`{
149 # DO NOT show anyone your private keys!!!
165 exec: {sendmail: ["%s"]}
169 nncp.DefaultSpoolPath,
172 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
173 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
174 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
175 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
176 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
177 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
179 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
180 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
181 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
182 nncp.DefaultSendmailPath,
185 cfgRaw = fmt.Sprintf(`{
186 # Path to encrypted packets spool directory
190 # Enforce specified umask usage
192 # Omit progress showing by default
194 # Do not use hdr/ files
197 # MultiCast Discovery:
198 # List of interface regular expressions where to listen for MCD announcements
200 # Interfaces regular expressions and intervals (in seconds) where to send
204 # Yggdrasil related aliases:
205 # yggdrasil-aliases: {
207 # bob-pub: 98de...ac19d
208 # alice-endpoint: tcp://example.com:1234?key=689c...13fb
209 # default-endpoints: tcp://[::1]:2345,alice-endpoint
212 # Enable notification email sending
215 # from: nncp@localhost
216 # to: user+file@example.com
219 # from: nncp@localhost
220 # to: user+freq@example.com
222 # # Send some exec commands execution notifications
224 # # bob neighbour's "somehandle" notification
226 # from: nncp+bob@localhost
227 # to: user+somehandle@example.com
229 # # Any neighboor's "anotherhandle"
231 # from: nncp@localhost
232 # to: user+anotherhandle@example.com
238 # DO NOT show anyone your private keys!!!
250 # You should give public keys below to your neighbours
257 # Default self's sendmail command is used for email notifications sending
262 # Example neighbour, most of fields are optional
265 # exchpub: MJACJ...FAI6A
266 # signpub: T4AFC...N2FRQ
267 # noisepub: UBM5K...VI42A
269 # # He is allowed to send email
270 # # exec: {sendmail: ["%s"]}
272 # # Allow incoming files saving in that directory
273 # # incoming: "/home/alice/incoming"
275 # # Transitional nodes path
276 # # via: ["bob", "eve"]
278 # # Inactivity timeout when session with remote peer should be terminated
279 # # onlinedeadline: 1800
281 # # Maximal online session lifetime
282 # # maxonlinetime: 3600
284 # # If neither freq section, nor freq.path exist, then no freqing allowed
286 # # # Allow freqing from that directory
287 # # path: "/home/bob/pub"
288 # # # Send freqed files with chunks
290 # # # Send freqed files with minumal chunk size
292 # # # Maximal allowable freqing file size
296 # # Set maximal packets per second receive and transmit rates
302 # # lan: "[fe80::1234%%igb0]:5400"
303 # # internet: alice.com:3389
306 # # Calls configuration
309 # # cron: "*/2 * * * *"
310 # # onlinedeadline: 1800
311 # # maxonlinetime: 1750
312 # # nice: PRIORITY+10
317 # # when-tx-exists: true
322 # # autotoss-doseen: true
323 # # autotoss-nofile: true
324 # # autotoss-nofreq: true
325 # # autotoss-noexec: true
326 # # autotoss-notrns: true
332 nncp.DefaultSpoolPath,
335 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
336 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
337 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
338 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
339 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
340 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
342 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
343 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
344 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
345 nncp.DefaultSendmailPath,
346 nncp.DefaultSendmailPath,
349 if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {