diff --git a/.gitignore b/.gitignore index 4b1438f..a6803b4 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ info.plist lib/ assets/ -icons/ icon.png Alfred_Workflow-1.37.2.dist-info/ workflow/ diff --git a/README.md b/README.md index 64ea99c..ccace59 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

- Alfred TOTP + Alfred TOTP
Alfred 2-Factor Authenticator Workflow diff --git a/alfred-totp.py b/alfred-totp.py index 410b042..2816912 100644 --- a/alfred-totp.py +++ b/alfred-totp.py @@ -46,7 +46,7 @@ def get_steamguard_code(secret): 'B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'T', 'V', 'W', 'X', 'Y'] - # py3 + # py3 ready """ byte_time = bytes.fromhex(('%016x' % int(time.time() // 30))) auth = hmac.new(base64.b64decode(secret), byte_time, hashlib.sha1) @@ -96,45 +96,36 @@ def get_steamguard_code(secret): # set_config('keychain_name', $query) # Unlock Keychain (to be closed in time interval of 1 min) - # py3 + # py3 ready # run(["security unlock-keychain -w {} -p {}".format(keychain_pass, keychain_name), shell=True) # py2 run("security unlock-keychain -p {} {}".format(keychain_pass, keychain_name), shell=True) # Dump TOTP Services - # py3 - #totp_services = sorted(filter(None, run(["security dump-keychain {} | grep 0x00000007 | awk -F= \'{{print $2}}\'".format(keychain_name)], stdout=PIPE, shell=True).stdout.decode('utf-8').replace("\"", "").split("\n")), key=str.lower) + # py3 ready + # totp_services = sorted(filter(None, run(["security dump-keychain {} | grep 0x00000007 | awk -F= \'{{print $2}}\'".format(keychain_name)], stdout=PIPE, shell=True).stdout.decode('utf-8').replace("\"", "").split("\n")), key=str.lower) # py2 - totp_services = sorted(filter(None, run("security dump-keychain {} | grep 0x00000007 | awk -F= \'{{print $2}}\'".format(keychain_name), shell=True).replace("\"", "").split("\n")), key=str.lower) - - # Get Steam Secret if present - # py3 - # steam_secret = list(filter(None, run(["security find-generic-password -j {} {} | grep icmt | awk -F= \'{{print $2}}\'".format("steamguard", keychain_name)], stdout=PIPE, shell=True).stdout.decode('utf-8').replace("\"", "").split("\n"))) - # Get Steam Account(s) - # py3 - # steam_accounts = sorted(filter(None, run(["security dump-keychain {} | grep -B 8 {} | grep 0x00000007 | awk -F= \'{{print $2}}\'".format(keychain_name, "steamguard")], stdout=PIPE, shell=True).stdout.decode('utf-8').replace("\"", "").split("\n")), key=str.lower) - # py2 - steam_accounts = sorted(filter(None, run("security dump-keychain {} | grep -B 8 {} | grep 0x00000007 | awk -F= \'{{print $2}}\'".format(keychain_name, "steamguard"), shell=True).replace("\"", "").split("\n")), key=str.lower) + # Grabbing "Service" key from keychain dump since 0x00000007 does not reflect after changes made from keychain + dict_totp = sorted(filter(None, run("security dump-keychain {} | grep -e svce -e icmt | awk -F= \'{{print $2}}\'| paste -d \":\" - -".format(keychain_name), shell=True).replace("\"", "").split("\n"))) + # reverse the order key:value, comment:service -> service:comment and map it. + totp_srv_cmts = dict((y, x) for x, y in dict(map(lambda s: s.split(':'), dict_totp)).iteritems()) # Generate OTPs for all services - for service in totp_services: + for service in totp_srv_cmts: # get key's secret from keychain secret = ''.join((filter(None, run("security find-generic-password -s {} -w {}".format(service, keychain_name), shell=True).split("\n")))) # if service is a steamguard, call steamguard code-gen method - if not service in steam_accounts: + if not totp_srv_cmts[service] == "steamguard": # Standard TOTP Services otp_key = ''.join((filter(None, run("/usr/local/bin/oathtool --totp -b \"{}\"".format(secret), shell=True).split("\n")))) - wf.add_item('{}'.format(service), otp_key, valid=True, arg=otp_key) + if not totp_srv_cmts[service] == "" and os.path.isfile("./icons/{}.png".format(totp_srv_cmts[service])): + wf.add_item('{}'.format(service), otp_key, valid=True, arg=otp_key, icon="./icons/{}.png".format(totp_srv_cmts[service])) + else: + wf.add_item('{}'.format(service), otp_key, valid=True, arg=otp_key) else: # Non-Standard TOTP Services (╯°□°)╯︵ ┻━┻ STEAM otp_key = get_steamguard_code(secret) - wf.add_item('{}'.format(service), otp_key, valid=True, arg=otp_key) - - # services_dict.update(dict( - # identifier=service, - # secret='key_secret', - # isSteam=False, - # )) + wf.add_item('{}'.format(service), otp_key, valid=True, arg=otp_key, icon="./icons/{}.png".format(totp_srv_cmts[service])) # # If `query` is `None` or an empty string, all items are returned # items = wf.filter(query, items) diff --git a/icons/amazon.png b/icons/amazon.png new file mode 100644 index 0000000..a854b90 Binary files /dev/null and b/icons/amazon.png differ diff --git a/icons/blockchain.png b/icons/blockchain.png new file mode 100644 index 0000000..39e654f Binary files /dev/null and b/icons/blockchain.png differ diff --git a/icons/cloudflare.png b/icons/cloudflare.png new file mode 100644 index 0000000..7347ead Binary files /dev/null and b/icons/cloudflare.png differ diff --git a/icons/discord.png b/icons/discord.png new file mode 100644 index 0000000..4112df3 Binary files /dev/null and b/icons/discord.png differ diff --git a/icons/firefox.png b/icons/firefox.png new file mode 100644 index 0000000..5c7ab53 Binary files /dev/null and b/icons/firefox.png differ diff --git a/icons/github.png b/icons/github.png new file mode 100644 index 0000000..d6da7d8 Binary files /dev/null and b/icons/github.png differ diff --git a/icons/google.png b/icons/google.png new file mode 100644 index 0000000..077663a Binary files /dev/null and b/icons/google.png differ diff --git a/icons/home-assistant.png b/icons/home-assistant.png new file mode 100644 index 0000000..c0ec0a3 Binary files /dev/null and b/icons/home-assistant.png differ diff --git a/icons/instagram.png b/icons/instagram.png new file mode 100644 index 0000000..4a777b1 Binary files /dev/null and b/icons/instagram.png differ diff --git a/icons/microsoft.png b/icons/microsoft.png new file mode 100644 index 0000000..9a59d6c Binary files /dev/null and b/icons/microsoft.png differ diff --git a/icons/paypal.png b/icons/paypal.png new file mode 100644 index 0000000..350866c Binary files /dev/null and b/icons/paypal.png differ diff --git a/icons/realvnc.png b/icons/realvnc.png new file mode 100644 index 0000000..a808ac1 Binary files /dev/null and b/icons/realvnc.png differ diff --git a/icons/steamguard.png b/icons/steamguard.png new file mode 100644 index 0000000..c10a861 Binary files /dev/null and b/icons/steamguard.png differ diff --git a/sync-workflow.sh b/sync-workflow.sh index 2705720..896a454 100755 --- a/sync-workflow.sh +++ b/sync-workflow.sh @@ -76,6 +76,7 @@ while [ "$1" != "" ]; do ;; revsync | --revsync) _init_env + _revsync_workflow exit ;; export| --export)