diff --git a/network/dataStructures/round.go b/network/dataStructures/round.go index adf1071e036c4c26447ab4908b81742c9b7ca7e0..3f0d9c50db144126af0e853dcd373762cbbf016f 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 733cc7f81c39e3e01da4c0d86e54436e8e9d9470..5654723d74c07c8082e1306d05812d2a6f662150 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)