From dfd88860c6b4e4428ea5816bafc757bfcae1f4ac Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Thu, 22 Mar 2018 14:07:44 -0400 Subject: [PATCH] Make sure the keystore directory exists when moving default keys Signed-off-by: Vladimir Diaz --- tuf/scripts/repo.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tuf/scripts/repo.py b/tuf/scripts/repo.py index 85332eaf..bf9d5ace 100755 --- a/tuf/scripts/repo.py +++ b/tuf/scripts/repo.py @@ -296,10 +296,16 @@ def gen_key(parsed_arguments): # working directory. By default, the filenames are written to .pub # and (private key). Move them from the CWD to the repo's keystore. if not parsed_arguments.filename: - shutil.move(keypath, os.path.join(parsed_arguments.path, - KEYSTORE_DIR, os.path.basename(keypath))) - shutil.move(keypath + '.pub', os.path.join(parsed_arguments.path, - KEYSTORE_DIR, os.path.basename(keypath + '.pub'))) + privkey_repo_path = os.path.join(parsed_arguments.path, + KEYSTORE_DIR, os.path.basename(keypath)) + pubkey_repo_path = os.path.join(parsed_arguments.path, + KEYSTORE_DIR, os.path.basename(keypath + '.pub')) + + securesystemslib.util.ensure_parent_dir(privkey_repo_path) + securesystemslib.util.ensure_parent_dir(pubkey_repo_path) + + shutil.move(keypath, privkey_repo_path) + shutil.move(keypath + '.pub', pubkey_repo_path)