Skip to content

Commit

Permalink
fix byte slice
Browse files Browse the repository at this point in the history
Signed-off-by: Bob Callaway <[email protected]>
  • Loading branch information
bobcallaway committed Oct 3, 2024
1 parent 4a0b31d commit 0e41de3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions cmd/cosign/cli/pivcli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/cosign/pivkey/pivkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0e41de3

Please sign in to comment.