cose

package
v0.0.0-...-60e628d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package cose contains the subset of the CBOR Object Signing and Encryption (COSE) standard needed for webauthn.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPublicKey     = errors.New("invalid public key")
	ErrInvalidSignature     = errors.New("invalid signature")
	ErrUnsupportedAlgorithm = errors.New("unsupported COSE algorithm")
	ErrUnsupportedCurve     = errors.New("unsupported elliptic curve")
	ErrUnsupportedKeyType   = errors.New("unsupported COSE key type")
)

Errors

Functions

This section is empty.

Types

type Algorithm

type Algorithm int

The Algorithm identifies a cryptographic algorithm as defined in https://www.iana.org/assignments/cose/cose.xhtml#algorithms.

const (
	// AlgorithmRS1 indicates RSASSA-PKCS1-v1_5 with SHA-1.
	AlgorithmRS1 Algorithm = -65535
	// AlgorithmRS512 indicates RSASSA-PKCS1-v1_5 with SHA-512.
	AlgorithmRS512 Algorithm = -259
	// AlgorithmRS384 indicates RSASSA-PKCS1-v1_5 with SHA-384.
	AlgorithmRS384 Algorithm = -258
	// AlgorithmRS256 indicates RSASSA-PKCS1-v1_5 with SHA-256.
	AlgorithmRS256 Algorithm = -257
	// AlgorithmPS512 indicates RSASSA-PSS with SHA-512.
	AlgorithmPS512 Algorithm = -39
	// AlgorithmPS384 indicates RSASSA-PSS with SHA-384.
	AlgorithmPS384 Algorithm = -38
	// AlgorithmPS256 indicates RSASSA-PSS with SHA-256.
	AlgorithmPS256 Algorithm = -37
	// AlgorithmES512 indicates ECDSA w/ SHA-512.
	AlgorithmES512 Algorithm = -36
	// AlgorithmES384 indicates ECDSA w/ SHA-384.
	AlgorithmES384 Algorithm = -35
	// AlgorithmEdDSA indicates EdDSA.
	AlgorithmEdDSA Algorithm = -8
	// AlgorithmES256 indicates ECDSA w/ SHA-256.
	AlgorithmES256 Algorithm = -7
)

func (Algorithm) Hash

func (alg Algorithm) Hash() crypto.Hash

Hash returns the cryptographic Hash used by the algorithm.

func (Algorithm) String

func (alg Algorithm) String() string

String returns the algorithm as a string.

func (Algorithm) X509SignatureAlgorithm

func (alg Algorithm) X509SignatureAlgorithm() x509.SignatureAlgorithm

X509SignatureAlgorithm returns the corresponding x509.SignatureAlgorithm for the Algorithm.

type Curve

type Curve int

Curve indicates the cryptographic elliptic curve used by an algorithm as defined in: https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves

const (
	CurveP256 Curve = iota + 1
	CurveP384
	CurveP521
	CurveX25519
	CurveX448
	CurveEd25519
	CurveEd448
	CurveSECP256K1
)

Elliptic curves

func (Curve) EllipticCurve

func (curve Curve) EllipticCurve() (ellipticCurve elliptic.Curve, ok bool)

EllipticCurve returns the elliptic.Curve for the given Curve.

func (Curve) String

func (curve Curve) String() string

String returns the curve as a string.

type ECDSAPublicKey

type ECDSAPublicKey struct {
	// contains filtered or unexported fields
}

An ECDSAPublicKey is a public key using ECDSA.

func NewECDSAPublicKey

func NewECDSAPublicKey(
	algorithm Algorithm,
	publicKey ecdsa.PublicKey,
) (*ECDSAPublicKey, error)

NewECDSAPublicKey creates a new ECDSAPublicKey from an existing key.

func UnmarshalECDSAPublicKey

func UnmarshalECDSAPublicKey(raw []byte) (key *ECDSAPublicKey, remaining []byte, err error)

UnmarshalECDSAPublicKey unmarshals an ECDSA key using the COSE_Key format.

func (ECDSAPublicKey) Algorithm

func (key ECDSAPublicKey) Algorithm() Algorithm

Algorithm returns the ECDSA algorithm.

func (ECDSAPublicKey) CryptoPublicKey

func (key ECDSAPublicKey) CryptoPublicKey() crypto.PublicKey

CryptoPublicKey returns the crypto ECDSA public key.

func (ECDSAPublicKey) Marshal

func (key ECDSAPublicKey) Marshal() ([]byte, error)

Marshal marshals the key.

func (ECDSAPublicKey) RawX962ECC

func (key ECDSAPublicKey) RawX962ECC() RawX962ECC

RawX962ECC returns the RawX962ECC formatted public key.

func (ECDSAPublicKey) Type

func (ECDSAPublicKey) Type() KeyType

Type returns EC2.

func (ECDSAPublicKey) Verify

func (key ECDSAPublicKey) Verify(data, signature []byte) error

Verify returns true if the signature is a valid ECDSA signature for data.

type EdDSAPublicKey

type EdDSAPublicKey struct {
	// contains filtered or unexported fields
}

An EdDSAPublicKey is a public key using EdDSA.

func UnmarshalEdDSAPublicKey

func UnmarshalEdDSAPublicKey(raw []byte) (key *EdDSAPublicKey, remaining []byte, err error)

UnmarshalEdDSAPublicKey unmarshals an EdDSA key using the COSE_Key format.

func (EdDSAPublicKey) Algorithm

func (EdDSAPublicKey) Algorithm() Algorithm

Algorithm returns EdDSA.

func (EdDSAPublicKey) CryptoPublicKey

func (key EdDSAPublicKey) CryptoPublicKey() crypto.PublicKey

CryptoPublicKey returns the crypto EdDSA public key.

func (EdDSAPublicKey) Marshal

func (key EdDSAPublicKey) Marshal() ([]byte, error)

Marshal marshals the key.

func (EdDSAPublicKey) Type

func (EdDSAPublicKey) Type() KeyType

Type returns OKP.

func (EdDSAPublicKey) Verify

func (key EdDSAPublicKey) Verify(data, signature []byte) error

Verify returns true if the signature is a valid EdDSA signature for data.

type KeyType

type KeyType byte

The KeyType indicates the encoding format used to encode a key.

const (
	// KeyTypeOctet is the key type (kty) used for EdDSA keys.
	KeyTypeOctet KeyType = iota + 1
	// KeyTypeElliptic is the key type (kty) used for ECDSA keys.
	KeyTypeElliptic
	// KeyTypeRSA is the key type (kty) used for RSA keys.
	KeyTypeRSA
)

func (KeyType) String

func (kty KeyType) String() string

String returns the key type as a string.

type PublicKey

type PublicKey interface {
	Algorithm() Algorithm
	CryptoPublicKey() crypto.PublicKey
	Marshal() ([]byte, error)
	Type() KeyType
	Verify(data, signature []byte) error
}

A PublicKey is a credential public key.

func UnmarshalPublicKey

func UnmarshalPublicKey(raw []byte) (key PublicKey, remaining []byte, err error)

UnmarshalPublicKey unmarshals a COSE_Key encoded public key from a slice of bytes.

type RSAPublicKey

type RSAPublicKey struct {
	// contains filtered or unexported fields
}

An RSAPublicKey is a public key using RSA.

func NewRSAPublicKey

func NewRSAPublicKey(
	algorithm Algorithm,
	publicKey rsa.PublicKey,
) (*RSAPublicKey, error)

NewRSAPublicKey creates a new RSAPublicKey.

func UnmarshalRSAPublicKey

func UnmarshalRSAPublicKey(raw []byte) (key *RSAPublicKey, remaining []byte, err error)

UnmarshalRSAPublicKey unmarshals an RSA key using the COSE_Key format.

func (RSAPublicKey) Algorithm

func (key RSAPublicKey) Algorithm() Algorithm

Algorithm returns the RSA algorithm.

func (RSAPublicKey) CryptoPublicKey

func (key RSAPublicKey) CryptoPublicKey() crypto.PublicKey

CryptoPublicKey returns the crypto RSA public key.

func (RSAPublicKey) Marshal

func (key RSAPublicKey) Marshal() ([]byte, error)

Marshal marshals the key.

func (RSAPublicKey) Type

func (RSAPublicKey) Type() KeyType

Type returns RSA.

func (RSAPublicKey) Verify

func (key RSAPublicKey) Verify(data, signature []byte) error

Verify returns true if the signature is a valid RSA signature for data.

type RawX962ECC

type RawX962ECC [65]byte

RawX962ECC represents the Raw ANSI X9.62 public key format for ALG_KEY_ECC_X962_RAW as defined in: https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-registry-v2.0-id-20180227.html#public-key-representation-formats

func NewRawX962ECC

func NewRawX962ECC(x, y [32]byte) RawX962ECC

NewRawX962ECC creates a new RawX962ECC.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL