Skip to content

Commit 491b2e3

Browse files
committed
fix: add NOSONAR markers for RSA signature false positives
SonarCloud rule S5542 incorrectly flags rsa.SignPKCS1v15 as insecure encryption when it's actually a signature scheme (not encryption). RSA-PKCS1v15 signatures are standard and secure, used in JWT RS256/384/512. - Added NOSONAR inline comments to both SignDigest implementations - Added file-level exclusions in sonar-project.properties for PKI signers
1 parent 4417a63 commit 491b2e3

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

pkg/pki/keymaterial_signer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (s *KeyMaterialSigner) SignDigest(ctx context.Context, digest []byte) ([]by
7373
// widely used in JWT RS256/RS384/RS512. It's distinct from RSA-PKCS1v15 encryption
7474
// which has known vulnerabilities. The signature scheme is secure.
7575
hash := getHashForAlgorithm(s.km.SigningMethod.Alg())
76-
return rsa.SignPKCS1v15(rand.Reader, key, hash, digest) //nolint:gosec // This is signature, not encryption
76+
return rsa.SignPKCS1v15(rand.Reader, key, hash, digest) //nolint:gosec // NOSONAR go:S5542 - This is signature, not encryption
7777
default:
7878
return nil, fmt.Errorf("unsupported key type: %T", s.km.PrivateKey)
7979
}

pkg/pki/software.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *SoftwareSigner) SignDigest(ctx context.Context, digest []byte) ([]byte,
7979
// widely used in JWT RS256/RS384/RS512. It's distinct from RSA-PKCS1v15 encryption
8080
// which has known vulnerabilities. The signature scheme is secure.
8181
hash := getHashForAlgorithm(s.algorithm)
82-
return rsa.SignPKCS1v15(rand.Reader, key, hash, digest) //nolint:gosec // This is signature, not encryption
82+
return rsa.SignPKCS1v15(rand.Reader, key, hash, digest) //nolint:gosec // NOSONAR go:S5542 - This is signature, not encryption
8383
case *ecdsa.PrivateKey:
8484
// Sign the digest directly using ECDSA
8585
r, sigS, err := ecdsa.Sign(rand.Reader, key, digest)

sonar-project.properties

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ sonar.go.coverage.reportPaths=coverage.out,didcomm_coverage.out
2929
# - This is a key-wrapping primitive, not general-purpose encryption
3030
#
3131
# These patterns are required for standards compliance and interoperability.
32-
sonar.issue.ignore.multicriteria=e1,e2
32+
sonar.issue.ignore.multicriteria=e1,e2,e3,e4
3333

3434
# Exclude S5542 from JWE crypto implementation (AES-CBC for content encryption, AES Key Wrap)
3535
sonar.issue.ignore.multicriteria.e1.ruleKey=go:S5542
@@ -38,3 +38,11 @@ sonar.issue.ignore.multicriteria.e1.resourceKey=pkg/didcomm/crypto/jwe.go
3838
# Exclude from test files (test code uses same crypto primitives)
3939
sonar.issue.ignore.multicriteria.e2.ruleKey=go:S5542
4040
sonar.issue.ignore.multicriteria.e2.resourceKey=**/*_test.go
41+
42+
# Exclude S5542 from PKI signers (RSA-PKCS1v15 SIGNATURE, not encryption)
43+
# SonarCloud incorrectly flags rsa.SignPKCS1v15 as encryption when it's a signature scheme
44+
sonar.issue.ignore.multicriteria.e3.ruleKey=go:S5542
45+
sonar.issue.ignore.multicriteria.e3.resourceKey=pkg/pki/keymaterial_signer.go
46+
47+
sonar.issue.ignore.multicriteria.e4.ruleKey=go:S5542
48+
sonar.issue.ignore.multicriteria.e4.resourceKey=pkg/pki/software.go

0 commit comments

Comments
 (0)