How to use the ledgerblue.hexLoader.HexLoader 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 / checkGenuine.py View on Github external
privateKey = PrivateKey()
    publicKey = str(privateKey.pubkey.serialize(compressed=False))
    args.rootPrivateKey = privateKey.serialize()

    genuine = False
    ui = False
    customCA = False

    dongle = getDongle(args.apdu)
    version = None

    secret = getDeployedSecretV2(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId, args.issuerKey)
    if secret != None:
        try:
            loader = HexLoader(dongle, 0xe0, True, secret)
            version = loader.getVersion()
            genuine = True
            apps = loader.listApp()
            while len(apps) != 0:
                for app in apps:
                    if (app['flags'] & 0x08):
                        ui = True
                    if (app['flags'] & 0x400):
                        customCA = True
                apps = loader.listApp(False)
        except:
            genuine = False        
    if genuine:
        if ui:
            print ("WARNING : Product is genuine but has a UI application loaded")
        if customCA:
github LedgerHQ / blue-loader-python / ledgerblue / setupCustomCA.py View on Github external
privateKey = PrivateKey()
		publicKey = binascii.hexlify(privateKey.pubkey.serialize(compressed=False))
		print("Generated random root public key : %s" % publicKey)
		args.rootPrivateKey = privateKey.serialize()
	if args.public is None:
		raise Exception("Missing public key")
	if args.name is None:
		raise Exception("Missing certificate name")

	public = bytearray.fromhex(args.public)


	dongle = getDongle(args.apdu)

	secret = getDeployedSecretV2(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
	loader = HexLoader(dongle, 0xe0, True, secret)

	loader.setupCustomCA(args.name, public)
github LedgerHQ / blue-loader-python / ledgerblue / runApp.py View on Github external
args = get_argparser().parse_args()

	if args.targetId is None:
		args.targetId = 0x31000002
	if args.rootPrivateKey is None:
		privateKey = PrivateKey()
		publicKey = binascii.hexlify(privateKey.pubkey.serialize(compressed=False))
		print("Generated random root public key : %s" % publicKey)
		args.rootPrivateKey = privateKey.serialize()
	if args.appName is None:
		raise Exception("Missing appname to run")

	dongle = getDongle(args.apdu)

	loader = HexLoader(dongle, 0xe0)

	loader.runApp(args.appName)
github LedgerHQ / blue-loader-python / ledgerblue / loadApp.py View on Github external
self.target = target
			def exchange(self, apdu):
				if (args.apdu):
					print(binascii.hexlify(apdu))
				apdu = binascii.hexlify(apdu)
				if sys.version_info.major == 2:
					self.target.write(str(apdu) + '\n')
				else:
					self.target.write(apdu + '\n'.encode())
				return bytearray([])
			def apduMaxDataSize(self):
				# ensure to allow for encryption of those apdu afterward
				return 240
		dongle = FileCard(fileTarget)

	loader = HexLoader(dongle, 0xe0, not(args.offline), secret, cleardata_block_len=cleardata_block_len)

	#tlv mode does not support explicit by name removal, would require a list app before to identify the hash to be removed
	if (not (args.appFlags & 2)) and args.delete:
			loader.deleteApp(args.appName)

	if (args.tlv):
		#if code length is not provided, then consider the whole provided hex file is the code and no data section is split
		code_length = printer.maxAddr() - printer.minAddr()
		if not args.dataSize is None:
			code_length -= args.dataSize
		else:
			args.dataSize = 0

		installparams = b""

		# express dependency
github LedgerHQ / blue-loader-python / ledgerblue / runScript.py View on Github external
def __init__(self, dongle, targetId, rootPrivateKey):
			secret = getDeployedSecretV2(dongle, rootPrivateKey, targetId)
			self.loader = HexLoader(dongle, 0xe0, True, secret)
github LedgerHQ / blue-loader-python / ledgerblue / loadMCU.py View on Github external
args = get_argparser().parse_args()

    if args.targetId == None:
    	raise Exception("Missing targetId")
    if args.fileName == None:
    	raise Exception("Missing fileName")

    parser = IntelHexParser(args.fileName)
    if args.bootAddr == None:
        args.bootAddr = parser.getBootAddr()

    dongle = getDongle(args.apdu)

    #relative load
    loader = HexLoader(dongle, 0xe0, False, None, False)

    loader.validateTargetId(args.targetId)
    hash = loader.load(0xFF, 0xF0, parser, reverse=args.reverse, doCRC=(not args.nocrc))
    loader.run(args.bootAddr)
github LedgerHQ / blue-loader-python / ledgerblue / resetCustomCA.py View on Github external
args = get_argparser().parse_args()

	if args.targetId is None:
		args.targetId = 0x31000002
	if args.rootPrivateKey is None:
		privateKey = PrivateKey()
		publicKey = binascii.hexlify(privateKey.pubkey.serialize(compressed=False))
		print("Generated random root public key : %s" % publicKey)
		args.rootPrivateKey = privateKey.serialize()


	dongle = getDongle(args.apdu)

	secret = getDeployedSecretV2(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
	loader = HexLoader(dongle, 0xe0, True, secret)

	loader.resetCustomCA()
github LedgerHQ / blue-loader-python / ledgerblue / listApps.py View on Github external
if args.targetId is None:
			args.targetId = 0x31000002
		if args.rootPrivateKey is None:
			privateKey = PrivateKey()
			publicKey = binascii.hexlify(privateKey.pubkey.serialize(compressed=False))
			print("Generated random root public key : %s" % publicKey)
			args.rootPrivateKey = privateKey.serialize()


		if args.deployLegacy:
			secret = getDeployedSecretV1(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
		else:
			secret = getDeployedSecretV2(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
	else:
		secret = None
	loader = HexLoader(dongle, 0xe0, args.scp, secret)
	apps = loader.listApp()
	while len(apps) != 0:
		print(apps)
		apps = loader.listApp(False)
github LedgerHQ / blue-loader-python / ledgerblue / deleteApp.py View on Github external
self.target = target
			def exchange(self, apdu):
				if (args.apdu):
					print(binascii.hexlify(apdu))
				apdu = binascii.hexlify(apdu)
				if sys.version_info.major == 2:
					self.target.write(str(apdu) + '\n')
				else:
					self.target.write(apdu + '\n'.encode())
				return bytearray([])
			def apduMaxDataSize(self):
				# ensure to allow for encryption of those apdu afterward
				return 240
		dongle = FileCard(fileTarget)

	loader = HexLoader(dongle, 0xe0, not(args.offline), secret)

	if args.appName != None and len(args.appName) > 0:
		for name in args.appName:
			loader.deleteApp(name)
	if args.appHash != None:
		loader.deleteAppByHash(args.appHash)
github LedgerHQ / blue-loader-python / ledgerblue / mcuBootloader.py View on Github external
import sys

	args = get_argparser().parse_args()

	if args.targetId == None:
		args.targetId = 0x31000002
	if args.rootPrivateKey == None:
		privateKey = PrivateKey()
		publicKey = binascii.hexlify(privateKey.pubkey.serialize(compressed=False))
		print("Generated random root public key : %s" % publicKey)
		args.rootPrivateKey = privateKey.serialize()

	dongle = getDongle(args.apdu)

	secret = getDeployedSecretV2(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
	loader = HexLoader(dongle, 0xe0, True, secret)
	loader.exchange(0xE0, 0, 0, 0, loader.encryptAES(b'\xB0'));