Skip to content
Snippets Groups Projects
Commit 00ccdb19 authored by Josh Brooks's avatar Josh Brooks
Browse files

Add update group function

parent 96851169
No related branches found
No related tags found
No related merge requests found
...@@ -40,7 +40,7 @@ func NewNdf(definition *ndf.NetworkDefinition) (*Ndf, error) { ...@@ -40,7 +40,7 @@ func NewNdf(definition *ndf.NetworkDefinition) (*Ndf, error) {
} }
//Updates to a new NDF if the passed NDF is valid //Updates to a new NDF if the passed NDF is valid
func (file *Ndf) Update(m *pb.NDF, e2eGroup *Group, cmixGroup *Group) error { func (file *Ndf) Update(m *pb.NDF) error {
//build the ndf object //build the ndf object
decoded, _, err := ndf.DecodeNDF(string(m.Ndf)) decoded, _, err := ndf.DecodeNDF(string(m.Ndf))
......
...@@ -18,7 +18,7 @@ func setup() *Ndf { ...@@ -18,7 +18,7 @@ func setup() *Ndf {
} }
ndf := &Ndf{} ndf := &Ndf{}
_ = ndf.Update(msg, nil, nil) _ = ndf.Update(msg)
return ndf return ndf
} }
...@@ -39,12 +39,12 @@ func TestNdf_Update(t *testing.T) { ...@@ -39,12 +39,12 @@ func TestNdf_Update(t *testing.T) {
} }
ndf := Ndf{} ndf := Ndf{}
err := ndf.Update(badMsg, nil, nil) err := ndf.Update(badMsg)
if err == nil { if err == nil {
t.Error("Should have returned error when unable to decode ndf") t.Error("Should have returned error when unable to decode ndf")
} }
err = ndf.Update(msg, nil, nil) err = ndf.Update(msg)
if err != nil { if err != nil {
t.Errorf("Failed to update ndf: %+v", err) t.Errorf("Failed to update ndf: %+v", err)
} }
......
...@@ -78,6 +78,26 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition) (* ...@@ -78,6 +78,26 @@ func NewInstance(c *connect.ProtoComms, partial, full *ndf.NetworkDefinition) (*
}, nil }, nil
} }
// UpdateGroup updates the groups of the network instance given an ndf
func (i *Instance) UpdateGroup(m *pb.NDF) error {
decoded, _, err := ndf.DecodeNDF(string(m.Ndf))
if err != nil {
return errors.WithMessage(err, "Could not decode the NDF")
}
err = i.cmixGroup.Update(decoded.CMIX.String())
if err != nil {
return errors.WithMessage(err, "Could not update cmix group")
}
err = i.e2eGroup.Update(decoded.E2E.String())
if err != nil {
return errors.WithMessage(err, "Could not update e2e group")
}
return nil
}
//update the partial ndf //update the partial ndf
func (i *Instance) UpdatePartialNdf(m *pb.NDF) error { func (i *Instance) UpdatePartialNdf(m *pb.NDF) error {
perm, success := i.comm.GetHost(id.PERMISSIONING) perm, success := i.comm.GetHost(id.PERMISSIONING)
...@@ -87,7 +107,7 @@ func (i *Instance) UpdatePartialNdf(m *pb.NDF) error { ...@@ -87,7 +107,7 @@ func (i *Instance) UpdatePartialNdf(m *pb.NDF) error {
"for NDF partial verification") "for NDF partial verification")
} }
return i.partial.update(m, perm.GetPubKey(), i.e2eGroup, i.cmixGroup) return i.partial.update(m, perm.GetPubKey())
} }
//update the full ndf //update the full ndf
...@@ -99,7 +119,7 @@ func (i *Instance) UpdateFullNdf(m *pb.NDF) error { ...@@ -99,7 +119,7 @@ func (i *Instance) UpdateFullNdf(m *pb.NDF) error {
"for full NDF verification") "for full NDF verification")
} }
return i.full.update(m, perm.GetPubKey(), i.e2eGroup, i.cmixGroup) return i.full.update(m, perm.GetPubKey())
} }
// Return the partial ndf from this instance // Return the partial ndf from this instance
......
...@@ -35,13 +35,13 @@ func NewSecuredNdf(definition *ndf.NetworkDefinition) (*SecuredNdf, error) { ...@@ -35,13 +35,13 @@ func NewSecuredNdf(definition *ndf.NetworkDefinition) (*SecuredNdf, error) {
} }
// unexported NDF update code // unexported NDF update code
func (sndf *SecuredNdf) update(m *pb.NDF, key *rsa.PublicKey, e2eGroup *ds.Group, cmixGroup *ds.Group) error { func (sndf *SecuredNdf) update(m *pb.NDF, key *rsa.PublicKey) error {
err := signature.Verify(m, key) err := signature.Verify(m, key)
if err != nil { if err != nil {
return errors.WithMessage(err, "Could not validate NDF") return errors.WithMessage(err, "Could not validate NDF")
} }
return sndf.f.Update(m, e2eGroup, cmixGroup) return sndf.f.Update(m)
} }
// Get the primitives object for an ndf // Get the primitives object for an ndf
......
...@@ -23,7 +23,7 @@ func setup() *ds.Ndf { ...@@ -23,7 +23,7 @@ func setup() *ds.Ndf {
} }
ndf := &ds.Ndf{} ndf := &ds.Ndf{}
_ = ndf.Update(msg, nil, nil) _ = ndf.Update(msg)
return ndf return ndf
} }
...@@ -71,13 +71,13 @@ func TestSecuredNdf_update(t *testing.T) { ...@@ -71,13 +71,13 @@ func TestSecuredNdf_update(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to secure ndf: %+v", err) t.Errorf("Failed to secure ndf: %+v", err)
} }
err = sndf.update(&f, privKey.GetPublic(), nil, nil) err = sndf.update(&f, privKey.GetPublic())
if err != nil { if err != nil {
t.Errorf("Could not update ndf: %s", err) t.Errorf("Could not update ndf: %s", err)
} }
err = sndf.update(&f, badPub, nil, nil) err = sndf.update(&f, badPub)
if err == nil { if err == nil {
t.Errorf("should have received bad key error") t.Errorf("should have received bad key error")
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment