2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2021 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
29 "github.com/hjson/hjson-go"
30 "golang.org/x/crypto/blake2b"
31 "golang.org/x/crypto/nacl/box"
33 "go.cypherpunks.ru/nncp/v7"
37 fmt.Fprintf(os.Stderr, nncp.UsageHeader())
38 fmt.Fprintln(os.Stderr, "nncp-cfgnew -- generate new configuration and keys\nOptions:")
44 areaName = flag.String("area", "", "Generate area's keypairs")
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())
61 pub, prv, err := box.GenerateKey(rand.Reader)
65 areaId := nncp.AreaId(blake2b.Sum256(pub[:]))
68 cfgRaw = fmt.Sprintf(`areas: {
71 # KEEP AWAY keypair from the nodes you want only participate in multicast
78 nncp.Base32Codec.EncodeToString(pub[:]),
79 nncp.Base32Codec.EncodeToString(prv[:]),
82 cfgRaw = fmt.Sprintf(`areas: {
86 # KEEP AWAY keypair from the nodes you want only participate in multicast
90 # List of subscribers you should multicast area messages to
93 # Allow incoming files (from the area) saving in that directory
94 # incoming: /home/areas/%s/incoming
96 # Allow incoming area commands execution
97 # exec: {sendmail: ["%s"]}
99 # Allow unknown sender's message tossing (relaying will be made anyway)
100 # allow-unknown: true
105 nncp.Base32Codec.EncodeToString(pub[:]),
106 nncp.Base32Codec.EncodeToString(prv[:]),
108 nncp.DefaultSendmailPath,
111 var cfgGeneral map[string]interface{}
112 if err = hjson.Unmarshal([]byte(cfgRaw), &cfgGeneral); err != nil {
115 marshaled, err := json.Marshal(cfgGeneral)
119 var areas map[string]nncp.AreaJSON
120 if err = json.Unmarshal(marshaled, &areas); err != nil {
126 nodeOur, err := nncp.NewNodeGenerate()
132 cfgRaw = fmt.Sprintf(`{
137 # DO NOT show anyone your private keys!!!
153 exec: {sendmail: ["%s"]}
157 nncp.DefaultSpoolPath,
160 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
161 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
162 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
163 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
164 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
165 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
167 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
168 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
169 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
170 nncp.DefaultSendmailPath,
173 cfgRaw = fmt.Sprintf(`{
174 # Path to encrypted packets spool directory
178 # Enforce specified umask usage
180 # Omit progress showing by default
182 # Do not use .hdr files
185 # MultiCast Discovery:
186 # List of interfaces where to listen for MCD announcements
187 # mcd-listen: ["em0", "igb1"]
188 # Interfaces and intervals (in seconds) where to send MCD announcements
189 # mcd-send: {em0: 60, igb1: 5}
191 # Enable notification email sending
194 # from: nncp@localhost
195 # to: user+file@example.com
198 # from: nncp@localhost
199 # to: user+freq@example.com
201 # # Send some exec commands execution notifications
203 # # bob neighbour's "somehandle" notification
205 # from: nncp+bob@localhost
206 # to: user+somehandle@example.com
208 # # Any neighboor's "anotherhandle"
210 # from: nncp@localhost
211 # to: user+anotherhandle@example.com
217 # DO NOT show anyone your private keys!!!
229 # You should give public keys below to your neighbours
236 # Default self's sendmail command is used for email notifications sending
241 # Example neighbour, most of fields are optional
244 # exchpub: MJACJ...FAI6A
245 # signpub: T4AFC...N2FRQ
246 # noisepub: UBM5K...VI42A
248 # # He is allowed to send email
249 # # exec: {sendmail: ["%s"]}
251 # # Allow incoming files saving in that directory
252 # # incoming: "/home/alice/incoming"
254 # # Transitional nodes path
255 # # via: ["bob", "eve"]
257 # # Inactivity timeout when session with remote peer should be terminated
258 # # onlinedeadline: 1800
260 # # Maximal online session lifetime
261 # # maxonlinetime: 3600
263 # # If neither freq section, nor freq.path exist, then no freqing allowed
265 # # # Allow freqing from that directory
266 # # path: "/home/bob/pub"
267 # # # Send freqed files with chunks
269 # # # Send freqed files with minumal chunk size
271 # # # Maximal allowable freqing file size
275 # # Set maximal packets per second receive and transmit rates
281 # # lan: "[fe80::1234%%igb0]:5400"
282 # # internet: alice.com:3389
285 # # Calls configuration
288 # # cron: "*/2 * * * *"
289 # # onlinedeadline: 1800
290 # # maxonlinetime: 1750
291 # # nice: PRIORITY+10
296 # # when-tx-exists: true
301 # # autotoss-doseen: true
302 # # autotoss-nofile: true
303 # # autotoss-nofreq: true
304 # # autotoss-noexec: true
305 # # autotoss-notrns: true
311 nncp.DefaultSpoolPath,
314 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
315 nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]),
316 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
317 nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]),
318 nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]),
319 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
321 nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]),
322 nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]),
323 nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]),
324 nncp.DefaultSendmailPath,
325 nncp.DefaultSendmailPath,
328 if _, err = nncp.CfgParse([]byte(cfgRaw)); err != nil {