X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=src%2Fcmd%2Fnncp-cfgnew%2Fmain.go;h=0ec00e91b2d0c65753e2e3fa9421814c02781316;hb=b47dbfe6687569650fa544a4ecf3e4ea388390cb;hp=e2eac99d0c8affde1cdf17aae09de357ea858499;hpb=2c00ac2b448c4c267e25d3bac91c2d7dc1c01aef;p=nncp.git diff --git a/src/cmd/nncp-cfgnew/main.go b/src/cmd/nncp-cfgnew/main.go index e2eac99..0ec00e9 100644 --- a/src/cmd/nncp-cfgnew/main.go +++ b/src/cmd/nncp-cfgnew/main.go @@ -1,6 +1,6 @@ /* NNCP -- Node to Node copy, utilities for store-and-forward data exchange -Copyright (C) 2016-2019 Sergey Matveev +Copyright (C) 2016-2021 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -19,11 +19,18 @@ along with this program. If not, see . package main import ( + "crypto/rand" + "encoding/json" "flag" "fmt" + "log" "os" - "go.cypherpunks.ru/nncp/v5" + "github.com/hjson/hjson-go" + "golang.org/x/crypto/blake2b" + "golang.org/x/crypto/nacl/box" + + "go.cypherpunks.ru/nncp/v8" ) func usage() { @@ -34,10 +41,12 @@ func usage() { func main() { var ( + areaName = flag.String("area", "", "Generate area's keypairs") noComments = flag.Bool("nocomments", false, "Do not include descriptive comments") version = flag.Bool("version", false, "Print version information") warranty = flag.Bool("warranty", false, "Print warranty information") ) + log.SetFlags(log.Lshortfile) flag.Usage = usage flag.Parse() if *warranty { @@ -48,9 +57,75 @@ func main() { fmt.Println(nncp.VersionGet()) return } + if *areaName != "" { + pub, prv, err := box.GenerateKey(rand.Reader) + if err != nil { + log.Fatalln(err) + } + areaId := nncp.AreaId(blake2b.Sum256(pub[:])) + var cfgRaw string + if *noComments { + cfgRaw = fmt.Sprintf(`areas: { + %s: { + id: %s + # KEEP AWAY keypair from the nodes you want only participate in multicast + pub: %s + prv: %s + } +}`, + *areaName, + areaId.String(), + nncp.Base32Codec.EncodeToString(pub[:]), + nncp.Base32Codec.EncodeToString(prv[:]), + ) + } else { + cfgRaw = fmt.Sprintf(`areas: { + %s: { + id: %s + + # KEEP AWAY keypair from the nodes you want only participate in multicast + pub: %s + prv: %s + + # List of subscribers you should multicast area messages to + # subs: ["alice"] + + # Allow incoming files (from the area) saving in that directory + # incoming: /home/areas/%s/incoming + + # Allow incoming area commands execution + # exec: {sendmail: ["%s"]} + + # Allow unknown sender's message tossing (relaying will be made anyway) + # allow-unknown: true + } +}`, + *areaName, + areaId.String(), + nncp.Base32Codec.EncodeToString(pub[:]), + nncp.Base32Codec.EncodeToString(prv[:]), + *areaName, + nncp.DefaultSendmailPath, + ) + } + var cfgGeneral map[string]interface{} + if err = hjson.Unmarshal([]byte(cfgRaw), &cfgGeneral); err != nil { + panic(err) + } + marshaled, err := json.Marshal(cfgGeneral) + if err != nil { + panic(err) + } + var areas map[string]nncp.AreaJSON + if err = json.Unmarshal(marshaled, &areas); err != nil { + panic(err) + } + fmt.Println(cfgRaw) + return + } nodeOur, err := nncp.NewNodeGenerate() if err != nil { - panic(err) + log.Fatalln(err) } var cfgRaw string if *noComments { @@ -82,16 +157,16 @@ func main() { nncp.DefaultSpoolPath, nncp.DefaultLogPath, nodeOur.Id.String(), - nncp.ToBase32(nodeOur.ExchPub[:]), - nncp.ToBase32(nodeOur.ExchPrv[:]), - nncp.ToBase32(nodeOur.SignPub[:]), - nncp.ToBase32(nodeOur.SignPrv[:]), - nncp.ToBase32(nodeOur.NoisePub[:]), - nncp.ToBase32(nodeOur.NoisePrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]), nodeOur.Id.String(), - nncp.ToBase32(nodeOur.ExchPub[:]), - nncp.ToBase32(nodeOur.SignPub[:]), - nncp.ToBase32(nodeOur.NoisePub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]), nncp.DefaultSendmailPath, ) } else { @@ -102,6 +177,16 @@ func main() { log: %s # Enforce specified umask usage # umask: "022" + # Omit progress showing by default + # noprogress: true + # Do not use hdr/ files + # nohdr: true + + # MultiCast Discovery: + # List of interfaces where to listen for MCD announcements + # mcd-listen: ["em0", "igb1"] + # Interfaces and intervals (in seconds) where to send MCD announcements + # mcd-send: {em0: 60, igb1: 5} # Enable notification email sending # notify: { @@ -208,7 +293,17 @@ func main() { # # txrate: 20 # # xx: rx # # addr: lan - # # }, + # # when-tx-exists: true + # # nock: true + # # mcd-ignore: true + # # + # # autotoss: false + # # autotoss-doseen: true + # # autotoss-nofile: true + # # autotoss-nofreq: true + # # autotoss-noexec: true + # # autotoss-notrns: true + # # } # # ] # } } @@ -216,16 +311,16 @@ func main() { nncp.DefaultSpoolPath, nncp.DefaultLogPath, nodeOur.Id.String(), - nncp.ToBase32(nodeOur.ExchPub[:]), - nncp.ToBase32(nodeOur.ExchPrv[:]), - nncp.ToBase32(nodeOur.SignPub[:]), - nncp.ToBase32(nodeOur.SignPrv[:]), - nncp.ToBase32(nodeOur.NoisePub[:]), - nncp.ToBase32(nodeOur.NoisePrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.ExchPrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.SignPrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.NoisePrv[:]), + nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]), nodeOur.Id.String(), - nncp.ToBase32(nodeOur.ExchPub[:]), - nncp.ToBase32(nodeOur.SignPub[:]), - nncp.ToBase32(nodeOur.NoisePub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.ExchPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.SignPub[:]), + nncp.Base32Codec.EncodeToString(nodeOur.NoisePub[:]), nncp.DefaultSendmailPath, nncp.DefaultSendmailPath, )