sscard

package module
v0.0.0-...-dfb25fa Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2018 License: BSD-2-Clause Imports: 8 Imported by: 1

README

Super Smart Card(sscard)

Super Smart Card API on top of scard(pcsc handler) with apdu commands.

Builtin APDU devices

  • Thai ID card (public data)
  • Simcard (public data)

Installation and requirements

See docs/INSTALLATION_xxx.md

TODO

# Linux: install pcsc library
sudo apt-get install pcscd

# goget
go get -u github.com/Napat/sscard

# go build example
go build -o sscard github.com/Napat/sscard/main

./sscard  # ./main.exe on windows(if no -o sscard)

Platforms

  • Windows 10
  • Linux: Ubuntu, Raspbian stretch(RPi3B)

References

Documentation

Index

Constants

This section is empty.

Variables

View Source
var APDUReadACC = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x78},
	{0xA0, 0xB0, 0x00, 0x00, 0x02},
}

APDUReadACC ...

View Source
var APDUReadAD = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0xAD},
	{0xA0, 0xB0, 0x00, 0x00, 0x03},
}

APDUReadAD ...

View Source
var APDUReadADN = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x10},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x3A},
	{0xA0, 0xB0, 0x00, 0x00, 0x0D},
}

APDUReadADN ...

View Source
var APDUReadBCCH = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x74},
	{0xA0, 0xB0, 0x00, 0x00, 0x10},
}

APDUReadBCCH ...

View Source
var APDUReadFDN = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x10},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x0B},
	{0xA0, 0xB0, 0x00, 0x00, 0x0D},
}

APDUReadFDN ...

View Source
var APDUReadFPLMN = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x7B},
	{0xA0, 0xB0, 0x00, 0x00, 0x0C},
}

APDUReadFPLMN ...

View Source
var APDUReadHPPLMN = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x31},
	{0xA0, 0xB0, 0x00, 0x00, 0x01},
}

APDUReadHPPLMN ...

View Source
var APDUReadICCID = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x2F, 0xE2},
	{0xA0, 0xB0, 0x00, 0x00, 0x0A},
}

APDUReadICCID ...

View Source
var APDUReadIMSI = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x07},
	{0xA0, 0xB0, 0x00, 0x00, 0x09},
}

APDUReadIMSI ...

View Source
var APDUReadKC = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x20},
	{0xA0, 0xB0, 0x00, 0x00, 0x09},
}

APDUReadKC ...

View Source
var APDUReadLOCI = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x7E},
	{0xA0, 0xB0, 0x00, 0x00, 0x0B},
}

APDUReadLOCI ...

View Source
var APDUReadMSISDN = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x10},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x40},
	{0xA0, 0xB0, 0x00, 0x00, 0x0D},
}

APDUReadMSISDN ...

View Source
var APDUReadPHASE = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x20},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0xAE},
	{0xA0, 0xB0, 0x00, 0x00, 0x01},
}

APDUReadPHASE ...

View Source
var APDUReadSMS = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x10},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x3C},
	{0xA0, 0xB2, 0x01, 0x04, 0xB0},
}

APDUReadSMS ...

View Source
var APDUReadSMSP = [][]byte{
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x7F, 0x10},
	{0xA0, 0xA4, 0x00, 0x00, 0x02, 0x6F, 0x42},
	{0xA0, 0xB0, 0x00, 0x00, 0x0D},
}

APDUReadSMSP ...

View Source
var APDUThaiIDCardAddress = [][]byte{
	{0x80, 0xB0, 0x15, 0x79, 0x02, 0x00, 0x64},
	{0x00, 0xc0, 0x00, 0x00, 0x64},
}

APDUThaiIDCardAddress Address resp: 704/82####...#...#...#...

View Source
var APDUThaiIDCardBirth = [][]byte{
	{0x80, 0xB0, 0x00, 0xD9, 0x02, 0x00, 0x08},
	{0x00, 0xc0, 0x00, 0x00, 0x08},
}

APDUThaiIDCardBirth Date of birth resp: 25351126

View Source
var APDUThaiIDCardCID = [][]byte{
	{0x80, 0xb0, 0x00, 0x04, 0x02, 0x00, 0x0d},
	{0x00, 0xc0, 0x00, 0x00, 0x0d},
}

APDUThaiIDCardCID ...

View Source
var APDUThaiIDCardExpiredate = [][]byte{
	{0x80, 0xB0, 0x01, 0x6F, 0x02, 0x00, 0x08},
	{0x00, 0xc0, 0x00, 0x00, 0x08},
}

APDUThaiIDCardExpiredate Expire Date resp: 25691125

View Source
var APDUThaiIDCardFullInfo = [][]byte{
	{0x80, 0xb0, 0x00, 0x11, 0x02, 0x00, 0xd1},
	{0x00, 0xc0, 0x00, 0x00, 0xd1},
}

APDUThaiIDCardFullInfo Fullname Thai + Eng + BirthDate + Sex

View Source
var APDUThaiIDCardFullnameEn = [][]byte{
	{0x80, 0xb0, 0x00, 0x75, 0x02, 0x00, 0x64},
	{0x00, 0xc0, 0x00, 0x00, 0x64},
}

APDUThaiIDCardFullnameEn Fullname English resp: Mr.#Napat##Rungruangbangchan

View Source
var APDUThaiIDCardFullnameTh = [][]byte{
	{0x80, 0xb0, 0x00, 0x11, 0x02, 0x00, 0x64},
	{0x00, 0xc0, 0x00, 0x00, 0x64},
}

APDUThaiIDCardFullnameTh Fullname Thai

View Source
var APDUThaiIDCardGender = [][]byte{
	{0x80, 0xB0, 0x00, 0xE1, 0x02, 0x00, 0x01},
	{0x00, 0xc0, 0x00, 0x00, 0x01},
}

APDUThaiIDCardGender Gender resp: 1=Male, 2=Female

View Source
var APDUThaiIDCardIssuedate = [][]byte{
	{0x80, 0xB0, 0x01, 0x67, 0x02, 0x00, 0x08},
	{0x00, 0xc0, 0x00, 0x00, 0x08},
}

APDUThaiIDCardIssuedate Issue Date resp: 25610119

View Source
var APDUThaiIDCardIssuer = [][]byte{
	{0x80, 0xB0, 0x01, 0x67, 0x02, 0x00, 0x08},
	{0x00, 0xc0, 0x00, 0x00, 0x08},
}

APDUThaiIDCardIssuer Card Issuer resp: 25610119

View Source
var APDUThaiIDCardPhoto = [][]byte{
	[]byte{0x80, 0xB0, 0x01, 0x7B, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x02, 0x7A, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x03, 0x79, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x04, 0x78, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x05, 0x77, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x06, 0x76, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x07, 0x75, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x08, 0x74, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x09, 0x73, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x0A, 0x72, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x0B, 0x71, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x0C, 0x70, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x0D, 0x6F, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x0E, 0x6E, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x0F, 0x6D, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x10, 0x6C, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x11, 0x6B, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x12, 0x6A, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x13, 0x69, 0x02, 0x00, 0xFF},
	[]byte{0x80, 0xB0, 0x14, 0x68, 0x02, 0x00, 0xFF},
}

APDUThaiIDCardPhoto Card Photo (JPEG)

View Source
var APDUThaiIDCardPhotoRsp = []byte{0x00, 0xc0, 0x00, 0x00, 0xFF}

APDUThaiIDCardPhotoRsp ...

View Source
var APDUThaiIDCardSelect = [][]byte{{0x00, 0xA4, 0x04, 0x00, 0x08, 0xA0, 0x00, 0x00, 0x00, 0x54, 0x48, 0x00, 0x01}}

APDUThaiIDCardSelect Select Thai ID Card

Functions

func APDUGetBlockRsp

func APDUGetBlockRsp(scardCard *scard.Card, apducmds [][]byte, apducmdRsp []byte) ([]byte, error)

APDUGetBlockRsp Send list of APDU and append all response

func APDUGetRsp

func APDUGetRsp(card *scard.Card, apducmds [][]byte, ispadzeroOptional ...bool) ([]byte, error)

APDUGetRsp Send list of APDU and get last command response ispadzeroOptional is optional(default = true) to replace adpu tail section

func CalculateChecksum

func CalculateChecksum(luhnString string, double bool) int

CalculateChecksum ... For calculate to find checksum digit must not include checksum digit For Validate -> include checksumdigit if sum % 10 = 0 ->> Valid

func CalculateChecksumByte

func CalculateChecksumByte(luhnByte []byte, double bool, length int) int

CalculateChecksumByte ... For calculate to find checksum digit must not include checksum digit For Validate -> include checksumdigit if sum % 10 = 0 ->> Valid

func DecodeICCID

func DecodeICCID(iccid []byte) []byte

DecodeICCID ...

func DecodeIMSI

func DecodeIMSI(ef []byte) []byte

DecodeIMSI ... swap hex in this format Source Hex : 59 02 30 59 20 57 03 30 Result Hex : 95 20 03 95 02 57 30 03

func EncodeICCID

func EncodeICCID(iccid []byte) []byte

EncodeICCID ...

func EncodeIMSI

func EncodeIMSI(imsi []byte) []byte

EncodeIMSI ...

func Generate

func Generate(size int) string

Generate creates and returns a string of the length of the argument targetSize. The returned string is valid according to the Luhn algorithm.

func LuhnByteValid

func LuhnByteValid(luhnByte []byte, length int) bool

LuhnByteValid returns a boolean indicating if the argument was valid according to the Luhn algorithm.

func LuhnStringValid

func LuhnStringValid(luhnString string) bool

LuhnStringValid returns a boolean indicating if the argument was valid according to the Luhn algorithm.

func WriteBlockToFile

func WriteBlockToFile(databytes []byte, fullname string) (int, error)

WriteBlockToFile i.e: write jpeg to file

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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