crypto

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// P256 curve
	P256 string = "P-256"
	// P384 curve
	P384 string = "P-384"
	// P521 curve
	P521 string = "P-521"
)
View Source
const (
	// AlgorithmES256 for creating ES256 based signatures
	AlgorithmES256 = "ES256"
	// AlgorithmObjectHash for creating ObjectHash+ES256 based signatures
	AlgorithmObjectHash = "OH_ES256"
)
View Source
const (
	EC             = "EC"  // Elliptic Curve
	InvalidKeyType = ""    // Invalid KeyType
	OctetSeq       = "oct" // Octet sequence (used to represent symmetric keys)
	RSA            = "RSA" // RSA
)

Supported values for KeyType

View Source
const (
	PrivateKeyType = "/key.private"
)
View Source
const (
	PublicKeyType = "/key.public"
)
View Source
const (
	SignatureType = "/signature"
)

Variables

View Source
var (
	// ErrInvalidObjectType is returned when the signature being verified
	// is not an encoded object of type "signature".
	ErrInvalidObjectType = errors.New("invalid object type")
	// ErrAlgorithNotImplemented is returned when the algorithm specified
	// has not been implemented
	ErrAlgorithNotImplemented = errors.New("algorithm not implemented")
)
View Source
var (
	// ErrCouldNotVerify is returned when the signature doesn't matches the
	// given key
	ErrCouldNotVerify = errors.New("could not verify signature")
)

Functions

func GenerateCertificate

func GenerateCertificate(key *PrivateKey) (*tls.Certificate, error)

GenerateCertificate for TLS serverset

func Sign

func Sign(o object.Object, key *PrivateKey) error

Sign any object (container) with given key and return a signature object (container)

func Verify

func Verify(o object.Object) error

Verify object

Types

type Fingerprint added in v0.3.2

type Fingerprint string

func (Fingerprint) Address added in v0.4.0

func (f Fingerprint) Address() string

func (Fingerprint) String added in v0.3.2

func (f Fingerprint) String() string

type Policy

type Policy struct {
	Description string   `json:"description,omitempty"`
	Subjects    []string `json:"subjects,omitempty"`
	Actions     []string `json:"actions,omitempty"`
	Effect      string   `json:"effect,omitempty"`
}

Policy for Object

type PrivateKey

type PrivateKey struct {
	Algorithm string `json:"alg:s,omitempty"`
	// KeyID                  string `json:"kid,omitempty"`
	KeyType string `json:"kty:s,omitempty"`
	// KeyUsage               string `json:"use,omitempty"`
	// KeyOps                 string `json:"key_ops,omitempty"`
	// X509CertChain          string `json:"x5c,omitempty"`
	// X509CertThumbprint     string `json:"x5t,omitempty"`
	// X509CertThumbprintS256 string `json:"x5tS256,omitempty"`
	// X509URL                string `json:"x5u,omitempty"`
	Curve string `json:"crv:s,omitempty"`
	X     []byte `json:"x:d,omitempty"`
	Y     []byte `json:"y:d,omitempty"`
	D     []byte `json:"d:d,omitempty"`

	PublicKey *PublicKey `json:"pub:o,omitempty"`
}

PrivateKey

func GenerateKey

func GenerateKey() (*PrivateKey, error)

GenerateKey creates a new ecdsa private key

func NewPrivateKey

func NewPrivateKey(key interface{}) (*PrivateKey, error)

NewPrivateKey creates a PrivateKey from the given key.

func (*PrivateKey) Fingerprint

func (k *PrivateKey) Fingerprint() Fingerprint

Fingerprint of the key

func (*PrivateKey) FromObject

func (s *PrivateKey) FromObject(o object.Object) error

FromObject populates the struct from a f12n object

func (PrivateKey) GetType

func (s PrivateKey) GetType() string

GetType returns the object's type

func (*PrivateKey) Key

func (k *PrivateKey) Key() interface{}

func (PrivateKey) ToObject

func (s PrivateKey) ToObject() object.Object

ToObject returns a f12n object

type PublicKey

type PublicKey struct {
	Algorithm string `json:"alg:s,omitempty"`
	// KeyID                  string `json:"kid,omitempty"`
	KeyType string `json:"kty:s,omitempty"`
	// KeyUsage               string `json:"use,omitempty"`
	// KeyOps                 string `json:"key_ops,omitempty"`
	// X509CertChain          string `json:"x5c,omitempty"`
	// X509CertThumbprint     string `json:"x5t,omitempty"`
	// X509CertThumbprintS256 string `json:"x5tS256,omitempty"`
	// X509URL                string `json:"x5u,omitempty"`
	Curve string `json:"crv:s,omitempty"`
	X     []byte `json:"x:d,omitempty"`
	Y     []byte `json:"y:d,omitempty"`

	Signature *Signature `json:"@signature:o,omitempty"`
}

func GetObjectKeys

func GetObjectKeys(o object.Object) (pks []*PublicKey)

func GetSignatureKeys

func GetSignatureKeys(sig *Signature) (pks []*PublicKey)

func NewPublicKey

func NewPublicKey(key interface{}) (*PublicKey, error)

NewPublicKey creates a PublicKey from the given key.

func (*PublicKey) Fingerprint

func (k *PublicKey) Fingerprint() Fingerprint

Fingerprint of the key

func (*PublicKey) FromObject

func (s *PublicKey) FromObject(o object.Object) error

FromObject populates the struct from a f12n object

func (PublicKey) GetType

func (s PublicKey) GetType() string

GetType returns the object's type

func (*PublicKey) Key

func (k *PublicKey) Key() interface{}

func (PublicKey) ToObject

func (s PublicKey) ToObject() object.Object

ToObject returns a f12n object

type Signature

type Signature struct {
	PublicKey *PublicKey `json:"pub:o"`
	Alg       string     `json:"alg:s"`
	R         []byte     `json:"r:d"`
	S         []byte     `json:"s:d"`
}

Signature object (container), currently supports only ES256

func GetObjectSignature

func GetObjectSignature(o object.Object) (*Signature, error)

func NewSignature

func NewSignature(
	key *PrivateKey,
	alg string,
	o object.Object,
) (*Signature, error)

NewSignature returns a signature given some bytes and a private key

func (*Signature) FromObject

func (s *Signature) FromObject(o object.Object) error

FromObject populates the struct from a f12n object

func (Signature) GetType

func (s Signature) GetType() string

GetType returns the object's type

func (Signature) ToObject

func (s Signature) ToObject() object.Object

ToObject returns a f12n object

Jump to

Keyboard shortcuts

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