From dcd94d7e571d5692e81972867931d326a95be910 Mon Sep 17 00:00:00 2001 From: Benjamin Wenger <ben@elixxir.ioo> Date: Sat, 29 Feb 2020 14:45:35 -0800 Subject: [PATCH] fixed signature clearing in mixmessages and added a basic test to securedNDF --- mixmessages/ndf.go | 4 +++- mixmessages/roundError.go | 4 +++- mixmessages/roundInfo.go | 4 +++- network/securedNdf_test.go | 40 +++++++++++++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/mixmessages/ndf.go b/mixmessages/ndf.go index 319e4701..90241b38 100644 --- a/mixmessages/ndf.go +++ b/mixmessages/ndf.go @@ -31,7 +31,9 @@ func (m *NDF) SetSig(newSig []byte) error { // ClearSignature clears out NDF's signature func (m *NDF) ClearSig() { - m.Signature = &RSASignature{} + if m.Signature!=nil{ + m.Signature.Signature = nil + } } // GetNonce gets the value of the nonce diff --git a/mixmessages/roundError.go b/mixmessages/roundError.go index 5c9f3871..b5adc455 100644 --- a/mixmessages/roundError.go +++ b/mixmessages/roundError.go @@ -31,7 +31,9 @@ func (m *RoundError) SetSig(newSig []byte) error { // ClearSignature clears out RoundError's signature func (m *RoundError) ClearSig() { - m.Signature = &RSASignature{} + if m.Signature!=nil{ + m.Signature.Signature=nil + } } // GetNonce gets the value of the nonce diff --git a/mixmessages/roundInfo.go b/mixmessages/roundInfo.go index dfa04896..930c8582 100644 --- a/mixmessages/roundInfo.go +++ b/mixmessages/roundInfo.go @@ -31,7 +31,9 @@ func (m *RoundInfo) SetSig(newSig []byte) error { // ClearSignature clears out roundInfo's signature func (m *RoundInfo) ClearSig() { - m.Signature = &RSASignature{} + if m.Signature!=nil{ + m.Signature.Signature=nil + } } // GetNonce gets the value of the nonce diff --git a/network/securedNdf_test.go b/network/securedNdf_test.go index 89c3d20a..4ab84182 100644 --- a/network/securedNdf_test.go +++ b/network/securedNdf_test.go @@ -1,6 +1,13 @@ package network -import "testing" +import ( + pb "gitlab.com/elixxir/comms/mixmessages" + "gitlab.com/elixxir/crypto/signature" + "gitlab.com/elixxir/crypto/signature/rsa" + "gitlab.com/elixxir/primitives/ndf" + "math/rand" + "testing" +) func TestNewSecuredNdf(t *testing.T) { sndf := NewSecuredNdf() @@ -9,3 +16,34 @@ func TestNewSecuredNdf(t *testing.T) { } } +func TestSecuredNdf_update(t *testing.T) { + src:=rand.New(rand.NewSource(42)) + privKey, err := rsa.GenerateKey(src, 768) + + if err!=nil{ + t.Errorf("Could not generate rsa key: %s", err) + } + + f := pb.NDF{} + + baseNDF := ndf.NetworkDefinition{} + f.Ndf, err = baseNDF.Marshal() + + if err!=nil{ + t.Errorf("Could not generate serialized ndf: %s", err) + } + + err = signature.Sign(&f, privKey) + + if err!=nil{ + t.Errorf("Could not sign serialized ndf: %s", err) + } + + sndf := NewSecuredNdf() + err = sndf.update(&f,privKey.GetPublic()) + + if err!=nil{ + t.Errorf("Could not update ndf: %s", err) + } + +} \ No newline at end of file -- GitLab