updated parser and get account details testing of encrypted data
This commit is contained in:
@@ -9,6 +9,7 @@ import getpass
|
||||
import logging
|
||||
import secrets
|
||||
import base64
|
||||
import optparse
|
||||
import hmac as pyhmac
|
||||
from kmip.core import enums
|
||||
from kmip.demos import utils
|
||||
@@ -190,14 +191,14 @@ def does_file_exist(filepath):
|
||||
def ask_for_account_details():
|
||||
print("Requesting account details to build the ini file.")
|
||||
account_email_address = input("Please enter Bitwarden account email address: ")
|
||||
#encrypted_account_email_address = encrypt(client, account_email_address)
|
||||
encrypted_account_email_address = encrypt(client, account_email_address)
|
||||
account_api_client_id = input("Please enter Bitwarden account API client ID: ")
|
||||
#encrypted_account_api_client_id = encrypt(client, account_api_client_id)
|
||||
encrypted_account_api_client_id = encrypt(client, account_api_client_id)
|
||||
while True:
|
||||
account_api_secret = getpass.getpass("Please enter Bitwarden account API secret: ")
|
||||
account_api_secret2 = getpass.getpass("Please confirm Bitwarden account API secret: ")
|
||||
if account_api_secret == account_api_secret2:
|
||||
#encrypted_account_api_secret = encrypt(client, account_api_secret)
|
||||
encrypted_account_api_secret = encrypt(client, account_api_secret)
|
||||
break
|
||||
else:
|
||||
print("The Bitwarden account API secrets do not match, please try again.")
|
||||
@@ -205,20 +206,20 @@ def ask_for_account_details():
|
||||
account_vault_password = getpass.getpass("Please enter Bitwarden account vault password: ")
|
||||
account_vault_password2 = getpass.getpass("Please confirm Bitwarden account vault password: ")
|
||||
if account_vault_password == account_vault_password2:
|
||||
#encrypted_account_vault_password = encrypt(client, account_vault_password)
|
||||
encrypted_account_vault_password = encrypt(client, account_vault_password)
|
||||
break
|
||||
else:
|
||||
print("The Bitwarden account vault passwords do not match, please try again.")
|
||||
|
||||
array = dict()
|
||||
array["account_email_address"] = account_email_address
|
||||
#array["encrypted_account_email_address"] = encrypted_account_email_address
|
||||
array["encrypted_account_email_address"] = encrypted_account_email_address
|
||||
array["account_api_client_id"] = account_api_client_id
|
||||
#array["encrypted_account_api_client_id"] = encrypted_account_api_client_id
|
||||
array["encrypted_account_api_client_id"] = encrypted_account_api_client_id
|
||||
array["account_api_secret"] = account_api_secret
|
||||
#array["encrypted_account_api_secret"] = encrypted_account_api_secret
|
||||
array["encrypted_account_api_secret"] = encrypted_account_api_secret
|
||||
array["account_vault_password"] = account_vault_password
|
||||
#array["encrypted_account_vault_password"] = encrypted_account_vault_password
|
||||
array["encrypted_account_vault_password"] = encrypted_account_vault_password
|
||||
return array
|
||||
|
||||
def select_account(accounts, wording = "edit"):
|
||||
@@ -251,20 +252,16 @@ if __name__ == "__main__":
|
||||
# decrypt all values for easy update a
|
||||
|
||||
# Build and parse arguments
|
||||
parser = utils.build_cli_parser(enums.Operation.DECRYPT)
|
||||
parser = optparse.OptionParser(
|
||||
usage="%prog [options]",
|
||||
description="Run KMIP client operation")
|
||||
|
||||
parser.add_option(
|
||||
"-e",
|
||||
"--encrypt",
|
||||
"-c",
|
||||
"--config",
|
||||
action="store_true",
|
||||
dest="encrypt",
|
||||
help="Encrypt a passphrase/password."
|
||||
)
|
||||
parser.add_option(
|
||||
"-d",
|
||||
"--decrypt",
|
||||
action="store_true",
|
||||
dest="decrypt",
|
||||
help="Decrypt a passphrase/password."
|
||||
dest="config",
|
||||
help="Edit configuration."
|
||||
)
|
||||
parser.add_option (
|
||||
"-v",
|
||||
@@ -286,8 +283,7 @@ if __name__ == "__main__":
|
||||
print(encrypt(client, "test"))
|
||||
client.close()
|
||||
|
||||
if False:
|
||||
#if opts.config:
|
||||
if opts.config:
|
||||
if not does_file_exist(secrets_ini_file):
|
||||
print("No Bitwarden accounts found, do you want to make a new one?")
|
||||
print("n) New account")
|
||||
@@ -325,6 +321,7 @@ if __name__ == "__main__":
|
||||
user_input = input("e/n/d/q> ")
|
||||
if user_input.casefold() == "e":
|
||||
account_section_to_edit = select_account(accounts)
|
||||
|
||||
elif user_input.casefold() == "n":
|
||||
account_details = ask_for_account_details()
|
||||
config.add_section(account_details["account_email_address"])
|
||||
@@ -334,6 +331,7 @@ if __name__ == "__main__":
|
||||
with open(secrets_ini_file, "w") as configfile:
|
||||
config.write(configfile)
|
||||
break
|
||||
|
||||
elif user_input.casefold() == "d":
|
||||
account_section_to_delete = select_account(accounts, "delete")
|
||||
print("Are you sure you wish to delete {} account? ".format(account_section_to_delete))
|
||||
@@ -344,8 +342,10 @@ if __name__ == "__main__":
|
||||
with open(secrets_ini_file, "w") as configfile:
|
||||
config.write(configfile)
|
||||
break
|
||||
|
||||
elif user_input.casefold() == "q":
|
||||
sys.exit(0)
|
||||
|
||||
else:
|
||||
print("This value must be one of the following characters: e, n, d, q.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user