From 0e41de3c6002ec7c1e70a85a806691b42c57b98d Mon Sep 17 00:00:00 2001 From: Bob Callaway Date: Thu, 3 Oct 2024 11:57:46 -0400 Subject: [PATCH] fix byte slice Signed-off-by: Bob Callaway --- cmd/cosign/cli/pivcli/commands.go | 10 +++++----- pkg/cosign/pivkey/pivkey.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/cosign/cli/pivcli/commands.go b/cmd/cosign/cli/pivcli/commands.go index de736dbafab..2f532eaaf79 100644 --- a/cmd/cosign/cli/pivcli/commands.go +++ b/cmd/cosign/cli/pivcli/commands.go @@ -46,7 +46,7 @@ func SetManagementKeyCmd(_ context.Context, oldKey, newKey string, randomKey boo if err != nil { return err } - var newBytes *[24]byte + var newBytes *[]byte if randomKey { if !Confirm("Resetting management key to random value. You must factory reset the device to change this value") { return nil @@ -286,14 +286,14 @@ func ResetKeyCmd(ctx context.Context) error { return yk.Reset() } -func keyBytes(s string) (*[24]byte, error) { +func keyBytes(s string) (*[]byte, error) { if s == "" { return &piv.DefaultManagementKey, nil } if len(s) > 24 { return nil, errors.New("key too long, must be <24 characters") } - ret := [24]byte{} + ret := []byte{} copy(ret[:], s) return &ret, nil } @@ -312,8 +312,8 @@ var Confirm = func(p string) bool { return strings.ToLower(result) == "y" } -func randomManagementKey() (*[24]byte, error) { - var newKeyBytes [24]byte +func randomManagementKey() (*[]byte, error) { + var newKeyBytes []byte n, err := io.ReadFull(rand.Reader, newKeyBytes[:]) if err != nil { return nil, err diff --git a/pkg/cosign/pivkey/pivkey.go b/pkg/cosign/pivkey/pivkey.go index 8208995f787..d5d35343f04 100644 --- a/pkg/cosign/pivkey/pivkey.go +++ b/pkg/cosign/pivkey/pivkey.go @@ -113,7 +113,7 @@ func (k *Key) GetAttestationCertificate() (*x509.Certificate, error) { return k.card.AttestationCertificate() } -func (k *Key) SetManagementKey(old, new [24]byte) error { +func (k *Key) SetManagementKey(old, new []byte) error { if k.card == nil { return KeyNotInitialized } @@ -153,7 +153,7 @@ func (k *Key) Unblock(puk, newPIN string) error { return k.card.Unblock(puk, newPIN) } -func (k *Key) GenerateKey(mgmtKey [24]byte, slot piv.Slot, opts piv.Key) (crypto.PublicKey, error) { +func (k *Key) GenerateKey(mgmtKey []byte, slot piv.Slot, opts piv.Key) (crypto.PublicKey, error) { if k.card == nil { return nil, KeyNotInitialized }