Skip to content

Commit 9507549

Browse files
authored
Fix TestEncryptOAEP and TLS failures in FIPS mode (#87)
1 parent 4a36d9a commit 9507549

File tree

1 file changed

+46
-13
lines changed

1 file changed

+46
-13
lines changed

patches/000-initial-setup.patch

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,8 @@ index 3278a7ff30..e4484540c1 100644
958958
n := new(big.Int)
959959
for i, test := range testEncryptOAEPData {
960960
n.SetString(test.modulus, 16)
961-
+ if boring.Enabled && !boringtest.Supports(t, "RSA1024") && n.BitLen() < 2048 {
962-
+ t.Logf("skipping encryption tests with BoringCrypto: too short key: %d", n.BitLen())
961+
+ if boring.Enabled {
962+
+ t.Log("skipping test in FIPS mode due to short keys and unpadded RSA operations not allowed with FIPS")
963963
+ continue
964964
+ }
965965
public := PublicKey{N: n, E: test.e}
@@ -1041,7 +1041,7 @@ index 1827f76458..140b1a3dd8 100644
10411041

10421042
// default defaultFIPSCurvePreferences is the FIPS-allowed curves,
10431043
diff --git a/src/crypto/tls/boring_test.go b/src/crypto/tls/boring_test.go
1044-
index ba68f355eb..8ddd2526c7 100644
1044+
index ba68f355eb..7bfe3f9417 100644
10451045
--- a/src/crypto/tls/boring_test.go
10461046
+++ b/src/crypto/tls/boring_test.go
10471047
@@ -9,6 +9,8 @@ package tls
@@ -1093,7 +1093,23 @@ index ba68f355eb..8ddd2526c7 100644
10931093
return true
10941094
}
10951095
return false
1096-
@@ -315,15 +325,31 @@ func TestBoringCertAlgs(t *testing.T) {
1096+
@@ -226,7 +236,14 @@ func TestBoringServerSignatureAndHash(t *testing.T) {
1097+
// 1.3, and the ECDSA ones bind to the curve used.
1098+
serverConfig.MaxVersion = VersionTLS12
1099+
1100+
- clientErr, serverErr := boringHandshake(t, testConfig, serverConfig)
1101+
+ clientConfig := testConfig.Clone()
1102+
+
1103+
+ if boring.Enabled {
1104+
+ serverConfig.Rand = boring.RandReader
1105+
+ clientConfig.Rand = boring.RandReader
1106+
+ }
1107+
+
1108+
+ clientErr, serverErr := boringHandshake(t, clientConfig, serverConfig)
1109+
if clientErr != nil {
1110+
t.Fatalf("expected handshake with %#x to succeed; client error: %v; server error: %v", sigHash, clientErr, serverErr)
1111+
}
1112+
@@ -315,15 +332,31 @@ func TestBoringCertAlgs(t *testing.T) {
10971113
R2 := boringCert(t, "R2", boringRSAKey(t, 512), nil, boringCertCA)
10981114

10991115
M1_R1 := boringCert(t, "M1_R1", boringECDSAKey(t, elliptic.P256()), R1, boringCertCA|boringCertFIPSOK)
@@ -1128,19 +1144,36 @@ index ba68f355eb..8ddd2526c7 100644
11281144

11291145
// client verifying server cert
11301146
testServerCert := func(t *testing.T, desc string, pool *x509.CertPool, key interface{}, list [][]byte, ok bool) {
1131-
@@ -362,6 +388,11 @@ func TestBoringCertAlgs(t *testing.T) {
1147+
@@ -336,6 +369,11 @@ func TestBoringCertAlgs(t *testing.T) {
1148+
serverConfig.Certificates = []Certificate{{Certificate: list, PrivateKey: key}}
1149+
serverConfig.BuildNameToCertificate()
1150+
1151+
+ if boring.Enabled {
1152+
+ serverConfig.Rand = boring.RandReader
1153+
+ clientConfig.Rand = boring.RandReader
1154+
+ }
1155+
+
1156+
clientErr, _ := boringHandshake(t, clientConfig, serverConfig)
1157+
1158+
if (clientErr == nil) == ok {
1159+
@@ -362,6 +400,16 @@ func TestBoringCertAlgs(t *testing.T) {
11321160
serverConfig := testConfig.Clone()
11331161
serverConfig.ClientCAs = pool
11341162
serverConfig.ClientAuth = RequireAndVerifyClientCert
11351163
+ if boring.Enabled {
11361164
+ serverConfig.Certificates[0].Certificate = [][]byte{testRSA2048Certificate}
11371165
+ serverConfig.Certificates[0].PrivateKey = testRSA2048PrivateKey
11381166
+ serverConfig.BuildNameToCertificate()
1167+
+ }
1168+
+
1169+
+ if boring.Enabled {
1170+
+ serverConfig.Rand = boring.RandReader
1171+
+ clientConfig.Rand = boring.RandReader
11391172
+ }
11401173

11411174
_, serverErr := boringHandshake(t, clientConfig, serverConfig)
11421175

1143-
@@ -384,8 +415,8 @@ func TestBoringCertAlgs(t *testing.T) {
1176+
@@ -384,8 +432,8 @@ func TestBoringCertAlgs(t *testing.T) {
11441177
// exhaustive test with computed answers.
11451178
r1pool := x509.NewCertPool()
11461179
r1pool.AddCert(R1.cert)
@@ -1151,7 +1184,7 @@ index ba68f355eb..8ddd2526c7 100644
11511184
fipstls.Force()
11521185
testServerCert(t, "basic (fips)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
11531186
testClientCert(t, "basic (fips, client cert)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
1154-
@@ -406,7 +437,7 @@ func TestBoringCertAlgs(t *testing.T) {
1187+
@@ -406,7 +454,7 @@ func TestBoringCertAlgs(t *testing.T) {
11551188
leaf = L2_I
11561189
}
11571190
for i := 0; i < 64; i++ {
@@ -1160,7 +1193,7 @@ index ba68f355eb..8ddd2526c7 100644
11601193
reachableFIPS := map[string]bool{leaf.parentOrg: leaf.fipsOK}
11611194
list := [][]byte{leaf.der}
11621195
listName := leaf.name
1163-
@@ -414,7 +445,7 @@ func TestBoringCertAlgs(t *testing.T) {
1196+
@@ -414,7 +462,7 @@ func TestBoringCertAlgs(t *testing.T) {
11641197
if cond != 0 {
11651198
list = append(list, c.der)
11661199
listName += "," + c.name
@@ -1169,7 +1202,7 @@ index ba68f355eb..8ddd2526c7 100644
11691202
reachable[c.parentOrg] = true
11701203
}
11711204
if reachableFIPS[c.org] && c.fipsOK {
1172-
@@ -438,7 +469,7 @@ func TestBoringCertAlgs(t *testing.T) {
1205+
@@ -438,7 +486,7 @@ func TestBoringCertAlgs(t *testing.T) {
11731206
if cond != 0 {
11741207
rootName += "," + c.name
11751208
pool.AddCert(c.cert)
@@ -1178,23 +1211,23 @@ index ba68f355eb..8ddd2526c7 100644
11781211
shouldVerify = true
11791212
}
11801213
if reachableFIPS[c.org] && c.fipsOK {
1181-
@@ -464,6 +495,7 @@ const (
1214+
@@ -464,6 +512,7 @@ const (
11821215
boringCertCA = iota
11831216
boringCertLeaf
11841217
boringCertFIPSOK = 0x80
11851218
+ boringCertNotBoring = 0x100
11861219
)
11871220

11881221
func boringRSAKey(t *testing.T, size int) *rsa.PrivateKey {
1189-
@@ -490,6 +522,7 @@ type boringCertificate struct {
1222+
@@ -490,6 +539,7 @@ type boringCertificate struct {
11901223
cert *x509.Certificate
11911224
key interface{}
11921225
fipsOK bool
11931226
+ notBoring bool
11941227
}
11951228

11961229
func boringCert(t *testing.T, name string, key interface{}, parent *boringCertificate, mode int) *boringCertificate {
1197-
@@ -511,7 +544,7 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
1230+
@@ -511,7 +561,7 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
11981231
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
11991232
BasicConstraintsValid: true,
12001233
}
@@ -1203,7 +1236,7 @@ index ba68f355eb..8ddd2526c7 100644
12031236
tmpl.DNSNames = []string{"example.com"}
12041237
} else {
12051238
tmpl.IsCA = true
1206-
@@ -548,7 +581,8 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
1239+
@@ -548,7 +598,8 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
12071240
}
12081241

12091242
fipsOK := mode&boringCertFIPSOK != 0

0 commit comments

Comments
 (0)