commit | 5b59fee131087c97a13d8eaf764ac651ba6d2d8d | [log] [tgz] |
---|---|---|
author | Dionna Glaze <dionnaglaze@google.com> | Mon Jul 11 22:57:02 2022 +0000 |
committer | Dionna Glaze <dionnaglaze@google.com> | Mon Jul 11 22:57:02 2022 +0000 |
tree | ee29224e85f5aff91b12582ade5e2f6ad9907162 |
First mirror commit.
A COSE library for go.
go-cose is compatible with modern Go releases in module mode, with Go installed:
go get github.com/veraison/go-cose
will resolve and add the package to the current development module, along with its dependencies.
Alternatively the same can be achieved if you use import in a package:
import "github.com/veraison/go-cose"
and run go get
without parameters.
Finally, to use the top-of-trunk version of this repo, use the following command:
go get github.com/veraison/go-cose@main
import "github.com/veraison/go-cose"
Construct a new COSE_Sign1 message, then sign it using ECDSA w/ SHA-512 and finally marshal it. For example:
// create a signer privateKey, _ := ecdsa.GenerateKey(elliptic.P521(), rand.Reader) signer, _ := cose.NewSigner(cose.AlgorithmES512, privateKey) // create message to be signed msg := cose.NewSign1Message() msgToSign.Payload = []byte("hello world") msg.Headers.Protected.SetAlgorithm(cose.AlgorithmES512) // sign message _ = msg.Sign(rand.Reader, nil, signer) // marshal message data, _ := msg.MarshalCBOR()
Verify a raw COSE_Sign1 message. For example:
// create a verifier from a trusted private key publicKey := privateKey.Public() verifier, _ := cose.NewVerifier(cose.AlgorithmES512, publicKey) // create a sign message from a raw COSE_Sign1 payload var msg cose.Sign1Message _ = msg.UnmarshalCBOR(raw) _ = msg.Verify(nil, verifier)
go-cose supports two different signature structures:
:warning: The COSE_Sign API is currently EXPERIMENTAL and may be changed or removed in a later release. In addition, the amount of functional and security testing it has received so far is significantly lower than the COSE_Sign1 API.
go-cose has built-in supports the following algorithms:
The supported algorithms can be extended at runtime by using cose.RegisterAlgorithm.
go-cose runs the GlueCOSE test suite on every local go test
execution. These are also executed on every CI job.
go-cose implements several fuzz tests using Go's native fuzzing.
Fuzzing requires Go 1.18 or higher, and can be executed as follows:
go test -fuzz=FuzzSign1