def callback_PinMatrixRequest(self, msg): if msg.type == 1: desc = 'old PIN' elif msg.type == 2: desc = 'new PIN' elif msg.type == 3: desc = 'new PIN again' else: desc = 'PIN' log("Please enter %s: " % desc) pin = getpass.getpass('') return proto.PinMatrixAck(pin=pin)
def callback_PinMatrixRequest(self, msg): if msg.type == 1: desc = 'current PIN' elif msg.type == 2: desc = 'new PIN' elif msg.type == 3: desc = 'new PIN again' else: desc = 'PIN' log("Use the numeric keypad to describe number positions. The layout is:") log(" 7 8 9") log(" 4 5 6") log(" 1 2 3") log("Please enter %s: " % desc) pin = getpass.getpass('') return proto.PinMatrixAck(pin=pin)
def callback_PinMatrixRequest(self, msg): if msg.type == 1: desc = 'old PIN' elif msg.type == 2: desc = 'new PIN' elif msg.type == 3: desc = 'new PIN again' else: desc = 'PIN' log("Please enter %s: " % desc) log("Here is the PIN matrix:") log(" +---+---+---+") log(" | A | B | C |") log(" +---+---+---+") log(" | D | E | F |") log(" +---+---+---+") log(" | G | H | I |") log(" +---+---+---+") pin = getpass.getpass('') pin = pin.lower().translate(string.maketrans("abcdefghi", "789456123")) return proto.PinMatrixAck(pin=pin)
def callback_PinMatrixRequest(self, msg): if self.pin_correct: pin = self.debug.read_pin_encoded() else: pin = '444222' return proto.PinMatrixAck(pin=pin)
def Deserialization(msg_id, message): if msg_id == 38: print('MessageType_SignMessage: ', message) signmessage = tz_messages.SignMessage() signmessage.ParseFromString(message) print(signmessage) print('Type:', type(signmessage.message)) # print int class print('Len:', len(signmessage.message)) for val in signmessage.message: print(val) elif msg_id == 39: print('MessageType_VerifyMessage: ', message) verify_message = tz_messages.VerifyMessage() verify_message.ParseFromString(message) # SerializeToOstream print(verify_message) elif msg_id == 40: print('MessageType_MessageSignature: ', message) signature_message = tz_messages.MessageSignature() signature_message.ParseFromString(message) print(signature_message) hex_list = [] for val in signature_message.signature: hex_list.append(hex(val)) print('Signature:', hex_list) elif msg_id == 0: print('MessageType_Initialize: ', message) init_message = tz_messages.Initialize() init_message.ParseFromString(message) print(init_message) elif msg_id == 55: print('MessageType_GetFeatures: ', message) getFeatures_message = tz_messages.GetFeatures() getFeatures_message.ParseFromString(message) print(getFeatures_message) elif msg_id == 17: print('MessageType_Features: ', message) features_message = tz_messages.Features() features_message.ParseFromString(message) print(features_message) elif msg_id == 11: print('MessageType_GetPublicKey: ', message) GetPublicKey_message = tz_messages.GetPublicKey() GetPublicKey_message.ParseFromString(message) print(GetPublicKey_message) print('Type:', type(GetPublicKey_message.address_n)) print('len:', len(GetPublicKey_message.address_n)) elif msg_id == 12: print('MessageType_PublicKey: ', message) PublicKey_message = tz_messages.PublicKey() PublicKey_message.ParseFromString(message) print(PublicKey_message) elif msg_id == 29: print('MessageType_GetAddress: ', message) GetAddress_message = tz_messages.GetAddress() GetAddress_message.ParseFromString(message) print(GetAddress_message) elif msg_id == 30: print('MessageType_Address: ', message) Address_message = tz_messages.Address() Address_message.ParseFromString(message) print(Address_message) elif msg_id == 34: print('MessageType_BackupDevice: ', message) BackupDevice_message = tz_messages.BackupDevice() BackupDevice_message.ParseFromString(message) print(BackupDevice_message) elif msg_id == 2: print('MessageType_Success: ', message) MessageType_Success = tz_messages.Success() MessageType_Success.ParseFromString(message) print(MessageType_Success) elif msg_id == 26: print('MessageType_ButtonRequest: ', message) MessageType_ButtonRequest = tz_messages.ButtonRequest() MessageType_ButtonRequest.ParseFromString(message) print(MessageType_ButtonRequest) elif msg_id == 27: print('MessageType_ButtonAck: ', message) MessageType_ButtonAck = tz_messages.ButtonAck() MessageType_ButtonAck.ParseFromString(message) print(MessageType_ButtonAck) elif msg_id == 25: print('MessageType_ApplySettings: ', message) MessageType_ApplySettings = tz_messages.ApplySettings() MessageType_ApplySettings.ParseFromString(message) print(MessageType_ApplySettings) elif msg_id == 4: print('MessageType_ChangePin: ', message) MessageType_ChangePin = tz_messages.ChangePin() MessageType_ChangePin.ParseFromString(message) print(MessageType_ChangePin) elif msg_id == 18: print('MessageType_PinMatrixRequest: ', message) MessageType_PinMatrixRequest = tz_messages.PinMatrixRequest() MessageType_PinMatrixRequest.ParseFromString(message) print(MessageType_PinMatrixRequest) elif msg_id == 19: print('MessageType_PinMatrixAck: ', message) MessageType_PinMatrixAck = tz_messages.PinMatrixAck() MessageType_PinMatrixAck.ParseFromString(message) print(MessageType_PinMatrixAck) elif msg_id == 5: print('MessageType_WipeDevice: ', message) MessageType_WipeDevice = tz_messages.WipeDevice() MessageType_WipeDevice.ParseFromString(message) print(MessageType_WipeDevice) elif msg_id == 14: print('MessageType_ResetDevice: ', message) MessageType_ResetDevice = tz_messages.ResetDevice() MessageType_ResetDevice.ParseFromString(message) print(MessageType_ResetDevice) elif msg_id == 35: print('MessageType_EntropyRequest: ', message) MessageType_EntropyRequest = tz_messages.EntropyRequest() MessageType_EntropyRequest.ParseFromString(message) print(MessageType_EntropyRequest) elif msg_id == 36: print('MessageType_EntropyAck: ', message) MessageType_EntropyAck = tz_messages.EntropyAck() MessageType_EntropyAck.ParseFromString(message) print(MessageType_EntropyAck) elif msg_id == 6: print('MessageType_FirmwareErase: ', message) MessageType_FirmwareErase = tz_messages.FirmwareErase() MessageType_FirmwareErase.ParseFromString(message) print(MessageType_FirmwareErase) elif msg_id == 7: print('MessageType_FirmwareUpload: ', message) MessageType_FirmwareUpload = tz_messages.FirmwareUpload() MessageType_FirmwareUpload.ParseFromString(message) print(MessageType_FirmwareUpload) elif msg_id == 8: print('MessageType_FirmwareRequest: ', message) MessageType_FirmwareRequest = tz_messages.FirmwareRequest() MessageType_FirmwareRequest.ParseFromString(message) print(MessageType_FirmwareRequest) elif msg_id == 45: print('MessageType_RecoveryDevice: ', message) MessageType_RecoveryDevice = tz_messages.RecoveryDevice() MessageType_RecoveryDevice.ParseFromString(message) print(MessageType_RecoveryDevice) elif msg_id == 46: print('MessageType_WordRequest: ', message) MessageType_WordRequest = tz_messages.WordRequest() MessageType_WordRequest.ParseFromString(message) print(MessageType_WordRequest) elif msg_id == 47: print('MessageType_WordAck: ', message) MessageType_WordAck = tz_messages.WordAck() MessageType_WordAck.ParseFromString(message) print(MessageType_WordAck) elif msg_id == 41: print('MessageType_PassphraseRequest: ', message) MessageType_PassphraseRequest = tz_messages.PassphraseRequest() MessageType_PassphraseRequest.ParseFromString(message) print(MessageType_PassphraseRequest) elif msg_id == 42: print('MessageType_PassphraseAck: ', message) MessageType_PassphraseAck = tz_messages.PassphraseAck() MessageType_PassphraseAck.ParseFromString(message) print(MessageType_PassphraseAck) # Ethereum elif msg_id == 58: print('MessageType_EthereumSignTx: ', message) MessageType_EthereumSignTx = tz_messages.EthereumSignTx() MessageType_EthereumSignTx.ParseFromString(message) print(MessageType_EthereumSignTx) elif msg_id == 59: print('MessageType_EthereumTxRequest: ', message) MessageType_EthereumTxRequest = tz_messages.EthereumTxRequest() MessageType_EthereumTxRequest.ParseFromString(message) print(MessageType_EthereumTxRequest) else: print('Unrecognized Message Id, Please modify the program.')