Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import binascii
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'));
dongle = getDongle(args.apdu)
if args.scp:
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)
import sys
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()
# Not true for scp < 3
# if signature is None:
# raise BaseException('Upgrades must be signed')
# ensure data can be decoded with code decryption key without troubles.
cleardata_block_len = 16
dongle = None
secret = None
if not args.offline:
dongle = getDongle(args.apdu)
if args.deployLegacy:
secret = getDeployedSecretV1(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
else:
secret = getDeployedSecretV2(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
else:
fileTarget = open(args.offline, "wb")
class FileCard():
def __init__(self, target):
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
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 = None
secret = None
if not args.offline:
dongle = getDongle(args.apdu)
if args.deployLegacy:
secret = getDeployedSecretV1(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
else:
secret = getDeployedSecretV2(dongle, bytearray.fromhex(args.rootPrivateKey), args.targetId)
else:
fileTarget = open(args.offline, "wb")
class FileCard():
def __init__(self, target):
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
def __init__(self, dongle, targetId, rootPrivateKey):
secret = getDeployedSecretV2(dongle, rootPrivateKey, targetId)
self.loader = HexLoader(dongle, 0xe0, True, secret)
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.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)