Skip to content

Commit 2f61277

Browse files
Potential fix for code scanning alert no. 2: Use of a weak cryptographic key
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 51fb251 commit 2f61277

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tls-demo/pkg/key/rsa.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
)
1111

1212
func CreateRSAPrivateKey(n int) (*rsa.PrivateKey, error) {
13+
if n < 2048 {
14+
return nil, fmt.Errorf("RSA key length too small: %d bits. Minimum is 2048 bits", n)
15+
}
1316
return rsa.GenerateKey(rand.Reader, n)
1417
}
1518

@@ -21,6 +24,9 @@ func RSAPrivateKeyToPEM(privateKey *rsa.PrivateKey) *pem.Block {
2124
}
2225

2326
func CreateRSAPrivateKeyAndSave(path string, n int) error {
27+
if n < 2048 {
28+
return fmt.Errorf("RSA key length too small: %d bits. Minimum is 2048 bits", n)
29+
}
2430
privateKey, err := CreateRSAPrivateKey(n)
2531
if err != nil {
2632
return err

0 commit comments

Comments
 (0)