How to use the ledgerblue.ledgerWrapper.unwrapResponseAPDU function in ledgerblue

To help you get started, we’ve selected a few ledgerblue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / blue-loader-python / experimental / bluepy / commBLE.py View on Github external
def exchange(self, apdu, timeout=20000):
		if self.debug:
			print("=> %s" % hexlify(apdu))
		apdu = wrapCommandAPDU(0, apdu, DEFAULT_BLE_CHUNK, True)		
		offset = 0
		while(offset < len(apdu)):			
			data = apdu[offset:offset + DEFAULT_BLE_CHUNK]
			self.writeCharacteristic.write(data, withResponse=True)
			offset += DEFAULT_BLE_CHUNK
			self.result = ""
		while True:
			if not self.device.waitForNotifications(BLE_NOTIFICATION_TIMEOUT):
				raise CommException("Timeout")
			response = unwrapResponseAPDU(0, self.result, DEFAULT_BLE_CHUNK, True)
			if response is not None:
				result = response
				dataStart = 0
				swOffset = len(response) - 2
				dataLength = len(response) - 2
				break
		sw = (result[swOffset] << 8) + result[swOffset + 1]
		response = result[dataStart : dataLength + dataStart]
		if self.debug:
			print("<= %s%.2x" % (hexlify(response), sw))
		if sw != 0x9000:
			raise CommException("Invalid status %04x" % sw, sw)
		return response
github LedgerHQ / blue-loader-python / ledgerblue / comm.py View on Github external
while(remaining != 0):
						if remaining > 64:
							blockLength = 64
						else:
							blockLength = remaining
						result.extend(bytearray(self.device.read(65))[0:blockLength])
						remaining -= blockLength
				swOffset = dataLength
				dataLength -= 2
				self.device.set_nonblocking(True)
			else:
				swOffset = 0
		else:
			self.device.set_nonblocking(False)
			while True:
				response = unwrapResponseAPDU(0x0101, result, 64)
				if response is not None:
					result = response
					dataStart = 0
					swOffset = len(response) - 2
					dataLength = len(response) - 2
					self.device.set_nonblocking(True)
					break
				result.extend(bytearray(self.device.read(65)))
		sw = (result[swOffset] << 8) + result[swOffset + 1]
		response = result[dataStart : dataLength + dataStart]
		if self.debug:
			print("HID <= %s%.2x" % (hexstr(response), sw))
		if sw != 0x9000 and (sw & 0xFF00) != 0x6100 and (sw & 0xFF00) != 0x6C00:
			possibleCause = "Unknown reason"
			if sw == 0x6982:
				possibleCause = "Have you uninstalled the existing CA with resetCustomCA first?"