scard

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2025 License: MIT, MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Scope
	SCOPE_USER     = pcsc.CARD_SCOPE_USER
	SCOPE_TERMINAL = pcsc.CARD_SCOPE_TERMINAL
	SCOPE_SYSTEM   = pcsc.CARD_SCOPE_SYSTEM
)

Variables

View Source
var (
	DoURL            = DataObject{/* contains filtered or unexported fields */}
	DoHistBytes      = DataObject{/* contains filtered or unexported fields */}
	DoCardRelData    = DataObject{/* contains filtered or unexported fields */}
	DoName           = DataObject{/* contains filtered or unexported fields */}
	DoLangPrefs      = DataObject{/* contains filtered or unexported fields */}
	DoSalutation     = DataObject{/* contains filtered or unexported fields */}
	DoAppRelData     = DataObject{/* contains filtered or unexported fields */}
	DoLoginData      = DataObject{/* contains filtered or unexported fields */}
	DoAID            = DataObject{/* contains filtered or unexported fields */}
	DoDiscrDOs       = DataObject{/* contains filtered or unexported fields */}
	DoCardCaps       = DataObject{/* contains filtered or unexported fields */}
	DoExtLenCaps     = DataObject{/* contains filtered or unexported fields */}
	DoAlgoAttrSign   = DataObject{/* contains filtered or unexported fields */}
	DoAlgoAttrEnc    = DataObject{/* contains filtered or unexported fields */}
	DoAlgoAttrAuth   = DataObject{/* contains filtered or unexported fields */}
	DoPWStatus       = DataObject{/* contains filtered or unexported fields */}
	DoFingerprints   = DataObject{/* contains filtered or unexported fields */}
	DoCAFingerprints = DataObject{/* contains filtered or unexported fields */}
	DoKeyGenDate     = DataObject{/* contains filtered or unexported fields */}
	DoSecSuppTmpl    = DataObject{/* contains filtered or unexported fields */}
	DoDigSigCtr      = DataObject{/* contains filtered or unexported fields */}
	DoPrivateDO1     = DataObject{/* contains filtered or unexported fields */}
	DoPrivateDO2     = DataObject{/* contains filtered or unexported fields */}
	DoPrivateDO3     = DataObject{/* contains filtered or unexported fields */}
	DoPrivateDO4     = DataObject{/* contains filtered or unexported fields */}
	DoCardholderCrt  = DataObject{/* contains filtered or unexported fields */}

	// V3.0
	DoGenFeatMgmt = DataObject{/* contains filtered or unexported fields */}
	DoAESKeyData  = DataObject{/* contains filtered or unexported fields */}
	DoUIFSig      = DataObject{/* contains filtered or unexported fields */}
	DoUIFDec      = DataObject{/* contains filtered or unexported fields */}
	DoUIFAut      = DataObject{/* contains filtered or unexported fields */}
	DoUIFAtt      = DataObject{/* contains filtered or unexported fields */}
	DoKDFDO       = DataObject{/* contains filtered or unexported fields */}
	DoAlgoInfo    = DataObject{/* contains filtered or unexported fields */}
)
View Source
var (
	// https://nvlpubs.nist.gov/nistpubs/specialpublications/nist.sp.800-73-4.pdf
	AidPIV = concat(RidNIST[:], 0x00, 0x00, 0x10, 0x00)

	// https://gnupg.org/ftp/specs/OpenPGP-smart-card-application-3.4.1.pdf
	AidOpenPGP = concat(RidFSFE[:], 0x01)

	// https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-20210615.html#nfc-applet-selection
	AidFIDO = concat(RidFIDO[:], 0x2f, 0x00, 0x01)

	// https://github.com/Yubico/yubikey-manager/blob/6496393f9269e86fb7b4b67907b397db33b50c2d/yubikit/core/smartcard.py#L66
	AidYubicoOTP           = concat(RidYubico[:], 0x20, 0x01)
	AidYubicoManagement    = concat(RidYubico[:], 0x47, 0x11, 0x17)
	AidYubicoOATH          = concat(RidYubico[:], 0x21, 0x01)
	AidYubicoHSMAuth       = concat(RidYubico[:], 0x21, 0x07, 0x01)
	AidSolokeysAdmin       = concat(RidSolokeys[:], 0x00, 0x00, 0x00, 0x01)
	AidSolokeysProvisioner = concat(RidSolokeys[:], 0x01, 0x00, 0x00, 0x01)
	AidCardManager         = concat(RidGlobalPlatform[:], 0x00, 0x00, 0x00)
	AidNDEF                = concat(RidNXPNFC[:], 0x01, 0x01)
)
View Source
var (
	// https://www.eftlab.com/knowledge-base/complete-list-of-registered-application-provider-identifiers-rid
	RidNIST           = RID{0xa0, 0x00, 0x00, 0x03, 0x08}
	RidFSFE           = RID{0xd2, 0x76, 0x00, 0x01, 0x24}
	RidYubico         = RID{0xa0, 0x00, 0x00, 0x05, 0x27}
	RidFIDO           = RID{0xa0, 0x00, 0x00, 0x06, 0x47}
	RidSolokeys       = RID{0xA0, 0x00, 0x00, 0x08, 0x47}
	RidGlobalPlatform = RID{0xa0, 0x00, 0x00, 0x01, 0x51}
	RidNXPNFC         = RID{0xD2, 0x76, 0x00, 0x00, 0x85}
)
View Source
var (
	ErrRespTooShort                        = errors.New("response too short")
	ErrUnspecifiedWarning                  = errors.New("no information given (warning)")
	ErrUnspecifiedWarningModified          = errors.New("no information given (warning), on-volatile memory has changed")
	ErrUnspecifiedError                    = errors.New("no information given (error)")
	ErrUnspecifiedErrorModified            = errors.New("no information given (error), on-volatile memory has changed")
	ErrWrongLength                         = errors.New("wrong length; no further indication")
	ErrUnsupportedFunction                 = errors.New("function in CLA not supported")
	ErrCommandNotAllowed                   = errors.New("command not allowed")
	ErrWrongParamsNoInfo                   = errors.New("no information given (error)")
	ErrWrongParams                         = errors.New("wrong parameters P1-P2")
	ErrUnsupportedInstruction              = errors.New("instruction code not supported or invalid")
	ErrUnsupportedClass                    = errors.New("class not supported")
	ErrNoDiag                              = errors.New("no precise diagnosis")
	ErrResponseMayBeCorrupted              = errors.New("part of returned data may be corrupted")
	ErrEOF                                 = errors.New("end of file or record reached before reading Ne bytes")
	ErrSelectedFileDeactivated             = errors.New("selected file deactivated")
	ErrInvalidFileControlInfo              = errors.New("file control information not formatted according to 5.3.3")
	ErrSelectedFileInTermination           = errors.New("selected file in termination state")
	ErrNoSensorData                        = errors.New("no input data available from a sensor on the card")
	ErrFileFilledUp                        = errors.New("file filled up by the last write")
	ErrImmediateResponseRequired           = errors.New("immediate response required by the card")
	ErrMemory                              = errors.New("memory failure")
	ErrLogicalChannelNotSupported          = errors.New("logical channel not supported")
	ErrSecureMessagingNotSupported         = errors.New("secure messaging not supported")
	ErrExpectedLastCommand                 = errors.New("last command of the chain expected")
	ErrCommandChainingNotSupported         = errors.New("command chaining not supported")
	ErrCommandIncompatibleWithFile         = errors.New("command incompatible with file structure")
	ErrSecurityStatusNotSatisfied          = errors.New("security status not satisfied")
	ErrAuthenticationMethodBlocked         = errors.New("authentication method blocked")
	ErrReferenceDataNotUsable              = errors.New("reference data not usable")
	ErrConditionsOfUseNotSatisfied         = errors.New("conditions of use not satisfied")
	ErrCommandNotAllowedNoCurrentEF        = errors.New("command not allowed (no current EF)")
	ErrExpectedSecureMessaging             = errors.New("expected secure messaging data objects missing")
	ErrIncorrectSecureMessagingDataObjects = errors.New("incorrect secure messaging data objects")
	ErrIncorrectData                       = errors.New("incorrect parameters in the command data field")
	ErrFunctionNotSupported                = errors.New("function not supported")
	ErrFileOrAppNotFound                   = errors.New("file or application not found")
	ErrRecordNotFound                      = errors.New("record not found")
	ErrNoSpace                             = errors.New("not enough memory space in the file")
	ErrInvalidNcWithTLV                    = errors.New("nc inconsistent with TLV structure")
	ErrIncorrectParams                     = errors.New("incorrect parameters P1-P2")
	ErrInvalidNcWithParams                 = errors.New("nc inconsistent with parameters P1-P2")
	ErrReferenceNotFound                   = errors.New("referenced data or reference data not found (exact meaning depending on the command)")
	ErrFileAlreadyExists                   = errors.New("file already exists")
	ErrNameAlreadyExists                   = errors.New("DF name already exists")
)

Functions

This section is empty.

Types

type AID

type AID []byte

AID represents an application identifier.

type APDU

type APDU struct {
	Cla  uint8  // Class
	Ins  uint8  // Instruction
	P1   uint8  // Parameter 1
	P2   uint8  // Parameter 2
	Data []byte // Command data
	Len  uint8  // Command data length
	Pib  bool   // Padding indicator byte present
	Elf  bool   // Use extended length fields
}

APDU represents an application data unit sent to a smart-card.

type ATR

type ATR []byte

func (ATR) String

func (atr ATR) String() string

Return string form of ATR.

type Card

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

Card represents a connection to a smart card.

func (*Card) ATR

func (c *Card) ATR() ATR

ATR returns the card ATR (Answer To Reset).

func (*Card) Disconnect

func (c *Card) Disconnect() error

Disconnect from card.

func (*Card) GetChallenge

func (c *Card) GetChallenge(length uint8) ([]byte, error)

func (*Card) Select

func (c *Card) Select(aid AID) error

func (*Card) Transmit

func (c *Card) Transmit(apdu APDU) ([]byte, error)

type Context

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

Context represents a smart card context required to access readers and cards.

func EstablishContext

func EstablishContext(scope ...uint32) (*Context, error)

EstablishContext establishes a smart card context. (This should be the first function to be called.)

func (*Context) ListReaders

func (ctx *Context) ListReaders() ([]*Reader, error)

ListReaders lists all smart card readers.

func (*Context) ListReadersWithCard

func (ctx *Context) ListReadersWithCard() ([]*Reader, error)

ListReadersWithCard lists smart card readers with inserted cards.

func (*Context) Release

func (ctx *Context) Release() error

Release resources associated with smart card context.

func (*Context) WaitForCardPresent

func (ctx *Context) WaitForCardPresent() (*Reader, error)

WaitForCardPresent blocks until a smart card is inserted into any reader or returns immediately if a card is already present.

type DataObject

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

type RID

type RID [5]byte

RID represents a registered application provider identifier.

func (RID) String

func (r RID) String() string

type Reader

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

Reader represents a smart card reader. Note that physical card readers with slots for multiple cards are represented by one Reader instance per slot.

func (*Reader) Connect

func (r *Reader) Connect() (*Card, error)

Connect to card.

func (*Reader) IsCardPresent

func (r *Reader) IsCardPresent() bool

IsCardPresent checks if a card is present in the reader.

func (*Reader) Name

func (r *Reader) Name() string

Name returns the name of the card reader.

func (*Reader) WaitUntilCardRemoved

func (r *Reader) WaitUntilCardRemoved()

WaitUntilCardRemoved blocks until the card is removed from the reader.

Jump to

Keyboard shortcuts

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