Allow complex string generation for /dev/shm and device ids

Former-commit-id: 534577ba9d348aa3bfbce63a940229594a2ae68d [formerly 0614c2c83b]
Former-commit-id: c28b84e388cb9969a881a2a0ab15dfd814875a47
This commit is contained in:
2022-11-05 15:21:30 -04:00
parent bb34025c31
commit 65be0eaf6f
+11 -6
View File
@@ -102,8 +102,11 @@ def string_gen(_complexity, _length): # generates and returns a random string b
import string import string
if _complexity == 's': if _complexity == 's':
_character_pool = string.ascii_letters + string.digits _character_pool = string.ascii_letters + string.digits
elif _complexity == 'f':
_character_pool = string.digits + string.ascii_letters + string.punctuation.replace('/', '').replace('\\', '')\
.replace("'", '').replace('"', '').replace('`', '')
else: else:
_character_pool = string.digits + string.ascii_letters + string.punctuation.replace('/', '').replace('\\', '') _character_pool = string.digits + string.ascii_letters + string.punctuation
_min_special, _special = round(.2 * _length), 0 _min_special, _special = round(.2 * _length), 0
while True: while True:
_gen = ''.join(SystemRandom().choice(_character_pool) for _ in range(_length)) _gen = ''.join(SystemRandom().choice(_character_pool) for _ in range(_length))
@@ -123,13 +126,15 @@ def pass_gen(): # prompts the user for necessary information to generate a pass
_gen = pass_gen() _gen = pass_gen()
return _gen return _gen
_complexity = str(input('password complexity - simple (for compatibility) or complex (for security)? (s/C) ')) _complexity = str(input('password complexity - simple (for compatibility) or complex (for security)? (s/C) '))
if _complexity != 's' and _complexity != 'S':
_complexity = 'c'
_gen = string_gen(_complexity.lower(), _length) _gen = string_gen(_complexity.lower(), _length)
return _gen return _gen
def shm_gen(_tmp_dir=path.expanduser('~/.config/sshyp/tmp/')): # creates a temporary directory for entry editing def shm_gen(_tmp_dir=path.expanduser('~/.config/sshyp/tmp/')): # creates a temporary directory for entry editing
_shm_folder_gen = string_gen('s', randint(12, 48)) _shm_folder_gen = string_gen('f', randint(12, 48))
_shm_entry_gen = string_gen('s', randint(12, 48)) _shm_entry_gen = string_gen('f', randint(12, 48))
Path(_tmp_dir + _shm_folder_gen).mkdir(0o700) Path(_tmp_dir + _shm_folder_gen).mkdir(0o700)
return _shm_folder_gen, _shm_entry_gen return _shm_folder_gen, _shm_entry_gen
@@ -150,7 +155,7 @@ def decrypt(_entry_dir, _shm_folder, _shm_entry, _gpg_com, _quick_pass,
if _shm_folder == 0 and _shm_entry == 0: if _shm_folder == 0 and _shm_entry == 0:
_output_target = f"/dev/null {path.expanduser('~/.config/sshyp/lock.gpg')}" _output_target = f"/dev/null {path.expanduser('~/.config/sshyp/lock.gpg')}"
else: else:
_output_target = f"{_tmp_dir}{_shm_folder}/{_shm_entry} '{_entry_dir}.gpg'" _output_target = f"'{_tmp_dir}{_shm_folder}/{_shm_entry}' '{_entry_dir}.gpg'"
try: try:
run(_unlock_method + _output_target, shell=True, stderr=PIPE, check=True, close_fds=True) run(_unlock_method + _output_target, shell=True, stderr=PIPE, check=True, close_fds=True)
except CalledProcessError: except CalledProcessError:
@@ -314,7 +319,7 @@ def tweak(): # runs configuration wizard
print(f"{_divider}\u001b[4;1mimportant:\u001b[0m this id \u001b[4;1mmust\u001b[0m be unique amongst your " print(f"{_divider}\u001b[4;1mimportant:\u001b[0m this id \u001b[4;1mmust\u001b[0m be unique amongst your "
f"client devices\n\nthis is used to keep track of database syncing and quick-unlock permissions\n") f"client devices\n\nthis is used to keep track of database syncing and quick-unlock permissions\n")
_device_id_prefix = str(input('device id: ')) + '-' _device_id_prefix = str(input('device id: ')) + '-'
_device_id_suffix = string_gen('s', randint(24, 48)) _device_id_suffix = string_gen('f', randint(24, 48))
_device_id = _device_id_prefix + _device_id_suffix _device_id = _device_id_prefix + _device_id_suffix
open(f"{path.expanduser('~/.config/sshyp/devices/')}{_device_id}", 'w') open(f"{path.expanduser('~/.config/sshyp/devices/')}{_device_id}", 'w')
@@ -325,7 +330,7 @@ def tweak(): # runs configuration wizard
if _sshyp_data[3] == 'y': if _sshyp_data[3] == 'y':
print(f"\nquick-unlock has been enabled client-side - in order for this device to be able to read " print(f"\nquick-unlock has been enabled client-side - in order for this device to be able to read "
f"entries,\nyou must first login to the sshyp server and run:\n\nsshyp whitelist setup " f"entries,\nyou must first login to the sshyp server and run:\n\nsshyp whitelist setup "
f"(if not already done)\nsshyp whitelist add {_device_id}") f"(if not already done)\nsshyp whitelist add '{_device_id}'")
# test server connection and attempt to register device id # test server connection and attempt to register device id
copy_id_check(_port, _username_ssh, _ip, _device_id) copy_id_check(_port, _username_ssh, _ip, _device_id)