Skip to content

Commit 6c2d6d7

Browse files
committed
[KeyManager] Fix compilation and lint errors
1 parent e5acfe0 commit 6c2d6d7

File tree

4 files changed

+59
-58
lines changed

4 files changed

+59
-58
lines changed

keymanager/key_protection_service/key_custody_core/kps_key_custody_core_cgo.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@ import "C"
1717
import (
1818
"fmt"
1919
"unsafe"
20-
"errors"
2120

2221
"github.com/google/uuid"
2322
"google.golang.org/protobuf/proto"
2423

2524
keymanager "github.com/google/go-tpm-tools/keymanager/km_common/proto"
2625
)
2726

28-
// ErrKeyNotFound is returned when a key is not found in the KPS core.
29-
var ErrKeyNotFound = errors.New("key not found in KPS")
30-
3127
const (
3228
uuidSize = 16
3329
kemPubKeySize = 32

keymanager/key_protection_service/key_custody_core/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package kpskcc
22

33
import (
4+
"errors"
5+
46
keymanager "github.com/google/go-tpm-tools/keymanager/km_common/proto"
57
"github.com/google/uuid"
68
)
79

10+
// ErrKeyNotFound is returned when a key is not found in the KPS core.
11+
var ErrKeyNotFound = errors.New("key not found in KPS")
12+
813
// KEMKeyInfo holds metadata for a single KEM key returned by EnumerateKEMKeys.
914
type KEMKeyInfo struct {
1015
ID uuid.UUID

keymanager/workload_service/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ func (s *Server) LookupBindingUUID(kemUUID uuid.UUID) (uuid.UUID, bool) {
335335
return info.bindingUUID, ok
336336
}
337337

338-
// GetBindingInfo returns the binding information associated with the given KEM UUID.
339-
func (s *Server) GetBindingInfo(kemUUID uuid.UUID) (bindingInfo, bool) {
338+
// getBindingInfo returns the binding information associated with the given KEM UUID.
339+
func (s *Server) getBindingInfo(kemUUID uuid.UUID) (bindingInfo, bool) {
340340
s.mu.RLock()
341341
info, ok := s.kemToBindingMap[kemUUID]
342342
s.mu.RUnlock()
@@ -382,7 +382,7 @@ func (s *Server) handleDecaps(w http.ResponseWriter, r *http.Request) {
382382
aad := decapsAADContext(kemUUID, req.Ciphertext.Algorithm)
383383

384384
// Look up the binding information for this KEM key.
385-
info, ok := s.GetBindingInfo(kemUUID)
385+
info, ok := s.getBindingInfo(kemUUID)
386386
if !ok {
387387
http.Error(w, fmt.Sprintf("KEM key handle not found: %s", kemUUID), http.StatusNotFound)
388388
return
@@ -629,7 +629,7 @@ func (s *Server) handleDestroy(w http.ResponseWriter, r *http.Request) {
629629
// handleGetBindingKeyClaims returns the claims for a binding key identified by its KEM UUID.
630630
func (s *Server) handleGetBindingKeyClaims(id uuid.UUID) (*keymanager.KeyClaims, error) {
631631
// Look up the binding information for this KEM key.
632-
info, ok := s.GetBindingInfo(id)
632+
info, ok := s.getBindingInfo(id)
633633
if !ok {
634634
return nil, fmt.Errorf("binding key ID not found for key handle: %s", id)
635635
}
@@ -672,7 +672,7 @@ func (s *Server) handleGetBindingKeyClaims(id uuid.UUID) (*keymanager.KeyClaims,
672672
// handleGetKEMKeyClaims returns the claims for a KEM key identified by its UUID.
673673
func (s *Server) handleGetKEMKeyClaims(id uuid.UUID) (*keymanager.KeyClaims, error) {
674674
// Look up the binding information for this KEM key.
675-
info, ok := s.GetBindingInfo(id)
675+
info, ok := s.getBindingInfo(id)
676676
if !ok {
677677
return nil, fmt.Errorf("KEM key handle not found: %s", id)
678678
}

keymanager/workload_service/server_test.go

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ func TestProcessClaims(t *testing.T) {
810810
// Let's create a new server with a mock that returns error.
811811
wsErr := &mockWorkloadService{err: fmt.Errorf("not found")}
812812
srvErr := newTestServer(t, kps, wsErr)
813-
813+
814814
// Populate map so WL service is called.
815815
srvErr.kemToBindingMap[notFoundUUID] = bindingInfo{
816816
bindingUUID: uuid.New(),
@@ -841,7 +841,7 @@ func TestProcessClaims(t *testing.T) {
841841

842842
kpsErr := &mockKeyProtectionService{err: fmt.Errorf("not found")}
843843
srvErr := newTestServer(t, kpsErr, ws)
844-
844+
845845
// Populate map so KPS is called.
846846
srvErr.kemToBindingMap[kemUUID] = bindingInfo{
847847
bindingUUID: bindingUUID,
@@ -1115,36 +1115,36 @@ func TestHandleDecap_ExpiredKey(t *testing.T) {
11151115
encKey := []byte("test-encapsulated-key-32-bytes!!")
11161116

11171117
tests := []struct {
1118-
name string
1119-
mapExpiresAt time.Time
1120-
kpsErr error
1121-
expectStatus int
1122-
expectKPSCalled bool
1123-
expectMapRemoved bool
1118+
name string
1119+
mapExpiresAt time.Time
1120+
kpsErr error
1121+
expectStatus int
1122+
expectKPSCalled bool
1123+
expectMapRemoved bool
11241124
}{
11251125
{
1126-
name: "Expired in map",
1126+
name: "Expired in map",
11271127
mapExpiresAt: time.Now().Add(-1 * time.Hour),
11281128
kpsErr: nil,
11291129
expectStatus: http.StatusGone,
1130-
expectKPSCalled: false,
1131-
expectMapRemoved: true,
1130+
expectKPSCalled: false,
1131+
expectMapRemoved: true,
11321132
},
11331133
{
1134-
name: "No map entry",
1134+
name: "No map entry",
11351135
mapExpiresAt: time.Time{}, // Not added to map
11361136
kpsErr: nil,
11371137
expectStatus: http.StatusNotFound,
1138-
expectKPSCalled: false,
1139-
expectMapRemoved: false,
1138+
expectKPSCalled: false,
1139+
expectMapRemoved: false,
11401140
},
11411141
{
1142-
name: "Expired in KPS",
1142+
name: "Expired in KPS",
11431143
mapExpiresAt: time.Now().Add(1 * time.Hour),
11441144
kpsErr: kpskcc.ErrKeyNotFound,
11451145
expectStatus: http.StatusGone,
1146-
expectKPSCalled: true,
1147-
expectMapRemoved: true,
1146+
expectKPSCalled: true,
1147+
expectMapRemoved: true,
11481148
},
11491149
}
11501150

@@ -1349,67 +1349,67 @@ func TestGetKeyClaims_ExpiredKey(t *testing.T) {
13491349
bindingUUID := uuid.New()
13501350

13511351
tests := []struct {
1352-
name string
1353-
keyType keymanager.KeyType
1354-
mapExpiresAt time.Time
1355-
kpsErr error
1356-
expectErr error
1357-
expectKPSCalled bool
1358-
expectMapRemoved bool
1352+
name string
1353+
keyType keymanager.KeyType
1354+
mapExpiresAt time.Time
1355+
kpsErr error
1356+
expectErr error
1357+
expectKPSCalled bool
1358+
expectMapRemoved bool
13591359
}{
13601360
{
1361-
name: "KEM key expired in map",
1362-
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_KEY,
1361+
name: "KEM key expired in map",
1362+
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_KEY,
13631363
mapExpiresAt: time.Now().Add(-1 * time.Hour),
13641364
kpsErr: nil,
13651365
expectErr: kpskcc.ErrKeyNotFound,
1366-
expectKPSCalled: false,
1367-
expectMapRemoved: true,
1366+
expectKPSCalled: false,
1367+
expectMapRemoved: true,
13681368
},
13691369
{
1370-
name: "Binding key expired in map",
1371-
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_BINDING,
1370+
name: "Binding key expired in map",
1371+
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_BINDING,
13721372
mapExpiresAt: time.Now().Add(-1 * time.Hour),
13731373
kpsErr: nil,
13741374
expectErr: kpskcc.ErrKeyNotFound,
1375-
expectKPSCalled: false,
1376-
expectMapRemoved: true,
1375+
expectKPSCalled: false,
1376+
expectMapRemoved: true,
13771377
},
13781378
{
1379-
name: "KEM key no map entry",
1380-
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_KEY,
1379+
name: "KEM key no map entry",
1380+
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_KEY,
13811381
mapExpiresAt: time.Time{}, // Not added to map
13821382
kpsErr: nil,
13831383
expectErr: errors.New("KEM key handle not found"),
1384-
expectKPSCalled: false,
1385-
expectMapRemoved: false,
1384+
expectKPSCalled: false,
1385+
expectMapRemoved: false,
13861386
},
13871387
{
1388-
name: "Binding key no map entry",
1389-
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_BINDING,
1388+
name: "Binding key no map entry",
1389+
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_BINDING,
13901390
mapExpiresAt: time.Time{}, // Not added to map
13911391
kpsErr: nil,
13921392
expectErr: errors.New("binding key ID not found"),
1393-
expectKPSCalled: false,
1394-
expectMapRemoved: false,
1393+
expectKPSCalled: false,
1394+
expectMapRemoved: false,
13951395
},
13961396
{
1397-
name: "KEM key expired in KPS",
1398-
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_KEY,
1397+
name: "KEM key expired in KPS",
1398+
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_KEY,
13991399
mapExpiresAt: time.Now().Add(1 * time.Hour),
14001400
kpsErr: kpskcc.ErrKeyNotFound,
14011401
expectErr: kpskcc.ErrKeyNotFound,
1402-
expectKPSCalled: true,
1403-
expectMapRemoved: true,
1402+
expectKPSCalled: true,
1403+
expectMapRemoved: true,
14041404
},
14051405
{
1406-
name: "Binding key expired in WL",
1407-
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_BINDING,
1406+
name: "Binding key expired in WL",
1407+
keyType: keymanager.KeyType_KEY_TYPE_VM_PROTECTION_BINDING,
14081408
mapExpiresAt: time.Now().Add(1 * time.Hour),
14091409
kpsErr: kpskcc.ErrKeyNotFound,
14101410
expectErr: kpskcc.ErrKeyNotFound,
1411-
expectKPSCalled: true,
1412-
expectMapRemoved: true,
1411+
expectKPSCalled: true,
1412+
expectMapRemoved: true,
14131413
},
14141414
}
14151415

@@ -1432,7 +1432,7 @@ func TestGetKeyClaims_ExpiredKey(t *testing.T) {
14321432
if err == nil {
14331433
t.Fatalf("expected error, got nil")
14341434
}
1435-
1435+
14361436
if tc.expectErr == kpskcc.ErrKeyNotFound {
14371437
if !errors.Is(err, kpskcc.ErrKeyNotFound) {
14381438
t.Errorf("expected ErrKeyNotFound, got %v", err)

0 commit comments

Comments
 (0)