keyconf

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package keyconf defines basic primitives for key configuration.

Type Key allows decoding and encoding PEM files that contain the key with attached metadata. The PEM files have special file names based on the type, usage, and version of the key. See the encoding and filename example for more information.

Index

Examples

Constants

View Source
const (
	IssSigKeyFile = "core-sig.seed" // TODO(roosd): rename "core-sig.key" -> "iss-sig.key"
	DecKeyFile    = "as-decrypt.key"
	OffKeyFile    = "offline-root.seed"
	OnKeyFile     = "online-root.seed"
	SigKeyFile    = "as-sig.seed"
	MasterKey0    = "master0.key"
	MasterKey1    = "master1.key"

	ASSigKeyFile = "as-signing.key"
	ASDecKeyFile = "as-decrypt.key"
	ASRevKeyFile = "as-revocation.key"

	IssuerRevKeyFile  = "issuer-revocation.key"
	IssuerCertKeyFile = "issuer-cert-signing.key"

	TRCOnlineKeyFile  = "trc-online.key"
	TRCOfflineKeyFile = "trc-offline.key"
	TRCIssuingKeyFile = "trc-issuing.key"

	RawKey = "raw"
)
View Source
const (
	ErrOpen    common.ErrMsg = "Unable to load key"
	ErrParse   common.ErrMsg = "Unable to parse key file"
	ErrUnknown common.ErrMsg = "Unknown algorithm"
)

Errors

Variables

View Source
var (
	// ErrNoAlgorithm indicates no algorithm was provided.
	ErrNoAlgorithm = serrors.New("no algorithm")
	// ErrNoKey indicates no key was provided.
	ErrNoKey = serrors.New("no key")
	// ErrUnsupportedUsage indicates the key usage is not known.
	ErrUnsupportedUsage = serrors.New("unsupported key usage")
	// ErrUnsupportedType indicates the key type is not known.
	ErrUnsupportedType = serrors.New("unsupported key type")
	// ErrWildcardIA indicates the IA contains a wildcard.
	ErrWildcardIA = serrors.New("wildcard IA")
)

Functions

func LoadKey

func LoadKey(file string, algo string) (common.RawBytes, error)

LoadKey decodes a base64 encoded key stored in file and returns the raw bytes.

func PrivateKeyFile

func PrivateKeyFile(usage Usage, version scrypto.KeyVersion) string

PrivateKeyFile returns the file name for the private key with the provided intended usage and version.

func PublicKeyFile

func PublicKeyFile(usage Usage, ia addr.IA, version scrypto.KeyVersion) string

PublicKeyFile returns the file name for the public key with the provided intended usage and version.

Types

type Conf

type Conf struct {
	// IssSigKey is the AS issuer signing Key.
	IssSigKey common.RawBytes
	// DecryptKey is the AS decryption key.
	DecryptKey common.RawBytes
	// OffRootKey is the AS offline root key.
	OffRootKey common.RawBytes
	// OnRootKey is the AS online root key.
	OnRootKey common.RawBytes
	// SignKey is the AS signing key.
	SignKey common.RawBytes
	// Master contains the AS master keys.
	Master Master
}

func Load

func Load(path string, issSigKey, onKey, offKey, master bool) (*Conf, error)

Load loads key configuration from specified path. issSigKey, onKey, offKey, master can be set true, to load the respective keys.

func (*Conf) String

func (c *Conf) String() string

type Key

type Key struct {
	Type      Type
	Usage     Usage
	Algorithm string
	Validity  scrypto.Validity
	Version   scrypto.KeyVersion
	IA        addr.IA
	Bytes     []byte
}

Key contains the key with additional metada.

On disk, the key is encoded in PEM with a file name specific to the type, usage, and version of the key. The IA is prepended to public key filenames to avoid collisions.

To see the resulting filename, check the example.

Example (Encoding)
k := Key{
	Type:      PublicKey,
	Usage:     ASSigKeyFile,
	Algorithm: scrypto.Ed25519,
	Validity: scrypto.Validity{
		NotBefore: util.UnixTime{Time: util.SecsToTime(1560000000)},
		NotAfter:  util.UnixTime{Time: util.SecsToTime(1600000000)},
	},
	Version: 2,
	IA:      xtest.MustParseIA("1-ff00:0:110"),
	Bytes:   make([]byte, ed25519.PublicKeySize),
}
block := k.PEM()
fmt.Println(string(pem.EncodeToMemory(&block)))
Output:

-----BEGIN PUBLIC KEY-----
algorithm: ed25519
ia: 1-ff00:0:110
not_after: 2020-09-13 12:26:40+0000
not_before: 2019-06-08 13:20:00+0000
usage: as-signing.key
version: 2

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
-----END PUBLIC KEY-----
Example (Filename)
publicKey := Key{
	Type:    PublicKey,
	Usage:   ASSigningKey,
	Version: 2,
	IA:      xtest.MustParseIA("1-ff00:0:110"),
}
privateKey := Key{
	Type:    PrivateKey,
	Usage:   ASRevocationKey,
	Version: 10,
	IA:      xtest.MustParseIA("1-ff00:0:110"),
}
fmt.Println("Public key: ", publicKey.File())
fmt.Println("Private key:", privateKey.File())
Output:

Public key:  ISD1-ASff00_0_110-as-signing-v2.pub
Private key: as-revocation-v10.key

func KeyFromPEM

func KeyFromPEM(block *pem.Block) (Key, error)

KeyFromPEM parses the PEM block.

func (Key) File

func (k Key) File() string

File returns the key filename based on the metadata.

func (Key) PEM

func (k Key) PEM() pem.Block

PEM encodes the key with metadata into a PEM block.

func (Key) String

func (k Key) String() string

type Master

type Master struct {
	Key0 common.RawBytes
	Key1 common.RawBytes
}

func LoadMaster

func LoadMaster(path string) (Master, error)

func (*Master) String

func (m *Master) String() string

type Type

type Type string

Type indicates the key type. (public|private|symmetric)

const (
	PublicKey    Type = "PUBLIC KEY"
	PrivateKey   Type = "PRIVATE KEY"
	SymmetricKey Type = "SYMMETRIC KEY"
)

Supported key types.

func (*Type) UnmarshalText

func (t *Type) UnmarshalText(text []byte) error

UnmarshalText assigns the key type if it is known. Otherwise ErrUnsupportedType.

type Usage

type Usage string

Usage describes how the key is intended to be used.

const (
	ASDecryptionKey Usage = "as-decrypt"
	ASRevocationKey Usage = "as-revocation"
	ASSigningKey    Usage = "as-signing"

	IssCertSigningKey Usage = "issuer-cert-signing"
	IssRevocationKey  Usage = "issuer-revocation"

	TRCIssuingKey       Usage = "trc-issuing"
	TRCVotingOfflineKey Usage = "trc-voting-offline"
	TRCVotingOnlineKey  Usage = "trc-voting-online"
)

All supported key usages.

func (*Usage) UnmarshalText

func (u *Usage) UnmarshalText(text []byte) error

UnmarshalText assigns the key usage if it is known. Otherwise ErrUnsupportedUsage.

Jump to

Keyboard shortcuts

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