Example #1
0
 def selectType(TYPE = TYPE_AUTO):
     if TYPE < 0 or TYPE > 0xD:
         raise apduBuilderException("invalid argument TYPE, a value between 0 and 13 was expected, got "+str(TYPE))
     
     apdu = ApduDefault(cla=0xFF,ins=0xA4,p1=0x00,p2=0x00,data=[TYPE])
     apdu.removeExpectedAnswer()
     return apdu
Example #2
0
 def I2C_selectPageSize(page_size = I2C_PAGE_SIZE_8BYTES):
     if page_size < 0x03 or page_size > 0x0A:
         raise apduBuilderException("invalid argument page_size, a value between 0x03 and 0x07 was expected, got "+str(page_size))
 
     apdu = ApduDefault(cla=0xFF,ins=0x01,p1=0x00,p2=0x00, data=(page_size,))
     apdu.removeExpectedAnswer()
     return apdu
Example #3
0
 def SLE_checkPinCode(pinBytes):
     if len(pinBytes) < 2 or len(pinBytes) > 3:
         raise apduBuilderException("invalid argument pinBytes, a list of bytes of lenght 2 or 3 was expected, got "+str(len(pinBytes)))
 
     apdu = ApduDefault(cla=0xFF,ins=0x20,p1=0x00,p2=0x00, data=pinBytes)
     apdu.removeExpectedAnswer()
     return apdu
Example #4
0
    def mifareClassifWrite(blockNumber, datas, Key=None):
        if blockNumber < 0 or blockNumber > 255:
            raise apduBuilderException(
                "invalid argument blockNumber, a value between 0 and 255 was expected, got "
                + str(blockNumber))

        if len(datas) < 1 or len(datas) > 255:
            raise apduBuilderException(
                "invalid datas size, must be a list from 1 to 255 item, got " +
                str(len(datas)))

        if (len(datas) % 16) != 0:
            raise apduBuilderException(
                "invalid datas size, must be a multiple of 16")

        if Key == None:
            return ApduDefault(cla=0xFF,
                               ins=0xF4,
                               p1=0x00,
                               p2=blockNumber,
                               data=datas)
        else:
            if len(Key) != 6:
                raise apduBuilderException(
                    "invalid key length, must be 6, got " + str(len(Key)))

            toSend = []
            toSend.extend(datas)
            toSend.extend(Key)
            return ApduDefault(cla=0xFF,
                               ins=0xF4,
                               p1=0x00,
                               p2=blockNumber,
                               data=toSend)
Example #5
0
    def encapsulate(datas,
                    protocolType=0x00,
                    timeoutType=0x00,
                    defaultSW=True):

        if len(datas) < 1 or len(datas) > 255:
            raise apduBuilderException(
                "invalid data size, a value between 1 and 255 was expected, got "
                + str(len(datas)))

        if timeoutType < 0 or timeoutType > 0x0D:
            raise apduBuilderException(
                "invalid argument timeoutType, a value between 0 and 13 was expected, got "
                + str(timeoutType))

        if protocolType != 0x00 and protocolType != 0x01 and protocolType != 0x02 and protocolType != 0x04 and protocolType != 0x05 and protocolType != 0x09 and protocolType != 0x0A and protocolType != 0x0C and protocolType != 0x0F and protocolType != 0x1F and protocolType != 0x2F and protocolType != 0x3F and protocolType != 0x4F and protocolType != 0x5F and protocolType != 0x6F and protocolType != 0x7F and protocolType != 0x80 and protocolType != 0x81 and protocolType != 0x82 and protocolType != 0x83 and protocolType != 0x84:
            raise apduBuilderException(
                "invalid argument protocolType, see the documentation")

        if not defaultSW:
            timeoutType &= 0x80

        return ApduDefault(cla=0xFF,
                           ins=0xFE,
                           p1=protocolType,
                           p2=timeoutType,
                           data=datas)
Example #6
0
    def verifyCommand(pin, reference=0, ReaderKey=None):
        if len(pin) < 1 or len(pin) > 255:
            raise apduBuilderException(
                "invalid pin size, must be a list from 1 to 255 item, got " +
                str(len(pin)))

        if reference < 0 or reference > 255:
            raise apduBuilderException(
                "invalid argument reference, a value between 0 and 255 was expected, got "
                + str(reference))

        structure = 0
        if ReaderKey != None:
            structure |= 0x40
            if ReaderKey < 0 or ReaderKey > 15:
                raise apduBuilderException(
                    "invalid argument ReaderKey, a value between 0 and 255 was expected, got "
                    + str(ReaderKey))

            structure |= (ReaderKey & 0xf)

        return ApduDefault(cla=0xFF,
                           ins=0x20,
                           p1=structure,
                           p2=reference,
                           data=pin)
Example #7
0
    def loadKey(key, InVolatile=True, isCardKey=True, ReaderKey=None):
        if len(key) < 1 or len(key) > 255:
            raise apduBuilderException(
                "invalid key size, must be a list from 1 to 255 item, got " +
                str(len(pin)))

        if KeyIndex < 0 or KeyIndex > 255:
            raise apduBuilderException(
                "invalid argument KeyIndex, a value between 0 and 255 was expected, got "
                + str(KeyIndex))

        P1 = 0x00

        if not InVolatile:
            P1 |= 0x20

        if not isCardKey:
            P1 |= 0x80

        if ReaderKey != None:
            if ReaderKey < 0 or ReaderKey > 15:
                raise apduBuilderException(
                    "invalid argument ReaderKey, a value between 0 and 15 was expected, got "
                    + str(ReaderKey))

            P1 |= 0x40
            P1 |= (ReaderKey & 0x0f)

        #the 0x10 bit is Reserved Future Use

        return ApduDefault(cla=0xFF,
                           ins=0x82,
                           p1=P1,
                           p2=KeyIndex,
                           data=keys[KeyName])
Example #8
0
    def mifareClassicRead(blockNumber, Key=None):
        if blockNumber < 0 or blockNumber > 255:
            raise apduBuilderException(
                "invalid argument blockNumber, a value between 0 and 255 was expected, got "
                + str(blockNumber))

        if Key == None:
            return ApduDefault(cla=0xFF, ins=0xF3, p1=0x00, p2=blockNumber)
        else:
            if len(Key) != 6:
                raise apduBuilderException(
                    "invalid key length, must be 6, got " + str(len(Key)))

            return ApduDefault(cla=0xFF,
                               ins=0xF3,
                               p1=0x00,
                               p2=blockNumber,
                               data=Key)
Example #9
0
    def write(adress, datas, area = WRITE_AREA_0):
        if adress < 0 or adress > 0x1ffff:
            raise apduBuilderException("invalid argument adress, a value between 0 and 1023 was expected, got "+str(TYPE))

        if len(datas) < 1 or len(datas) > 255:
            raise apduBuilderException("invalid datas size, must be a list from 1 to 255 item, got "+str(len(datas)))

        if area < 0xd0 or area > 0xd4:
            raise apduBuilderException("invalid argument area, a value between 0xd0 and 0xd4 was expected, got "+str(area))

        if adress >= 0x10000:
            area |= 0x1

        msb = (adress >> 8) & 0xFF
        lsb = adress & 0xFF

        apdu = ApduDefault(cla=0xFF,ins=area,p1=msb,p2=lsb, data=datas)
        apdu.removeExpectedAnswer()
        return apdu
Example #10
0
    def generalAuthenticate(blockNumber,
                            KeyIndex,
                            InVolatile=True,
                            isTypeA=True):
        data = [0x01]  #Auth version

        data.extend(
            pcscAPDUBuilder.getAuthenticateData(blockNumber, KeyIndex,
                                                InVolatile, isTypeA))

        return ApduDefault(cla=0xFF, ins=0x86, p1=0x00, p2=0x00, data=datas)
Example #11
0
    def setBuzzerDuration(duration):
        if duration < 0 or duration > 60000:
            raise apduBuilderException(
                "invalid argument duration, a value between 0 and 60000 was expected, got "
                + str(duration))

        lsb = duration & 0xFF
        msb = (duration >> 8) & 0xFF

        return ApduDefault(cla=0xFF,
                           ins=0xF0,
                           p1=0x00,
                           p2=0x00,
                           data=[0x1C, msb, lsb])
Example #12
0
    def readBinary(address=0, expected=0):
        if address < 0 or address > 65535:
            raise apduBuilderException(
                "invalid argument address, a value between 0 and 65535 was expected, got "
                + str(address))

        lsb = address & 0xFF
        msb = (address >> 8) & 0xFF

        return ApduDefault(cla=0xFF,
                           ins=0xB0,
                           p1=msb,
                           p2=lsb,
                           expected_answer=expected)
Example #13
0
    def updateBinary(datas, address=0):
        if address < 0 or address > 65535:
            raise apduBuilderException(
                "invalid argument address, a value between 0 and 65535 was expected, got "
                + str(address))

        if len(datas) < 1 or len(datas) > 255:
            raise apduBuilderException(
                "invalid datas size, must be a list from 1 to 255 item, got " +
                str(len(datas)))

        lsb = address & 0xFF
        msb = (address >> 8) & 0xFF

        return ApduDefault(cla=0xFF, ins=0xD6, p1=msb, p2=lsb, data=datas)
Example #14
0
    def setLedColorFun(red, green, yellow_blue=None):
        if red < 0 or red > 5:
            raise apduBuilderException(
                "invalid argument red, a value between 0 and 5 was expected, got "
                + str(red))

        if green < 0 or green > 5:
            raise apduBuilderException(
                "invalid argument green, a value between 0 and 5 was expected, got "
                + str(green))

        if yellow_blue == None:
            d = [0x1E, red, green]
        else:
            if yellow_blue < 0 or yellow_blue > 5:
                raise apduBuilderException(
                    "invalid argument yellow_blue, a value between 0 and 5 was expected, got "
                    + str(yellow_blue))
            d = [0x1E, red, green, yellow_blue]

        return ApduDefault(cla=0xFF, ins=0xF0, p1=0x00, p2=0x00, data=d)
Example #15
0
    def test(expected_answer_size=0, delay_to_answer=0, datas=[]):

        if expected_answer_size < 0 or expected_answer_size > 255:
            raise apduBuilderException(
                "invalid argument expected_answer_size, a value between 0 and 255 was expected, got "
                + str(expected_answer_size))

        if delay_to_answer < 0 or delay_to_answer > 63:
            raise apduBuilderException(
                "invalid argument delay_to_answer, a value between 0 and 63 was expected, got "
                + str(delay_to_answer))

        if len(datas) < 0 or len(datas) > 255:
            raise apduBuilderException(
                "invalid argument datas, a value list of length 0 to 255 was expected, got "
                + str(len(datas)))

        return ApduDefault(cla=0xFF,
                           ins=0xFD,
                           p1=expected_answer_size,
                           p2=delay_to_answer,
                           data=datas)
Example #16
0
 def getDataCB(P1, P2, Data):
     return ApduDefault(cla=0xFF, ins=0xCA, p1=P1, p2=P2, data=Data)
Example #17
0
 def getDataCA(P1, P2):
     return ApduDefault(cla=0xFF, ins=0xCA, p1=P1, p2=P2)
Example #18
0
 def configureCalypsoSamDisableInternalDigestUpdate():
     return ApduDefault(cla=0xFF, ins=0xFC, p1=0x08, p2=0x01)
Example #19
0
 def configureCalypsoSamSetSpeed115200():
     return ApduDefault(cla=0xFF, ins=0xFC, p1=0x04, p2=0x01)
Example #20
0
 def slotControlSuspendCardTracking():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x01, p2=0x00)
Example #21
0
 def slotControlEnableTCLAgain():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x20, p2=0x06)
Example #22
0
 def slotControlDisableEveryTCL():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x20, p2=0x05)
Example #23
0
 def slotControlTCLActivationTypeB():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x20, p2=0x02)
Example #24
0
 def slotControlResetRFField():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x10, p2=0x02)
Example #25
0
 def slotControlStopRFField():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x10, p2=0x00)
Example #26
0
 def slotControlResetAfterNextDisconnectAndDisableNextTCL():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x20, p2=0x07)
Example #27
0
 def slotControlStop():
     "stop the slot"
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0xDE, p2=0xAD)
Example #28
0
 def slotControlTCLDeactivation():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x20, p2=0x00)
Example #29
0
 def slotControlResumeCardTracking():
     return ApduDefault(cla=0xFF, ins=0xFB, p1=0x00, p2=0x00)