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

Use the correct verifier for RSA PSS scheme keys #625

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions examples/repository/basic_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,9 @@ func main() {

// Use a mixture of key types
// ==========================
// Create an RSA key
// Create an RSA key.
// Note TUF should use an RSA PSS key scheme, not RSA PKCS1v15.
// Reference: https://theupdateframework.github.io/specification/latest/#file-formats-keys
anotherRootKeyRSA, _ := rsa.GenerateKey(rand.Reader, 2048)
if err != nil {
panic(fmt.Sprintln("basic_repository.go:", "RSA key generation failed", err))
Expand Down Expand Up @@ -549,7 +551,7 @@ func main() {
}

// Sign root with the new RSA and ECDSA keys
outofbandSignerRSA, err := signature.LoadSigner(anotherRootKeyRSA, crypto.SHA256)
outofbandSignerRSA, err := signature.LoadRSAPSSSigner(anotherRootKeyRSA, crypto.SHA256, &rsa.PSSOptions{Hash: crypto.SHA256})
if err != nil {
panic(fmt.Sprintln("basic_repository.go:", "loading RSA signer failed", err))
}
Expand Down
17 changes: 16 additions & 1 deletion metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"bytes"
"crypto"
"crypto/hmac"
"crypto/rsa"
"crypto/sha256"
"crypto/sha512"
"encoding/base64"
Expand Down Expand Up @@ -322,7 +323,21 @@ func (meta *Metadata[T]) VerifyDelegate(delegatedRole string, delegatedMetadata
}
}
// load a verifier based on that key
verifier, err := signature.LoadVerifier(publicKey, hash)
// handle RSA PSS scheme separately as the LoadVerifier function doesn't identify it correctly
// Note we should support RSA PSS, not RSA PKCS1v15 (which is what LoadVerifier would return)
// Reference: https://theupdateframework.github.io/specification/latest/#file-formats-keys
var verifier signature.Verifier
if key.Type == KeyTypeRSASSA_PSS_SHA256 {
// Load a verifier for rsa
publicKeyRSAPSS, ok := publicKey.(*rsa.PublicKey)
if !ok {
return &ErrType{Msg: "failed to convert public key to RSA PSS key"}
}
verifier, err = signature.LoadRSAPSSVerifier(publicKeyRSAPSS, hash, &rsa.PSSOptions{Hash: crypto.SHA256})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, if you're using the Verifier interface, you can also load a verifier with a PSS option now - https://github.com/sigstore/sigstore/blob/main/pkg/signature/signerverifier_test.go#L30-L38

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this only seems true for SignerVerifier, not Verifier

} else {
// Load a verifier for ed25519 and ecdsa
verifier, err = signature.LoadVerifier(publicKey, hash)
}
if err != nil {
return err
}
Expand Down
Loading