summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2012-10-20 16:49:59 +0200
committerFlorian Bruhin <git@the-compiler.org>2012-10-20 16:49:59 +0200
commit8a183bf6dbd5a132999a3c9883d3b3d48299ed45 (patch)
treea33d5daed46bfe823f7a5742df1cd904b22f434b
parentbe32b4291a1a723c3b99850937b8be51c8a79be3 (diff)
downloadsgp-8a183bf6dbd5a132999a3c9883d3b3d48299ed45.tar.gz
sgp-8a183bf6dbd5a132999a3c9883d3b3d48299ed45.zip
whitespace
-rwxr-xr-xsgp.py23
1 files changed, 0 insertions, 23 deletions
diff --git a/sgp.py b/sgp.py
index 6097a18..7a37f6f 100755
--- a/sgp.py
+++ b/sgp.py
@@ -7,7 +7,6 @@ import subprocess
import os
import sys
-
config = {
'verify': {
'hash': "",
@@ -22,11 +21,9 @@ config = {
def b64_md5(string):
md5 = hashlib.md5(string.encode('UTF-8')).digest()
-
altchars = '98'.encode('ASCII')
b64 = base64.b64encode(md5, altchars)
b64 = b64.decode('ASCII').replace('=', 'A')
-
return(b64)
def sgp_gen(pwd, length):
@@ -37,7 +34,6 @@ def sgp_gen(pwd, length):
while not re.match('^[a-z].*([A-Z].*[0-9]|[0-9].*[A-Z]).*', pwd[:length]):
pwd = b64_md5(pwd)
-
return(pwd[:length])
def sgp(url, password):
@@ -208,23 +204,17 @@ def url_to_domain(domain):
'xz.cn', 'yamagata.jp', 'yamaguci.jp', 'yamanashi.jp', 'yk.ca',
'yn.cn', 'yokohama.jp', 'za.com', 'zj.cn', 'zlg.br'
]
-
protos = ['http', 'https', 'ftp', 'ftps', 'webdav', 'gopher', 'rtsp',
'irc' , 'nntp' , 'pop', 'imap', 'smtp']
-
# Remove whitspace and convert to lowercase
hostname = domain.strip().lower()
-
# Remove protocol
for e in protos:
hostname = hostname.replace(e + '://', "")
-
# Remove everything after an : or /
hostname = re.match('([^/:]+)', hostname).group()
-
# Split on dots (subdomains)
hostname = hostname.split('.')
-
# If the domain has >3 parts and it's a common second-level domain,
# take the last three parts
if domain in tldlist and len(hostname) >= 3:
@@ -236,10 +226,8 @@ def url_to_domain(domain):
# If it has only one part, take it.
else:
domain = hostname
-
# Add the dots again
domain = '.'.join(domain)
-
return(domain)
def minify_javascript(password):
@@ -257,11 +245,8 @@ def minify_javascript(password):
}
})();
''')
-
js = "document.activeElement.value = '" + password + "'"
-
js = js.strip().replace('\n', ' ')
-
return(js)
def sha256hash(masterpassword):
@@ -272,10 +257,8 @@ def verify_masterpassword(masterpassword):
salt = config['verify']['salt']
hash_config = config['verify']['hash']
hash_given = sha256hash(salt + masterpassword)
-
if hash_config == "":
return(None)
-
if hash_config == hash_given:
return(True)
else:
@@ -283,13 +266,11 @@ def verify_masterpassword(masterpassword):
def call_zenity(*args):
args = [ '--' + arg for arg in args ]
-
try:
out = subprocess.check_output(['zenity', '--title=superpassgen'] +
args)
except subprocess.CalledProcessError:
sys.exit(0)
-
out = out.decode('UTF-8').rstrip('\n')
return(out)
@@ -297,12 +278,10 @@ def output_dwb(masterpassword):
url = os.environ['DWB_URI']
password = sgp(url, masterpassword)
out = "js " + minify_javascript(password)
-
if 'DWB_FIFO' in os.environ:
out += '\n'
with open(os.environ['DWB_FIFO'], 'w') as outfile:
outfile.write(out)
-
else:
print(out)
@@ -310,7 +289,6 @@ def output_console(masterpassword):
verify_salt = base64.b64encode(os.urandom(48)).decode('UTF-8')
masterpassword = verify_salt + masterpassword
verify_hash = sha256hash(masterpassword)
-
print("To turn on password verification, change the config at the top "
"of the script to the following:")
print()
@@ -325,7 +303,6 @@ def output_console(masterpassword):
def main():
if 'DISPLAY' not in os.environ:
raise OSError("DISPLAY is not set!")
-
masterpassword = call_zenity('password')
verification = verify_masterpassword(masterpassword)
if verification == False: