def test_arqc_req_payment(self): # Payment of £1234.56, account number of 78901234 req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70], value=1234.56, challenge=78901234) data = unformat_bytes('''80 AE 80 00 1D 00 00 00 12 34 56 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 78 90 12 34 00''') self.assertEqual(req.marshal(), data) # Payment of £15.00, account number of 78901234 req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70], value=15.00, challenge=78901234) data = unformat_bytes('''80 AE 80 00 1D 00 00 00 00 15 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 78 90 12 34 00''') self.assertEqual(req.marshal(), data)
def test_length_parsing(): data = unformat_bytes("42 01 03") tlv = TLV.unmarshal(data) assert tlv[0x42][0] == 3 data = unformat_bytes("42 81 01 07") tlv = TLV.unmarshal(data) assert tlv[0x42][0] == 7 data = unformat_bytes("42 82 00 01 07") tlv = TLV.unmarshal(data) assert tlv[0x42][0] == 7 data = unformat_bytes("42 83 00 00 01 07") tlv = TLV.unmarshal(data) assert tlv[0x42][0] == 7
def test_arqc_req(): # Comparing with a valid test request from barclays_pinsentry.c req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70]) data = unformat_bytes( """80 AE 80 00 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00""") assert req.marshal() == data
def test_arqc_req_challenge(self): # Challenge of 78901234 req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70], challenge=78901234) data = unformat_bytes( '''80 AE 80 00 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 78 90 12 34 00''') self.assertEqual(req.marshal(), data)
def test_arqc_req(self): # Comparing with a valid test request from barclays_pinsentry.c req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70]) data = unformat_bytes( '''80 AE 80 00 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 00 00 00 00 00''') self.assertEqual(req.marshal(), data)
def test_length_parsing(self): data = unformat_bytes("42 01 03") tlv = TLV.unmarshal(data) self.assertEqual(tlv[0x42][0], 3) data = unformat_bytes("42 81 01 07") tlv = TLV.unmarshal(data) self.assertEqual(tlv[0x42][0], 7) data = unformat_bytes("42 82 00 01 07") tlv = TLV.unmarshal(data) self.assertEqual(tlv[0x42][0], 7) data = unformat_bytes("42 83 00 00 01 07") tlv = TLV.unmarshal(data) self.assertEqual(tlv[0x42][0], 7)
def test_arqc_req_challenge(): # Challenge of 78901234 req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70], challenge=78901234) data = unformat_bytes( """80 AE 80 00 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 78 90 12 34 00""") assert req.marshal() == data
def test_arqc_req_payment(): # Payment of £1234.56, account number of 78901234 req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70], value=1234.56, challenge=78901234) data = unformat_bytes( """80 AE 80 00 1D 00 00 00 12 34 56 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 78 90 12 34 00""") assert req.marshal() == data # Payment of £15.00, account number of 78901234 req = get_arqc_req(TLV.unmarshal(APP_DATA)[0x70], value=15.00, challenge=78901234) data = unformat_bytes( """80 AE 80 00 1D 00 00 00 00 15 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 01 01 01 00 78 90 12 34 00""") assert req.marshal() == data
def test_tlv(self): data = unformat_bytes( '''6F 1D 84 07 A0 00 00 00 03 80 02 A5 12 50 08 42 41 52 43 4C 41 59 53 87 01 00 5F 2D 02 65 6E''') tlv = TLV.unmarshal(data) self.assertIn(0x50, tlv[Tag.FCI][Tag.FCI_PROP]) data = unformat_bytes( '''77 1E 9F 27 01 80 9F 36 02 00 05 9F 26 08 6E CF 93 47 C1 A9 24 71 9F 10 07 06 0B 0A 03 A4 90 00''') tlv = TLV.unmarshal(data) self.assertIn(Tag.RMTF2, tlv) self.assertIn((0x9F, 0x26), tlv[Tag.RMTF2]) self.assertEqual(tlv[Tag.RMTF2][(0x9F, 0x26)], unformat_bytes('6E CF 93 47 C1 A9 24 71')) data = unformat_bytes('9F 17 01 03') tlv = TLV.unmarshal(data) self.assertEqual(tlv[(0x9F, 0x17)][0], 3)
def test_tlv(self): data = unformat_bytes( """6F 1D 84 07 A0 00 00 00 03 80 02 A5 12 50 08 42 41 52 43 4C 41 59 53 87 01 00 5F 2D 02 65 6E""") tlv = TLV.unmarshal(data) self.assertIn(0x50, tlv[Tag.FCI][Tag.FCI_PROP]) data = unformat_bytes( """77 1E 9F 27 01 80 9F 36 02 00 05 9F 26 08 6E CF 93 47 C1 A9 24 71 9F 10 07 06 0B 0A 03 A4 90 00""") tlv = TLV.unmarshal(data) self.assertIn(Tag.RMTF2, tlv) self.assertIn((0x9F, 0x26), tlv[Tag.RMTF2]) self.assertEqual(tlv[Tag.RMTF2][(0x9F, 0x26)], unformat_bytes("6E CF 93 47 C1 A9 24 71")) data = unformat_bytes("9F 17 01 03") tlv = TLV.unmarshal(data) self.assertEqual(tlv[(0x9F, 0x17)][0], 3) data = unformat_bytes("DF DF 39 01 07") tlv = TLV.unmarshal(data) self.assertEqual(tlv[(0xDF, 0xDF, 0x39)][0], 7)
def test_tlv(): data = unformat_bytes( """6F 1D 84 07 A0 00 00 00 03 80 02 A5 12 50 08 42 41 52 43 4C 41 59 53 87 01 00 5F 2D 02 65 6E""" ) tlv = TLV.unmarshal(data) assert 0x50 in tlv[Tag.FCI][Tag.FCI_PROP] data = unformat_bytes( """77 1E 9F 27 01 80 9F 36 02 00 05 9F 26 08 6E CF 93 47 C1 A9 24 71 9F 10 07 06 0B 0A 03 A4 90 00""" ) tlv = TLV.unmarshal(data) assert Tag.RMTF2 in tlv assert (0x9F, 0x26) in tlv[Tag.RMTF2] assert tlv[Tag.RMTF2][(0x9F, 0x26)] == unformat_bytes("6E CF 93 47 C1 A9 24 71") data = unformat_bytes("9F 17 01 03") tlv = TLV.unmarshal(data) assert tlv[(0x9F, 0x17)][0] == 3 data = unformat_bytes("DF DF 39 01 07") tlv = TLV.unmarshal(data) assert tlv[(0xDF, 0xDF, 0x39)][0] == 7
def test_duplicate_tags(self): # An ADF entry with a number of records: data = unformat_bytes( '''70 4A 61 16 4F 07 A0 00 00 00 29 10 10 50 08 4C 49 4E 4B 20 41 54 4D 87 01 01 61 18 4F 07 A0 00 00 00 03 10 10 50 0A 56 49 53 41 20 44 45 42 49 54 87 01 02 61 16 4F 07 A0 00 00 00 03 80 02 50 08 42 41 52 43 4C 41 59 53 87 01 00''') tlv = TLV.unmarshal(data) self.assertIn(Tag.RECORD, tlv) self.assertIn(Tag.APP, tlv[Tag.RECORD]) # We expect this to be a list of TLV objects self.assertIs(list, type(tlv[Tag.RECORD][Tag.APP])) self.assertEqual(len(tlv[Tag.RECORD][Tag.APP]), 3) repr(tlv)
def test_duplicate_tags(): # An ADF entry with a number of records: data = unformat_bytes( """70 4A 61 16 4F 07 A0 00 00 00 29 10 10 50 08 4C 49 4E 4B 20 41 54 4D 87 01 01 61 18 4F 07 A0 00 00 00 03 10 10 50 0A 56 49 53 41 20 44 45 42 49 54 87 01 02 61 16 4F 07 A0 00 00 00 03 80 02 50 08 42 41 52 43 4C 41 59 53 87 01 00""" ) tlv = TLV.unmarshal(data) assert Tag.RECORD in tlv assert Tag.APP in tlv[Tag.RECORD] # We expect this to be a list of TLV objects assert type(tlv[Tag.RECORD][Tag.APP]) is list assert len(tlv[Tag.RECORD][Tag.APP]) == 3 repr(tlv)
def test_invalid_tlv(self): # An actual bit of data found on a card. 0x61 indicates that it's TLV format but # no following bytes make it invalid. data = unformat_bytes('61') self.assertEqual(TLV.unmarshal(data), [0x61])
def test_nested_dol(self): tlv = TLV.unmarshal(APP_DATA) repr(tlv) self.assertIn(Tag.RECORD, tlv) self.assertIs(type(tlv[Tag.RECORD][Tag.CDOL1]), DOL)
def test_invalid_tlv(): # An actual bit of data found on a card. 0x61 indicates that it's TLV format but # no following bytes make it invalid. data = unformat_bytes("61") assert TLV.unmarshal(data) == [0x61]
def test_nested_dol(): tlv = TLV.unmarshal(APP_DATA) repr(tlv) assert Tag.RECORD in tlv assert type(tlv[Tag.RECORD][Tag.CDOL1]) is DOL