Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
keyid = key_object['keyid']
self.assertEqual([keyid], self.metadata.signing_keys)
self.metadata.unload_signing_key(key_object)
self.assertEqual(self.metadata.signing_keys, [])
# Test improperly formatted arguments.
self.assertRaises(tuf.FormatError, self.metadata.unload_signing_key, 3)
# Test non-existent key argument.
key_path = os.path.join('repository_data',
'keystore', 'targets_key')
unused_key_object = repo_tool.import_rsa_privatekey_from_file(key_path,
'password')
self.assertRaises(tuf.Error, self.metadata.unload_signing_key,
unused_key_object)
# Import the top-level and delegated role public keys.
role_keys['root']['public'] = \
repo_tool.import_rsa_publickey_from_file(root_key_file+'.pub')
role_keys['targets']['public'] = \
repo_tool.import_ed25519_publickey_from_file(targets_key_file+'.pub')
role_keys['snapshot']['public'] = \
repo_tool.import_ed25519_publickey_from_file(snapshot_key_file+'.pub')
role_keys['timestamp']['public'] = \
repo_tool.import_ed25519_publickey_from_file(timestamp_key_file+'.pub')
role_keys['role1']['public'] = \
repo_tool.import_ed25519_publickey_from_file(delegation_key_file+'.pub')
# Import the private keys of the top-level and delegated roles.
role_keys['root']['private'] = \
repo_tool.import_rsa_privatekey_from_file(root_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['targets']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(targets_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['snapshot']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(snapshot_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['timestamp']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(timestamp_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['role1']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(delegation_key_file,
EXPECTED_KEYFILE_PASSWORD)
return role_keys
# Import the top-level and delegated role public keys.
role_keys['root']['public'] = \
repo_tool.import_rsa_publickey_from_file(root_key_file+'.pub')
role_keys['targets']['public'] = \
repo_tool.import_ed25519_publickey_from_file(targets_key_file+'.pub')
role_keys['snapshot']['public'] = \
repo_tool.import_ed25519_publickey_from_file(snapshot_key_file+'.pub')
role_keys['timestamp']['public'] = \
repo_tool.import_ed25519_publickey_from_file(timestamp_key_file+'.pub')
role_keys['role1']['public'] = \
repo_tool.import_ed25519_publickey_from_file(delegation_key_file+'.pub')
# Import the private keys of the top-level and delegated roles.
role_keys['root']['private'] = \
repo_tool.import_rsa_privatekey_from_file(root_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['targets']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(targets_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['snapshot']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(snapshot_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['timestamp']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(timestamp_key_file,
EXPECTED_KEYFILE_PASSWORD)
role_keys['role1']['private'] = \
repo_tool.import_ed25519_privatekey_from_file(delegation_key_file,
EXPECTED_KEYFILE_PASSWORD)
return role_keys
timestamp_privkey_path = os.path.join(keystore_directory, 'timestamp_key')
role1_privkey_path = os.path.join(keystore_directory, 'delegation_key')
root_privkey = \
repo_tool.import_rsa_privatekey_from_file(root_privkey_path, 'password')
targets_privkey = \
repo_tool.import_rsa_privatekey_from_file(targets_privkey_path,
'password')
snapshot_privkey = \
repo_tool.import_rsa_privatekey_from_file(snapshot_privkey_path,
'password')
timestamp_privkey = \
repo_tool.import_rsa_privatekey_from_file(timestamp_privkey_path,
'password')
role1_privkey = \
repo_tool.import_rsa_privatekey_from_file(role1_privkey_path,
'password')
# (2) Add top-level verification keys.
repository.root.add_verification_key(root_pubkey)
repository.targets.add_verification_key(targets_pubkey)
repository.snapshot.add_verification_key(snapshot_pubkey)
# Verify that repository.write() fails for insufficient threshold
# of signatures (default threshold = 1).
self.assertRaises(tuf.UnsignedMetadataError, repository.write)
repository.timestamp.add_verification_key(timestamp_pubkey)
# (3) Load top-level signing keys.
public_brakes_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'brakes.pub')
public_acme_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'acme.pub')
public_cell_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'cell.pub')
private_director_key = repotool.import_rsa_privatekey_from_file(KEYS_DIR +
'director', password='pw')
if not online_only:
private_images_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'images', password='pw')
private_brakes_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'brakes', password='pw')
private_acme_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'acme', password='pw')
private_cell_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'cell', password='pw')
public_images_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'images.pub')
public_director_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'director.pub')
public_brakes_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'brakes.pub')
public_acme_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'acme.pub')
public_cell_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'cell.pub')
private_director_key = repotool.import_rsa_privatekey_from_file(KEYS_DIR +
'director', password='pw')
if not online_only:
private_images_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'images', password='pw')
private_brakes_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'brakes', password='pw')
private_acme_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'acme', password='pw')
private_cell_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'cell', password='pw')
# Import public and private keys from the generated files.
public_root_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'root.pub')
public_time_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'time.pub')
public_snap_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'snap.pub')
public_targets_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'targets.pub')
private_time_key = repotool.import_rsa_privatekey_from_file(KEYS_DIR +
'time', password='pw')
private_snap_key = repotool.import_rsa_privatekey_from_file(KEYS_DIR +
'snap', password='pw')
if not online_only:
private_root_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'root', password='pw')
private_targets_key = repotool.import_rsa_privatekey_from_file(
KEYS_OFFLINE_DIR + 'targets', password='pw')
# Import delegated keys.
public_images_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'images.pub')
public_director_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'director.pub')
public_brakes_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'brakes.pub')
public_acme_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'acme.pub')
public_cell_key = repotool.import_rsa_publickey_from_file(KEYS_DIR +
'cell.pub')
private_director_key = repotool.import_rsa_privatekey_from_file(KEYS_DIR +