keycard

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: MPL-2.0 Imports: 20 Imported by: 3

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
  • STORE DATA
  • GET DATA
  • VERIFY PIN
  • CHANGE PIN
  • UNBLOCK PIN
  • LOAD KEY
  • DERIVE KEY
  • GENERATE MNEMONIC
  • REMOVE KEY
  • GENERATE KEY
  • INIT
  • SIGN
  • SET PINLESS PATH
  • EXPORT KEY

Documentation

Index

Constants

View Source
const (
	InsInit                 = 0xFE
	InsFactoryReset         = 0xFD
	InsOpenSecureChannel    = 0x10
	InsMutuallyAuthenticate = 0x11
	InsPair                 = 0x12
	InsUnpair               = 0x13
	InsIdentify             = 0x14
	InsGetStatus            = 0xF2
	InsGenerateKey          = 0xD4
	InsRemoveKey            = 0xD3
	InsVerifyPIN            = 0x20
	InsChangePIN            = 0x21
	InsUnblockPIN           = 0x22
	InsDeriveKey            = 0xD1
	InsExportKey            = 0xC2
	InsSign                 = 0xC0
	InsSetPinlessPath       = 0xC1
	InsGetData              = 0xCA
	InsLoadKey              = 0xD0
	InsGenerateMnemonic     = 0xD2
	InsStoreData            = 0xE2

	P1PairingFirstStep              = 0x00
	P1PairingFinalStep              = 0x01
	P1GetStatusApplication          = 0x00
	P1GetStatusKeyPath              = 0x01
	P1DeriveKeyFromMaster           = 0x00
	P1DeriveKeyFromParent           = 0x40
	P1DeriveKeyFromCurrent          = 0x80
	P1ChangePinPIN                  = 0x00
	P1ChangePinPUK                  = 0x01
	P1ChangePinPairingSecret        = 0x02
	P1SignCurrentKey                = 0x00
	P1SignDerive                    = 0x01
	P1SignDeriveAndMakeCurrent      = 0x02
	P1SignPinless                   = 0x03
	P1StoreDataPublic               = 0x00
	P1StoreDataNDEF                 = 0x01
	P1StoreDataCash                 = 0x02
	P1ExportKeyCurrent              = 0x00
	P1ExportKeyDerive               = 0x01
	P1ExportKeyDeriveAndMakeCurrent = 0x02
	P2ExportKeyPrivateAndPublic     = 0x00
	P2ExportKeyPublicOnly           = 0x01
	P2ExportKeyExtendedPublic       = 0x02
	P1LoadKeySeed                   = 0x03
	P1FactoryResetMagic             = 0xAA
	P2FactoryResetMagic             = 0x55

	SwNoAvailablePairingSlots = 0x6A84
)

Variables

View Source
var ErrBadChecksumSize = errors.New("bad checksum size")
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
		0x02: return extended public key
 @param {pathStr}
		Derivation path of format "m/x/x/x/x/x", e.g. "m/44'/0'/0'/0/0"

func NewCommandFactoryReset added in v0.3.0

func NewCommandFactoryReset() *apdu.Command

func NewCommandGenerateKey

func NewCommandGenerateKey() *apdu.Command

func NewCommandGenerateMnemonic

func NewCommandGenerateMnemonic(checksumSize byte) *apdu.Command

func NewCommandGetData

func NewCommandGetData(typ uint8) *apdu.Command

func NewCommandGetStatus

func NewCommandGetStatus(p1 uint8) *apdu.Command

func NewCommandIdentify added in v0.3.0

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

func NewCommandInit

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

func NewCommandLoadSeed

func NewCommandLoadSeed(seed []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, pathStr string) (*apdu.Command, error)

func NewCommandStoreData

func NewCommandStoreData(typ uint8, data []byte) *apdu.Command

func NewCommandUnblockPIN

func NewCommandUnblockPIN(puk string, newPIN string) *apdu.Command

func NewCommandUnpair

func NewCommandUnpair(index uint8) *apdu.Command

func NewCommandVerifyPIN

func NewCommandVerifyPIN(pin string) *apdu.Command

Types

type CashCommandSet

type CashCommandSet struct {
	CashApplicationInfo *types.CashApplicationInfo
	// contains filtered or unexported fields
}

func NewCashCommandSet

func NewCashCommandSet(c types.Channel) *CashCommandSet

func (*CashCommandSet) Select

func (cs *CashCommandSet) Select() error

func (*CashCommandSet) Sign

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

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) ExportKey

func (cs *CommandSet) ExportKey(derive bool, makeCurrent bool, onlyPublic bool, path string) ([]byte, []byte, error)

func (*CommandSet) FactoryReset added in v0.3.0

func (cs *CommandSet) FactoryReset() error

func (*CommandSet) GenerateKey

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

func (*CommandSet) GenerateMnemonic

func (cs *CommandSet) GenerateMnemonic(checksumSize int) ([]int, error)

func (*CommandSet) GetData

func (cs *CommandSet) GetData(typ uint8) ([]byte, error)

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) Identify added in v0.3.0

func (cs *CommandSet) Identify() ([]byte, error)

func (*CommandSet) Init

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

func (*CommandSet) LoadSeed

func (cs *CommandSet) LoadSeed(seed []byte) ([]byte, 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) SignWithPath

func (cs *CommandSet) SignWithPath(data []byte, path string) (*types.Signature, error)

func (*CommandSet) StoreData

func (cs *CommandSet) StoreData(typ uint8, data []byte) error

func (*CommandSet) UnblockPIN

func (cs *CommandSet) UnblockPIN(puk string, newPIN string) 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)

type WrongPINError

type WrongPINError struct {
	RemainingAttempts int
}

func (*WrongPINError) Error

func (e *WrongPINError) Error() string

type WrongPUKError

type WrongPUKError struct {
	RemainingAttempts int
}

func (*WrongPUKError) Error

func (e *WrongPUKError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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