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