From 0a29afe5c282879bbe297b5628fffd94955ef2ce Mon Sep 17 00:00:00 2001 From: josh <josh@elixxir.io> Date: Wed, 14 Apr 2021 12:52:40 -0700 Subject: [PATCH] Clean up ecPublic key handling --- network/dataStructures/round.go | 4 +--- network/instance.go | 33 +++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/network/dataStructures/round.go b/network/dataStructures/round.go index adf1071e..3f0d9c50 100644 --- a/network/dataStructures/round.go +++ b/network/dataStructures/round.go @@ -60,9 +60,7 @@ func (r *Round) Get() *pb.RoundInfo { jww.FATAL.Panicf("Could not validate "+ "the roundInfo signature: %+v: %v", r.info, err) } - } - - if r.ecPubKey != nil { + } else { // Check the sig, panic if failure err := signature.VerifyEddsa(r.info, r.ecPubKey) if err != nil { diff --git a/network/instance.go b/network/instance.go index 733cc7f8..5654723d 100644 --- a/network/instance.go +++ b/network/instance.go @@ -12,6 +12,7 @@ package network import ( "bytes" "fmt" + "github.com/katzenpost/core/crypto/eddsa" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" pb "gitlab.com/elixxir/comms/mixmessages" @@ -51,7 +52,7 @@ type Instance struct { // using the RSA key or the EC key. // Set to true, they shall use elliptic, set to false they shall use RSA useElliptic bool - + ecPublicKey *eddsa.PublicKey // Waiting Rounds waitingRounds *ds.WaitingRounds @@ -168,6 +169,24 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition, er useElliptic: useElliptic, } + i.ecPublicKey, err = ec.LoadPublicKeyFromString(i.GetEllipticPublicKey()) + if err != nil { + return nil, errors.WithMessage(err, fmt.Sprintf("Could not load elliptic key from ndf")) + } + + var ecPublicKey *eddsa.PublicKey + if full != nil && full.Registration.EllipticPubKey != "" { + ecPublicKey, err = ec.LoadPublicKeyFromString(i.GetEllipticPublicKey()) + if err != nil { + return nil, errors.WithMessage(err, fmt.Sprintf("Could not load elliptic key from ndf")) + } + } else if partial.Registration.EllipticPubKey != "" { + ecPublicKey, err = ec.LoadPublicKeyFromString(i.GetEllipticPublicKey()) + if err != nil { + return nil, errors.WithMessage(err, fmt.Sprintf("Could not load elliptic key from ndf")) + } + } + cmix := "" if full != nil && full.CMIX.Prime != "" { cmix, _ = full.CMIX.String() @@ -196,6 +215,12 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition, er } } + if ecPublicKey != nil { + i.ecPublicKey = ecPublicKey + } else { + jww.DEBUG.Printf("Elliptic public key was not set, could not be found in NDF") + } + i.waitingRounds = ds.NewWaitingRounds() i.events = ds.NewRoundEvents() i.validationLevel = validationLevel @@ -480,11 +505,7 @@ func (i *Instance) RoundUpdate(info *pb.RoundInfo) error { var rnd *ds.Round if i.useElliptic { // Use the elliptic key only - ecPublicKey, err := ec.LoadPublicKeyFromString(i.GetEllipticPublicKey()) - if err != nil { - return errors.WithMessage(err, fmt.Sprintf("Could not load elliptic key from ndf")) - } - rnd = ds.NewRound(info, nil, ecPublicKey) + rnd = ds.NewRound(info, nil, i.ecPublicKey) } else { // Use the rsa key only rnd = ds.NewRound(info, perm.GetPubKey(), nil) -- GitLab