0

如何验证在 golang dev 无聊的加密分支中是否为二进制启用了 fips 模式?除了内部 golang 测试之外,我没有看到简单的方法

4

1 回答 1

4

从这个文件:

https://go.googlesource.com/go/+/dev.boringcrypto/src/crypto/tls/fipsonly/fipsonly.go

// Package fipsonly restricts all TLS configuration to FIPS-approved settings.
//
// The effect is triggered by importing the package anywhere in a program, as in:
//
//  import _ "crypto/tls/fipsonly"
//
// This package only exists in the dev.boringcrypto branch of Go.

通过在您的程序中包含该 import 语句,它只会在您使用 dev.boringcrypto 分支时编译。

这是一个测试 main.go:

package main

import (
    "fmt"
    _ "crypto/tls/fipsonly"
)

func main() {
    fmt.Println("Hello FIPS")
}

使用 Go 的 dev.boringcrypto 分支:

$ go version
go version go1.12.9b4 linux/amd64
$ go run main.go
Hello FIPS

使用 Go 的正常版本:

$ go version
go version go1.12.9 darwin/amd64
$ go run main.go
main.go:4:2: cannot find package "crypto/tls/fipsonly" in any of:
    /Users/ray/.gimme/versions/go1.12.9.darwin.amd64/src/crypto/tls/fipsonly (from $GOROOT)
    /Users/ray/go/src/crypto/tls/fipsonly (from $GOPATH)
于 2019-08-21T15:45:57.273 回答