Created
February 23, 2018 09:37
-
-
Save mnl/2faaa9c99a2071c3341950af5fe23547 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Puts a SuperGenPass in XA_PRIMARY hashed fom url in XA_PRIMARY or XA_CLIPBOARD | |
# and a password. xclip gets the url and Zenity gets user input. openssl hashes. | |
readonly length=15 | |
readonly digest=md5 | |
validHash() { | |
# Password should be hashed at least 10 times until it begins with | |
# lowercase and contains both uppercase and number characters. | |
[[ $i -ge 10 ]] && | |
[[ "$hash" =~ (^[a-z].*) ]] && | |
[[ "$hash" =~ ([A-Z]) ]] && | |
[[ "$hash" =~ ([0-9]) ]] | |
} | |
validDomain() { | |
declare -l url | |
if [[ $domain == "" ]]; then | |
url="$(xclip -o)" #First run: get XA_PRIMARY | |
else | |
url="$(xclip -selection clipboard -o)" #Second run: Try with XA_CLIPBOARD | |
fi | |
url="${url#*//}" # strip protocol | |
domain="${url%%/*}" # strip path, query, etc | |
regex="^.*\\..*$" # Contains a dot | |
if [[ "${domain}" =~ $regex ]]; then | |
regex="^.*\\..*\\..*$" # Contains two dots | |
if [[ "${domain}" =~ $regex ]]; then | |
domain="${domain#*.}" # Strip (first) subdomain | |
fi | |
else | |
return 1 # No dots, probably not an url | |
fi | |
} | |
if validDomain || validDomain; then | |
master=$(zenity --entry --hide-text --ok-label="Copy" --text="Password for ${domain}")||\ | |
(echo "Input aborted" >&2; exit 1) | |
trap "unset master hash domain" EXIT 15 2 5 6 | |
else | |
echo "Invalid url" >&2; exit 1 | |
fi | |
declare hash=$master:$domain | |
let i=0 | |
until validHash | |
do | |
let "i++" | |
hash=$(echo -n "$hash" | openssl ${digest} -binary | openssl base64) | |
hash=${hash//+/9}; hash=${hash//\//8}; hash=${hash//=/A} # tr +/= 98A | |
done | |
echo ${hash:0:length}|xclip -i -l 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment