cmd/go,crypto: reject using Go+BoringCrypto and fips140 together

The combination is untested and nonsensical. Both are solutions to the
same problem.

For #69536

Change-Id: I95cc3baaf03b64ce08096e304e311a29e9577385
Reviewed-on: https://go-review.googlesource.com/c/go/+/637177
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Russ Cox <rsc@golang.org>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Filippo Valsorda 2024-12-17 19:57:54 +01:00 committed by Gopher Robot
parent 971448ddf8
commit 8ff4cee564
6 changed files with 25 additions and 0 deletions

View file

@ -119,6 +119,10 @@ func Init() {
if Snapshot() { if Snapshot() {
fsys.Bind(Dir(), filepath.Join(cfg.GOROOT, "src/crypto/internal/fips140")) fsys.Bind(Dir(), filepath.Join(cfg.GOROOT, "src/crypto/internal/fips140"))
} }
if cfg.Experiment.BoringCrypto && Enabled() {
base.Fatalf("go: cannot use GOFIPS140 with GOEXPERIMENT=boringcrypto")
}
} }
var initDone bool var initDone bool

View file

@ -1,5 +1,8 @@
# Test query for non-defaults in the env # Test query for non-defaults in the env
# Go+BoringCrypto conflicts with GOFIPS140.
[GOEXPERIMENT:boringcrypto] skip
env GOROOT=./a env GOROOT=./a
env GOTOOLCHAIN=local env GOTOOLCHAIN=local
env GOSUMDB=nodefault env GOSUMDB=nodefault

View file

@ -1,3 +1,6 @@
# Go+BoringCrypto conflicts with GOFIPS140.
[GOEXPERIMENT:boringcrypto] skip
# list with GOFIPS140=off # list with GOFIPS140=off
env GOFIPS140=off env GOFIPS140=off
go list -f '{{.DefaultGODEBUG}}' go list -f '{{.DefaultGODEBUG}}'

View file

@ -7,6 +7,9 @@ env alias=inprocess
skip 'no snapshots yet' skip 'no snapshots yet'
env GOFIPS140=$snap env GOFIPS140=$snap
# Go+BoringCrypto conflicts with GOFIPS140.
[GOEXPERIMENT:boringcrypto] skip
# default GODEBUG includes fips140=on # default GODEBUG includes fips140=on
go list -f '{{.DefaultGODEBUG}}' go list -f '{{.DefaultGODEBUG}}'
stdout fips140=on stdout fips140=on

View file

@ -16,6 +16,7 @@ import "C"
import ( import (
"crypto/internal/boring/sig" "crypto/internal/boring/sig"
_ "crypto/internal/boring/syso" _ "crypto/internal/boring/syso"
"crypto/internal/fips140"
"internal/stringslite" "internal/stringslite"
"math/bits" "math/bits"
"unsafe" "unsafe"
@ -31,6 +32,12 @@ func init() {
sig.BoringCrypto() sig.BoringCrypto()
} }
func init() {
if fips140.Enabled {
panic("boringcrypto: cannot use GODEBUG=fips140 with GOEXPERIMENT=boringcrypto")
}
}
// Unreachable marks code that should be unreachable // Unreachable marks code that should be unreachable
// when BoringCrypto is in use. It panics. // when BoringCrypto is in use. It panics.
func Unreachable() { func Unreachable() {

View file

@ -5,6 +5,7 @@
package fipstest package fipstest
import ( import (
"crypto/internal/boring"
. "crypto/internal/fips140/check" . "crypto/internal/fips140/check"
"crypto/internal/fips140/check/checktest" "crypto/internal/fips140/check/checktest"
"fmt" "fmt"
@ -22,6 +23,10 @@ import (
const enableFIPSTest = true const enableFIPSTest = true
func TestFIPSCheckVerify(t *testing.T) { func TestFIPSCheckVerify(t *testing.T) {
if boring.Enabled {
t.Skip("not testing fips140 with boringcrypto enabled")
}
if Verified { if Verified {
t.Logf("verified") t.Logf("verified")
return return