Documentation
¶
Overview ¶
Package card provides functions for communication with smart cards. It includes implementations for handling different types of smart cards and reading associated documents.
Index ¶
- Constants
- Variables
- func FormatState(state scard.StateFlag) string
- func PadPin(pin string) []byte
- func PinTriesLeft(rsp []byte) int
- func Transmit(cmd []byte) ([]byte, error)
- func ValidatePin(pin string) bool
- type Apollo
- type Atr
- type Card
- type CardDocument
- type CardDocumentType
- type Gemalto
- func (card *Gemalto) Atr() Atr
- func (card *Gemalto) ChangePin(newPin, oldPin string) (int, error)
- func (card *Gemalto) GetCertificates() []x509.Certificate
- func (card *Gemalto) GetDocument() (document.Document, error)
- func (card *Gemalto) InitCard() error
- func (card *Gemalto) InitCrypto() error
- func (card *Gemalto) LoadCertificates() error
- func (card *Gemalto) ReadCard() error
- func (card *Gemalto) ReadFile(name []byte) ([]byte, error)
- func (card *Gemalto) ReadSignatures() error
- func (card *Gemalto) Test() bool
- type MedicalCard
- type UnknownDocumentCard
- func (card *UnknownDocumentCard) Atr() Atr
- func (card *UnknownDocumentCard) GetDocument() (document.Document, error)
- func (card *UnknownDocumentCard) InitCard() error
- func (card *UnknownDocumentCard) ReadCard() error
- func (card *UnknownDocumentCard) ReadFile(_ []byte) ([]byte, error)
- func (card *UnknownDocumentCard) Test() bool
- type VehicleCard
- type VirtualCard
Constants ¶
const ( UnknownDocumentCardType = CardDocumentType(iota) ApolloIdDocumentCardType GemaltoIdDocumentCardType MedicalDocumentCardType VehicleDocumentCardType )
Variables ¶
var APOLLO_ATR = Atr([]byte{
0x3B, 0xB9, 0x18, 0x00, 0x81, 0x31, 0xFE, 0x9E, 0x80,
0x73, 0xFF, 0x61, 0x40, 0x83, 0x00, 0x00, 0x00, 0xDF,
})
var ErrUnknownCard = errors.New("unknown card")
var GEMALTO_ATR_1 = Atr([]byte{
0x3B, 0xFF, 0x94, 0x00, 0x00, 0x81, 0x31, 0x80,
0x43, 0x80, 0x31, 0x80, 0x65, 0xB0, 0x85, 0x02,
0x01, 0xF3, 0x12, 0x0F, 0xFF, 0x82, 0x90, 0x00,
0x79,
})
var GEMALTO_ATR_2 = Atr([]byte{
0x3B, 0xF9, 0x96, 0x00, 0x00, 0x80, 0x31, 0xFE,
0x45, 0x53, 0x43, 0x45, 0x37, 0x20, 0x47, 0x43,
0x4E, 0x33, 0x5E,
})
Available since January 2023 (maybe). Replaced very soon with an even newer version.
var GEMALTO_ATR_3 = Atr([]byte{
0x3B, 0x9E, 0x96, 0x80, 0x31, 0xFE, 0x45, 0x53,
0x43, 0x45, 0x20, 0x38, 0x2E, 0x30, 0x2D, 0x43,
0x31, 0x56, 0x30, 0x0D, 0x0A, 0x6F,
})
Available since July 2023.
var GEMALTO_ATR_4 = Atr([]byte{
0x3B, 0x9E, 0x96, 0x80, 0x31, 0xFE, 0x45, 0x53,
0x43, 0x45, 0x20, 0x38, 0x2E, 0x30, 0x2D, 0x43,
0x32, 0x56, 0x30, 0x0D, 0x0A, 0x6C,
})
Available since June 2024.
var ID_DOCUMENT_FILE_LOC = []byte{0x0F, 0x02}
Location of the file with document data.
var ID_PERSONAL_FILE_LOC = []byte{0x0F, 0x03}
Location of the file with personal data.
var ID_PHOTO_FILE_LOC = []byte{0x0F, 0x06}
Location of the the portrait. Portrait is encoded as JPEG.
var ID_RESIDENCE_FILE_LOC = []byte{0x0F, 0x04}
Location of the file with residence data.
var MEDICAL_ATR_1 = Atr([]byte{
0x3B, 0xF4, 0x13, 0x00, 0x00, 0x81, 0x31, 0xFE,
0x45, 0x52, 0x46, 0x5A, 0x4F, 0xED,
})
Possibly the first version of the medical card. Newer version has the GEMALTO_ATR_2 for the ATR.
var MEDICAL_ATR_2 = Atr([]byte{
0x3B, 0x9E, 0x97, 0x80, 0x31, 0xFE, 0x45, 0x53,
0x43, 0x45, 0x20, 0x38, 0x2E, 0x30, 0x2D, 0x43,
0x31, 0x56, 0x30, 0x0D, 0x0A, 0x6E,
})
Available since March 2023?
var MED_DOCUMENT_FILE_LOC = []byte{0x0D, 0x01}
Location of the file with document data.
var MED_FIXED_PERSONAL_FILE_LOC = []byte{0x0D, 0x02}
Location of the file with fixed personal data.
var MED_VARIABLE_ADMIN_FILE_LOC = []byte{0x0D, 0x04}
Location of the file with variable administrative data.
var MED_VARIABLE_PERSONAL_FILE_LOC = []byte{0x0D, 0x03}
Location of the file with variable personal data.
var VEHICLE_ATR_0 = Atr([]byte{
0x3B, 0xDB, 0x96, 0x00, 0x80, 0xB1, 0xFE, 0x45,
0x1F, 0x83, 0x00, 0x31, 0xC0, 0x64, 0x1A, 0x18,
0x01, 0x00, 0x0F, 0x90, 0x00, 0x52,
})
Possibly deprecated.
var VEHICLE_ATR_1 = Atr([]byte{
0x3B, 0xFF, 0x94, 0x00, 0x00, 0x81, 0x31, 0x80,
0x43, 0x80, 0x31, 0x80, 0x65, 0xB0, 0x85, 0x02,
0x01, 0xF3, 0x12, 0x0F, 0xFF, 0x82, 0x90, 0x00,
0x79,
})
Same as GEMALTO_ATR_1
var VEHICLE_ATR_2 = Atr([]byte{
0x3B, 0x9D, 0x13, 0x81, 0x31, 0x60, 0x37, 0x80,
0x31, 0xC0, 0x69, 0x4D, 0x54, 0x43, 0x4F, 0x53,
0x73, 0x02, 0x02, 0x04, 0x40,
})
var VEHICLE_ATR_3 = Atr([]byte{
0x3B, 0x9D, 0x13, 0x81, 0x31, 0x60, 0x37, 0x80,
0x31, 0xC0, 0x69, 0x4D, 0x54, 0x43, 0x4F, 0x53,
0x73, 0x02, 0x05, 0x04, 0x47,
})
var VEHICLE_ATR_4 = Atr([]byte{
0x3B, 0x9D, 0x18, 0x81, 0x31, 0xFC, 0x35, 0x80,
0x31, 0xC0, 0x69, 0x4D, 0x54, 0x43, 0x4F, 0x53,
0x73, 0x02, 0x05, 0x02, 0xD4,
})
Functions ¶
func FormatState ¶ added in v2.1.4
func PinTriesLeft ¶ added in v2.1.5
func ValidatePin ¶
Checks if the PIN consists only of digits, and it's length is between 4 and 8.
Types ¶
type Apollo ¶
type Apollo struct {
// contains filtered or unexported fields
}
Apollo is the type of the first smart ID cards. Apollo cards are not manufactured anymore, and this code could be removed in the future.
type Card ¶
type Card interface {
Status() (*scard.CardStatus, error)
Transmit([]byte) ([]byte, error)
BeginTransaction() error
EndTransaction(scard.Disposition) error
}
Represents a physical or virtual smart card. Essentially it is just a wrapper for the scard.Card type, but it also allows virtual cards which can be useful for testing.
type CardDocument ¶
type CardDocument interface {
ReadFile([]byte) ([]byte, error)
InitCard() error
ReadCard() error
GetDocument() (doc.Document, error)
Test() bool
Atr() Atr
}
Represents a smart card with a document. All types of documents that Bas Celik can read should satisfy this interface
func DetectCardDocument ¶
func DetectCardDocument(sc Card) (CardDocument, error)
Detects Card Document from card's ATR Ambiguous cases are solved by reading specific card content
type CardDocumentType ¶
type CardDocumentType uint8
Represents a different types of smart card documents. Each value of `CardDocumentType` is represented with a struct that satisfies `CardDocument` interface.
func DetectCardDocumentByAtr ¶
func DetectCardDocumentByAtr(atr Atr) []CardDocumentType
type Gemalto ¶
type Gemalto struct {
// contains filtered or unexported fields
}
Gemalto represents ID cards based with Gemalto Java OS. Gemalto replaced Apollo cards around 2014.
func (*Gemalto) ChangePin ¶
Returns number of tries left, and occurred error. -1 signifies unknown number of tries left
func (*Gemalto) GetCertificates ¶ added in v2.2.0
func (card *Gemalto) GetCertificates() []x509.Certificate
func (*Gemalto) InitCrypto ¶
Initialize card's cryptography application
func (*Gemalto) LoadCertificates ¶ added in v2.2.0
func (*Gemalto) ReadSignatures ¶ added in v2.2.0
type MedicalCard ¶
type MedicalCard struct {
// contains filtered or unexported fields
}
Represents a smart card that holds a Serbian medical insurance document.
func (*MedicalCard) Atr ¶
func (card *MedicalCard) Atr() Atr
func (*MedicalCard) GetDocument ¶
func (card *MedicalCard) GetDocument() (document.Document, error)
func (*MedicalCard) InitCard ¶
func (card *MedicalCard) InitCard() error
func (*MedicalCard) ReadCard ¶
func (card *MedicalCard) ReadCard() error
func (*MedicalCard) Test ¶
func (card *MedicalCard) Test() bool
Newer medical cards share ATR with the ID cards (GEMALTO_ATR_2)
type UnknownDocumentCard ¶
type UnknownDocumentCard struct {
// contains filtered or unexported fields
}
func (*UnknownDocumentCard) Atr ¶
func (card *UnknownDocumentCard) Atr() Atr
func (*UnknownDocumentCard) GetDocument ¶
func (card *UnknownDocumentCard) GetDocument() (document.Document, error)
func (*UnknownDocumentCard) InitCard ¶
func (card *UnknownDocumentCard) InitCard() error
func (*UnknownDocumentCard) ReadCard ¶
func (card *UnknownDocumentCard) ReadCard() error
func (*UnknownDocumentCard) ReadFile ¶
func (card *UnknownDocumentCard) ReadFile(_ []byte) ([]byte, error)
func (*UnknownDocumentCard) Test ¶
func (card *UnknownDocumentCard) Test() bool
type VehicleCard ¶
type VehicleCard struct {
// contains filtered or unexported fields
}
Represents a smart card that contains a Serbian vehicle document.
func (*VehicleCard) Atr ¶
func (card *VehicleCard) Atr() Atr
func (*VehicleCard) GetDocument ¶
func (card *VehicleCard) GetDocument() (document.Document, error)
func (*VehicleCard) InitCard ¶
func (card *VehicleCard) InitCard() error
Initializes vehicle card by trying three different sets of commands. The procedure is reverse-engineered from the official binary.
func (*VehicleCard) ReadCard ¶
func (card *VehicleCard) ReadCard() error
func (*VehicleCard) Test ¶
func (card *VehicleCard) Test() bool
type VirtualCard ¶
type VirtualCard struct {
// contains filtered or unexported fields
}
func MakeVirtualCard ¶
func MakeVirtualCard(atr []byte, fs map[uint32][]byte) *VirtualCard
func (*VirtualCard) Status ¶
func (card *VirtualCard) Status() (*scard.CardStatus, error)