Skip to content

Commit a2f4a5a

Browse files
FiloSottilemknyszek
authored andcommitted
[release-branch.go1.20] Revert "crypto/internal/boring: upgrade module to fips-20220613" +1
This reverts CL 553875 ("crypto/internal/boring: upgrade module to fips-20220613") and CL 553876 ("crypto/tls: align FIPS-only mode with BoringSSL policy"). Fixes #65322 Updates #65321 Updates #64717 Updates #62372 Change-Id: I0938b97e5b4904e6532448b8ae76e920d03d0508 Reviewed-on: https://go-review.googlesource.com/c/go/+/558796 Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]> Auto-Submit: Filippo Valsorda <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> (cherry picked from commit 09b5de4) Reviewed-on: https://go-review.googlesource.com/c/go/+/560276
1 parent 746a072 commit a2f4a5a

19 files changed

+73
-156
lines changed

src/crypto/internal/boring/Dockerfile

+11-17
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,15 @@ WORKDIR /boring
1313
ENV LANG=C
1414
ENV LANGUAGE=
1515

16-
# Following NIST submission draft for In Progress module validation.
17-
# This corresponds to boringssl.googlesource.com/boringssl tag fips-20220613.
16+
# Following NIST submission draft dated July 3, 2021.
17+
# This corresponds to boringssl.googlesource.com/boringssl tag fips-20210429.
18+
ENV ClangV=12
1819
RUN apt-get update && \
19-
apt-get install --no-install-recommends -y cmake xz-utils wget unzip ca-certificates python lsb-release software-properties-common gnupg
20-
21-
# Install Clang.
22-
ENV ClangV=14
23-
RUN \
24-
wget https://apt.llvm.org/llvm.sh && \
25-
chmod +x llvm.sh && \
26-
./llvm.sh $ClangV
20+
apt-get install --no-install-recommends -y cmake xz-utils wget unzip ca-certificates clang-$ClangV python
2721

2822
# Download, validate, unpack, build, and install Ninja.
29-
ENV NinjaV=1.10.1
30-
ENV NinjaH=a6b6f7ac360d4aabd54e299cc1d8fa7b234cd81b9401693da21221c62569a23e
23+
ENV NinjaV=1.10.2
24+
ENV NinjaH=ce35865411f0490368a8fc383f29071de6690cbadc27704734978221f25e2bed
3125
RUN \
3226
wget https://github.com/ninja-build/ninja/archive/refs/tags/v$NinjaV.tar.gz && \
3327
echo "$NinjaH v$NinjaV.tar.gz" >sha && sha256sum -c sha && \
@@ -39,9 +33,9 @@ RUN \
3933

4034
# Download, validate, unpack, and install Go.
4135
ARG GOARCH
42-
ENV GoV=1.18.1
43-
ENV GoHamd64=b3b815f47ababac13810fc6021eb73d65478e0b2db4b09d348eefad9581a2334
44-
ENV GoHarm64=56a91851c97fb4697077abbca38860f735c32b38993ff79b088dac46e4735633
36+
ENV GoV=1.16.5
37+
ENV GoHamd64=b12c23023b68de22f74c0524f10b753e7b08b1504cb7e417eccebdd3fae49061
38+
ENV GoHarm64=d5446b46ef6f36fdffa852f73dfbbe78c1ddf010b99fa4964944b9ae8b4d6799
4539
RUN \
4640
eval GoH=\${GoH$GOARCH} && \
4741
wget https://golang.org/dl/go$GoV.linux-$GOARCH.tar.gz && \
@@ -51,8 +45,8 @@ RUN \
5145
ln -s /usr/local/go/bin/go /usr/local/bin/
5246

5347
# Download, validate, and unpack BoringCrypto.
54-
ENV BoringV=0c6f40132b828e92ba365c6b7680e32820c63fa7
55-
ENV BoringH=62f733289f2d677c2723f556aa58034c438f3a7bbca6c12b156538a88e38da8a
48+
ENV BoringV=853ca1ea1168dff08011e5d42d94609cc0ca2e27
49+
ENV BoringH=a4d069ccef6f3c7bc0c68de82b91414f05cb817494cd1ab483dcf3368883c7c2
5650
RUN \
5751
wget https://commondatastorage.googleapis.com/chromium-boringssl-fips/boringssl-$BoringV.tar.xz && \
5852
echo "$BoringH boringssl-$BoringV.tar.xz" >sha && sha256sum -c sha && \

src/crypto/internal/boring/LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ When building with GOEXPERIMENT=boringcrypto, the following applies.
66
The goboringcrypto_linux_amd64.syso object file is built
77
from BoringSSL source code by build/build.sh and is covered
88
by the BoringSSL license reproduced below and also at
9-
https://boringssl.googlesource.com/boringssl/+/fips-20220613/LICENSE.
9+
https://boringssl.googlesource.com/boringssl/+/fips-20190808/LICENSE.
1010

1111
BoringSSL is a fork of OpenSSL. As such, large parts of it fall under OpenSSL
1212
licensing. Files that are completely new have a Google copyright and an ISC

src/crypto/internal/boring/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ syso/goboringcrypto_linux_arm64.syso is built with:
2727

2828
GOARCH=arm64 ./build.sh
2929

30-
Both run using Docker.
31-
30+
Both run on an x86 Debian Linux system using Docker.
3231
For the arm64 build to run on an x86 system, you need
3332

3433
apt-get install qemu-user-static qemu-binfmt-support
3534

3635
to allow the x86 kernel to run arm64 binaries via QEMU.
3736

38-
For the amd64 build to run on an Apple Silicon macOS, you need Rosetta 2.
39-
4037
See build.sh for more details about the build.
38+
39+

src/crypto/internal/boring/aes.go

+7-22
Original file line numberDiff line numberDiff line change
@@ -228,41 +228,26 @@ func (c *aesCipher) NewGCM(nonceSize, tagSize int) (cipher.AEAD, error) {
228228
if tagSize != gcmTagSize {
229229
return cipher.NewGCMWithTagSize(&noGCM{c}, tagSize)
230230
}
231-
return c.newGCM(0)
231+
return c.newGCM(false)
232232
}
233233

234-
const (
235-
VersionTLS12 = 0x0303
236-
VersionTLS13 = 0x0304
237-
)
238-
239234
func NewGCMTLS(c cipher.Block) (cipher.AEAD, error) {
240-
return c.(*aesCipher).newGCM(VersionTLS12)
241-
}
242-
243-
func NewGCMTLS13(c cipher.Block) (cipher.AEAD, error) {
244-
return c.(*aesCipher).newGCM(VersionTLS13)
235+
return c.(*aesCipher).newGCM(true)
245236
}
246237

247-
func (c *aesCipher) newGCM(tlsVersion uint16) (cipher.AEAD, error) {
238+
func (c *aesCipher) newGCM(tls bool) (cipher.AEAD, error) {
248239
var aead *C.GO_EVP_AEAD
249240
switch len(c.key) * 8 {
250241
case 128:
251-
switch tlsVersion {
252-
case VersionTLS12:
242+
if tls {
253243
aead = C._goboringcrypto_EVP_aead_aes_128_gcm_tls12()
254-
case VersionTLS13:
255-
aead = C._goboringcrypto_EVP_aead_aes_128_gcm_tls13()
256-
default:
244+
} else {
257245
aead = C._goboringcrypto_EVP_aead_aes_128_gcm()
258246
}
259247
case 256:
260-
switch tlsVersion {
261-
case VersionTLS12:
248+
if tls {
262249
aead = C._goboringcrypto_EVP_aead_aes_256_gcm_tls12()
263-
case VersionTLS13:
264-
aead = C._goboringcrypto_EVP_aead_aes_256_gcm_tls13()
265-
default:
250+
} else {
266251
aead = C._goboringcrypto_EVP_aead_aes_256_gcm()
267252
}
268253
default:

src/crypto/internal/boring/build-goboring.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ awk -f boringx.awk goboringcrypto.h # writes goboringcrypto.x
122122
awk -f boringh.awk goboringcrypto.h # writes goboringcrypto[01].h
123123

124124
ls -l ../boringssl/include
125-
clang++ -fPIC -I../boringssl/include -O2 -o a.out goboringcrypto.cc
125+
clang++ -std=c++11 -fPIC -I../boringssl/include -O2 -o a.out goboringcrypto.cc
126126
./a.out || exit 2
127127

128128
# clang implements u128 % u128 -> u128 by calling __umodti3,

src/crypto/internal/boring/build.sh

-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ platform=""
2222
buildargs=""
2323
case "$GOARCH" in
2424
amd64)
25-
if ! docker run --rm -t amd64/ubuntu:focal uname -m >/dev/null 2>&1; then
26-
echo "# Docker cannot run amd64 binaries."
27-
exit 1
28-
fi
29-
platform="--platform linux/amd64"
30-
buildargs="--build-arg ubuntu=amd64/ubuntu"
3125
;;
3226
arm64)
3327
if ! docker run --rm -t arm64v8/ubuntu:focal uname -m >/dev/null 2>&1; then

src/crypto/internal/boring/goboringcrypto.h

-2
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ void _goboringcrypto_EVP_AEAD_CTX_cleanup(GO_EVP_AEAD_CTX*);
125125
int _goboringcrypto_EVP_AEAD_CTX_seal(const GO_EVP_AEAD_CTX*, uint8_t*, size_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t);
126126
int _goboringcrypto_EVP_AEAD_CTX_open(const GO_EVP_AEAD_CTX*, uint8_t*, size_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t, const uint8_t*, size_t);
127127
const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_128_gcm_tls12(void);
128-
const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_128_gcm_tls13(void);
129128
const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm_tls12(void);
130-
const GO_EVP_AEAD* _goboringcrypto_EVP_aead_aes_256_gcm_tls13(void);
131129
enum go_evp_aead_direction_t {
132130
go_evp_aead_open = 0,
133131
go_evp_aead_seal = 1

src/crypto/internal/boring/notboring.go

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func NewHMAC(h func() hash.Hash, key []byte) hash.Hash { panic("boringcrypto: no
5050

5151
func NewAESCipher(key []byte) (cipher.Block, error) { panic("boringcrypto: not available") }
5252
func NewGCMTLS(cipher.Block) (cipher.AEAD, error) { panic("boringcrypto: not available") }
53-
func NewGCMTLS13(cipher.Block) (cipher.AEAD, error) { panic("boringcrypto: not available") }
5453

5554
type PublicKeyECDSA struct{ _ int }
5655
type PrivateKeyECDSA struct{ _ int }
Binary file not shown.
Binary file not shown.

src/crypto/tls/boring.go

+11-15
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66

77
package tls
88

9-
import "crypto/internal/boring/fipstls"
10-
11-
// The FIPS-only policies enforced here currently match BoringSSL's
12-
// ssl_policy_fips_202205.
9+
import (
10+
"crypto/internal/boring/fipstls"
11+
)
1312

1413
// needFIPS returns fipstls.Required(); it avoids a new import in common.go.
1514
func needFIPS() bool {
@@ -18,19 +17,19 @@ func needFIPS() bool {
1817

1918
// fipsMinVersion replaces c.minVersion in FIPS-only mode.
2019
func fipsMinVersion(c *Config) uint16 {
21-
// FIPS requires TLS 1.2 or TLS 1.3.
20+
// FIPS requires TLS 1.2.
2221
return VersionTLS12
2322
}
2423

2524
// fipsMaxVersion replaces c.maxVersion in FIPS-only mode.
2625
func fipsMaxVersion(c *Config) uint16 {
27-
// FIPS requires TLS 1.2 or TLS 1.3.
28-
return VersionTLS13
26+
// FIPS requires TLS 1.2.
27+
return VersionTLS12
2928
}
3029

3130
// default defaultFIPSCurvePreferences is the FIPS-allowed curves,
3231
// in preference order (most preferable first).
33-
var defaultFIPSCurvePreferences = []CurveID{CurveP256, CurveP384}
32+
var defaultFIPSCurvePreferences = []CurveID{CurveP256, CurveP384, CurveP521}
3433

3534
// fipsCurvePreferences replaces c.curvePreferences in FIPS-only mode.
3635
func fipsCurvePreferences(c *Config) []CurveID {
@@ -55,6 +54,8 @@ var defaultCipherSuitesFIPS = []uint16{
5554
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
5655
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5756
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
57+
TLS_RSA_WITH_AES_128_GCM_SHA256,
58+
TLS_RSA_WITH_AES_256_GCM_SHA384,
5859
}
5960

6061
// fipsCipherSuites replaces c.cipherSuites in FIPS-only mode.
@@ -74,14 +75,8 @@ func fipsCipherSuites(c *Config) []uint16 {
7475
return list
7576
}
7677

77-
// defaultCipherSuitesTLS13FIPS are the FIPS-allowed cipher suites for TLS 1.3.
78-
var defaultCipherSuitesTLS13FIPS = []uint16{
79-
TLS_AES_128_GCM_SHA256,
80-
TLS_AES_256_GCM_SHA384,
81-
}
82-
8378
// fipsSupportedSignatureAlgorithms currently are a subset of
84-
// defaultSupportedSignatureAlgorithms without Ed25519, SHA-1, and P-521.
79+
// defaultSupportedSignatureAlgorithms without Ed25519 and SHA-1.
8580
var fipsSupportedSignatureAlgorithms = []SignatureScheme{
8681
PSSWithSHA256,
8782
PSSWithSHA384,
@@ -91,6 +86,7 @@ var fipsSupportedSignatureAlgorithms = []SignatureScheme{
9186
PKCS1WithSHA384,
9287
ECDSAWithP384AndSHA384,
9388
PKCS1WithSHA512,
89+
ECDSAWithP521AndSHA512,
9490
}
9591

9692
// supportedSignatureAlgorithms returns the supported signature algorithms.

src/crypto/tls/boring_test.go

+18-51
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,6 @@ import (
2525
"time"
2626
)
2727

28-
func allCipherSuitesIncludingTLS13() []uint16 {
29-
s := allCipherSuites()
30-
for _, suite := range cipherSuitesTLS13 {
31-
s = append(s, suite.id)
32-
}
33-
return s
34-
}
35-
36-
func isTLS13CipherSuite(id uint16) bool {
37-
for _, suite := range cipherSuitesTLS13 {
38-
if id == suite.id {
39-
return true
40-
}
41-
}
42-
return false
43-
}
44-
45-
func generateKeyShare(group CurveID) keyShare {
46-
key, err := generateECDHEKey(rand.Reader, group)
47-
if err != nil {
48-
panic(err)
49-
}
50-
return keyShare{group: group, data: key.PublicKey().Bytes()}
51-
}
52-
5328
func TestBoringServerProtocolVersion(t *testing.T) {
5429
test := func(name string, v uint16, msg string) {
5530
t.Run(name, func(t *testing.T) {
@@ -58,11 +33,8 @@ func TestBoringServerProtocolVersion(t *testing.T) {
5833
clientHello := &clientHelloMsg{
5934
vers: v,
6035
random: make([]byte, 32),
61-
cipherSuites: allCipherSuitesIncludingTLS13(),
36+
cipherSuites: allCipherSuites(),
6237
compressionMethods: []uint8{compressionNone},
63-
supportedCurves: defaultCurvePreferences,
64-
keyShares: []keyShare{generateKeyShare(CurveP256)},
65-
supportedPoints: []uint8{pointFormatUncompressed},
6638
supportedVersions: []uint16{v},
6739
}
6840
testClientHelloFailure(t, serverConfig, clientHello, msg)
@@ -76,33 +48,33 @@ func TestBoringServerProtocolVersion(t *testing.T) {
7648

7749
fipstls.Force()
7850
defer fipstls.Abandon()
79-
test("VersionSSL30/fipstls", VersionSSL30, "client offered only unsupported versions")
80-
test("VersionTLS10/fipstls", VersionTLS10, "client offered only unsupported versions")
81-
test("VersionTLS11/fipstls", VersionTLS11, "client offered only unsupported versions")
82-
test("VersionTLS12/fipstls", VersionTLS12, "")
83-
test("VersionTLS13/fipstls", VersionTLS13, "")
51+
test("VersionSSL30", VersionSSL30, "client offered only unsupported versions")
52+
test("VersionTLS10", VersionTLS10, "client offered only unsupported versions")
53+
test("VersionTLS11", VersionTLS11, "client offered only unsupported versions")
54+
test("VersionTLS12", VersionTLS12, "")
55+
test("VersionTLS13", VersionTLS13, "client offered only unsupported versions")
8456
}
8557

8658
func isBoringVersion(v uint16) bool {
87-
return v == VersionTLS12 || v == VersionTLS13
59+
return v == VersionTLS12
8860
}
8961

9062
func isBoringCipherSuite(id uint16) bool {
9163
switch id {
92-
case TLS_AES_128_GCM_SHA256,
93-
TLS_AES_256_GCM_SHA384,
94-
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
64+
case TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
9565
TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
9666
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
97-
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384:
67+
TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
68+
TLS_RSA_WITH_AES_128_GCM_SHA256,
69+
TLS_RSA_WITH_AES_256_GCM_SHA384:
9870
return true
9971
}
10072
return false
10173
}
10274

10375
func isBoringCurve(id CurveID) bool {
10476
switch id {
105-
case CurveP256, CurveP384:
77+
case CurveP256, CurveP384, CurveP521:
10678
return true
10779
}
10880
return false
@@ -114,7 +86,7 @@ func isECDSA(id uint16) bool {
11486
return suite.flags&suiteECSign == suiteECSign
11587
}
11688
}
117-
return false // TLS 1.3 cipher suites are not tied to the signature algorithm.
89+
panic(fmt.Sprintf("unknown cipher suite %#x", id))
11890
}
11991

12092
func isBoringSignatureScheme(alg SignatureScheme) bool {
@@ -126,6 +98,7 @@ func isBoringSignatureScheme(alg SignatureScheme) bool {
12698
PKCS1WithSHA384,
12799
ECDSAWithP384AndSHA384,
128100
PKCS1WithSHA512,
101+
ECDSAWithP521AndSHA512,
129102
PSSWithSHA256,
130103
PSSWithSHA384,
131104
PSSWithSHA512:
@@ -136,9 +109,10 @@ func isBoringSignatureScheme(alg SignatureScheme) bool {
136109

137110
func TestBoringServerCipherSuites(t *testing.T) {
138111
serverConfig := testConfig.Clone()
112+
serverConfig.CipherSuites = allCipherSuites()
139113
serverConfig.Certificates = make([]Certificate, 1)
140114

141-
for _, id := range allCipherSuitesIncludingTLS13() {
115+
for _, id := range allCipherSuites() {
142116
if isECDSA(id) {
143117
serverConfig.Certificates[0].Certificate = [][]byte{testECDSACertificate}
144118
serverConfig.Certificates[0].PrivateKey = testECDSAPrivateKey
@@ -147,19 +121,14 @@ func TestBoringServerCipherSuites(t *testing.T) {
147121
serverConfig.Certificates[0].PrivateKey = testRSAPrivateKey
148122
}
149123
serverConfig.BuildNameToCertificate()
150-
t.Run(fmt.Sprintf("suite=%s", CipherSuiteName(id)), func(t *testing.T) {
124+
t.Run(fmt.Sprintf("suite=%#x", id), func(t *testing.T) {
151125
clientHello := &clientHelloMsg{
152126
vers: VersionTLS12,
153127
random: make([]byte, 32),
154128
cipherSuites: []uint16{id},
155129
compressionMethods: []uint8{compressionNone},
156130
supportedCurves: defaultCurvePreferences,
157-
keyShares: []keyShare{generateKeyShare(CurveP256)},
158131
supportedPoints: []uint8{pointFormatUncompressed},
159-
supportedVersions: []uint16{VersionTLS12},
160-
}
161-
if isTLS13CipherSuite(id) {
162-
clientHello.supportedVersions = []uint16{VersionTLS13}
163132
}
164133

165134
testClientHello(t, serverConfig, clientHello)
@@ -191,9 +160,7 @@ func TestBoringServerCurves(t *testing.T) {
191160
cipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
192161
compressionMethods: []uint8{compressionNone},
193162
supportedCurves: []CurveID{curveid},
194-
keyShares: []keyShare{generateKeyShare(curveid)},
195163
supportedPoints: []uint8{pointFormatUncompressed},
196-
supportedVersions: []uint16{VersionTLS12},
197164
}
198165

199166
testClientHello(t, serverConfig, clientHello)
@@ -312,7 +279,7 @@ func TestBoringClientHello(t *testing.T) {
312279
}
313280

314281
if !isBoringVersion(hello.vers) {
315-
t.Errorf("client vers=%#x", hello.vers)
282+
t.Errorf("client vers=%#x, want %#x (TLS 1.2)", hello.vers, VersionTLS12)
316283
}
317284
for _, v := range hello.supportedVersions {
318285
if !isBoringVersion(v) {

0 commit comments

Comments
 (0)