def do_enc_sec_create_file(self, cmd): command = Command() sk = cmd.split(",")[1] cmd = cmd.split(",")[0] cmd = cmd.split(" ") mode = cmd[0] data = int_to_hex_str(cmd[1]) # file info command.cla = "84" command.ins = "E0" command.p1 = "00" command.p2 = "00" if mode == "df": name = parse_string(cmd[2]) command.lc = int_to_hex_str(len(name.split(" ")) + 3) command.datos = data command.dfname = name else: # mode ef command.lc = "0B" command.datos = data unauth_command = command.toString() s2 = c.sign_command(unauth_command, sk) print("s2: " + s2.hex()) sign = int_to_hex_str("0x" + s2[-3:].hex()) edata = c.encrypt_data(data, sk) command.datos = int_to_hex_str("0x" + edata) command = command.toString() + " " + sign + " 03" # le 03 print(command)
def do_sec_update_record(self, cmd): command = Command() sk = cmd.split(",")[1] cmd = cmd.split(",")[0] cmd = cmd.split(" ") command.cla = "00" command.ins = "DC" command.p1 = int_to_hex_str(cmd[0]) if cmd[1] == "id": # implicit id command.p2 = int_to_hex_str( int('100', 2) + (int(cmd[2], 16) * 2)**2) # shiftear 2 data = parse_string(''.join(cmd[3:])) else: command.p2 = "04" data = parse_string(''.join(cmd[1:])) command.lc = int_to_hex_str(len(data.split(" ")) + 3) command.datos = data unauth_command = command.toString() s2 = c.sign_command(unauth_command, sk) print("s2: " + s2.hex()) sign = int_to_hex_str("0x" + s2[-3:].hex()) command = unauth_command + " " + sign + " 03" # le 03 print(command)
def do_enc_sec_update_binary(self, cmd): command = Command() sk = cmd.split(",")[1] cmd = cmd.split(",")[0] cmd = cmd.split(" ") command.cla = "04" command.ins = "D6" if cmd[1] == "id": # implicit id command.p1 = int_to_hex_str(int('10000000', 2) + int(cmd[2], 16)) command.p2 = int_to_hex_str(cmd[0]) data = parse_string(''.join(cmd[3:])) else: offset = int_to_hex_str(cmd[0], bytelength=2).split(" ") command.p2 = offset[0] command.p1 = offset[1] data = parse_string(''.join(cmd[1:])) command.lc = int_to_hex_str(len(data.split(" ")) + 3) command.datos = data unauth_command = command.toString() s2 = c.sign_command(unauth_command, sk) print("s2: " + s2.hex()) sign = int_to_hex_str("0x" + s2[-3:].hex()) edata = c.encrypt_data(data, sk) command.datos = int_to_hex_str("0x" + edata) command = command.toString() + " " + sign + " 03" # le 03 print(command)
def do_sec_append_record(self, cmd): command = Command() sk = cmd.split(",")[1] cmd = cmd.split(",")[0] cmd = cmd.split(" ") data = parse_string(''.join(cmd)) command.cla = "00" command.ins = "E2" command.p1 = "00" command.p2 = "00" command.lc = int_to_hex_str(len(data.split(" ")) + 3) command.datos = data unauth_command = command.toString() s2 = c.sign_command(unauth_command, sk) print("s2: " + s2.hex()) sign = int_to_hex_str("0x" + s2[-3:].hex()) command = unauth_command + " " + sign + " 03" # le 03 print(command)