@@ -11,14 +11,19 @@ function _lazy_connect_init() {
11
11
echo -n " Secret Key: "
12
12
read -s secret_key
13
13
echo " **********"
14
- echo $secret_key > $_lazy_connect_config_dir /secret
14
+
15
+ echo ' Storing secret in keychain...'
16
+ old_secret=~ /.config/lazy-connect/secret
17
+ [ -f " $old_secret " ] && rm " $old_secret "
18
+ security delete-generic-password -a lazy-connect -s lazy-connect & > /dev/null
19
+ security add-generic-password -a lazy-connect -p " $secret_key " -s lazy-connect
15
20
;;
16
21
esac
17
22
_lazy_connect_vpn_refresh
18
23
}
19
24
20
25
function _lazy_connect_vpn_refresh() {
21
- local backup_file=/tmp/lazy-connect-vpns-` date +%-H-%M-%S-%F`
26
+ local backup_file=/tmp/lazy-connect-vpns-$( date +%-H-%M-%S-%F)
22
27
[ -f $_lazy_connect_config_dir /vpns ] && cp $_lazy_connect_config_dir /vpns $backup_file
23
28
osascript << EOF |
24
29
tell application "System Events"
@@ -40,8 +45,9 @@ function _lazy_connect_vpn_refresh() {
40
45
end tell
41
46
end tell
42
47
EOF
43
- tr ' ,' ' \n' | sed ' s/^[[:space:]]//g' > $_lazy_connect_config_dir /vpns
48
+ tr ' ,' ' \n' | sed ' s/^[[:space:]]//g' > $_lazy_connect_config_dir /vpns
44
49
50
+ echo " Storing the VPN list..."
45
51
if [ -f $backup_file ]; then
46
52
echo -e " \nDiff:\n$( diff -y $backup_file $_lazy_connect_config_dir /vpns) "
47
53
else
@@ -59,8 +65,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
59
65
and connect to it automatically.
60
66
61
67
-n - Connect to VPN by autofilling password
62
- -i - Initialize lazy-connect.
63
- Stores the secret and VPN list to ~/.config/lazy-connect/
68
+ -i - Initialize lazy-connect. Stores the TOTP secret and VPN list
64
69
-u - Update lazy-connect
65
70
-r - Refresh vpn list in ~/.config/lazy-connect
66
71
-h - Show this help
@@ -80,7 +85,7 @@ function _lazy_connect_get_totp() {
80
85
exit 1
81
86
fi
82
87
if [ -z " $LAZY_CONNECT_TOTP_QUERY " ]; then
83
- echo " Error: LAZY_CONNECT_TOTP_QUERY not set"
88
+ echo " Error: LAZY_CONNECT_TOTP_QUERY not set. "
84
89
exit 1
85
90
else
86
91
password=$( ykman oath code $LAZY_CONNECT_TOTP_QUERY 2> /dev/null | awk ' {print $2}' )
@@ -96,11 +101,11 @@ function _lazy_connect() {
96
101
if [ -z " $password " ]; then
97
102
case $TOTP_MODE in
98
103
oathtool)
99
- echo " Error: Unable to generate otp using oathtool"
104
+ echo " Error: Unable to generate otp using oathtool. "
100
105
return 1
101
106
;;
102
107
yubikey)
103
- echo " Error: No YubiKey found"
108
+ echo " Error: No YubiKey found. "
104
109
return 1
105
110
;;
106
111
esac
@@ -187,8 +192,15 @@ function lazy-connect() {
187
192
esac
188
193
done
189
194
190
- secret=$( cat $_lazy_connect_config_dir /secret)
191
- vpn_name=$( cat $_lazy_connect_config_dir /vpns \
192
- | fzf --height=10 --ansi --reverse --query " $* " --select-1)
195
+ local secret=$( security find-generic-password -a lazy-connect -w 2> /dev/null | tr -d ' \n' )
196
+ if [ -z " $secret " ]; then
197
+ echo " Secret not found in keychain. Initialize lazy-connect and try again."
198
+ return 1
199
+ fi
200
+
201
+ vpn_name=$( cat $_lazy_connect_config_dir /vpns |
202
+ fzf --height=10 --ansi --reverse --query " $* " --select-1)
193
203
[ -z " $vpn_name " ] || _lazy_connect " $vpn_name " " $secret "
194
204
}
205
+
206
+ lazy-connect " $@ "
0 commit comments