Skip to content

Commit

Permalink
ENCRYPTED COSIGN PRIVATE KEY -> ENCRYPTED SIGSTORE PRIVATE KEY (#101)
Browse files Browse the repository at this point in the history
* ENCRYPTED COSIGN PRIVATE KEY -> ENCRYPTED SIGSTORE PRIVATE KEY

Signed-off-by: Jake Sanders <jsand@google.com>

* also support decrypting Cosign encrypted private keys

Signed-off-by: Jake Sanders <jsand@google.com>
  • Loading branch information
Jake Sanders committed Jul 22, 2021
1 parent fd3b694 commit 90b4c06
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pkg/cryptoutils/privatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ import (
)

const (
PrivateKeyPEMType PEMType = "PRIVATE KEY"
EncryptedCosignPrivateKeyPEMType PEMType = "ENCRYPTED COSIGN PRIVATE KEY"
PrivateKeyPEMType PEMType = "PRIVATE KEY"
encryptedCosignPrivateKeyPEMType PEMType = "ENCRYPTED COSIGN PRIVATE KEY"
EncryptedSigstorePrivateKeyPEMType PEMType = "ENCRYPTED SIGSTORE PRIVATE KEY"
)

func pemEncodeKeyPair(priv crypto.PrivateKey, pub crypto.PublicKey, pf PassFunc) (privPEM, pubPEM []byte, err error) {
Expand All @@ -57,7 +58,7 @@ func pemEncodeKeyPair(priv crypto.PrivateKey, pub crypto.PublicKey, pf PassFunc)
if derBytes, err = encrypted.Encrypt(derBytes, password); err != nil {
return nil, nil, err
}
return PEMEncode(EncryptedCosignPrivateKeyPEMType, derBytes), pubPEM, nil
return PEMEncode(EncryptedSigstorePrivateKeyPEMType, derBytes), pubPEM, nil
}

// GeneratePEMEncodedECDSAKeyPair generates an ECDSA keypair, optionally password encrypted using a provided PassFunc, and PEM encoded.
Expand Down Expand Up @@ -102,7 +103,7 @@ func UnmarshalPEMToPrivateKey(pemBytes []byte, pf PassFunc) (crypto.PrivateKey,
switch derBlock.Type {
case string(PrivateKeyPEMType):
return x509.ParsePKCS8PrivateKey(derBlock.Bytes)
case string(EncryptedCosignPrivateKeyPEMType):
case string(EncryptedSigstorePrivateKeyPEMType), string(encryptedCosignPrivateKeyPEMType):
derBytes := derBlock.Bytes
if pf != nil {
password, err := pf(false)
Expand Down

0 comments on commit 90b4c06

Please sign in to comment.