Skip to content

Commit ca88faa

Browse files
committed
Offload TLS PRF to OpenSSL backend
For FIPS compliance, this offloads the PRF computation in TLS to OpenSSL, based on the work by Quim Muntal in: microsoft/go#1036 Note that, on RHEL-9, this may cause interoperability issue against the peers which do not use extended master secret, yielding a connection close with internal_error alert. The way to mitigate that behavior is described at: https://www.redhat.com/en/blog/tls-extended-master-secret-and-fips-rhel
1 parent 56ac3db commit ca88faa

File tree

2 files changed

+405
-68
lines changed

2 files changed

+405
-68
lines changed

patches/000-initial-setup.patch

+56-68
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ index f933f2800a..223ce04340 100644
135135
testenv.MustHaveExternalNetwork(t)
136136

137137
// Create a temp dir and modcache subdir.
138+
diff --git a/src/crypto/internal/backend/bbig/big.go b/src/crypto/internal/backend/bbig/big.go
139+
new file mode 100644
140+
index 0000000000..5652398605
141+
--- /dev/null
142+
+++ b/src/crypto/internal/backend/bbig/big.go
143+
@@ -0,0 +1,15 @@
144+
+// Copyright 2022 The Go Authors. All rights reserved.
145+
+// Use of this source code is governed by a BSD-style
146+
+// license that can be found in the LICENSE file.
147+
+
148+
+// This is a mirror of
149+
+// https://github.com/golang/go/blob/36b87f273cc43e21685179dc1664ebb5493d26ae/src/crypto/internal/boring/bbig/big.go.
150+
+
151+
+package bbig
152+
+
153+
+import (
154+
+ "github.com/golang-fips/openssl/v2/bbig"
155+
+)
156+
+
157+
+var Enc = bbig.Enc
158+
+var Dec = bbig.Dec
138159
diff --git a/src/crypto/internal/backend/boringtest/config.go b/src/crypto/internal/backend/boringtest/config.go
139160
new file mode 100644
140161
index 0000000000..6c8c00d11e
@@ -192,10 +213,10 @@ new file mode 100644
192213
index 0000000000..e69de29bb2
193214
diff --git a/src/crypto/internal/backend/nobackend.go b/src/crypto/internal/backend/nobackend.go
194215
new file mode 100644
195-
index 0000000000..15c1ee8cbe
216+
index 0000000000..528ded04d7
196217
--- /dev/null
197218
+++ b/src/crypto/internal/backend/nobackend.go
198-
@@ -0,0 +1,163 @@
219+
@@ -0,0 +1,170 @@
199220
+// Copyright 2017 The Go Authors. All rights reserved.
200221
+// Use of this source code is governed by a BSD-style
201222
+// license that can be found in the LICENSE file.
@@ -359,12 +380,19 @@ index 0000000000..15c1ee8cbe
359380
+func HashSignECDSA(priv *PrivateKeyECDSA, hash []byte, h crypto.Hash) (*big.Int, *big.Int, error) {
360381
+ panic("boringcrypto: not available")
361382
+}
383+
+
384+
+func SupportsTLS1PRF() bool {
385+
+ panic("boringcrypto: not available")
386+
+}
387+
+func TLS1PRF(result, secret, label, seed []byte, h func() hash.Hash) error {
388+
+ panic("boringcrypto: not available")
389+
+}
362390
diff --git a/src/crypto/internal/backend/openssl.go b/src/crypto/internal/backend/openssl.go
363391
new file mode 100644
364-
index 0000000000..2087c555a4
392+
index 0000000000..6ec71c625d
365393
--- /dev/null
366394
+++ b/src/crypto/internal/backend/openssl.go
367-
@@ -0,0 +1,122 @@
395+
@@ -0,0 +1,125 @@
368396
+// Copyright 2017 The Go Authors. All rights reserved.
369397
+// Use of this source code is governed by a BSD-style
370398
+// license that can be found in the LICENSE file.
@@ -487,27 +515,9 @@ index 0000000000..2087c555a4
487515
+var ExtractHKDF = openssl.ExtractHKDF
488516
+var ExpandHKDF = openssl.ExpandHKDF
489517
+var SupportsHKDF = openssl.SupportsHKDF
490-
diff --git a/src/crypto/internal/backend/bbig/big.go b/src/crypto/internal/backend/bbig/big.go
491-
new file mode 100644
492-
index 0000000000..7fac1ec7e1
493-
--- /dev/null
494-
+++ b/src/crypto/internal/backend/bbig/big.go
495-
@@ -0,0 +1,15 @@
496-
+// Copyright 2022 The Go Authors. All rights reserved.
497-
+// Use of this source code is governed by a BSD-style
498-
+// license that can be found in the LICENSE file.
499-
+
500-
+// This is a mirror of
501-
+// https://github.com/golang/go/blob/36b87f273cc43e21685179dc1664ebb5493d26ae/src/crypto/internal/boring/bbig/big.go.
502-
+
503-
+package bbig
504-
+
505-
+import (
506-
+ "github.com/golang-fips/openssl/v2/bbig"
507-
+)
508518
+
509-
+var Enc = bbig.Enc
510-
+var Dec = bbig.Dec
519+
+var SupportsTLS1PRF = openssl.SupportsTLS1PRF
520+
+var TLS1PRF = openssl.TLS1PRF
511521
diff --git a/src/crypto/rsa/pkcs1v15_test.go b/src/crypto/rsa/pkcs1v15_test.go
512522
index dfa1eddc88..39a4fc184a 100644
513523
--- a/src/crypto/rsa/pkcs1v15_test.go
@@ -734,28 +744,6 @@ index cf03e3cb7e..1226149321 100644
734744
t.Fatalf("SignPSS unexpected error: got %v, want %v", err, InvalidSaltLenErr)
735745
}
736746

737-
diff --git a/src/crypto/rsa/rsa.go b/src/crypto/rsa/rsa.go
738-
index 63bc8dad1a..ab56ccd1ed 100644
739-
--- a/src/crypto/rsa/rsa.go
740-
+++ b/src/crypto/rsa/rsa.go
741-
@@ -509,7 +509,7 @@ func EncryptOAEP(hash hash.Hash, random io.Reader, pub *PublicKey, msg []byte, l
742-
if err != nil {
743-
return nil, err
744-
}
745-
- return boring.EncryptRSAOAEP(hash, hash, bkey, msg, label)
746-
+ return boring.EncryptRSAOAEP(hash, hash, bkey, msg, label)
747-
}
748-
boring.UnreachableExceptTests()
749-
750-
@@ -680,7 +680,7 @@ func decryptOAEP(hash, mgfHash hash.Hash, random io.Reader, priv *PrivateKey, ci
751-
if err != nil {
752-
return nil, err
753-
}
754-
- out, err := boring.DecryptRSAOAEP(hash, mgfHash, bkey, ciphertext, label)
755-
+ out, err := boring.DecryptRSAOAEP(hash, mgfHash, bkey, ciphertext, label)
756-
if err != nil {
757-
return nil, ErrDecryption
758-
}
759747
diff --git a/src/crypto/rsa/rsa_test.go b/src/crypto/rsa/rsa_test.go
760748
index 3278a7ff30..b994daec19 100644
761749
--- a/src/crypto/rsa/rsa_test.go
@@ -1128,7 +1116,7 @@ index ba68f355eb..7bfe3f9417 100644
11281116

11291117
// A self-signed test certificate with an RSA key of size 2048, for testing
11301118
diff --git a/src/crypto/tls/cipher_suites.go b/src/crypto/tls/cipher_suites.go
1131-
index 04e6dfe018..b6ed936cd1 100644
1119+
index 589e8b6faf..669208bb86 100644
11321120
--- a/src/crypto/tls/cipher_suites.go
11331121
+++ b/src/crypto/tls/cipher_suites.go
11341122
@@ -354,6 +354,11 @@ var defaultCipherSuitesTLS13NoAES = []uint16{
@@ -1144,7 +1132,7 @@ index 04e6dfe018..b6ed936cd1 100644
11441132
hasGCMAsmAMD64 = cpu.X86.HasAES && cpu.X86.HasPCLMULQDQ
11451133
hasGCMAsmARM64 = cpu.ARM64.HasAES && cpu.ARM64.HasPMULL
11461134
diff --git a/src/crypto/tls/common.go b/src/crypto/tls/common.go
1147-
index 5394d64ac6..db4e2dbf60 100644
1135+
index e0885a0da9..5edbd19995 100644
11481136
--- a/src/crypto/tls/common.go
11491137
+++ b/src/crypto/tls/common.go
11501138
@@ -12,6 +12,7 @@ import (
@@ -1155,7 +1143,7 @@ index 5394d64ac6..db4e2dbf60 100644
11551143
"crypto/rand"
11561144
"crypto/rsa"
11571145
"crypto/sha512"
1158-
@@ -994,6 +995,9 @@ const roleServer = false
1146+
@@ -1031,6 +1032,9 @@ const roleServer = false
11591147
func (c *Config) supportedVersions(isClient bool) []uint16 {
11601148
versions := make([]uint16, 0, len(supportedVersions))
11611149
for _, v := range supportedVersions {
@@ -1166,10 +1154,10 @@ index 5394d64ac6..db4e2dbf60 100644
11661154
continue
11671155
}
11681156
diff --git a/src/crypto/tls/handshake_client.go b/src/crypto/tls/handshake_client.go
1169-
index 63d86b9f3a..a8ee915041 100644
1157+
index 4649f36dea..5e1976caf3 100644
11701158
--- a/src/crypto/tls/handshake_client.go
11711159
+++ b/src/crypto/tls/handshake_client.go
1172-
@@ -127,7 +127,9 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, *ecdh.PrivateKey, error) {
1160+
@@ -139,7 +139,9 @@ func (c *Conn) makeClientHello() (*clientHelloMsg, *ecdh.PrivateKey, error) {
11731161
if len(hello.supportedVersions) == 1 {
11741162
hello.cipherSuites = nil
11751163
}
@@ -1181,10 +1169,10 @@ index 63d86b9f3a..a8ee915041 100644
11811169
} else {
11821170
hello.cipherSuites = append(hello.cipherSuites, defaultCipherSuitesTLS13NoAES...)
11831171
diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go
1184-
index 22be38faff..d460eeb880 100644
1172+
index a2052ceb70..1666b58ef3 100644
11851173
--- a/src/crypto/tls/handshake_client_test.go
11861174
+++ b/src/crypto/tls/handshake_client_test.go
1187-
@@ -2156,6 +2156,7 @@ func testBuffering(t *testing.T, version uint16) {
1175+
@@ -2198,6 +2198,7 @@ func testBuffering(t *testing.T, version uint16) {
11881176
}
11891177

11901178
func TestAlertFlushing(t *testing.T) {
@@ -1193,7 +1181,7 @@ index 22be38faff..d460eeb880 100644
11931181
done := make(chan bool)
11941182

11951183
diff --git a/src/crypto/tls/handshake_client_tls13.go b/src/crypto/tls/handshake_client_tls13.go
1196-
index 4a8661085e..87fe11de5c 100644
1184+
index 2f59f6888c..a84cede1b0 100644
11971185
--- a/src/crypto/tls/handshake_client_tls13.go
11981186
+++ b/src/crypto/tls/handshake_client_tls13.go
11991187
@@ -41,10 +41,6 @@ type clientHandshakeStateTLS13 struct {
@@ -1208,10 +1196,10 @@ index 4a8661085e..87fe11de5c 100644
12081196
// sections 4.1.2 and 4.1.3.
12091197
if c.handshakes > 0 {
12101198
diff --git a/src/crypto/tls/handshake_server_tls13.go b/src/crypto/tls/handshake_server_tls13.go
1211-
index b7b568cd84..af75e7dbe0 100644
1199+
index 07b1a3851e..938a329668 100644
12121200
--- a/src/crypto/tls/handshake_server_tls13.go
12131201
+++ b/src/crypto/tls/handshake_server_tls13.go
1214-
@@ -44,10 +44,6 @@ type serverHandshakeStateTLS13 struct {
1202+
@@ -45,10 +45,6 @@ type serverHandshakeStateTLS13 struct {
12151203
func (hs *serverHandshakeStateTLS13) handshake() error {
12161204
c := hs.c
12171205

@@ -1223,7 +1211,7 @@ index b7b568cd84..af75e7dbe0 100644
12231211
if err := hs.processClientHello(); err != nil {
12241212
return err
12251213
diff --git a/src/crypto/tls/key_schedule.go b/src/crypto/tls/key_schedule.go
1226-
index ae8f80a7cf..30a8450f40 100644
1214+
index d7f082c9ee..e7a360fdd4 100644
12271215
--- a/src/crypto/tls/key_schedule.go
12281216
+++ b/src/crypto/tls/key_schedule.go
12291217
@@ -7,6 +7,7 @@ package tls
@@ -1234,7 +1222,7 @@ index ae8f80a7cf..30a8450f40 100644
12341222
"errors"
12351223
"fmt"
12361224
"hash"
1237-
@@ -58,9 +59,20 @@ func (c *cipherSuiteTLS13) expandLabel(secret []byte, label string, context []by
1225+
@@ -59,9 +60,20 @@ func (c *cipherSuiteTLS13) expandLabel(secret []byte, label string, context []by
12381226
panic(fmt.Errorf("failed to construct HKDF label: %s", err))
12391227
}
12401228
out := make([]byte, length)
@@ -1258,7 +1246,7 @@ index ae8f80a7cf..30a8450f40 100644
12581246
}
12591247
return out
12601248
}
1261-
@@ -78,7 +90,15 @@ func (c *cipherSuiteTLS13) extract(newSecret, currentSecret []byte) []byte {
1249+
@@ -79,7 +91,15 @@ func (c *cipherSuiteTLS13) extract(newSecret, currentSecret []byte) []byte {
12621250
if newSecret == nil {
12631251
newSecret = make([]byte, c.hash.Size())
12641252
}
@@ -1305,7 +1293,7 @@ index 33fd0ed52b..102acda578 100644
13051293
I_R1 := testBoringCert(t, "I_R1", boringRSAKey(t, 3072), R1, boringCertCA|boringCertFIPSOK)
13061294
testBoringCert(t, "I_R2", I_R1.key, R2, boringCertCA|boringCertFIPSOK)
13071295
diff --git a/src/crypto/x509/x509_test.go b/src/crypto/x509/x509_test.go
1308-
index 8846b00312..8734dd03c1 100644
1296+
index 19deeab54d..0c2cbf3182 100644
13091297
--- a/src/crypto/x509/x509_test.go
13101298
+++ b/src/crypto/x509/x509_test.go
13111299
@@ -12,6 +12,8 @@ import (
@@ -1424,7 +1412,7 @@ index 8846b00312..8734dd03c1 100644
14241412
commonName := "test.example.com"
14251413
template := Certificate{
14261414
SerialNumber: big.NewInt(1),
1427-
@@ -3607,11 +3638,19 @@ func TestParseRevocationList(t *testing.T) {
1415+
@@ -3682,11 +3713,19 @@ func TestParseRevocationList(t *testing.T) {
14281416
}
14291417

14301418
func TestRevocationListCheckSignatureFrom(t *testing.T) {
@@ -1447,10 +1435,10 @@ index 8846b00312..8734dd03c1 100644
14471435
t.Fatalf("failed to generate test key: %s", err)
14481436
}
14491437
diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go
1450-
index 08452c7b1d..0732db0662 100644
1438+
index 592f2fd72a..1c1caa6897 100644
14511439
--- a/src/go/build/deps_test.go
14521440
+++ b/src/go/build/deps_test.go
1453-
@@ -396,9 +396,11 @@ var depsRules = `
1441+
@@ -423,9 +423,11 @@ var depsRules = `
14541442
< crypto/internal/alias
14551443
< crypto/cipher;
14561444

@@ -1463,7 +1451,7 @@ index 08452c7b1d..0732db0662 100644
14631451
< crypto/boring;
14641452

14651453
crypto/internal/alias
1466-
@@ -427,11 +429,13 @@ var depsRules = `
1454+
@@ -454,11 +456,13 @@ var depsRules = `
14671455
crypto/sha512
14681456
< CRYPTO;
14691457

@@ -1478,15 +1466,15 @@ index 08452c7b1d..0732db0662 100644
14781466
< crypto/rand
14791467
< crypto/ed25519
14801468
< encoding/asn1
1481-
@@ -629,6 +633,7 @@ func listStdPkgs(goroot string) ([]string, error) {
1469+
@@ -663,6 +667,7 @@ func listStdPkgs(goroot string) ([]string, error) {
14821470
}
14831471

14841472
func TestDependencies(t *testing.T) {
14851473
+ t.Skip("openssl based toolchain has different dependencies than upstream")
14861474
if !testenv.HasSrc() {
14871475
// Tests run in a limited file system and we do not
14881476
// provide access to every source file.
1489-
@@ -671,7 +676,7 @@ var buildIgnore = []byte("\n//go:build ignore")
1477+
@@ -705,7 +710,7 @@ var buildIgnore = []byte("\n//go:build ignore")
14901478

14911479
func findImports(pkg string) ([]string, error) {
14921480
vpkg := pkg
@@ -1495,7 +1483,7 @@ index 08452c7b1d..0732db0662 100644
14951483
vpkg = "vendor/" + pkg
14961484
}
14971485
dir := filepath.Join(Default.GOROOT, "src", vpkg)
1498-
@@ -681,7 +686,7 @@ func findImports(pkg string) ([]string, error) {
1486+
@@ -715,7 +720,7 @@ func findImports(pkg string) ([]string, error) {
14991487
}
15001488
var imports []string
15011489
var haveImport = map[string]bool{}
@@ -1505,7 +1493,7 @@ index 08452c7b1d..0732db0662 100644
15051493
}
15061494
fset := token.NewFileSet()
15071495
diff --git a/src/runtime/pprof/proto_test.go b/src/runtime/pprof/proto_test.go
1508-
index 780b481de8..63db9e9ed7 100644
1496+
index 8ec9c9109a..d7f287261f 100644
15091497
--- a/src/runtime/pprof/proto_test.go
15101498
+++ b/src/runtime/pprof/proto_test.go
15111499
@@ -15,6 +15,7 @@ import (

0 commit comments

Comments
 (0)