Verify FIPS mode in golang boringssl - go

how to verify if fips mode is enabled for binary in golang dev boring crypto branch ?
I dont see an easy way apart from internal golang tests

From this file:
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.
By including that import statement in your program, it will only compile if you're using the dev.boringcrypto branch.
Here's a test main.go:
package main
import (
"fmt"
_ "crypto/tls/fipsonly"
)
func main() {
fmt.Println("Hello FIPS")
}
Using the dev.boringcrypto branch of Go:
$ go version
go version go1.12.9b4 linux/amd64
$ go run main.go
Hello FIPS
Using the normal release of 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)

Related

Endorsers Instantiate Chaincode with error "cannot find package"

I created a chaincode and I imported a package to it.
import (
"bytes"
"encoding/json"
"fmt"
"strings"
"golang.org/x/crypto/bcrypt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer")
I can install that chaincode to all endorsers. But when I instantiated it to all endorsers, it faced the error:
endorser failed with error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "/chaincode/input/src/github.com/marbles02/marbles_chaincode.go:85:2: cannot find package "golang.org/x/crypto/bcrypt" in any of:
/usr/local/go/src/golang.org/x/crypto/bcrypt (from $GOROOT)
/chaincode/input/src/golang.org/x/crypto/bcrypt (from $GOPATH)
/go/src/golang.org/x/crypto/bcrypt
I tried to copy golang.org/x/crypto/bcrypt package to the /usr/local/go/src/ in the root directory, but it has the same error.
Try Installing the dependencies in the chaincode directory using below commands:
go mod init will create go.mod and go.sum files.
go mod vendor for creating a vendor directory.
Also if using fabric:v2.X.X then shim and peer packages moved to different libraries.
so change the peer and shim packages to below in the chaincode.go file.
peer --> github.com/hyperledger/fabric-protos-go/peer.
shim --> github.com/hyperledger/fabric-chaincode-go/shim
Make sure to add peerand shim changes before running go mod initcommand OR if you are already have a vendor directory then try go mod tidy and then go mod vendor commands to update the packages.

Build dependencis for aws-sdk-go fails on Go version 1.13

I have been trying to build a module on Go v1.13 with dependencies on github.com/aws/aws-lambda-go and github.com/aws/aws-sdk-go which fail on the two imports:
"github.com/aws/aws-sdk-go/aws/service/s3"
"github.com/aws/aws-sdk-go/aws/service/s3/s3manager"
The stderr is as follows for GOOS=linux GOARCH=amd64 go build -o dist/api ./api where the api directory contains my module definition:
api/main.go:11:2: cannot find package "github.com/aws/aws-sdk-go/aws/service/s3" in any of:
/usr/local/go/src/github.com/aws/aws-sdk-go/aws/service/s3 (from $GOROOT)
/u/go/src/github.com/aws/aws-sdk-go/aws/service/s3 (from $GOPATH)
api/main.go:12:2: cannot find package "github.com/aws/aws-sdk-go/aws/service/s3/s3manager" in any of:
/usr/local/go/src/github.com/aws/aws-sdk-go/aws/service/s3/s3manager (from $GOROOT)
/u/go/src/github.com/aws/aws-sdk-go/aws/service/s3/s3manager (from $GOPATH)
Honestly, I have no clue why this is happening and any inputs would be appreciated.
Already tried using go get to ensure that the dependencies have been pulled:
$ go get github.com/aws/aws-sdk-go
and the requested import paths are present under $GOPATH/src/github.com/aws/aws-sdk/go/aws/service/s3 and $GOPATH/src/github.com/aws/aws-sdk/go/aws/service/s3/s3manager
Also, tried clearing the cache using go clean --cache --modcache whilst removing previously pulled modules.
On closer inspection, something that I completely overlooked, the import path is /u/go/src/github.com/aws/aws-sdk-go/aws/service/s3 instead of /u/go/src/github.com/aws/aws-sdk-go/service/s3 with the former having an additional aws subpath inside aws-sdk-go.
Just realized the copy/paste error I had made in the code.
import (
"github.com/aws/aws-sdk-go/aws/service/s3"
"github.com/aws/aws-sdk-go/aws/service/s3/s3manager"
)
instead of
import (
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)

"cannot find package" error on godoc playable examples

I'm trying to make palyable example on godoc.
OS X Yosemite 10.10.5
Go: go1.7.4 darwin/amd64
test code:
$GOPATH/src/hoge/hoge_test.go
package hoge_test
import (
"fmt"
"hoge"
"testing"
)
func ExampleHoge() {
fmt.Println(hoge.Hoge())
// Output:
// hoge!!
}
The test passes:
$ go test hoge
ok hoge 0.011s
Godoc
$ godoc -play -http=:8080
I can see the hoge package's example playground as I expected on a web browser, but an error below occurs when I 'Run' the example.
tmp/sandbox389904218/main.go:5:2: cannot find package "hoge" in any of:
/usr/local/go/src/hoge (from $GOROOT)
/go/src/hoge (from $GOPATH)
I set my own GOPATH, but it's not /go as shown in the error.
What I need to run examples.
Additional
I've got a reason of the error above.
Godoc playable example redirects to play.golang.org to run the code, so the GOPATH in the error seems to be on the play.golang.org environment.
I'm still not sure how to run my own pkg example though...
This is because godoc uses the golang.org/x/tools/playground tool, which just proxies requests to golang.org. It does not appear that you can run your example functions unless they are in a package that is published on golang.org. Here's the relevant file in github: https://github.com/golang/tools/blob/master/playground/common.go which is referenced by the godoc tool here: https://github.com/golang/tools/blob/master/cmd/godoc/play.go

Go install: “Can't load package” (even though GOPATH is set)

I'm just getting started with the Go programming language and installed Go using the Windows installer from the website. I tested installation by using go run hello.go and that works. The problem comes when I try to build my first program:
$ echo $GOROOT
C:\Go\
$ echo $GOPATH
/cygdrive/c/Users/Paul/Documents/Home/go
mkdir -p $GOPATH/src/hello
Inside that directory I have a simple hello.go program:
package main
import "fmt"
func main() {
fmt.Printf("Hello, world.\n")
}
The problem comes when I try to build and install:
$ go install hello
can't load package: package hello: cannot find package "hello" in any of:
C:\Go\src\hello (from $GOROOT)
\cygdrive\c\Users\Paul\Documents\Home\go\src\hello (from $GOPATH)
GOPATH environment variable must contain valid path.
\cygdrive\c\Users\Paul\Documents\Home\go\src\hello is not a valid path on Windows.
Try setting GOPATH=c:\Users\Paul\Documents\Home\go instead.

Go cannot find package in windows

I have installed a package in windows using
go get github.com/couchbaselabs/go-couchbase
No message apprear after installation.
Then I tried to include in Go
import (
"github.com/couchbaselabs/go-couchbase"
)
However,when I build, I got the message
main.go:7:2: cannot find package "github.com/couchbaselabs/go-couchbase" in any of:
c:\go\src\pkg\github.com\couchbaselabs\go-couchbase (from $GOROOT)
C:\Go\src\Chaatz\src\github.com\couchbaselabs\go-couchbase (from $GOPATH)
C:\Go\src\github.com\couchbaselabs\go-couchbase
Am I miss something, or the package is installed to other path?
For example,
>set gopath
GOPATH=C:\gopath
>go get -v github.com/couchbaselabs/go-couchbase
github.com/couchbaselabs/go-couchbase (download)
github.com/couchbase/gomemcached (download)
github.com/couchbaselabs/retriever (download)
github.com/natefinch/npipe (download)
github.com/couchbase/gomemcached
github.com/couchbaselabs/retriever/lockfile
github.com/natefinch/npipe
github.com/couchbaselabs/retriever/logger
github.com/couchbaselabs/retriever/stats
github.com/couchbase/gomemcached/client
github.com/couchbaselabs/go-couchbase
>go version
go version go1.3 windows/amd64
>type cb.go
package main
import (
"fmt"
"github.com/couchbaselabs/go-couchbase"
)
func main() {
var _ couchbase.Bucket
fmt.Println("couchbase")
}
>go run cb.go
couchbase
>

Resources