Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: gcb v1.0 support #691

Merged
merged 21 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ require (
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.2.0 // indirect
Expand Down
43 changes: 36 additions & 7 deletions verifiers/internal/gcb/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,20 @@ import (
//go:embed materials/*
var publicKeys embed.FS

const GlobalPAEKeyID = "projects/verified-builder/locations/global/keyRings/attestor/cryptoKeys/provenanceSigner/cryptoKeyVersions/1"
const GlobalPAEPublicKeyName = "global-pae"
const (
// v1.0 global keys.
// Run command `gcloud kms keys versions get-public-key 1 --keyring attestor --key google-hosted-worker --project verified-builder --location global`.
V10GlobalPAEKeyID = "projects/verified-builder/locations/global/keyRings/attestor/cryptoKeys/google-hosted-worker/cryptoKeyVersions/1"

// v0.1 global keys.
// Run command `gcloud kms keys versions get-public-key 1 --keyring attestor --key provenanceSigner --project verified-builder --location global`.
V01GlobalPAEKeyID = "projects/verified-builder/locations/global/keyRings/attestor/cryptoKeys/provenanceSigner/cryptoKeyVersions/1"
)

var globalKeyNames = map[string]string{
V10GlobalPAEKeyID: "global-pae-google-hosted-worker_1",
V01GlobalPAEKeyID: "global-pae-provenanceSigner_1",
}

type PublicKey struct {
value []byte
Expand Down Expand Up @@ -69,18 +81,31 @@ func (p *PublicKey) VerifySignature(digest [32]byte, sig []byte) error {
return nil
}

func (p *PublicKey) Name() string {
return p.region
}

type GlobalPAEKey struct {
publicKey *PublicKey
id string
Verifier *dsselib.EnvelopeVerifier
}

func NewGlobalPAEKey() (*GlobalPAEKey, error) {
publicKey, err := NewPublicKey(GlobalPAEPublicKeyName)
func NewGlobalPAEKey(id string) (*GlobalPAEKey, error) {
name, ok := globalKeyNames[id]
if !ok {
return nil, fmt.Errorf("%w: unknown key %v", serrors.ErrorInternal, id)
}

publicKey, err := NewPublicKey(name)
if err != nil {
return nil, fmt.Errorf("unable to create public key for Global PAE key: %w", err)
return nil, fmt.Errorf("%w: unable to create public key for Global PAE key %v", err, name)
}

globalPaeKey := &GlobalPAEKey{publicKey: publicKey}
globalPaeKey := &GlobalPAEKey{
publicKey: publicKey,
id: id,
}
envVerifier, err := dsselib.NewEnvelopeVerifier(globalPaeKey)
if err != nil {
return nil, err
Expand All @@ -104,10 +129,14 @@ func (v *GlobalPAEKey) Verify(_ context.Context, data, sig []byte) error {

// KeyID implements dsse.Verifier.KeyID.
func (v *GlobalPAEKey) KeyID() (string, error) {
return GlobalPAEKeyID, nil
return v.id, nil
}

// Public implements dsse.Verifier.Public.
func (v *GlobalPAEKey) Public() crypto.PublicKey {
return v.publicKey
}

func (v *GlobalPAEKey) Name() string {
return v.publicKey.Name()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEg9KII7kzr/30HBluf00y9WwtMFkE
qc3oCcFVH3QJ37IBLUv/MUApbnNHFfD75ayJ/a0F45xa+MLv5zoep+GxsA==
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEdMcJUyKbmarf6dydhfmAjgmK6c42
oCCNRR1se3Bi3VO65KcGk6qyci6/bsu2s4u+dLKWrsUQomEw4v3FtVctoA==
-----END PUBLIC KEY-----
Loading
Loading