Exemplo n.º 1
0
 def _eraseAll ():
     data, sw1, sw2 = self.session.sendCommandAPDU([0xff, 0x00, 0x00, 0x00, 0x08, 0xd4, 0x40, 0x01, 0x90, 0xfc, 0x00, 0x00, 0x00])
     if sw1 != 0x61:
         return False
     elif sw1 == 0x61 and sw2 != 0:
         data, sw1, sw2 = self.getAnswer (sw2)
         dfdata, dfsw1, dfsw2 = errors.evaluateResponse (data)
         return errors.isOpOk (dfsw1, dfsw2)
Exemplo n.º 2
0
    def auth(self, key = 16*'00', key_num=0x00):
        """Authentification process
        
        Do the authentification 1st step, get the tag nonce and do byte shifting
        """
        sys.stdout.write("Authenticating... ")
        cmd = toBytes ("FF 00 00 00 0A D4 40 01 90 0A 00 00 01")
        cmd.append(key_num)
        cmd.append(0x00)
        data, sw1, sw2 = self.session.sendCommandAPDU( cmd )
        if sw1!=0x61 or sw2!=0x0F:
            sys.stdout.write("[Fail]\n")
            return False
        
        data, sw1, sw2 = self.getAnswer (sw2)
        dfdata, dfsw1, dfsw2 = errors.evaluateResponse (data)
        if (dfsw1 != 0x91):
            sys.stdout.write('[Fail]\n')
            return False

        n_t = crc.mergeList(dfdata)
        n2_t = unhexlify( n_t )
        response, nr = challenge.generateResponse(n2_t, key)
        
        cmd = "FF 00 00 00 19 D4 40 01 90 AF 00 00 10"
        cmd += hexlify(response)
        cmd += "00"
        data, sw1, sw2 = self.session.sendCommandAPDU( toBytes(cmd) )
        if sw1!=0x61 or sw2!=0x0F:
            sys.stdout.write("[Fail]\n")
            return False
        
        data, sw1, sw2 = self.getAnswer (sw2)

        dfdata, dfsw1, dfsw2 = errors.evaluateResponse (data)
        if not errors.isOpOk (dfsw1, dfsw2):
            sys.stdout.write('[Fail]\n')
            return False

        n2_r = crc.mergeList(dfdata)

        if challenge.verifyResponse(n2_r, nr, key):
            sys.stdout.write("[Done]\n")
        else:
            sys.stdout.write("[Fail]\n")
Exemplo n.º 3
0
 def _selectApplication ():
     data, sw1, sw2 = self.session.sendCommandAPDU([0xff, 0x00, 0x00, 0x00, 0x0c,
                                                    0xd4, 0x40, 0x01, 0x90, 0x5a,
                                                    0x00, 0x00, 0x03]
                                                 + [aid, 0x00, 0x00] + [0x00])
     if sw1 != 0x61:
         return False
     else:
         data, sw1, sw2 = self.getAnswer (sw2)
         dfdata, dfsw1, dfsw2 = errors.evaluateResponse (data)
         return errors.isOpOk (dfsw1, dfsw2)
Exemplo n.º 4
0
 def _createApplication ():
     data, sw1, sw2 = self.session.sendCommandAPDU([0xff, 0x00, 0x00, 0x00, 0x0e,
                                                    0xd4, 0x40, 0x01, 0x90, 0xca,
                                                    0x00, 0x00, 0x05]
                                                 + [aid, 0x00, 0x00]
                                                 + [keySetup]
                                                 + [numKeys] + [0x00])
     if sw1 != 0x61:
         return False
     elif sw1 == 0x61:
         data, sw1, sw2 = self.getAnswer (sw2)
         dfdata, dfsw1, dfsw2 = errors.evaluateResponse (data)
         return errors.isOpOk (dfsw1, dfsw2)