Exemple #1
0
 def initializeForPurchase(self, isEP, keyIndex, amount, terminalNumber):
     if isEP:
         cmd = '80500102' + LV(keyIndex + amount + terminalNumber)
     else:
         cmd = '80500101' + LV(keyIndex + amount + terminalNumber)
     self.apdu = cmd
     self.postProcess()
Exemple #2
0
def install(aid, card):
    card.Transmit('00A4040000')
    gp = GP.GP('404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F', '0C')
    gp.Authentication(card, '01')
    gp.Delete(aid, card)
    p = 'C900' + 'EF' + LV('A0' + LV('A5038201C0810101') + 'CF' + LV('00'))
    #p = 'C900'
    gp.Install(SZT_PKG_AID, SZT_MDL_AID, aid, card, p)
Exemple #3
0
def installProxy(card):
    aid = ProxyInstanceAID
    card.Transmit('00A4040000')
    gp = GP.GP('404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F', '0C')
    gp.Authentication(card, '01')
    gp.Delete(aid, card)
    p = 'C900' + 'EF' + LV('A0' + LV('A5038201C0810101') + 'CF' + LV('80'))
    gp.Install(ProxyPackageAID, ProxyModuleAID, ProxyInstanceAID, card, p,
               '00')  #JCOP
Exemple #4
0
 def writeKey(self, p1, p2, keyData, key='', iv=''):
     if key == '':
         cmd = '80D4' + p1 + p2 + LV(keyData)
     else:
         keyData = LV(keyData) + '80'
         while len(keyData) % 16 != 0:
             keyData += '00'
         keyData = Algo_DES_Encryption_ECB(keyData, key)
         cmd = '84D4' + p1 + p2 + '%02X' % (len(keyData) / 2 + 4) + keyData
         cmd = cmd + Algo_MAC(cmd, iv, key)[:8]
     self.apdu = cmd
     self.postProcess()
Exemple #5
0
def perso(aid, card):
    cfgDict = {}
    cfgDict['AID'] = aid
    card.Transmit('00A40400' + LV(aid))
    gp = GP.GP('404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F', '0C')
    gp.Authentication(card, '03')
    perso_apdu_list = _getPersoData(cfgDict)
    for i in perso_apdu_list[:-1]:
        print i
        gp.Send('80EC0001' + LV(LV(i)), card, expSW='9000')
    gp.Send('80EC8001' + LV(LV(perso_apdu_list[-1])), card, expSW='9000')
Exemple #6
0
 def reloadPin(self, newPin, key):
     if len(newPin) % 2 != 0:
         newPin += 'F'
     key = Algo_Xor(key[:16], key[16:])
     cmd = '805E0000' + LV(newPin + Algo_MAC(newPin, '00' * 8, key)[:8])
     self.apdu = cmd
     self.postProcess()
Exemple #7
0
def _installPBOC(card):
    aid = 'A00000033301010600030800005A5954'
    card.Transmit('00A4040000')
    gp = GP.GP('404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F', '0C')
    gp.Authentication(card, '01')
    gp.Delete(aid, card)
    #p = 'C9'+LV('E10101F10130')+'EF'+ LV('A0'+LV('A5038201C0810100')+'A1'+LV('A6'+LV('BF0C'+LV('61'+LV('4F'+LV(aid)+'50'+LV('50424F435F437265646974')+'870101')))+'A3'+LV('4F'+LV('325041592e5359532e4444463031'))+'87'+LV('01')))
    #p = 'C900'
    p = 'C9' + LV(
        'E10101F10130'
    ) + 'EF44A008A5038201C0810101A138A624BF0C21611F4F10A00000033301010600030800005A5954500B50424F435F437265646974A3104F0E325041592E5359532E4444463031'
    gp.Install(PBOC_PKG_AID, PBOC_MDL_AID, aid, card, p)
    card.Transmit('00A40400' + LV('A00000015143525300'))
    card.Transmit('80F00101' + LV('4F' + LV(aid)))
Exemple #8
0
 def changePin(self, oldPin, newPin):
     if len(oldPin) % 2 != 0:
         oldPin += 'F'
     if len(newPin) % 2 != 0:
         newPin += 'F'
     cmd = '805E0100' + LV(oldPin + 'FF' + newPin)
     self.apdu = cmd
     self.postProcess()
Exemple #9
0
 def appendRecord(self, sfi, data, key='', iv=''):
     if key == '':
         cmd = '00E200' + '%02X' % (int(sfi, 16) * 8) + LV(data)
     else:
         cmd = '04E200' + '%02X' % (int(sfi, 16) *
                                    8) + '%02X' % (len(data) / 2 + 4) + data
         cmd = cmd + Algo_MAC(cmd, iv, key)[:8]
     self.apdu = cmd
     self.postProcess()
Exemple #10
0
 def updateBinary(self, sfi, offset, data, key='', iv=''):
     if key == '':
         cmd = '00D6' + '%02X' % (int(sfi, 16) + 0x80) + offset + LV(data)
     else:
         cmd = '04D6' + '%02X' % (int(sfi, 16) + 0x80) + offset + '%02X' % (
             len(data) / 2 + 4) + data
         cmd = cmd + Algo_MAC(cmd, iv, key)[:8]
     self.apdu = cmd
     self.postProcess()
Exemple #11
0
 def unblockPin(self, pin, randData, key):
     if len(pin) % 2 != 0:
         pin += 'F'
     pin = LV(pin) + '80'
     pin += '0' * (16 - len(pin))
     pin = Algo_DES_Encryption_ECB(pin, key)
     cmd = '842400000C' + pin
     cmd = cmd + Algo_MAC(cmd, randData, key)[:8]
     self.apdu = cmd
     self.postProcess()
Exemple #12
0
 def updateRecord(self, p1, sfi, data, mode='04', key='', iv=''):
     # mode 4 as No
     # mode 0 as tag`
     p2 = '%02X' % ((int(sfi, 16) << 3) + int(mode, 16))
     if key == '':
         cmd = '00DC' + p1 + p2 + LV(data)
     else:
         cmd = '04DC' + p1 + p2 + '%02X' % (len(data) / 2 + 4) + data
         cmd = cmd + Algo_MAC(cmd, iv, key)[:8]
     self.apdu = cmd
     self.postProcess()
Exemple #13
0
def _installPPSE(card):
    card.Transmit('00A4040000')
    gp = GP.GP('404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F',
               '404142434445464748494A4B4C4D4E4F', '0C')
    gp.Authentication(card, '01')
    aid = '325041592e5359532e4444463031'

    gp.Delete(aid, card)
    p = 'C900' + 'EF' + LV('A0' + LV('A5038201C0810101'))
    P = 'C9038FF000EF0AA008810101A5038201C0'
    gp.Install(PKG_AID, MDL_AID, aid, card, p)
    apdu = APDU(card)
    apdu.selectAID(PPSE_AID)
    apdu.gpInit('404142434445464748494A4B4C4D4E4F',
                '404142434445464748494A4B4C4D4E4F',
                '404142434445464748494A4B4C4D4E4F', '0C')
    apdu.gpAuth()
    DGI9102_PPSE = '9102' + LV('A5' + LV81('BF0C' + LV(
        '61' + LV('4F' + LV('A00000033301010600030800005A5954') + '50' +
                  LV('50424F435F437265646974') + '870101'))))

    apdu.gpStoreData(DGI9102_PPSE, last=True)
Exemple #14
0
 def creditForLoad(self, dateTime, mac2):
     self.apdu = '80520000' + LV(dateTime + mac2)
     self.postProcess()
Exemple #15
0
 def debitForPurchase(self, terminalCounter, dateTime, mac1):
     self.apdu = '80540100' + LV(terminalCounter + dateTime + mac1)
     self.postProcess()
Exemple #16
0
 def initForLoad(self, isEP, keyIndex, amount, terminalNumber):
     if isEP:
         self.apdu = ('80500002' + LV(keyIndex + amount + terminalNumber))
     else:
         self.apdu = ('80500001' + LV(keyIndex + amount + terminalNumber))
     self.postProcess()
Exemple #17
0
 def initForCappLoad(self, isEP, keyIndex, amount, terminalNumber):
     if isEP:
         self.apdu = '80500602' + LV(keyIndex + amount + terminalNumber)
     else:
         self.apdu = '80500601' + LV(keyIndex + amount + terminalNumber)
Exemple #18
0
 def selectFID(self, fid):
     self.apdu = '00A40000' + LV(fid)
     self.postProcess()
Exemple #19
0
 def createFile(self, fid, apduB):
     self.apdu = '80E0' + fid + LV(apduB)
     self.postProcess()
Exemple #20
0
 def getLoadProof(self, random, aid):
     self.apdu = '80440000' + LV(random + LV(aid))
     self.postProcess()
Exemple #21
0
 def updateCappDataCache(self, tag, sfi, data):
     cmd = '80DC' + tag + '%02X' % (int(sfi, 16) * 8) + LV(data)
     self.apdu = cmd
     self.postProcess()
Exemple #22
0
 def appletBackUp(self, oldAID, newAID, schemeID, random, key):
     authData = Algo_DES_Encryption_ECB(random, key)
     apduB = 'E1' + LV(LV(oldAID) + LV(newAID) + LV(schemeID) + authData)
     self.apdu = '80AA0000' + LV(apduB)
     self.postProcess()
Exemple #23
0
 def appletRestore(self, l):
     apduB = ''
     for e in l:
         apduB += LV(e[0] + e[1])
     self.apdu = '80AA0100' + LV(apduB)
     self.postProcess()
Exemple #24
0
 def getAppletRandom(self, aidList):
     apdub = ''
     for e in aidList:
         apdub += LV(e)
     self.apdu = '80AA0600' + LV(apdub)
     self.postProcess()
Exemple #25
0
 def internalAuthentication(self, data):
     cmd = '0088' + '0000' + LV(data)
     self.apdu = cmd
     self.postProcess()
Exemple #26
0
 def updateCappBinaryCache(self, sfi, offset, data):
     cmd = '80D6' + '%02X' % (int(sfi, 16) + 0x80) + offset + LV(data)
     self.apdu = cmd
     self.postProcess()
Exemple #27
0
 def initializePurchaseWithLoyalty(self, keyIndex, amount, terminalNumber,
                                   bonusRate):
     cmd = '80501102' + LV(keyIndex + amount + terminalNumber + bonusRate)
     self.apdu = cmd
     self.postProcess()
Exemple #28
0
 def selectAID(self, aid):
     self.apdu = '00A40400' + LV(aid)
     self.postProcess()
Exemple #29
0
 def externalAuthentication(self, index, rand, key):
     cmd = '008200' + index + LV(Algo_DES_Encryption_ECB(rand, key))
     self.apdu = cmd
     self.postProcess()
Exemple #30
0
 def verifyPin(self, pin):
     if len(pin) % 2 != 0:
         pin += 'F'
     cmd = '00200000' + LV(pin)
     self.apdu = cmd
     self.postProcess()