-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassman
executable file
·117 lines (107 loc) · 3.29 KB
/
passman
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash -
#===============================================================================
#
# FILE: passman.sh
#
# USAGE: ./passman.sh [-option]
#
# DESCRIPTION: A tiny password manager for the command line. Uses openssl rsautl encryption.
#
# OPTIONS: -a to add a new account and password; -g to get the password for an account
# REQUIREMENTS: xclip, openssl
# BUGS: ---
# NOTES: ---
# AUTHOR: Gabriel Silva Miranda
# CREATED: 10/10/2019 16:44
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
help(){
echo -e "usage: passman [option]\n\nOptions:\n\t-a\tAdd an account and password\n\t-g\tGet the password for an account\n\t-l\tList password files\n"
}
genKey(){
echo "No key found! Would you like to generate a key? y/n"
local option
read option
if [[ "$option" == "y" ]] || [[ "$option" == "Y" ]];
then
openssl genrsa -aes256 -out ~/.local/bin/.key 2048
elif [[ "$option" == "n" ]] || [[ "$option" == "N" ]];
then
echo "Closing!"
exit
else
genKey
fi
}
encryptPass(){
local user
local pass
read -p "Enter an account name: " user
read -p "Enter a password: " -s pass
echo $pass | openssl rsautl -inkey $HOME/.local/bin/.key -encrypt >> ~/.local/share/passwords/$user.bin
echo -e "\nDone!"
}
decryptPass(){
local user
read -p "Enter the account name: " user
findfile=`find ~/.local/share/passwords/$user.bin 2>/dev/null`
if [ "$findfile" == "$HOME/.local/share/passwords/$user.bin" ];
then
openssl rsautl -inkey $HOME/.local/bin/.key -decrypt < ~/.local/share/passwords/$user.bin | xclip -selection c
echo "The password was sent to your clipboard (Ctrl+V)!"
else
echo "No match found!"
fi
}
listPass(){
ls ~/.local/share/passwords/
}
findkey=`find ~/.local/bin/.key 2>/dev/null`
findpass=`find ~/.local/share/passwords -maxdepth 0 2>/dev/null`
if (($# > 0)); then
case $1 in
-a)
if [ "$findkey" == "$HOME/.local/bin/.key" ];
then
if [ "$findpass" == "$HOME/.local/share/passwords" ];
then
encryptPass
else
mkdir ~/.local/share/passwords
encryptPass
fi
else
genKey
if [ "$findpass" == "$HOME/.local/share/passwords" ];
then
encryptPass
else
mkdir ~/.local/share/passwords
encryptPass
fi
fi
;;
-g)
if [ "$findpass" == "$HOME/.local/share/passwords" ];
then
decryptPass
else
echo "There are no passwords stored!"
fi
;;
-l)
if [ "$findpass" == "$HOME/.local/share/passwords" ];
then
listPass
else
mkdir ~/.local/share/passwords
echo "There ano no passwords stored! Password directory created"
fi
;;
*)
help
;;
esac
else help
fi