Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark COSE Sign as experimental #58

Merged
merged 1 commit into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ _ = msg.Verify(nil, verifier)
go-cose supports two different signature structures:
- [cose.Sign1Message](https://pkg.go.dev/github.com/veraison/go-cose#Sign1Message) implements [COSE_Sign1](https://datatracker.ietf.org/doc/html/rfc8152#section-4.2).
- [cose.SignMessage](https://pkg.go.dev/github.com/veraison/go-cose#SignMessage) implements [COSE_Sign](https://datatracker.ietf.org/doc/html/rfc8152#section-4.1).
> :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.

### Built-in Algorithms

Expand Down
3 changes: 3 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
)

// This example demonstrates signing and verifying COSE_Sign signatures.
//
// The COSE Sign API is EXPERIMENTAL and may be changed or removed in a later
// release.
func ExampleSignMessage() {
// create a signature holder
sigHolder := cose.NewSignature()
Expand Down
72 changes: 72 additions & 0 deletions sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,24 @@ var signaturePrefix = []byte{
// Signature represents a decoded COSE_Signature.
//
// Reference: https://tools.ietf.org/html/rfc8152#section-4.1
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
type Signature struct {
Headers Headers
Signature []byte
}

// NewSignature returns a Signature with header initialized.
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func NewSignature() *Signature {
return &Signature{
Headers: Headers{
Expand All @@ -48,6 +60,12 @@ func NewSignature() *Signature {
}

// MarshalCBOR encodes Signature into a COSE_Signature object.
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (s *Signature) MarshalCBOR() ([]byte, error) {
if s == nil {
return nil, errors.New("cbor: MarshalCBOR on nil Signature pointer")
Expand All @@ -72,6 +90,12 @@ func (s *Signature) MarshalCBOR() ([]byte, error) {
}

// UnmarshalCBOR decodes a COSE_Signature object into Signature.
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (s *Signature) UnmarshalCBOR(data []byte) error {
if s == nil {
return errors.New("cbor: UnmarshalCBOR on nil Signature pointer")
Expand Down Expand Up @@ -110,6 +134,12 @@ func (s *Signature) UnmarshalCBOR(data []byte) error {
// payload of its parent message.
//
// Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-4.4
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (s *Signature) Sign(rand io.Reader, signer Signer, protected cbor.RawMessage, payload, external []byte) error {
if s == nil {
return errors.New("signing nil Signature")
Expand Down Expand Up @@ -151,6 +181,12 @@ func (s *Signature) Sign(rand io.Reader, signer Signer, protected cbor.RawMessag
// payload of its parent message.
//
// Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-4.4
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (s *Signature) Verify(verifier Verifier, protected cbor.RawMessage, payload, external []byte) error {
if s == nil {
return errors.New("verifying nil Signature")
Expand Down Expand Up @@ -251,13 +287,25 @@ var signMessagePrefix = []byte{
// SignMessage represents a decoded COSE_Sign message.
//
// Reference: https://tools.ietf.org/html/rfc8152#section-4.1
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
type SignMessage struct {
Headers Headers
Payload []byte
Signatures []*Signature
}

// NewSignMessage returns a SignMessage with header initialized.
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func NewSignMessage() *SignMessage {
return &SignMessage{
Headers: Headers{
Expand All @@ -268,6 +316,12 @@ func NewSignMessage() *SignMessage {
}

// MarshalCBOR encodes SignMessage into a COSE_Sign_Tagged object.
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (m *SignMessage) MarshalCBOR() ([]byte, error) {
if m == nil {
return nil, errors.New("cbor: MarshalCBOR on nil SignMessage pointer")
Expand Down Expand Up @@ -304,6 +358,12 @@ func (m *SignMessage) MarshalCBOR() ([]byte, error) {
}

// UnmarshalCBOR decodes a COSE_Sign_Tagged object into SignMessage.
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (m *SignMessage) UnmarshalCBOR(data []byte) error {
if m == nil {
return errors.New("cbor: UnmarshalCBOR on nil SignMessage pointer")
Expand Down Expand Up @@ -352,6 +412,12 @@ func (m *SignMessage) UnmarshalCBOR(data []byte) error {
// See `Signature.Sign()` for advanced signing scenarios.
//
// Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-4.4
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (m *SignMessage) Sign(rand io.Reader, external []byte, signers ...Signer) error {
if m == nil {
return errors.New("signing nil SignMessage")
Expand Down Expand Up @@ -392,6 +458,12 @@ func (m *SignMessage) Sign(rand io.Reader, external []byte, signers ...Signer) e
// policies.
//
// Reference: https://datatracker.ietf.org/doc/html/rfc8152#section-4.4
//
// Experimental
//
// Notice: The COSE Sign API is EXPERIMENTAL and may be changed or removed in a
// later release.
//
func (m *SignMessage) Verify(external []byte, verifiers ...Verifier) error {
if m == nil {
return errors.New("verifying nil SignMessage")
Expand Down