Skip to content

Commit 39300ba

Browse files
authored
Merge pull request #1505 from microsoft/dev/qmuntal/allowfips
Build the Go toolchain using `allowcryptofallback`
2 parents 88aa286 + 737cf89 commit 39300ba

9 files changed

+64
-84
lines changed

eng/_util/cmd/run-builder/systemfips_fallback.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
//go:build !windows
5-
// +build !windows
4+
//go:build !windows && !linux
65

76
package main
87

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
package main
5+
6+
import (
7+
"log"
8+
"os"
9+
)
10+
11+
// enableSystemWideFIPS enables Mariner and Azure Linux 3 process-wide FIPS mode.
12+
func enableSystemWideFIPS() (restore func(), err error) {
13+
// FIPS mode is enabled if OPENSSL_FORCE_FIPS_MODE is set, regardless of the value.
14+
_, ok := os.LookupEnv("OPENSSL_FORCE_FIPS_MODE")
15+
if ok {
16+
log.Println("FIPS mode already enabled.")
17+
return nil, nil
18+
}
19+
20+
env("OPENSSL_FORCE_FIPS_MODE", "1")
21+
log.Println("Enabled Mariner and Azure Linux 3 FIPS mode.")
22+
23+
return func() {
24+
err := os.Unsetenv("OPENSSL_FORCE_FIPS_MODE")
25+
if err != nil {
26+
log.Printf("Unable to unset OPENSSL_FORCE_FIPS_MODE: %v\n", err)
27+
return
28+
}
29+
log.Println("Successfully unset OPENSSL_FORCE_FIPS_MODE.")
30+
}, nil
31+
}

patches/0003-Implement-crypto-internal-backend.patch

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Subject: [PATCH] Implement crypto/internal/backend
1515
.../internal/backend/bbig/big_openssl.go | 12 +
1616
src/crypto/internal/backend/boring_linux.go | 279 ++++++++++++++
1717
src/crypto/internal/backend/cng_windows.go | 336 ++++++++++++++++
18-
src/crypto/internal/backend/common.go | 58 +++
18+
src/crypto/internal/backend/common.go | 59 +++
1919
src/crypto/internal/backend/darwin_darwin.go | 359 +++++++++++++++++
2020
src/crypto/internal/backend/fips140/boring.go | 11 +
2121
src/crypto/internal/backend/fips140/cng.go | 33 ++
@@ -45,7 +45,7 @@ Subject: [PATCH] Implement crypto/internal/backend
4545
...ckenderr_gen_requirefips_nosystemcrypto.go | 17 +
4646
.../backenderr_gen_systemcrypto_nobackend.go | 16 +
4747
src/runtime/runtime_boring.go | 5 +
48-
41 files changed, 2491 insertions(+), 1 deletion(-)
48+
41 files changed, 2492 insertions(+), 1 deletion(-)
4949
create mode 100644 src/crypto/internal/backend/backend_test.go
5050
create mode 100644 src/crypto/internal/backend/backendgen.go
5151
create mode 100644 src/crypto/internal/backend/backendgen_test.go
@@ -1173,10 +1173,10 @@ index 00000000000000..31dfc9b19ee63e
11731173
+}
11741174
diff --git a/src/crypto/internal/backend/common.go b/src/crypto/internal/backend/common.go
11751175
new file mode 100644
1176-
index 00000000000000..84447174284ffd
1176+
index 00000000000000..9436b00381aaf8
11771177
--- /dev/null
11781178
+++ b/src/crypto/internal/backend/common.go
1179-
@@ -0,0 +1,58 @@
1179+
@@ -0,0 +1,59 @@
11801180
+// Copyright 2022 The Go Authors. All rights reserved.
11811181
+// Use of this source code is governed by a BSD-style
11821182
+// license that can be found in the LICENSE file.
@@ -1186,11 +1186,12 @@ index 00000000000000..84447174284ffd
11861186
+import (
11871187
+ "crypto/internal/backend/fips140"
11881188
+ "crypto/internal/boring/sig"
1189+
+ "internal/goexperiment"
11891190
+ "runtime"
11901191
+)
11911192
+
11921193
+func init() {
1193-
+ if fips140.Enabled() {
1194+
+ if !goexperiment.AllowCryptoFallback && fips140.Enabled() {
11941195
+ if !Enabled {
11951196
+ if runtime.GOOS != "linux" && runtime.GOOS != "windows" && runtime.GOOS != "darwin" {
11961197
+ panic("FIPS mode requested (" + fips140.Message + ") but no crypto backend is supported on " + runtime.GOOS)

patches/0004-Use-crypto-backends.patch

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Subject: [PATCH] Use crypto backends
55

66
---
77
src/cmd/api/boring_test.go | 2 +-
8+
src/cmd/dist/build.go | 13 ++
89
src/cmd/dist/test.go | 8 +-
910
src/cmd/go/go_boring_test.go | 11 +-
1011
src/cmd/go/testdata/script/darwin_no_cgo.txt | 2 +
@@ -81,7 +82,7 @@ Subject: [PATCH] Use crypto backends
8182
src/net/smtp/smtp_test.go | 72 ++++---
8283
src/os/exec/exec_test.go | 9 +
8384
src/runtime/pprof/vminfo_darwin_test.go | 6 +
84-
77 files changed, 1097 insertions(+), 109 deletions(-)
85+
78 files changed, 1110 insertions(+), 109 deletions(-)
8586
create mode 100644 src/crypto/dsa/boring.go
8687
create mode 100644 src/crypto/dsa/notboring.go
8788
create mode 100644 src/crypto/ecdsa/badlinkname.go
@@ -106,6 +107,30 @@ index f0e3575637c62a..9eab3b4e66e60b 100644
106107

107108
package main
108109

110+
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
111+
index 1f467647f56143..4d770d7fc239e2 100644
112+
--- a/src/cmd/dist/build.go
113+
+++ b/src/cmd/dist/build.go
114+
@@ -1543,6 +1543,19 @@ func cmdbootstrap() {
115+
xprintf("Building Go toolchain2 using go_bootstrap and Go toolchain1.\n")
116+
os.Setenv("CC", compilerEnvLookup("CC", defaultcc, goos, goarch))
117+
// Now that cmd/go is in charge of the build process, enable GOEXPERIMENT.
118+
+ //
119+
+ // Build the Go toolchain with "GOEXPERIMENT=allowcryptofallback". This
120+
+ // allows toolchains not built with "GOEXPERIMENT=systemcrypto" to be used
121+
+ // when GOFIPS=1 is set. For example, when running "GOFIPS=1 go test ./..."
122+
+ // or "GOFIPS=1 go run .".
123+
+ // Shadow goexperiment so that the global variable is not modified.
124+
+ goexperiment := goexperiment
125+
+ if !strings.Contains(goexperiment, "allowcryptofallback") {
126+
+ if goexperiment != "" {
127+
+ goexperiment += ","
128+
+ }
129+
+ goexperiment += "allowcryptofallback"
130+
+ }
131+
os.Setenv("GOEXPERIMENT", goexperiment)
132+
// No need to enable PGO for toolchain2.
133+
goInstall(toolenv(), goBootstrap, append([]string{"-pgo=off"}, toolchain...)...)
109134
diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go
110135
index 0c992118f4287b..3316bb52a61ff1 100644
111136
--- a/src/cmd/dist/test.go

patches/0007-unset-GOFIPS-when-running-the-Go-toolchain.patch

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)