keycard

package module
v0.0.0-...-8d18b63 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2019 License: MPL-2.0 Imports: 20 Imported by: 0

README

keycard-go

keycard-go is a set of Go packages built to interact with the Status Keycard.

If you only need a tool to initialize your card, check out keycard-cli.

Keycard commands

  • SELECT
  • INIT
  • OPEN SECURE CHANNEL
  • MUTUALLY AUTHENTICATE
  • PAIR
  • UNPAIR
  • GET STATUS
  • SET NDEF
  • VERIFY PIN
  • CHANGE PIN
  • UNBLOCK PIN
  • LOAD KEY
  • DERIVE KEY
  • GENERATE MNEMONIC
  • REMOVE KEY
  • GENERATE KEY
  • INIT
  • DUPLICATE KEY
  • SIGN
  • SET PINLESS PATH
  • EXPORT KEY

Documentation

Index

Constants

View Source
const (
	InsInit                 = 0xFE
	InsOpenSecureChannel    = 0x10
	InsMutuallyAuthenticate = 0x11
	InsPair                 = 0x12
	InsUnpair               = 0x13
	InsGetStatus            = 0xF2
	InsGenerateKey          = 0xD4
	InsRemoveKey            = 0xD3
	InsVerifyPIN            = 0x20
	InsChangePIN            = 0x21
	InsDeriveKey            = 0xD1
	InsExportKey            = 0xC2
	InsSign                 = 0xC0
	InsSetPinlessPath       = 0xC1

	P1PairingFirstStep         = 0x00
	P1PairingFinalStep         = 0x01
	P1GetStatusApplication     = 0x00
	P1GetStatusKeyPath         = 0x01
	P1DeriveKeyFromMaster      = 0x00
	P1DeriveKeyFromParent      = 0x01
	P1DeriveKeyFromCurrent     = 0x10
	P1ChangePinPIN             = 0x00
	P1ChangePinPUK             = 0x01
	P1ChangePinPairingSecret   = 0x02
	P1SignCurrentKey           = 0x00
	P1SignDerive               = 0x01
	P1SignDeriveAndMakeCurrent = 0x02
	P1SignPinless              = 0x03

	SwNoAvailablePairingSlots = 0x6A84
)

Variables

View Source
var ErrInvalidResponseMAC = errors.New("invalid response MAC")
View Source
var ErrNoAvailablePairingSlots = errors.New("no available pairing slots")

Functions

func NewCommandChangePIN

func NewCommandChangePIN(pin string) *apdu.Command

func NewCommandChangePUK

func NewCommandChangePUK(puk string) *apdu.Command

func NewCommandChangePairingSecret

func NewCommandChangePairingSecret(secret []byte) *apdu.Command

func NewCommandDeriveKey

func NewCommandDeriveKey(pathStr string) (*apdu.Command, error)

func NewCommandExportKey

func NewCommandExportKey(p1 uint8, p2 uint8, pathStr string) (*apdu.Command, error)

Export a key

	@param {p1}
		0x00: current key - returns the key that is currently loaded and ready for signing. Does not use derivation path
		0x01: derive - returns derived key
		0x02: derive and make current - returns derived key and also sets it to the current key
 @param {p2}
		0x00: return public and private key pair
		0x01: return only the public key
 @param {pathStr}
		Derivation path of format "m/x/x/x/x/x", e.g. "m/44'/0'/0'/0/0"

func NewCommandGenerateKey

func NewCommandGenerateKey(p1 uint8) *apdu.Command

func NewCommandGetStatus

func NewCommandGetStatus(p1 uint8) *apdu.Command

func NewCommandInit

func NewCommandInit(data []byte) *apdu.Command

func NewCommandMutuallyAuthenticate

func NewCommandMutuallyAuthenticate(data []byte) *apdu.Command

func NewCommandOpenSecureChannel

func NewCommandOpenSecureChannel(pairingIndex uint8, pubKey []byte) *apdu.Command

func NewCommandPairFinalStep

func NewCommandPairFinalStep(cryptogramHash []byte) *apdu.Command

func NewCommandPairFirstStep

func NewCommandPairFirstStep(challenge []byte) *apdu.Command

func NewCommandRemoveKey

func NewCommandRemoveKey() *apdu.Command

func NewCommandSetPinlessPath

func NewCommandSetPinlessPath(pathStr string) (*apdu.Command, error)

func NewCommandSign

func NewCommandSign(data []byte, p1 uint8) (*apdu.Command, error)

func NewCommandUnpair

func NewCommandUnpair(index uint8) *apdu.Command

func NewCommandVerifyPIN

func NewCommandVerifyPIN(pin string) *apdu.Command

Types

type CommandSet

type CommandSet struct {
	ApplicationInfo *types.ApplicationInfo
	PairingInfo     *types.PairingInfo
	// contains filtered or unexported fields
}

func NewCommandSet

func NewCommandSet(c types.Channel) *CommandSet

func (*CommandSet) ChangePIN

func (cs *CommandSet) ChangePIN(pin string) error

func (*CommandSet) ChangePUK

func (cs *CommandSet) ChangePUK(puk string) error

func (*CommandSet) ChangePairingSecret

func (cs *CommandSet) ChangePairingSecret(password string) error

func (*CommandSet) DeriveKey

func (cs *CommandSet) DeriveKey(path string) error

func (*CommandSet) GenerateKey

func (cs *CommandSet) GenerateKey(exportable uint8) ([]byte, error)

func (*CommandSet) GenericCommand

func (cs *CommandSet) GenericCommand(tag uint8, command uint8, p1 uint8, p2 uint8, data []byte) ([]byte, error)

Call any command which does not require a secure channel

func (*CommandSet) GetStatus

func (cs *CommandSet) GetStatus(info uint8) (*types.ApplicationStatus, error)

func (*CommandSet) GetStatusApplication

func (cs *CommandSet) GetStatusApplication() (*types.ApplicationStatus, error)

func (*CommandSet) GetStatusKeyPath

func (cs *CommandSet) GetStatusKeyPath() (*types.ApplicationStatus, error)

func (*CommandSet) Init

func (cs *CommandSet) Init(secrets *Secrets) error

func (*CommandSet) OpenSecureChannel

func (cs *CommandSet) OpenSecureChannel() error

func (*CommandSet) Pair

func (cs *CommandSet) Pair(pairingPass string) error

func (*CommandSet) RemoveKey

func (cs *CommandSet) RemoveKey() error

func (*CommandSet) Select

func (cs *CommandSet) Select() error

func (*CommandSet) SetPairingInfo

func (cs *CommandSet) SetPairingInfo(key []byte, index int)

func (*CommandSet) SetPinlessPath

func (cs *CommandSet) SetPinlessPath(path string) error

func (*CommandSet) Sign

func (cs *CommandSet) Sign(data []byte) (*types.Signature, error)

func (*CommandSet) SignPinless

func (cs *CommandSet) SignPinless(data []byte) (*types.Signature, error)

func (*CommandSet) Unpair

func (cs *CommandSet) Unpair(index uint8) error

func (*CommandSet) VerifyPIN

func (cs *CommandSet) VerifyPIN(pin string) error

type Secrets

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

Secrets contains the secret data needed to pair a client with a card.

func GenerateSecrets

func GenerateSecrets() (*Secrets, error)

GenerateSecrets generate a new Secrets with random puk and pairing password.

func NewSecrets

func NewSecrets(pin, puk, pairingPass string) *Secrets

func (*Secrets) PairingPass

func (s *Secrets) PairingPass() string

PairingPass returns the pairing password string.

func (*Secrets) PairingToken

func (s *Secrets) PairingToken() []byte

PairingToken returns the pairing token generated from the random pairing password.

func (*Secrets) Pin

func (s *Secrets) Pin() string

Pin returns the pin string.

func (*Secrets) Puk

func (s *Secrets) Puk() string

Puk returns the puk string.

type SecureChannel

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

func NewSecureChannel

func NewSecureChannel(c types.Channel) *SecureChannel

func (*SecureChannel) GenerateSecret

func (sc *SecureChannel) GenerateSecret(cardPubKeyData []byte) error

func (*SecureChannel) Init

func (sc *SecureChannel) Init(iv, encKey, macKey []byte)

func (*SecureChannel) OneShotEncrypt

func (sc *SecureChannel) OneShotEncrypt(secrets *Secrets) ([]byte, error)

func (*SecureChannel) PublicKey

func (sc *SecureChannel) PublicKey() *ecdsa.PublicKey

func (*SecureChannel) RawPublicKey

func (sc *SecureChannel) RawPublicKey() []byte

func (*SecureChannel) Reset

func (sc *SecureChannel) Reset()

func (*SecureChannel) Secret

func (sc *SecureChannel) Secret() []byte

func (*SecureChannel) Send

func (sc *SecureChannel) Send(cmd *apdu.Command) (*apdu.Response, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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