Ejemplo n.º 1
0
    def _send_apdu_raw(self, pdu):

        apdu = h2i(pdu)

        data, sw1, sw2 = self._con.transmit(apdu)

        sw = [sw1, sw2]

        # Return value
        return i2h(data), i2h(sw)
Ejemplo n.º 2
0
    def send_apdu_raw(self, pdu):
        """see LinkBase.send_apdu_raw"""
        # print("PDU: " + pdu)
        apdu = h2i(pdu)

        data, sw1, sw2 = self._con.transmit(apdu)
        # print("DATA: " + data)
        sw = [sw1, sw2]
        # Return value
        # print("DATA: " + i2h(data)," SW: " + i2h(sw))
        return i2h(data), i2h(sw)
Ejemplo n.º 3
0
Archivo: pcsc.py Proyecto: yhzs8/pysim
    def send_apdu_raw(self, pdu):
        """see LinkBase.send_apdu_raw"""

        apdu = h2i(pdu)

        data, sw1, sw2 = self._con.transmit(apdu)

        sw = [sw1, sw2]

        # Return value
        return i2h(data), i2h(sw)
Ejemplo n.º 4
0
		def decode_duration(enc:Hexstr) -> int:
			time_unit = enc[:2]
			length = h2i(enc[2:4])
			if time_unit == '04':
				return length * 10*24*60*60
			elif time_unit == '03':
				return length * 24*60*60
			elif time_unit == '02':
				return length * 60*60
			elif time_unit == '01':
				return length * 60
			elif time_unit == '00':
				return length
			else:
				raise ValueError('Time unit must be 0x00..0x04')
Ejemplo n.º 5
0
    def send_apdu_raw(self, pdu):
        """see LinkBase.send_apdu_raw"""

        if self._verbose is True:
            print("C-APDU : " + pdu)

        apdu = h2i(pdu)

        data, sw1, sw2 = self._con.transmit(apdu)

        sw = [sw1, sw2]

        if self._verbose is True:
            print("R-APDU + SW : " + i2h(data) + i2h(sw))

        # Return value
        return i2h(data), i2h(sw)
Ejemplo n.º 6
0
    def send_apdu_raw(self, pdu):
        """see LinkBase.send_apdu_raw"""

        str_pdu = str.upper(pdu)

        #print "CMD\t" + ' '.join([str_pdu[i:i+2] for i in range(0, len(str_pdu), 2)]) + ' \\'

        apdu = h2i(pdu)

        data, sw1, sw2 = self._con.transmit(apdu)

        sw = [sw1, sw2]

        #print "RESP: " + str.upper(i2h(sw)) + " " + str.upper(i2h(data))
        #print "\t" + '(' + str.upper(i2h([sw1])) + ' ' + str.upper(i2h([sw2])) + ')'

        # Return value
        return i2h(data), i2h(sw)
Ejemplo n.º 7
0
	def send_apdu_raw(self, pdu):
		"""see LinkBase.send_apdu_raw"""

		apdu = h2i(pdu)
		# print("apdu >>> ")
		print(''.join(format(apdu, '02x') for apdu in apdu))

		data, sw1, sw2 = self._con.transmit(apdu)
		#print ("response code: " + "sw1: " +str(hex(sw1)) +  " sw2: " + str(hex(sw2)))
		print (''.join(format(data, '02x') for data in data)) 
		# print("DATA: ")
		# print(hex(data))
		# print("sw1: ")
		# print(hex(sw1))
		# print("sw2: ")
		# print(hex(sw2))
		sw = [sw1, sw2]

		# Return value
		return i2h(data), i2h(sw)
Ejemplo n.º 8
0
    ac.select_usim()
    ac.send_terminal_profile()

if len(args.aram_apdu) > 0:
    # Select the ARA-M applet from its AID
    aram_rv = rv = ac._tp.send_apdu('00A4040009A00000015141434C00')
    if '9000' != aram_rv[1]:
        raise RuntimeError("SW match failed! Expected %s and got %s." %
                           ('9000', aram_rv[1]))
    # Add/Delete Access rules list in ARA-M
    rv = ac._tp.send_apdu(args.aram_apdu)
    if '9000' != rv[1] and '6a88' != rv[1]:
        raise RuntimeError("SW match failed! Expected %s and got %s." %
                           ('9000', rv[1]))
    if '80CAFF4000' == args.aram_apdu:
        res = h2i(rv[0])
        n = 0
        # REF-AR-DO - Tag value is E2 - Search for starting point of certificate
        while res[n] != 0xe2:
            n += 1
        i = 1
        total_len = len(res[n:])
        while n <= total_len:
            # Additional 2 bytes for REF-AR-DO Tag value E2 and length byte
            cert_len = res[n + 1:n + 2][0] + 2
            cert = ['%02x' % x for x in res[n:n + cert_len]]
            print "Certificate " + str(i) + ": " + ''.join(cert)
            i += 1
            n += cert_len

# for RFM testing