iso7816

package
v0.47.4 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 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_INCORRECT_P1_OR_P2_PARAMETER = 0x6A86
View Source
const RAPDU_STATUS_LC_INCONSISTENT_WITH_P1P2 = 0x6A87 // Lc inconsistent with P1-P2
View Source
const RAPDU_STATUS_SELECTED_FILE_INVALIDATED = 0x6283 // warning
View Source
const RAPDU_STATUS_SUCCESS = 0x9000
View Source
const READ_FILE_MAX_CHUNKS = 1000

default to 1,000 chunks when reading a file - some older passports support <100 byte reads

View Source
const READ_FILE_MAX_TLV_LENGTH = tlv.TlvLength(65535)

default to 65,535 maximum file (TLV) size - as we always read the first 4 bytes (so max 2 byte length)

Variables

This section is empty.

Functions

This section is empty.

Types

type ApduLog

type ApduLog struct {
	Entries []*ApduLogEntry `json:"entries,omitempty"`
}

func NewApduLog

func NewApduLog() *ApduLog

func (*ApduLog) Add added in v0.19.3

func (l *ApduLog) Add(entry *ApduLogEntry)

func (*ApduLog) AllEntries added in v0.19.3

func (l *ApduLog) AllEntries() []*ApduLogEntry

type ApduLogEntry added in v0.19.3

type ApduLogEntry struct {
	Desc      string        `json:"desc,omitempty"`
	Tx        []byte        `json:"tx,omitempty"`
	Rx        []byte        `json:"rx,omitempty"`
	Child     *ApduLogEntry `json:"child,omitempty"`
	DurMs     int64         `json:"durMs,omitempty"`
	StartTime time.Time     `json:"startTime"`
	// contains filtered or unexported fields
}

func NewApduLogEntry added in v0.19.3

func NewApduLogEntry(desc string, tx []byte) *ApduLogEntry

func (*ApduLogEntry) Finalise added in v0.19.3

func (e *ApduLogEntry) Finalise(rx []byte)

func (*ApduLogEntry) SetChild added in v0.19.3

func (e *ApduLogEntry) SetChild(child *ApduLogEntry)

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, rspHexStr string)

func (*MockTransceiver) Transceive

func (transceiver *MockTransceiver) Transceive(_ int, _ int, _ int, _ int, _ []byte, _ int, encodedData []byte) []byte

type MockTransceiverReqRsp

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

type NfcSession

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

func NewNfcSession

func NewNfcSession(transceiver Transceiver) *NfcSession

func (*NfcSession) ApduLog

func (nfc *NfcSession) ApduLog() *ApduLog

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) ([]byte, error)

func (*NfcSession) GetChallenge

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

func (*NfcSession) InternalAuthenticate added in v0.19.3

func (nfc *NfcSession) InternalAuthenticate(data []byte) (out []byte, err error)

func (*NfcSession) LastApdu added in v0.37.0

func (nfc *NfcSession) LastApdu() *ApduLogEntry

func (*NfcSession) MseSetAT

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

func (*NfcSession) ReadBinaryFromOffset

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

NB may not return requested length

func (*NfcSession) ReadFile

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

returns: file contents OR nil if file not found

func (*NfcSession) SM

func (nfc *NfcSession) SM() SecureMessenger

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)

func (*NfcSession) SetMaxLe added in v0.19.3

func (nfc *NfcSession) SetMaxLe(value int)

func (*NfcSession) SetSecureMessaging added in v0.19.3

func (nfc *NfcSession) SetSecureMessaging(sm SecureMessenger)

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) KsEnc added in v0.13.0

func (sm SecureMessaging) KsEnc() []byte

func (SecureMessaging) SSC added in v0.19.3

func (sm SecureMessaging) SSC() []byte

func (*SecureMessaging) SetSSC

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

func (SecureMessaging) String

func (sm SecureMessaging) String() string

type SecureMessenger added in v0.19.3

type SecureMessenger interface {
	SSC() []byte
	SetSSC([]byte) error
	KsEnc() []byte
	String() string
	Encode(*CApdu) (*CApdu, error)
	Decode([]byte) (*RApdu, error)
}

type StaticTransceiver

type StaticTransceiver struct {
	RApdu []byte
}

func (*StaticTransceiver) Transceive

func (transceiver *StaticTransceiver) Transceive(_ int, _ int, _ int, _ int, _ []byte, _ int, _ []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