Skip to content

Commit 2c31991

Browse files
authored
Backport #87 (Fix TestEncryptOAEP and TLS failures in FIPS mode) (#88)
1 parent 72d6791 commit 2c31991

File tree

2 files changed

+85
-27
lines changed

2 files changed

+85
-27
lines changed

patches/000-initial-setup.patch

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ index 51f9760187..eceb31aa71 100644
820820
t.Fatal(err)
821821
}
822822
diff --git a/src/crypto/rsa/rsa_test.go b/src/crypto/rsa/rsa_test.go
823-
index 766d9a954f..7d24a08882 100644
823+
index 766d9a954f..ef84e75b04 100644
824824
--- a/src/crypto/rsa/rsa_test.go
825825
+++ b/src/crypto/rsa/rsa_test.go
826826
@@ -16,6 +16,7 @@ import (
@@ -875,8 +875,8 @@ index 766d9a954f..7d24a08882 100644
875875
n := new(big.Int)
876876
for i, test := range testEncryptOAEPData {
877877
n.SetString(test.modulus, 16)
878-
+ if boring.Enabled && !boringtest.Supports(t, "RSA1024") && n.BitLen() < 2048 {
879-
+ t.Logf("skipping encryption tests with BoringCrypto: too short key: %d", n.BitLen())
878+
+ if boring.Enabled {
879+
+ t.Log("skipping test in FIPS mode due to short keys and unpadded RSA operations not allowed with FIPS")
880880
+ continue
881881
+ }
882882
public := PublicKey{N: n, E: test.e}
@@ -947,7 +947,7 @@ index 1827f76458..140b1a3dd8 100644
947947

948948
// default defaultFIPSCurvePreferences is the FIPS-allowed curves,
949949
diff --git a/src/crypto/tls/boring_test.go b/src/crypto/tls/boring_test.go
950-
index ba68f355eb..8ddd2526c7 100644
950+
index ba68f355eb..7bfe3f9417 100644
951951
--- a/src/crypto/tls/boring_test.go
952952
+++ b/src/crypto/tls/boring_test.go
953953
@@ -9,6 +9,8 @@ package tls
@@ -999,7 +999,23 @@ index ba68f355eb..8ddd2526c7 100644
999999
return true
10001000
}
10011001
return false
1002-
@@ -315,15 +325,31 @@ func TestBoringCertAlgs(t *testing.T) {
1002+
@@ -226,7 +236,14 @@ func TestBoringServerSignatureAndHash(t *testing.T) {
1003+
// 1.3, and the ECDSA ones bind to the curve used.
1004+
serverConfig.MaxVersion = VersionTLS12
1005+
1006+
- clientErr, serverErr := boringHandshake(t, testConfig, serverConfig)
1007+
+ clientConfig := testConfig.Clone()
1008+
+
1009+
+ if boring.Enabled {
1010+
+ serverConfig.Rand = boring.RandReader
1011+
+ clientConfig.Rand = boring.RandReader
1012+
+ }
1013+
+
1014+
+ clientErr, serverErr := boringHandshake(t, clientConfig, serverConfig)
1015+
if clientErr != nil {
1016+
t.Fatalf("expected handshake with %#x to succeed; client error: %v; server error: %v", sigHash, clientErr, serverErr)
1017+
}
1018+
@@ -315,15 +332,31 @@ func TestBoringCertAlgs(t *testing.T) {
10031019
R2 := boringCert(t, "R2", boringRSAKey(t, 512), nil, boringCertCA)
10041020

10051021
M1_R1 := boringCert(t, "M1_R1", boringECDSAKey(t, elliptic.P256()), R1, boringCertCA|boringCertFIPSOK)
@@ -1034,19 +1050,36 @@ index ba68f355eb..8ddd2526c7 100644
10341050

10351051
// client verifying server cert
10361052
testServerCert := func(t *testing.T, desc string, pool *x509.CertPool, key interface{}, list [][]byte, ok bool) {
1037-
@@ -362,6 +388,11 @@ func TestBoringCertAlgs(t *testing.T) {
1053+
@@ -336,6 +369,11 @@ func TestBoringCertAlgs(t *testing.T) {
1054+
serverConfig.Certificates = []Certificate{{Certificate: list, PrivateKey: key}}
1055+
serverConfig.BuildNameToCertificate()
1056+
1057+
+ if boring.Enabled {
1058+
+ serverConfig.Rand = boring.RandReader
1059+
+ clientConfig.Rand = boring.RandReader
1060+
+ }
1061+
+
1062+
clientErr, _ := boringHandshake(t, clientConfig, serverConfig)
1063+
1064+
if (clientErr == nil) == ok {
1065+
@@ -362,6 +400,16 @@ func TestBoringCertAlgs(t *testing.T) {
10381066
serverConfig := testConfig.Clone()
10391067
serverConfig.ClientCAs = pool
10401068
serverConfig.ClientAuth = RequireAndVerifyClientCert
10411069
+ if boring.Enabled {
10421070
+ serverConfig.Certificates[0].Certificate = [][]byte{testRSA2048Certificate}
10431071
+ serverConfig.Certificates[0].PrivateKey = testRSA2048PrivateKey
10441072
+ serverConfig.BuildNameToCertificate()
1073+
+ }
1074+
+
1075+
+ if boring.Enabled {
1076+
+ serverConfig.Rand = boring.RandReader
1077+
+ clientConfig.Rand = boring.RandReader
10451078
+ }
10461079

10471080
_, serverErr := boringHandshake(t, clientConfig, serverConfig)
10481081

1049-
@@ -384,8 +415,8 @@ func TestBoringCertAlgs(t *testing.T) {
1082+
@@ -384,8 +432,8 @@ func TestBoringCertAlgs(t *testing.T) {
10501083
// exhaustive test with computed answers.
10511084
r1pool := x509.NewCertPool()
10521085
r1pool.AddCert(R1.cert)
@@ -1057,7 +1090,7 @@ index ba68f355eb..8ddd2526c7 100644
10571090
fipstls.Force()
10581091
testServerCert(t, "basic (fips)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
10591092
testClientCert(t, "basic (fips, client cert)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
1060-
@@ -406,7 +437,7 @@ func TestBoringCertAlgs(t *testing.T) {
1093+
@@ -406,7 +454,7 @@ func TestBoringCertAlgs(t *testing.T) {
10611094
leaf = L2_I
10621095
}
10631096
for i := 0; i < 64; i++ {
@@ -1066,7 +1099,7 @@ index ba68f355eb..8ddd2526c7 100644
10661099
reachableFIPS := map[string]bool{leaf.parentOrg: leaf.fipsOK}
10671100
list := [][]byte{leaf.der}
10681101
listName := leaf.name
1069-
@@ -414,7 +445,7 @@ func TestBoringCertAlgs(t *testing.T) {
1102+
@@ -414,7 +462,7 @@ func TestBoringCertAlgs(t *testing.T) {
10701103
if cond != 0 {
10711104
list = append(list, c.der)
10721105
listName += "," + c.name
@@ -1075,7 +1108,7 @@ index ba68f355eb..8ddd2526c7 100644
10751108
reachable[c.parentOrg] = true
10761109
}
10771110
if reachableFIPS[c.org] && c.fipsOK {
1078-
@@ -438,7 +469,7 @@ func TestBoringCertAlgs(t *testing.T) {
1111+
@@ -438,7 +486,7 @@ func TestBoringCertAlgs(t *testing.T) {
10791112
if cond != 0 {
10801113
rootName += "," + c.name
10811114
pool.AddCert(c.cert)
@@ -1084,23 +1117,23 @@ index ba68f355eb..8ddd2526c7 100644
10841117
shouldVerify = true
10851118
}
10861119
if reachableFIPS[c.org] && c.fipsOK {
1087-
@@ -464,6 +495,7 @@ const (
1120+
@@ -464,6 +512,7 @@ const (
10881121
boringCertCA = iota
10891122
boringCertLeaf
10901123
boringCertFIPSOK = 0x80
10911124
+ boringCertNotBoring = 0x100
10921125
)
10931126

10941127
func boringRSAKey(t *testing.T, size int) *rsa.PrivateKey {
1095-
@@ -490,6 +522,7 @@ type boringCertificate struct {
1128+
@@ -490,6 +539,7 @@ type boringCertificate struct {
10961129
cert *x509.Certificate
10971130
key interface{}
10981131
fipsOK bool
10991132
+ notBoring bool
11001133
}
11011134

11021135
func boringCert(t *testing.T, name string, key interface{}, parent *boringCertificate, mode int) *boringCertificate {
1103-
@@ -511,7 +544,7 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
1136+
@@ -511,7 +561,7 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
11041137
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
11051138
BasicConstraintsValid: true,
11061139
}
@@ -1109,7 +1142,7 @@ index ba68f355eb..8ddd2526c7 100644
11091142
tmpl.DNSNames = []string{"example.com"}
11101143
} else {
11111144
tmpl.IsCA = true
1112-
@@ -548,7 +581,8 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
1145+
@@ -548,7 +598,8 @@ func boringCert(t *testing.T, name string, key interface{}, parent *boringCertif
11131146
}
11141147

11151148
fipsOK := mode&boringCertFIPSOK != 0
@@ -1173,10 +1206,10 @@ index 898d2e9af6..553dc02446 100644
11731206
} else {
11741207
hello.cipherSuites = append(hello.cipherSuites, defaultCipherSuitesTLS13NoAES...)
11751208
diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go
1176-
index 749c9fc954..2e37a1867c 100644
1209+
index 22be38faff..d460eeb880 100644
11771210
--- a/src/crypto/tls/handshake_client_test.go
11781211
+++ b/src/crypto/tls/handshake_client_test.go
1179-
@@ -2135,6 +2135,7 @@ func testBuffering(t *testing.T, version uint16) {
1212+
@@ -2156,6 +2156,7 @@ func testBuffering(t *testing.T, version uint16) {
11801213
}
11811214

11821215
func TestAlertFlushing(t *testing.T) {
@@ -1185,7 +1218,7 @@ index 749c9fc954..2e37a1867c 100644
11851218
done := make(chan bool)
11861219

11871220
diff --git a/src/crypto/tls/handshake_client_tls13.go b/src/crypto/tls/handshake_client_tls13.go
1188-
index 0f2dee42de..b7a087eea9 100644
1221+
index f32d71c191..8dd1e30192 100644
11891222
--- a/src/crypto/tls/handshake_client_tls13.go
11901223
+++ b/src/crypto/tls/handshake_client_tls13.go
11911224
@@ -41,10 +41,6 @@ type clientHandshakeStateTLS13 struct {

patches/001-initial-openssl-for-fips.patch

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ index c941124fb2..7ea291c6f4 100644
14011401
if err != nil {
14021402
return nil, err
14031403
diff --git a/src/crypto/rsa/rsa_test.go b/src/crypto/rsa/rsa_test.go
1404-
index 7d24a08882..fa3f094330 100644
1404+
index ef84e75b04..49e08d5698 100644
14051405
--- a/src/crypto/rsa/rsa_test.go
14061406
+++ b/src/crypto/rsa/rsa_test.go
14071407
@@ -15,7 +15,7 @@ import (
@@ -1453,9 +1453,9 @@ index 7d24a08882..fa3f094330 100644
14531453
n := new(big.Int)
14541454
for i, test := range testEncryptOAEPData {
14551455
n.SetString(test.modulus, 16)
1456-
- if boring.Enabled && !boringtest.Supports(t, "RSA1024") && n.BitLen() < 2048 {
1457-
+ if boring.Enabled() && !boringtest.Supports(t, "RSA1024") && n.BitLen() < 2048 {
1458-
t.Logf("skipping encryption tests with BoringCrypto: too short key: %d", n.BitLen())
1456+
- if boring.Enabled {
1457+
+ if boring.Enabled() {
1458+
t.Log("skipping test in FIPS mode due to short keys and unpadded RSA operations not allowed with FIPS")
14591459
continue
14601460
}
14611461
@@ -292,7 +292,7 @@ func TestDecryptOAEP(t *testing.T) {
@@ -1735,7 +1735,7 @@ index 140b1a3dd8..fe6fa96d28 100644
17351735
}
17361736
}
17371737
diff --git a/src/crypto/tls/boring_test.go b/src/crypto/tls/boring_test.go
1738-
index 8ddd2526c7..5b041ef1d3 100644
1738+
index 7bfe3f9417..49702f59ba 100644
17391739
--- a/src/crypto/tls/boring_test.go
17401740
+++ b/src/crypto/tls/boring_test.go
17411741
@@ -2,14 +2,14 @@
@@ -1764,7 +1764,25 @@ index 8ddd2526c7..5b041ef1d3 100644
17641764
test("VersionTLS13", VersionTLS13, "client offered only unsupported versions")
17651765
} else {
17661766
test("VersionTLS13", VersionTLS13, "")
1767-
@@ -388,7 +388,7 @@ func TestBoringCertAlgs(t *testing.T) {
1767+
@@ -238,7 +238,7 @@ func TestBoringServerSignatureAndHash(t *testing.T) {
1768+
1769+
clientConfig := testConfig.Clone()
1770+
1771+
- if boring.Enabled {
1772+
+ if boring.Enabled() {
1773+
serverConfig.Rand = boring.RandReader
1774+
clientConfig.Rand = boring.RandReader
1775+
}
1776+
@@ -369,7 +369,7 @@ func TestBoringCertAlgs(t *testing.T) {
1777+
serverConfig.Certificates = []Certificate{{Certificate: list, PrivateKey: key}}
1778+
serverConfig.BuildNameToCertificate()
1779+
1780+
- if boring.Enabled {
1781+
+ if boring.Enabled() {
1782+
serverConfig.Rand = boring.RandReader
1783+
clientConfig.Rand = boring.RandReader
1784+
}
1785+
@@ -400,13 +400,13 @@ func TestBoringCertAlgs(t *testing.T) {
17681786
serverConfig := testConfig.Clone()
17691787
serverConfig.ClientCAs = pool
17701788
serverConfig.ClientAuth = RequireAndVerifyClientCert
@@ -1773,7 +1791,14 @@ index 8ddd2526c7..5b041ef1d3 100644
17731791
serverConfig.Certificates[0].Certificate = [][]byte{testRSA2048Certificate}
17741792
serverConfig.Certificates[0].PrivateKey = testRSA2048PrivateKey
17751793
serverConfig.BuildNameToCertificate()
1776-
@@ -415,8 +415,8 @@ func TestBoringCertAlgs(t *testing.T) {
1794+
}
1795+
1796+
- if boring.Enabled {
1797+
+ if boring.Enabled() {
1798+
serverConfig.Rand = boring.RandReader
1799+
clientConfig.Rand = boring.RandReader
1800+
}
1801+
@@ -432,8 +432,8 @@ func TestBoringCertAlgs(t *testing.T) {
17771802
// exhaustive test with computed answers.
17781803
r1pool := x509.NewCertPool()
17791804
r1pool.AddCert(R1.cert)
@@ -1784,7 +1809,7 @@ index 8ddd2526c7..5b041ef1d3 100644
17841809
fipstls.Force()
17851810
testServerCert(t, "basic (fips)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
17861811
testClientCert(t, "basic (fips, client cert)", r1pool, L2_I.key, [][]byte{L2_I.der, I_R1.der}, false)
1787-
@@ -437,7 +437,7 @@ func TestBoringCertAlgs(t *testing.T) {
1812+
@@ -454,7 +454,7 @@ func TestBoringCertAlgs(t *testing.T) {
17881813
leaf = L2_I
17891814
}
17901815
for i := 0; i < 64; i++ {
@@ -1793,7 +1818,7 @@ index 8ddd2526c7..5b041ef1d3 100644
17931818
reachableFIPS := map[string]bool{leaf.parentOrg: leaf.fipsOK}
17941819
list := [][]byte{leaf.der}
17951820
listName := leaf.name
1796-
@@ -445,7 +445,7 @@ func TestBoringCertAlgs(t *testing.T) {
1821+
@@ -462,7 +462,7 @@ func TestBoringCertAlgs(t *testing.T) {
17971822
if cond != 0 {
17981823
list = append(list, c.der)
17991824
listName += "," + c.name
@@ -1802,7 +1827,7 @@ index 8ddd2526c7..5b041ef1d3 100644
18021827
reachable[c.parentOrg] = true
18031828
}
18041829
if reachableFIPS[c.org] && c.fipsOK {
1805-
@@ -469,7 +469,7 @@ func TestBoringCertAlgs(t *testing.T) {
1830+
@@ -486,7 +486,7 @@ func TestBoringCertAlgs(t *testing.T) {
18061831
if cond != 0 {
18071832
rootName += "," + c.name
18081833
pool.AddCert(c.cert)

0 commit comments

Comments
 (0)