-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsgpclip
executable file
·58 lines (51 loc) · 1.73 KB
/
sgpclip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Graphical SuperGenPass implementation. mnl@vandal.nu 2017
# Put an url in clipboard memory, launch the script and enter password.
# The url gets replaced with a sgp hash that can be pasted once.
# Uses Zenity for input and OpenSSL for hashing
# Set defaults
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() { # Checks clipboard (primary then clip) for a domain name
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 ( broken for co.uk domains etc. )
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 # Clear password vars from memory
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 -A)
hash=${hash//+/9}; hash=${hash//\//8}; hash=${hash//=/A} # tr +/= 98A
done
echo ${hash:0:length}|xclip -i -l 1 # Paste once