aboutsummaryrefslogtreecommitdiff
path: root/.local/share/pass-extensions/duplicates.bash
blob: b7e57a4c86b5cf85e68e3878f8016a9439ee2749 (plain)
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
#!/bin/bash
declare -A dupe_tally dupe_map

pass_names="$(pass names)"
[ $? -ne 0 ] && exit 1

pass_count="$(echo "$pass_names" | wc -l)"
if [ "$pass_count" -gt 10 ] ; then
	cat << EOF >&2
pass-duplicates needs to decrypt all your passwords one-by-one to cross-match
them. This is all done in-memory, and nothing is saved to disk. You appear to
have $pass_count passwords, so this may take some time...

EOF
fi

while read pass_name ; do
	hash="$(pass show "$pass_name" | head -n1 | sha1sum | cut -c1-40)"

	dupe_map["$pass_name"]="$hash"
	dupe_tally["$hash"]=$(( ${dupe_tally["$hash"]} + 1 ))
done < <(echo "$pass_names")

unique_duplicates=0
total_shared=0

for talley_key in "${!dupe_tally[@]}" ; do
	[ "${dupe_tally["$talley_key"]}" -le 1 ] && continue;
	unique_duplicates=$(( $unique_duplicates + 1 ))

	echo "same password:"
	for pass_name in "${!dupe_map[@]}" ; do
		[ "${dupe_map["$pass_name"]}" != "$talley_key" ] && continue;
		echo "- $pass_name"
		total_shared=$(( $total_shared + 1 ))
	done
	echo
done

echo "summary:"
if [ $unique_duplicates -eq 0 ] ; then
	echo "- no duplicates"
else
	cat << EOF
- found $unique_duplicates password(s) that were used more than once
- you should change all $total_shared passwords listed above
EOF
fi