Skip to content

Commit

Permalink
Improved and renamed example file; fixed req arg for py34
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Maier <andreas.r.maier@gmx.de>
  • Loading branch information
andy-maier committed Mar 29, 2021
1 parent 510fd59 commit 0c499bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
5 changes: 3 additions & 2 deletions easy_vault/_easy_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import yaml
import six
from cryptography.fernet import Fernet, InvalidToken
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC

Expand Down Expand Up @@ -389,9 +390,9 @@ def generate_key(password):
salt = b'fixed'
bpassword = password.encode('utf-8')
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000)
algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000,
backend=default_backend())
key = base64.urlsafe_b64encode(kdf.derive(bpassword))
print("Debug: password={}, key={!r}".format(password, key))
return key

@staticmethod
Expand Down
21 changes: 5 additions & 16 deletions examples/access_vault.py → examples/show_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import sys
import os
import getpass
from pprint import pprint
from easy_vault import EasyVault, EasyVaultException, KeyRingLib
import easy_vault


def main():
Expand All @@ -38,26 +37,16 @@ def main():
format(fn=vault_file))
return 1

keyringlib = KeyRingLib()
password = keyringlib.get_password(vault_file)
if password is None:
password = getpass.getpass("Enter password for vault file {fn}:".
format(fn=vault_file))
print("Setting password for vault file {fn} in keyring".
format(fn=vault_file))
keyringlib.set_password(vault_file, password)
else:
print("Using password for vault file {fn} from keyring".
format(fn=vault_file))

vault = EasyVault(vault_file, password)
password = easy_vault.get_password(vault_file)
vault = easy_vault.EasyVault(vault_file, password)
try:
encrypted = "encrypted" if vault.is_encrypted() else "unencrypted"
print("Vault file {fn} is {e}".format(fn=vault_file, e=encrypted))
vault_obj = vault.get_yaml()
except EasyVaultException as exc:
except easy_vault.EasyVaultException as exc:
print("Error: {}".format(exc))
return 1
easy_vault.set_password(vault_file, password)

print("Content of YAML vault file {fn}:".format(fn=vault_file))
pprint(vault_obj)
Expand Down

0 comments on commit 0c499bf

Please sign in to comment.