Skip to content

Commit

Permalink
Merge pull request #120 from gmacf/resolve
Browse files Browse the repository at this point in the history
Pass the resolved Chassis object to Sign().
  • Loading branch information
melzhan authored Dec 20, 2023
2 parents b6a5341 + 50a5496 commit 8406a68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion server/entitymanager/entitymanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (m *InMemoryEntityManager) SetStatus(ctx context.Context, req *bpb.ReportSt
}

// Sign unmarshals the SignedResponse bytes then generates a signature from its Ownership Certificate private key.
func (m *InMemoryEntityManager) Sign(ctx context.Context, resp *bpb.GetBootstrapDataResponse, chassis *service.EntityLookup, controllerCard string) error {
func (m *InMemoryEntityManager) Sign(ctx context.Context, resp *bpb.GetBootstrapDataResponse, chassis *service.Chassis, controllerCard string) error {
m.mu.Lock()
defer m.mu.Unlock()
// Check if security artifacts are provided for signing.
Expand Down
13 changes: 10 additions & 3 deletions server/entitymanager/entitymanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,23 @@ func TestSign(t *testing.T) {
ctx := context.Background()
tests := []struct {
desc string
chassis service.EntityLookup
chassis service.Chassis
serial string
resp *bpb.GetBootstrapDataResponse
wantOC bool
wantErr bool
}{{
desc: "Success",
chassis: service.EntityLookup{
chassis: service.Chassis{
Manufacturer: "Cisco",
SerialNumber: "123",
Serial: "123",
ControlCards: []*service.ControlCard{
{
Serial: "123A",
Manufacturer: "Cisco",
PartNumber: "123A",
},
},
},
serial: "123A",
resp: &bpb.GetBootstrapDataResponse{
Expand Down
4 changes: 2 additions & 2 deletions server/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ type EntityManager interface {
ResolveChassis(context.Context, *EntityLookup, string) (*Chassis, error)
GetBootstrapData(context.Context, *Chassis, string) (*bpb.BootstrapDataResponse, error)
SetStatus(context.Context, *bpb.ReportStatusRequest) error
Sign(context.Context, *bpb.GetBootstrapDataResponse, *EntityLookup, string) error
Sign(context.Context, *bpb.GetBootstrapDataResponse, *Chassis, string) error
}

// Service represents the server and entity manager.
Expand Down Expand Up @@ -247,7 +247,7 @@ func (s *Service) GetBootstrapData(ctx context.Context, req *bpb.GetBootstrapDat
log.Infof("=============================================================================")
log.Infof("====================== Signing the response with nonce ======================")
log.Infof("=============================================================================")
if err := s.em.Sign(ctx, resp, lookup, req.GetControlCardState().GetSerialNumber()); err != nil {
if err := s.em.Sign(ctx, resp, chassis, req.GetControlCardState().GetSerialNumber()); err != nil {
return nil, err
}
log.Infof("Signed with nonce")
Expand Down

0 comments on commit 8406a68

Please sign in to comment.