Last active
March 6, 2020 10:22
-
-
Save joshuagl/bb2e5a372988bbc05be4a382bb4b9c59 to your computer and use it in GitHub Desktop.
A quick script to test file hashing using blake algorithms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /usr/bin/env python | |
# Requires branches of tuf and securesystemslib | |
# https://github.com/secure-systems-lab/securesystemslib/pull/218 | |
# https://github.com/theupdateframework/tuf/pull/993 | |
# Demonstrates the shortest path forwards for easily enabling blake2 | |
# file hashing algorithms in a tuf repository | |
from tuf.repository_tool import * | |
import tuf.settings | |
repository = create_new_repository("repository") | |
generate_and_write_rsa_keypair('targets_key', password='password') | |
repository.targets.add_verification_key(import_rsa_publickey_from_file('targets_key.pub')) | |
private_targets_key = import_rsa_privatekey_from_file('targets_key', "password") | |
repository.targets.load_signing_key(private_targets_key) | |
with open("repository/targets/hello.txt", "w") as f: f.write("hello") | |
repository.targets.add_target("hello.txt") | |
tuf.settings.FILE_HASH_ALGORITHMS = ["blake2s", "blake2b"] | |
repository.write("targets") | |
with open("repository/metadata.staged/targets.json") as f: print(f.read()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment