How to use the ledgerblue.BlueHSMServer_pb2.Request 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 / ledgerblue / updateFirmware.py View on Github external
if (bytes(responseData[0:4]) == b"SECU"):
			raise Exception("Security exception " + chr(responseData[4]))

		responseData = dongle.exchange(responseData)

		request = Request()
		request.reference = "distributeFirmware11_scan"
		request.parameters = b"\xFF" + b"\xFF" + bytes(responseData)
		request.id = response.id
		request.largeStack = True

		response = serverQuery(request, args.url)
		responseData = bytearray(response.response)


	request = Request()
	request.reference = "distributeFirmware11_scan"
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "firmware"
	parameter.name = args.firmware
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "firmwareKey"
	parameter.name = args.firmwareKey
	request.id = response.id
	request.largeStack = True

	response = serverQuery(request, args.url)
	responseData = bytearray(response.response)

	offset = 0
github LedgerHQ / blue-loader-python / ledgerblue / endorsementSetupLedger.py View on Github external
serverQuery(request, args.url)
			index += 1

	# Commit agreement

	request = Request()
	request.reference = "signEndorsement"
	request.id = response.id
	response = serverQuery(request, args.url)

	# Send endorsement request

	apdu = bytearray([0xe0, 0xC0, args.key, 0x00, 0x00])
	endorsementData = dongle.exchange(apdu)

	request = Request()
	request.reference = "signEndorsement"
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "endorsementKey"
	parameter.name = args.endorsement
	request.parameters = bytes(endorsementData)
	request.id = response.id
	response = serverQuery(request, args.url)
	certificate = bytearray(response.response)

	# Commit endorsement certificate

	apdu = bytearray([0xe0, 0xC2, 0x00, 0x00, len(certificate)]) + certificate
	dongle.exchange(apdu)
	print("Endorsement setup finalized")
github LedgerHQ / blue-loader-python / ledgerblue / endorsementSetupLedger.py View on Github external
apdu = bytearray([0xE0, 0x51, 0x80, 0x00]) + bytearray([len(certificate)]) + certificate
	dongle.exchange(apdu)

	# Walk the chain

	index = 0
	while True:
			if index == 0:
				certificate = bytearray(dongle.exchange(bytearray.fromhex('E052000000')))
			elif index == 1:
				certificate = bytearray(dongle.exchange(bytearray.fromhex('E052800000')))
			else:
					break
			if len(certificate) == 0:
				break
			request = Request()
			request.reference = "signEndorsement"
			request.id = response.id
			request.parameters = bytes(certificate)
			serverQuery(request, args.url)
			index += 1

	# Commit agreement

	request = Request()
	request.reference = "signEndorsement"
	request.id = response.id
	response = serverQuery(request, args.url)

	# Send endorsement request

	apdu = bytearray([0xe0, 0xC0, args.key, 0x00, 0x00])
github LedgerHQ / blue-loader-python / ledgerblue / updateFirmware.py View on Github external
request.largeStack = True

	response = serverQuery(request, args.url)
	responseData = bytearray(response.response)

	dongle.exchange(bytearray.fromhex('E053000000'))

	for i in range(100):
		if len(responseData) == 0:
			break
		if (bytes(responseData[0:4]) == b"SECU"):
			raise Exception("Security exception " + chr(responseData[4]))

		responseData = dongle.exchange(responseData)

		request = Request()
		request.reference = "distributeFirmware11_scan"
		request.parameters = b"\xFF" + b"\xFF" + bytes(responseData)
		request.id = response.id
		request.largeStack = True

		response = serverQuery(request, args.url)
		responseData = bytearray(response.response)


	request = Request()
	request.reference = "distributeFirmware11_scan"
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "firmware"
	parameter.name = args.firmware
	parameter = request.remote_parameters.add()
github LedgerHQ / blue-loader-python / ledgerblue / endorsementSetupLedger.py View on Github external
elif index == 1:
				certificate = bytearray(dongle.exchange(bytearray.fromhex('E052800000')))
			else:
					break
			if len(certificate) == 0:
				break
			request = Request()
			request.reference = "signEndorsement"
			request.id = response.id
			request.parameters = bytes(certificate)
			serverQuery(request, args.url)
			index += 1

	# Commit agreement

	request = Request()
	request.reference = "signEndorsement"
	request.id = response.id
	response = serverQuery(request, args.url)

	# Send endorsement request

	apdu = bytearray([0xe0, 0xC0, args.key, 0x00, 0x00])
	endorsementData = dongle.exchange(apdu)

	request = Request()
	request.reference = "signEndorsement"
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "endorsementKey"
	parameter.name = args.endorsement
	request.parameters = bytes(endorsementData)
github LedgerHQ / blue-loader-python / ledgerblue / updateFirmware.py View on Github external
if args.targetId&0xF >= 0x3:
		offset += 8
		masterPublicKey = response.response[offset : offset + 65]
		offset += 65
		masterPublicKeySignatureLength = response.response[offset + 1] + 2
		masterPublicKeySignature = response.response[offset : offset + masterPublicKeySignatureLength]

	# Initialize chain

	apdu = bytearray([0xe0, 0x50, 0x00, 0x00, 0x08]) + nonce
	deviceInit = dongle.exchange(apdu)
	deviceNonce = deviceInit[4 : 4 + 8]

	# Get remote certificate

	request = Request()
	request.reference = "distributeFirmware11_scan"
	request.id = response.id
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "persoKey"
	parameter.name = args.perso
	request.parameters = bytes(deviceNonce)	
	request.largeStack = True

	response = serverQuery(request, args.url)

	offset = 0

	if sys.version_info.major == 2:
		responseLength = ord(response.response[offset + 1])
	else:
github LedgerHQ / blue-loader-python / ledgerblue / endorsementSetupLedger.py View on Github external
if args.key != 1 and args.key != 2:
			raise Exception("Invalid endorsement scheme number")
	if args.targetId == None:
		args.targetId = 0x31000002 # Ledger Blue by default

	dongle = getDongle(args.apdu)

	# Identify

	targetid = bytearray(struct.pack('>I', args.targetId))
	apdu = bytearray([0xe0, 0x04, 0x00, 0x00]) + bytearray([len(targetid)]) + targetid
	dongle.exchange(apdu)

	# Get nonce and ephemeral key

	request = Request()
	request.reference = "signEndorsement"
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "persoKey"
	parameter.name = args.perso

	response = serverQuery(request, args.url)

	offset = 0

	remotePublicKey = response.response[offset : offset + 65]
	offset += 65
	nonce = response.response[offset : offset + 8]

	# Initialize chain
github LedgerHQ / blue-loader-python / ledgerblue / updateFirmware.py View on Github external
if args.firmwareKey == None:
		raise Exception("No firmware key specified")
	if args.targetId == None:
		args.targetId = 0x31000002 # Ledger Blue by default

	dongle = getDongle(args.apdu)

	# Identify

	targetid = bytearray(struct.pack('>I', args.targetId))
	apdu = bytearray([0xe0, 0x04, 0x00, 0x00]) + bytearray([len(targetid)]) + targetid
	dongle.exchange(apdu)

	# Get nonce and ephemeral key

	request = Request()
	request.reference = "distributeFirmware11_scan"
	parameter = request.remote_parameters.add()
	parameter.local = False
	parameter.alias = "persoKey"
	parameter.name = args.perso
	if args.targetId&0xF >= 0x3:
		parameter = request.remote_parameters.add()
		parameter.local = False
		parameter.alias = "scpv2"
		parameter.name = "dummy"
	request.largeStack = True

	response = serverQuery(request, args.url)

	offset = 0
github LedgerHQ / blue-loader-python / ledgerblue / updateFirmware.py View on Github external
apdu = bytearray([0xE0, 0x51, 0x80, 0x00]) + bytearray([len(certificate)]) + certificate
	dongle.exchange(apdu)

	# Walk the chain

	index = 0
	while True:
			if index == 0:
				certificate = bytearray(dongle.exchange(bytearray.fromhex('E052000000')))
			elif index == 1:
				certificate = bytearray(dongle.exchange(bytearray.fromhex('E052800000')))
			else:
					break
			if len(certificate) == 0:
				break
			request = Request()
			request.reference = "distributeFirmware11_scan"
			request.id = response.id
			request.parameters = bytes(certificate)
			request.largeStack = True
			serverQuery(request, args.url)
			index += 1

	# Commit agreement and send firmware

	request = Request()
	request.reference = "distributeFirmware11_scan"
	if args.targetId&0xF >= 0x3:
		parameter = request.remote_parameters.add()
		parameter.local = False
		parameter.alias = "scpv2"
		parameter.name = "dummy"