globalplatform

package
v0.0.0-...-1153de6 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MPL-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	ClaISO7816 = 0x00
	ClaGp      = 0x80
	ClaMac     = 0x84

	InsSelect               = 0xA4
	InsInitializeUpdate     = 0x50
	InsExternalAuthenticate = 0x82
	InsGetResponse          = 0xC0
	InsDelete               = 0xE4
	InsLoad                 = 0xE8
	InsInstall              = 0xE6
	InsGetStatus            = 0xF2

	P1ExternalAuthenticateCMAC         = 0x01
	P1InstallForLoad                   = 0x02
	P1InstallForInstall                = 0x04
	P1InstallForMakeSelectable         = 0x08
	P1LoadMoreBlocks                   = 0x00
	P1LoadLastBlock                    = 0x80
	P1GetStatusIssuerSecurityDomain    = 0x80
	P1GetStatusApplications            = 0x40
	P1GetStatusExecLoadFiles           = 0x20
	P1GetStatusExecLoadFilesAndModules = 0x10

	P2GetStatusTLVData             = 0x02
	P2DeleteObject                 = 0x00
	P2DeleteObjectAndRelatedObject = 0x80

	Sw1ResponseDataIncomplete = 0x61

	SwOK                            = 0x9000
	SwFileNotFound                  = 0x6A82
	SwReferencedDataNotFound        = 0x6A88
	SwSecurityConditionNotSatisfied = 0x6982
	SwAuthenticationMethodBlocked   = 0x6983
)

Constants used in apdu commands and responses as defined by iso7816 and globalplatform.

Variables

View Source
var ErrSecureChannelNotOpen = errors.New("secure channel not open")

Functions

func NewCommandDelete

func NewCommandDelete(aid []byte, p2 uint8) *apdu.Command

NewCommandDelete returns a Delete command as defined in the globalplatform specifications.

func NewCommandExternalAuthenticate

func NewCommandExternalAuthenticate(encKey, cardChallenge, hostChallenge []byte) (*apdu.Command, error)

NewCommandExternalAuthenticate returns an External Authenticate command as defined in the globalplatform specifications.

func NewCommandGetResponse

func NewCommandGetResponse(length uint8) *apdu.Command

NewCommandGetResponse returns a Get Response command as defined in the globalplatform specifications.

func NewCommandGetStatus

func NewCommandGetStatus(aid []byte, p1 uint8) *apdu.Command

NewCommandGetStatus returns a Get Status command as defined in the globalplatform specifications.

func NewCommandInitializeUpdate

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

NewCommandInitializeUpdate returns an Initialize Update command as defined in the globalplatform specifications.

func NewCommandInstallForInstall

func NewCommandInstallForInstall(pkgAID, appletAID, instanceAID, params []byte) *apdu.Command

NewCommandInstallForInstall returns an Install command with the install-for-instalp parameter as defined in the globalplatform specifications.

func NewCommandInstallForLoad

func NewCommandInstallForLoad(aid, sdaid []byte) *apdu.Command

NewCommandInstallForLoad returns an Install command with the install-for-load parameter as defined in the globalplatform specifications.

func NewCommandSelect

func NewCommandSelect(aid []byte) *apdu.Command

NewCommandSelect returns a Select command as defined in the globalplatform specifications.

Types

type CommandSet

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

func NewCommandSet

func NewCommandSet(c types.Channel) *CommandSet

func (*CommandSet) Channel

func (cs *CommandSet) Channel() types.Channel

func (*CommandSet) Delete

func (cs *CommandSet) Delete(aid []byte, p2 uint8) error

func (*CommandSet) DeleteKeycardInstancesAndPackage

func (cs *CommandSet) DeleteKeycardInstancesAndPackage() error

func (*CommandSet) DeleteObject

func (cs *CommandSet) DeleteObject(aid []byte) error

func (*CommandSet) DeleteObjectAndRelatedObject

func (cs *CommandSet) DeleteObjectAndRelatedObject(aid []byte) error

func (*CommandSet) GetStatus

func (cs *CommandSet) GetStatus() (*types.CardStatus, error)

func (*CommandSet) InstallCashApplet

func (cs *CommandSet) InstallCashApplet() error

func (*CommandSet) InstallForInstall

func (cs *CommandSet) InstallForInstall(packageAID, appletAID, instanceAID, params []byte) error

func (*CommandSet) InstallKeycardApplet

func (cs *CommandSet) InstallKeycardApplet() error

func (*CommandSet) InstallNDEFApplet

func (cs *CommandSet) InstallNDEFApplet(ndefRecord []byte) error

func (*CommandSet) LoadKeycardPackage

func (cs *CommandSet) LoadKeycardPackage(capFile *os.File, callback LoadingCallback) error

func (*CommandSet) LoadPackage

func (cs *CommandSet) LoadPackage(capFile *os.File, pkgAID []byte, callback LoadingCallback) error

func (*CommandSet) OpenSecureChannel

func (cs *CommandSet) OpenSecureChannel() error

func (*CommandSet) SecureChannel

func (cs *CommandSet) SecureChannel() *SecureChannel

func (*CommandSet) Select

func (cs *CommandSet) Select() error

func (*CommandSet) SelectAID

func (cs *CommandSet) SelectAID(aid []byte) error

type LoadCommandStream

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

LoadCommandStream implement a struct that generates multiple Load commands used to load files to smartcards.

func NewLoadCommandStream

func NewLoadCommandStream(file *os.File) (*LoadCommandStream, error)

NewLoadCommandStream returns a new LoadCommandStream to load the specified file.

func (*LoadCommandStream) BlocksCount

func (lcs *LoadCommandStream) BlocksCount() int

BlocksCount returns the total number of blocks based on data length and blockSize

func (*LoadCommandStream) GetCommand

func (lcs *LoadCommandStream) GetCommand() *apdu.Command

GetCommand returns the current apdu command.

func (*LoadCommandStream) Index

func (lcs *LoadCommandStream) Index() uint8

Index returns the command index.

func (*LoadCommandStream) Next

func (lcs *LoadCommandStream) Next() bool

Next returns initialize the data for the next Load command. TODO:@gravityblast update blockSize when using encrypted data

type LoadingCallback

type LoadingCallback = func(loadingBlock, totalBlocks int)

type SCP02Keys

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

SCP02Keys is a struct that contains encoding and MAC keys used to communicate with smartcards.

func NewSCP02Keys

func NewSCP02Keys(enc, mac []byte) *SCP02Keys

NewSCP02Keys returns a new SCP02Keys with the specified ENC and MAC keys.

func (*SCP02Keys) Enc

func (k *SCP02Keys) Enc() []byte

Enc returns the enc key data.

func (*SCP02Keys) Mac

func (k *SCP02Keys) Mac() []byte

Mac returns the MAC key data.

type SCP02Wrapper

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

SCP02Wrapper is a wrapper for apdu commands inside a global platform secure channel.

func NewSCP02Wrapper

func NewSCP02Wrapper(macKey []byte) *SCP02Wrapper

NewSCP02Wrapper returns a new SCP02Wrapper using the specified key for MAC generation.

func (*SCP02Wrapper) Wrap

func (w *SCP02Wrapper) Wrap(cmd *apdu.Command) (*apdu.Command, error)

Wrap wraps the apdu command adding the MAC to the end of the command. Future implementations will encrypt the message when needed.

type SecureChannel

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

SecureChannel wraps another channel and sends wrapped commands using SCP02Wrapper.

func NewSecureChannel

func NewSecureChannel(session *Session, c types.Channel) *SecureChannel

NewSecureChannel returns a new SecureChannel based on a session and wrapping a Channel c.

func (*SecureChannel) Send

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

Send sends wrapped commands to the inner channel.

type Session

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

Session is a struct containing the keys and challenges used in the current communication with a card.

func NewSession

func NewSession(cardKeys *SCP02Keys, resp *apdu.Response, hostChallenge []byte) (*Session, error)

NewSession returns a new session after validating the cryptogram received from the card.

func (*Session) CardChallenge

func (s *Session) CardChallenge() []byte

CardChallenge returns the current card challenge.

func (*Session) HostChallenge

func (s *Session) HostChallenge() []byte

HostChallenge returns the current host challenge.

func (*Session) Keys

func (s *Session) Keys() *SCP02Keys

Keys return the current SCP02Keys.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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