iso7816

package
v0.0.0-...-5586a3f Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package iso7816 implements utilities for interacting with the Contactless IC.

Support is provided for: - Command/Response APDUs (C-APDU.R-APDU) - Secure Messaging - NFC Session (including APDU logging) - Transceiver interface

Index

Constants

View Source
const CLA_MASK byte = 0x0C
View Source
const INS_EXTERNAL_AUTHENTICATE = byte(0x82)
View Source
const INS_GENERAL_AUTHENTICATE = byte(0x86)
View Source
const INS_GET_CHALLENGE = byte(0x84)
View Source
const INS_INTERNAL_AUTHENTICATE = byte(0x88)
View Source
const INS_MANAGE_SE = byte(0x22)
View Source
const INS_READ_BINARY = byte(0xB0)
View Source
const INS_SELECT = byte(0xA4)
View Source
const RAPDU_SECURITY_CONDITION_NOT_SATIFIED = 0x6982
View Source
const RAPDU_STATUS_FILENOTFOUND = 0x6A82
View Source
const RAPDU_STATUS_FUNCTION_NOT_SUPPORTED = 0x6A81
View Source
const RAPDU_STATUS_SELECTED_FILE_INVALIDATED = 0x6283 // warning
View Source
const RAPDU_STATUS_SUCCESS = 0x9000

Variables

This section is empty.

Functions

This section is empty.

Types

type ApduLog

type ApduLog struct {
	Desc      string
	Tx        []byte
	Rx        []byte
	Child     *ApduLog // optional (e.g. if secure-messaging enabled)
	DurMs     int
	StartTime time.Time
}

func NewApduLog

func NewApduLog(desc string, tx []byte) *ApduLog

creates a new instance, records the desc/tx information and starts the timer

func (*ApduLog) Finalise

func (apduLog *ApduLog) Finalise(rx []byte)

finalises an instance, records rx and calculates duration(ms)

type CApdu

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

func NewCApdu

func NewCApdu(cla byte, ins byte, p1 byte, p2 byte, data []byte, le int) *CApdu

func (*CApdu) Encode

func (apdu *CApdu) Encode() []byte

func (*CApdu) EncodeHeader

func (apdu *CApdu) EncodeHeader() []byte

func (*CApdu) EncodeLc

func (apdu *CApdu) EncodeLc() []byte

func (*CApdu) EncodeLe

func (apdu *CApdu) EncodeLe() []byte

func (*CApdu) HaveData

func (apdu *CApdu) HaveData() bool

func (*CApdu) HaveLe

func (apdu *CApdu) HaveLe() bool

func (*CApdu) IsExtended

func (apdu *CApdu) IsExtended() bool

func (CApdu) String

func (cApdu CApdu) String() string

type MockTransceiver

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

func (*MockTransceiver) AddReqRsp

func (transceiver *MockTransceiver) AddReqRsp(reqHexStr string, rspHexStr string)

func (*MockTransceiver) Transceive

func (transceiver *MockTransceiver) Transceive(cla int, ins int, p1 int, p2 int, data []byte, le int, encodedData []byte) []byte

type MockTransceiverReqRsp

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

type NfcSession

type NfcSession struct {
	SM      *SecureMessaging
	MaxLe   int
	ApduLog []ApduLog
	// contains filtered or unexported fields
}

func NewNfcSession

func NewNfcSession(transceiver Transceiver) *NfcSession

func (*NfcSession) DoAPDU

func (nfc *NfcSession) DoAPDU(cApdu *CApdu, desc string) (rApdu *RApdu, err error)

func (*NfcSession) ExternalAuthenticate

func (nfc *NfcSession) ExternalAuthenticate(data []byte, le int) (out []byte, err error)

func (*NfcSession) GeneralAuthenticate

func (nfc *NfcSession) GeneralAuthenticate(commandChaining bool, data []byte) *RApdu

func (*NfcSession) GetChallenge

func (nfc *NfcSession) GetChallenge(length int) (out []byte, err error)

func (*NfcSession) MseSetAT

func (nfc *NfcSession) MseSetAT(p1 uint8, p2 uint8, data []byte) (err error)

func (*NfcSession) ReadBinaryFromOffset

func (nfc *NfcSession) ReadBinaryFromOffset(offset int, length int) []byte

NB may not return requested length

func (*NfcSession) ReadFile

func (nfc *NfcSession) ReadFile(fileId uint16) (fileData []byte)

returns: file contents OR nil if file not found

func (*NfcSession) SelectAid

func (nfc *NfcSession) SelectAid(aid []byte) (selected bool, err error)

func (*NfcSession) SelectEF

func (nfc *NfcSession) SelectEF(fileId uint16) (selected bool, err error)

returns: false if file-not-found, otherwise true

func (*NfcSession) SelectMF

func (nfc *NfcSession) SelectMF() (err error)

0 0 0 0 1 0 0 0 – Select from MF (data field=path without the identifier of the MF)

type RApdu

type RApdu struct {
	Data   []byte
	Status uint16
}

func NewRApdu

func NewRApdu(status uint16, data []byte) *RApdu

func ParseRApdu

func ParseRApdu(data []byte) (rapdu *RApdu, err error)

func (*RApdu) Encode

func (rApdu *RApdu) Encode() []byte

func (*RApdu) FileNotFound

func (apdu *RApdu) FileNotFound() bool

func (*RApdu) IsSuccess

func (apdu *RApdu) IsSuccess() bool

func (*RApdu) String

func (apdu *RApdu) String() string

type SecureMessaging

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

func NewSecureMessaging

func NewSecureMessaging(alg cryptoutils.BlockCipherAlg, ksEnc []byte, ksMac []byte) (sm *SecureMessaging, err error)

func (*SecureMessaging) Decode

func (sm *SecureMessaging) Decode(rApduBytes []byte) (rApdu *RApdu, err error)

func (*SecureMessaging) Encode

func (sm *SecureMessaging) Encode(cApdu *CApdu) (out *CApdu, err error)

func (SecureMessaging) Equal

func (sm1 SecureMessaging) Equal(sm2 SecureMessaging) bool

func (SecureMessaging) GetKsEnc

func (sm SecureMessaging) GetKsEnc() []byte

func (*SecureMessaging) SetSSC

func (sm *SecureMessaging) SetSSC(ssc []byte)

func (SecureMessaging) String

func (sm SecureMessaging) String() string

type StaticTransceiver

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

func (*StaticTransceiver) Transceive

func (transceiver *StaticTransceiver) Transceive(cla int, ins int, p1 int, p2 int, data []byte, le int, encodedData []byte) []byte

type Transceiver

type Transceiver interface {
	Transceive(cla int, ins int, p1 int, p2 int, data []byte, le int, encodedData []byte) []byte
}

Jump to

Keyboard shortcuts

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