Skip to content

Commit 87678f0

Browse files
committed
Fix GOLANG_FIPS=0 and enable CGO for bin/go
Pick up these two patches from the go1.23-fips-release branch.
1 parent 896a14d commit 87678f0

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
File renamed without changes.

patches/001-fix-linkage.patch

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
2+
index 32e59b446a..b55f29298b 100644
3+
--- a/src/cmd/dist/build.go
4+
+++ b/src/cmd/dist/build.go
5+
@@ -1309,7 +1309,9 @@ func toolenv() []string {
6+
// we disable cgo to get static binaries for cmd/go and cmd/pprof,
7+
// so that they work on systems without the same dynamic libraries
8+
// as the original build system.
9+
- env = append(env, "CGO_ENABLED=0")
10+
+ //
11+
+ // Setting CGO_ENABLED to 0 prevents cmd/go and the like from linking with vendored openssl symbols.
12+
+ // env = append(env, "CGO_ENABLED=0")
13+
}
14+
if isRelease || os.Getenv("GO_BUILDER_NAME") != "" {
15+
// Add -trimpath for reproducible builds of releases.

patches/002-fix-std-crypto.patch

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
diff --git a/src/crypto/internal/backend/openssl.go b/src/crypto/internal/backend/openssl.go
2+
index 3d3a9a36ee..b7a65a1f6e 100644
3+
--- a/src/crypto/internal/backend/openssl.go
4+
+++ b/src/crypto/internal/backend/openssl.go
5+
@@ -25,6 +25,21 @@ var enabled bool
6+
var knownVersions = [...]string{"3", "1.1", "11", "111", "1.0.2", "1.0.0", "10"}
7+
8+
func init() {
9+
+ // 0: FIPS opt-out: abort the process if it is enabled and can't be disabled.
10+
+ // 1: FIPS required: abort the process if it is not enabled and can't be enabled.
11+
+ // other values: do not override OpenSSL configured FIPS mode.
12+
+ var fips string
13+
+ if v, ok := syscall.Getenv("GOLANG_FIPS"); ok {
14+
+ fips = v
15+
+ } else if hostFIPSModeEnabled() {
16+
+ // System configuration can only force FIPS mode.
17+
+ fips = "1"
18+
+ }
19+
+
20+
+ if fips != "1" {
21+
+ return
22+
+ }
23+
+
24+
version, _ := syscall.Getenv("GO_OPENSSL_VERSION_OVERRIDE")
25+
if version == "" {
26+
var fallbackVersion string
27+
@@ -49,16 +64,6 @@ func init() {
28+
if err := openssl.Init(version); err != nil {
29+
panic("opensslcrypto: can't initialize OpenSSL " + version + ": " + err.Error())
30+
}
31+
- // 0: FIPS opt-out: abort the process if it is enabled and can't be disabled.
32+
- // 1: FIPS required: abort the process if it is not enabled and can't be enabled.
33+
- // other values: do not override OpenSSL configured FIPS mode.
34+
- var fips string
35+
- if v, ok := syscall.Getenv("GOLANG_FIPS"); ok {
36+
- fips = v
37+
- } else if hostFIPSModeEnabled() {
38+
- // System configuration can only force FIPS mode.
39+
- fips = "1"
40+
- }
41+
switch fips {
42+
case "0":
43+
if openssl.FIPS() {

0 commit comments

Comments
 (0)