mirror of
https://github.com/rwinkhart/sshyp-labs.git
synced 2026-08-28 04:46:48 -04:00
[export-to-libmutton] Extract TOTP keys and move to dedicated field specified by the libmutton spec
This commit is contained in:
@@ -5,8 +5,6 @@ from pathlib import Path
|
|||||||
from shutil import rmtree
|
from shutil import rmtree
|
||||||
from sshyp import decrypt
|
from sshyp import decrypt
|
||||||
|
|
||||||
# TODO extract and move MFA data to dedicated field, if present
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
_pasture = path.expanduser('~/.local/share/sshyp')
|
_pasture = path.expanduser('~/.local/share/sshyp')
|
||||||
|
|
||||||
@@ -18,7 +16,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# prompt for unlock and display do not close warning
|
# prompt for unlock and display do not close warning
|
||||||
decrypt(None)
|
decrypt(None)
|
||||||
print('\nentry conversion may take some time (especially on slower devices)\ndo not terminate this process!\n')
|
print('\nentry conversion may take some time (especially on slower devices) - do not terminate this process!\n')
|
||||||
|
|
||||||
# iterate over entires, exporting them in the libmutton format
|
# iterate over entires, exporting them in the libmutton format
|
||||||
if path.isdir(_pasture):
|
if path.isdir(_pasture):
|
||||||
@@ -36,20 +34,37 @@ if __name__ == "__main__":
|
|||||||
system(f"gpg -d '{_dirPath}/{_filename}.gpg' > '{_dirPath.replace(_pasture, _pasture + '.export')}/{_filename}.gpg'")
|
system(f"gpg -d '{_dirPath}/{_filename}.gpg' > '{_dirPath.replace(_pasture, _pasture + '.export')}/{_filename}.gpg'")
|
||||||
|
|
||||||
_old_contents, _new_contents = open(f"{_dirPath.replace(_pasture, _pasture + '.export')}/{_filename}.gpg", 'r').readlines(), ''
|
_old_contents, _new_contents = open(f"{_dirPath.replace(_pasture, _pasture + '.export')}/{_filename}.gpg", 'r').readlines(), ''
|
||||||
|
_old_contents_length = len(_old_contents)
|
||||||
|
|
||||||
|
# extract sshyp-mfa data for new reserved line
|
||||||
|
if _old_contents_length >= 5:
|
||||||
|
if _old_contents[4].startswith('otpauth://'):
|
||||||
|
# check if sshyp-mfa data is standard TOTP or Steam
|
||||||
|
if _old_contents[4][10:].startswith('steam'):
|
||||||
|
print("\n\u001b[38;5;3mlibmutton uses a different form of secret key for Steam, and as such, your Steam TOTP secret will not be migrated\u001b[0m\n")
|
||||||
|
_secret = '\n'
|
||||||
|
else:
|
||||||
|
# extract TOTP secret
|
||||||
|
_secret = _old_contents[4].split('?secret=')[1].split('&issuer=')[0]+'\n'
|
||||||
|
else:
|
||||||
|
_secret = '\n'
|
||||||
|
|
||||||
# add a new line reserved for libmutton's TOTP support (between username and URL)
|
# add a new line reserved for libmutton's TOTP support (between username and URL)
|
||||||
for _num in range(len(_old_contents)):
|
for _num in range(len(_old_contents)):
|
||||||
match _num:
|
if _num == 0:
|
||||||
case 0:
|
_new_contents += _old_contents[0]
|
||||||
_new_contents += _old_contents[0]
|
elif _num == 1:
|
||||||
case 1:
|
_new_contents += _old_contents[1]
|
||||||
_new_contents += _old_contents[1]
|
elif _num == 2:
|
||||||
case 2:
|
_new_contents += _secret
|
||||||
_new_contents += ''
|
elif _num == 3:
|
||||||
case 3:
|
_new_contents += _old_contents[2]
|
||||||
_new_contents += _old_contents[2]
|
elif _num == 4:
|
||||||
case _:
|
# append as normal notes line if no sshyp-mfa data was found
|
||||||
|
if _secret == '\n':
|
||||||
_new_contents += _old_contents[_num]
|
_new_contents += _old_contents[_num]
|
||||||
|
else:
|
||||||
|
_new_contents += _old_contents[_num]
|
||||||
|
|
||||||
# remove any trailing whitespace
|
# remove any trailing whitespace
|
||||||
for _num in reversed(range(len(_new_contents))):
|
for _num in reversed(range(len(_new_contents))):
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@ exe = https://raw.githubusercontent.com/rwinkhart/sshyp-labs/v1.5.1.3/extensions
|
|||||||
ini = https://raw.githubusercontent.com/rwinkhart/sshyp-labs/v1.5.1.3/extensions/sshyp-mfa/sshyp-mfa.ini
|
ini = https://raw.githubusercontent.com/rwinkhart/sshyp-labs/v1.5.1.3/extensions/sshyp-mfa/sshyp-mfa.ini
|
||||||
|
|
||||||
[export-to-libmutton]
|
[export-to-libmutton]
|
||||||
desc = ALPHA - DO NOT USE - exports sshyp entries to ~/.local/share/sshyp.export for use with libmutton v0.2.0
|
desc = exports sshyp entries to ~/.local/share/sshyp.export for use with libmutton v0.2.0
|
||||||
usage = sshyp export
|
usage = sshyp export
|
||||||
exe = https://raw.githubusercontent.com/rwinkhart/sshyp-labs/main/extensions/export-to-libmutton/export-to-libmutton.py
|
exe = https://raw.githubusercontent.com/rwinkhart/sshyp-labs/main/extensions/export-to-libmutton/export-to-libmutton.py
|
||||||
ini = https://raw.githubusercontent.com/rwinkhart/sshyp-labs/main/extensions/export-to-libmutton/export-to-libmutton.ini
|
ini = https://raw.githubusercontent.com/rwinkhart/sshyp-labs/main/extensions/export-to-libmutton/export-to-libmutton.ini
|
||||||
|
|||||||
Reference in New Issue
Block a user