Skip to content

Commit

Permalink
parse keychain svce/icmt
Browse files Browse the repository at this point in the history
switched from parsing 0x00000007 to svce, parse comment(icmt) to map icons
  • Loading branch information
iganeshk committed Jan 24, 2020
1 parent f6ceb3c commit 421bcae
Show file tree
Hide file tree
Showing 17 changed files with 17 additions and 26 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
info.plist
lib/
assets/
icons/
icon.png
Alfred_Workflow-1.37.2.dist-info/
workflow/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align="center">
<a href="https://github.com/iganeshk/alfred-totp" title="Alfred TOTP Workflow">
<img alt="Alfred TOTP" src="../assets/icon.png?raw=true"/ width="75%">
<img alt="Alfred TOTP" src="../assets/icon.png?raw=true"/ width="25%">
</a>
<br />
Alfred 2-Factor Authenticator Workflow
Expand Down
39 changes: 15 additions & 24 deletions alfred-totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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] == "<NULL>" 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)
Expand Down
Binary file added icons/amazon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/blockchain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/cloudflare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/discord.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/firefox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/google.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/home-assistant.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/instagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/microsoft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/paypal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/realvnc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/steamguard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sync-workflow.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ while [ "$1" != "" ]; do
;;
revsync | --revsync)
_init_env
_revsync_workflow
exit
;;
export| --export)
Expand Down

0 comments on commit 421bcae

Please sign in to comment.