2017-09-22 15:38:08 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2017-10-06 20:55:10 +00:00
|
|
|
import json
|
2017-09-22 15:38:08 +00:00
|
|
|
from workflow import Workflow, ICON_WEB, web
|
|
|
|
|
2017-10-06 20:55:10 +00:00
|
|
|
descriptions = {
|
|
|
|
"htpasswd_apr1": "APR1 (htpasswd)",
|
|
|
|
"htpasswd_bcrypt": "bcrypt (htpasswd)",
|
|
|
|
"htpasswd_sha256": "SHA256 (htpasswd)",
|
|
|
|
"htpasswd_sha512": "SHA512 (htpasswd)",
|
|
|
|
"password": "Password",
|
|
|
|
"sha1": "SHA1",
|
|
|
|
"sha256": "SHA256",
|
|
|
|
"sha512": "SHA512",
|
|
|
|
}
|
|
|
|
|
2017-09-22 15:38:08 +00:00
|
|
|
|
|
|
|
def main(wf):
|
|
|
|
password_length = 20
|
|
|
|
use_special = False
|
2017-10-31 11:15:13 +00:00
|
|
|
use_xkcd = False
|
2017-09-22 15:38:08 +00:00
|
|
|
|
|
|
|
if len(wf.args):
|
|
|
|
for arg in wf.args[0].split():
|
|
|
|
if arg.isdigit():
|
|
|
|
password_length = int(arg)
|
|
|
|
elif arg == 's':
|
|
|
|
use_special = True
|
2017-10-31 11:15:13 +00:00
|
|
|
elif arg == 'x':
|
|
|
|
use_xkcd = True
|
2017-09-22 15:38:08 +00:00
|
|
|
|
2017-10-31 11:15:13 +00:00
|
|
|
if password_length < 4 or password_length > 256:
|
2017-09-22 15:38:08 +00:00
|
|
|
wf.add_item(title="Password length out of bounds",
|
2017-10-31 11:15:13 +00:00
|
|
|
subtitle="Please use a reasonable password length between 4 and 256")
|
2017-09-22 15:38:08 +00:00
|
|
|
wf.send_feedback()
|
|
|
|
return 1
|
|
|
|
|
2017-10-06 20:55:10 +00:00
|
|
|
command = ["./password_darwin_amd64",
|
|
|
|
"get", "-j", "-l",
|
|
|
|
str(password_length)]
|
2017-09-22 15:38:08 +00:00
|
|
|
if use_special:
|
|
|
|
command.append("-s")
|
2017-10-31 11:15:13 +00:00
|
|
|
if use_xkcd:
|
|
|
|
command.append("-x")
|
2017-10-06 20:55:10 +00:00
|
|
|
result = json.loads(subprocess.check_output(command).strip())
|
|
|
|
|
|
|
|
hashed = []
|
|
|
|
for key, value in result.iteritems():
|
|
|
|
hashed.append("{}: {}".format(key, value))
|
2017-09-22 15:38:08 +00:00
|
|
|
|
2017-10-06 20:55:10 +00:00
|
|
|
wf.add_item(title=result['password'],
|
|
|
|
subtitle="Press Cmd+C to copy",
|
2018-03-20 18:03:46 +00:00
|
|
|
arg=result['password'],
|
|
|
|
valid=True)
|
2017-10-06 20:55:10 +00:00
|
|
|
wf.add_item(title="Copy hashed versions",
|
|
|
|
subtitle="Press Cmd+C to copy",
|
2018-03-20 18:03:46 +00:00
|
|
|
arg="\n".join(hashed),
|
|
|
|
valid=True)
|
2017-09-22 15:38:08 +00:00
|
|
|
wf.send_feedback()
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
wf = Workflow(update_settings={
|
|
|
|
'github_slug': 'Luzifer/password',
|
|
|
|
})
|
|
|
|
|
|
|
|
if wf.update_available:
|
|
|
|
# Download new version and tell Alfred to install it
|
|
|
|
wf.start_update()
|
|
|
|
|
|
|
|
sys.exit(wf.run(main))
|