Skip to content

Commit

Permalink
Fix : Failing Fuzz tests for FuzzRSAPSSSignerVerfier (#664)
Browse files Browse the repository at this point in the history
- Fixed the failing fuzz test case

Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>

Signed-off-by: naveensrinivasan <172697+naveensrinivasan@users.noreply.github.com>
  • Loading branch information
naveensrinivasan committed Sep 2, 2022
1 parent 42f5598 commit 0372dec
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions test/fuzz/signature/fuzz_signature_test.go
Expand Up @@ -23,9 +23,10 @@ import (
"crypto/elliptic"
"crypto/rsa"
"math/big"
"strings"
"testing"

"github.com/sigstore/sigstore/pkg/cryptoutils"

fuzz "github.com/AdaLogics/go-fuzz-headers"
"github.com/sigstore/sigstore/pkg/signature"
)
Expand Down Expand Up @@ -153,21 +154,11 @@ func FuzzRSAPKCS1v15SignerVerfier(f *testing.F) {

func FuzzRSAPSSSignerVerfier(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
if len(data) == 0 {
t.Skip("not valid key")
}

s := string(data)

// Skip when the data is not a valid RSA PSS signature.
if strings.TrimSpace(s) == "" {
t.Skip("not valid key")
privateKey, err := cryptoutils.UnmarshalPEMToPrivateKey(data, cryptoutils.SkipPassword)
if err != nil {
t.Skip()
}

f := fuzz.NewConsumer(data)
x := rsa.PrivateKey{}
f.GenerateStruct(&x)
signer, err := signature.LoadRSAPSSSignerVerifier(&x, crypto.SHA512, nil)
signer, err := signature.LoadRSAPSSSignerVerifier(privateKey.(*rsa.PrivateKey), crypto.SHA512, nil)
if err != nil {
if signer != nil {
t.Errorf("key %v is not nil when there is an error %v ", signer, err)
Expand Down

0 comments on commit 0372dec

Please sign in to comment.