From: Sergey Matveev Date: Sun, 8 Aug 2021 12:11:40 +0000 (+0300) Subject: Additional public keys existence checks X-Git-Tag: v7.6.0^2 X-Git-Url: http://www.git.cypherpunks.ru/?p=nncp.git;a=commitdiff_plain;h=54611d620bb927666b94e0f6e3c5f723bd7a7cf4 Additional public keys existence checks --- diff --git a/doc/news.ru.texi b/doc/news.ru.texi index 497509d..5de3cba 100644 --- a/doc/news.ru.texi +++ b/doc/news.ru.texi @@ -10,6 +10,10 @@ дескриптор (@env{$NNCPLOG=FD:5} например). Что дружелюбно к использованию под @command{daemontools}. +@item +Добавлены дополнительные проверки наличия публичных ключей в +конфигурационном файле, предотвращающие падения некоторых команд. + @end itemize @node Релиз 7.5.1 diff --git a/doc/news.texi b/doc/news.texi index 80153a8..e737a52 100644 --- a/doc/news.texi +++ b/doc/news.texi @@ -12,6 +12,10 @@ Logging may be done to specified opened file descriptor (@env{$NNCPLOG=FD:5} for example). That is friendly to use under @command{daemontools}. +@item +Added additional checks of public keys existence in configuration file, +preventing some commands from failing. + @end itemize @node Release 7_5_1 diff --git a/src/cfg.go b/src/cfg.go index 22da596..55c9dd0 100644 --- a/src/cfg.go +++ b/src/cfg.go @@ -21,6 +21,7 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "log" "os" "path" @@ -445,6 +446,9 @@ func NewArea(ctx *Ctx, name string, cfg *AreaJSON) (*Area, error) { copy(area.Pub[:], pub) } if cfg.Prv != nil { + if area.Pub == nil { + return nil, fmt.Errorf("area %s: prv requires pub presence", name) + } prv, err := Base32Codec.DecodeString(*cfg.Prv) if err != nil { return nil, err diff --git a/src/cmd/nncp-caller/main.go b/src/cmd/nncp-caller/main.go index 614a051..177065f 100644 --- a/src/cmd/nncp-caller/main.go +++ b/src/cmd/nncp-caller/main.go @@ -94,6 +94,9 @@ func main() { if err != nil { log.Fatalln("Invalid NODE specified:", err) } + if node.NoisePub == nil { + log.Fatalln("Node", nodeId, "does not have online communication capability") + } if len(node.Calls) == 0 { ctx.LogD( "caller-no-calls", diff --git a/src/sp.go b/src/sp.go index 099aa47..3de629b 100644 --- a/src/sp.go +++ b/src/sp.go @@ -549,6 +549,9 @@ func (state *SPState) StartR(conn ConnDeadlined) error { var node *Node for _, n := range state.Ctx.Neigh { + if n.NoisePub == nil { + continue + } if subtle.ConstantTimeCompare(state.hs.PeerStatic(), n.NoisePub[:]) == 1 { node = n break diff --git a/src/tx.go b/src/tx.go index 337bcfd..0ddbd51 100644 --- a/src/tx.go +++ b/src/tx.go @@ -60,7 +60,7 @@ func (ctx *Ctx) Tx( if areaId != nil { area = ctx.AreaId2Area[*areaId] if area.Prv == nil { - return nil, errors.New("unknown area id") + return nil, errors.New("area has no encryption keys") } } hops := make([]*Node, 0, 1+len(node.Via))