1
0
mirror of https://github.com/golang/go synced 2024-11-16 20:54:48 -07:00

crypto/x509: allow BoringCrypto to use 4096-bit keys

FIPS-140 has been updated to allow 4096-bit RSA keys.
Allow them in certificate processing.

Fixes #41147.

Change-Id: I4c6bcb1b137a200dfe70cebc605ae57f49871184
Reviewed-on: https://go-review.googlesource.com/c/go/+/447655
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
This commit is contained in:
Russ Cox 2022-11-03 13:08:52 -04:00 committed by Gopher Robot
parent 821e31042a
commit 9ff2a6677f
4 changed files with 73 additions and 52 deletions

View File

@ -16,6 +16,7 @@ import (
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"internal/obscuretestdata"
"math/big"
"net"
"runtime"
@ -311,7 +312,7 @@ func TestBoringCertAlgs(t *testing.T) {
// Set up some roots, intermediate CAs, and leaf certs with various algorithms.
// X_Y is X signed by Y.
R1 := boringCert(t, "R1", boringRSAKey(t, 2048), nil, boringCertCA|boringCertFIPSOK)
R2 := boringCert(t, "R2", boringRSAKey(t, 4096), nil, boringCertCA)
R2 := boringCert(t, "R2", boringRSAKey(t, 512), nil, boringCertCA)
M1_R1 := boringCert(t, "M1_R1", boringECDSAKey(t, elliptic.P256()), R1, boringCertCA|boringCertFIPSOK)
M2_R1 := boringCert(t, "M2_R1", boringECDSAKey(t, elliptic.P224()), R1, boringCertCA)
@ -558,56 +559,56 @@ var (
)
func init() {
block, _ := pem.Decode([]byte(`
-----BEGIN CERTIFICATE-----
MIIC/zCCAeegAwIBAgIRALHHX/kh4+4zMU9DarzBEcQwDQYJKoZIhvcNAQELBQAw
EjEQMA4GA1UEChMHQWNtZSBDbzAeFw0xMTAxMDExNTA0MDVaFw0yMDEyMjkxNTA0
MDVaMBIxEDAOBgNVBAoTB0FjbWUgQ28wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKA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5RWXD==
-----RAQ EFN CEVINGR XRL-----`)))
var err error
testRSA2048PrivateKey, err = x509.ParsePKCS1PrivateKey(block.Bytes)
if err != nil {

View File

@ -21,12 +21,13 @@ func boringAllowCert(c *Certificate) bool {
return true
}
// The key must be RSA 2048, RSA 3072, or ECDSA P-256, P-384, or P-521.
// The key must be RSA 2048, RSA 3072, RSA 4096,
// or ECDSA P-256, P-384, P-521.
switch k := c.PublicKey.(type) {
default:
return false
case *rsa.PublicKey:
if size := k.N.BitLen(); size != 2048 && size != 3072 {
if size := k.N.BitLen(); size != 2048 && size != 3072 && size != 4096 {
return false
}
case *ecdsa.PublicKey:

View File

@ -54,7 +54,8 @@ type boringCertificate struct {
func TestBoringAllowCert(t *testing.T) {
R1 := testBoringCert(t, "R1", boringRSAKey(t, 2048), nil, boringCertCA|boringCertFIPSOK)
R2 := testBoringCert(t, "R2", boringRSAKey(t, 4096), nil, boringCertCA)
R2 := testBoringCert(t, "R2", boringRSAKey(t, 8192), nil, boringCertCA)
R3 := testBoringCert(t, "R3", boringRSAKey(t, 4096), nil, boringCertCA|boringCertFIPSOK)
M1_R1 := testBoringCert(t, "M1_R1", boringECDSAKey(t, elliptic.P256()), R1, boringCertCA|boringCertFIPSOK)
M2_R1 := testBoringCert(t, "M2_R1", boringECDSAKey(t, elliptic.P224()), R1, boringCertCA)
@ -64,6 +65,9 @@ func TestBoringAllowCert(t *testing.T) {
testBoringCert(t, "I_M1", I_R1.key, M1_R1, boringCertCA|boringCertFIPSOK)
testBoringCert(t, "I_M2", I_R1.key, M2_R1, boringCertCA|boringCertFIPSOK)
I_R3 := testBoringCert(t, "I_R3", boringRSAKey(t, 3072), R3, boringCertCA|boringCertFIPSOK)
testBoringCert(t, "I_R3", I_R3.key, R3, boringCertCA|boringCertFIPSOK)
testBoringCert(t, "L1_I", boringECDSAKey(t, elliptic.P384()), I_R1, boringCertLeaf|boringCertFIPSOK)
testBoringCert(t, "L2_I", boringRSAKey(t, 1024), I_R1, boringCertLeaf)
}

View File

@ -13,6 +13,21 @@ import (
"os"
)
// Rot13 returns the rot13 encoding or decoding of its input.
func Rot13(data []byte) []byte {
out := make([]byte, len(data))
copy(out, data)
for i, c := range out {
switch {
case 'A' <= c && c <= 'M' || 'a' <= c && c <= 'm':
out[i] = c + 13
case 'N' <= c && c <= 'Z' || 'n' <= c && c <= 'z':
out[i] = c - 13
}
}
return out
}
// DecodeToTempFile decodes the named file to a temporary location.
// If successful, it returns the path of the decoded file.
// The caller is responsible for ensuring that the temporary file is removed.