diff --git a/README.md b/README.md new file mode 100644 index 0000000..0413658 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +## go-fips + +Proof-Of-Concept for using golang and building a FIPS enabled application. + + +## Setup + +See http://www.openssl.org/docs/fips/UserGuide-2.0.pdf +to set up an environment where fips mode can be enabled + +## Building + + go build . + +or + + go build -tags fips . + +## Testing + + go test . + +or + + go test -tags fips . + diff --git a/fips_on.go b/fips_on.go index c86e0c1..2ee05c8 100644 --- a/fips_on.go +++ b/fips_on.go @@ -30,8 +30,8 @@ func ModeSet(mode ONOFF) (ONOFF, error) { func LastError() string { buf := C.malloc(1024) e := C.ERR_get_error() // a C.ulong - C.ERR_load_crypto_strings() - defer C.ERR_free_strings() + C.ERR_load_crypto_strings() + defer C.ERR_free_strings() C.ERR_error_string_n(e, (*C.char)(buf), 1024) defer C.free(buf) return C.GoString((*C.char)(buf)) diff --git a/fips_test.go b/fips_test.go index bb0693f..73d3121 100644 --- a/fips_test.go +++ b/fips_test.go @@ -1,10 +1,21 @@ package fips -import ( - "fmt" - "testing" -) +import "testing" func TestTest(t *testing.T) { - fmt.Println(ModeSet(ON)) + expected := ON + o, err := ModeSet(expected) + if err != nil { + if err == ErrFipsDisabled { + // ModeSet will not turn it on if fips is not linked in + expected = OFF + } else { + // the error is something else + t.Fatal(err) + } + } + + if o != expected { + t.Errorf("expected %q, got %q", expected, o) + } }