-
Notifications
You must be signed in to change notification settings - Fork 27
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: add support for additional transparency log key types #197
Changes from 4 commits
034e5ba
a40be1a
b40d2ea
058111c
3e057ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ package root | |
import ( | ||
"crypto" | ||
"crypto/ecdsa" | ||
"crypto/ed25519" | ||
"crypto/rsa" | ||
"crypto/x509" | ||
"encoding/hex" | ||
"fmt" | ||
|
@@ -136,41 +138,69 @@ func ParseTransparencyLogs(tlogs []*prototrustroot.TransparencyLogInstance) (tra | |
return nil, fmt.Errorf("unsupported hash function for the tlog") | ||
} | ||
|
||
tlogEntry := &TransparencyLog{ | ||
BaseURL: tlog.GetBaseUrl(), | ||
ID: tlog.GetLogId().GetKeyId(), | ||
HashFunc: hashFunc, | ||
SignatureHashFunc: crypto.SHA256, | ||
} | ||
|
||
switch tlog.GetPublicKey().GetKeyDetails() { | ||
case protocommon.PublicKeyDetails_PKIX_ECDSA_P256_SHA_256: | ||
case protocommon.PublicKeyDetails_PKIX_ECDSA_P256_SHA_256, | ||
protocommon.PublicKeyDetails_PKIX_ECDSA_P384_SHA_384, | ||
protocommon.PublicKeyDetails_PKIX_ECDSA_P521_SHA_512, | ||
protocommon.PublicKeyDetails_PKIX_ECDSA_P256_HMAC_SHA_256: //nolint:staticcheck | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to support |
||
key, err := x509.ParsePKIXPublicKey(tlog.GetPublicKey().GetRawBytes()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var ecKey *ecdsa.PublicKey | ||
var ok bool | ||
if ecKey, ok = key.(*ecdsa.PublicKey); !ok { | ||
return nil, fmt.Errorf("tlog public key is not ECDSA P256") | ||
return nil, fmt.Errorf("tlog public key is not ECDSA: %s", tlog.GetPublicKey().GetKeyDetails()) | ||
} | ||
tlogEntry.PublicKey = ecKey | ||
// This key format has public key in PKIX RSA format and PKCS1#1v1.5 or RSASSA-PSS signature | ||
case protocommon.PublicKeyDetails_PKIX_RSA_PKCS1V15_2048_SHA256, | ||
protocommon.PublicKeyDetails_PKIX_RSA_PKCS1V15_3072_SHA256, | ||
protocommon.PublicKeyDetails_PKIX_RSA_PKCS1V15_4096_SHA256, | ||
protocommon.PublicKeyDetails_PKIX_RSA_PSS_2048_SHA256, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can skip support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have removed PKIX-PSS but I havent removed PKIX-PKCS1v1.5 |
||
protocommon.PublicKeyDetails_PKIX_RSA_PSS_3072_SHA256, | ||
protocommon.PublicKeyDetails_PKIX_RSA_PSS_4096_SHA256: | ||
key, err := x509.ParsePKIXPublicKey(tlog.GetPublicKey().GetRawBytes()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
transparencyLogs[encodedKeyID] = &TransparencyLog{ | ||
BaseURL: tlog.GetBaseUrl(), | ||
ID: tlog.GetLogId().GetKeyId(), | ||
HashFunc: hashFunc, | ||
PublicKey: ecKey, | ||
SignatureHashFunc: crypto.SHA256, | ||
var rsaKey *rsa.PublicKey | ||
var ok bool | ||
if rsaKey, ok = key.(*rsa.PublicKey); !ok { | ||
return nil, fmt.Errorf("tlog public key is not RSA: %s", tlog.GetPublicKey().GetKeyDetails()) | ||
} | ||
tlogEntry.PublicKey = rsaKey | ||
case protocommon.PublicKeyDetails_PKIX_ED25519, protocommon.PublicKeyDetails_PKIX_ED25519_PH: //nolint:staticcheck | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, we can skip |
||
key, err := x509.ParsePKIXPublicKey(tlog.GetPublicKey().GetRawBytes()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var edKey ed25519.PublicKey | ||
var ok bool | ||
if edKey, ok = key.(ed25519.PublicKey); !ok { | ||
return nil, fmt.Errorf("tlog public key is not RSA: %s", tlog.GetPublicKey().GetKeyDetails()) | ||
} | ||
tlogEntry.PublicKey = edKey | ||
// This key format is deprecated, but currently in use for Sigstore staging instance | ||
case protocommon.PublicKeyDetails_PKCS1_RSA_PKCS1V5: //nolint:staticcheck | ||
key, err := x509.ParsePKCS1PublicKey(tlog.GetPublicKey().GetRawBytes()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
transparencyLogs[encodedKeyID] = &TransparencyLog{ | ||
BaseURL: tlog.GetBaseUrl(), | ||
ID: tlog.GetLogId().GetKeyId(), | ||
HashFunc: hashFunc, | ||
PublicKey: key, | ||
SignatureHashFunc: crypto.SHA256, | ||
} | ||
tlogEntry.PublicKey = key | ||
default: | ||
return nil, fmt.Errorf("unsupported tlog public key type: %s", tlog.GetPublicKey().GetKeyDetails()) | ||
} | ||
|
||
transparencyLogs[encodedKeyID] = tlogEntry | ||
|
||
if validFor := tlog.GetPublicKey().GetValidFor(); validFor != nil { | ||
if validFor.GetStart() != nil { | ||
transparencyLogs[encodedKeyID].ValidityPeriodStart = validFor.GetStart().AsTime() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The signature hash algorithm will differ depending on the signature scheme. I'd recommend a function like https://github.com/slsa-framework/slsa-verifier/blob/d96b9777090694fa5096ee1b9c710a46b5a66f5e/cli/slsa-verifier/verify/verify_vsa.go#L95-L117 to handle the mapping
tldr - RSA can always be SHA256, ECDSA P256 and P384 should be SHA256, P521 SHA512, and ed25519 is SHA512.