Skip to content

Commit 5780d0b

Browse files
author
Dinesh Kumar
committed
Fixing merge conflicts after master merge
2 parents 4a705a1 + b40c016 commit 5780d0b

File tree

2 files changed

+36
-25
lines changed

2 files changed

+36
-25
lines changed

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@ Shell function to fuzzy search an IPSec VPN by name and connect to it automatica
44

55
## Prerequisite
66

7-
1. [fzf](https://github.com/junegunn/fzf)
8-
2. [OATH Toolkit](https://www.nongnu.org/oath-toolkit/index.html)
7+
1. [fzf](https://github.com/junegunn/fzf)
8+
2. [OATH Toolkit](https://www.nongnu.org/oath-toolkit/index.html)
99

1010
```
1111
brew install oath-toolkit fzf
1212
```
1313

1414
## Install
1515

16-
```
17-
git clone https://github.com/arunvelsriram/lazy-connect.git ~/.lazy-connect
18-
```
16+
### Using Homebrew
1917

2018
```
21-
# zsh users
22-
echo "[ -f ~/.lazy-connect/lazy-connect.sh ] && source ~/.lazy-connect/lazy-connect.sh" >> ~/.zshrc
23-
source ~/.zshrc
19+
brew tap arunvelsriram/stable
20+
brew install lazy-connect
2421
```
2522

23+
### Manual
24+
2625
```
27-
# bash users
28-
echo "[ -f ~/.lazy-connect/lazy-connect.sh ] && source ~/.lazy-connect/lazy-connect.sh" >> ~/.bashrc
29-
source ~/.bashrc
26+
git clone https://github.com/arunvelsriram/lazy-connect.git ~/.lazy-connect
27+
sudo ln -s ~/.lazy-connect/lazy-connect /usr/local/bin/lazy-connect
3028
```
3129

3230
### Usage
@@ -54,7 +52,7 @@ When disabled, the password is copied to clipboard, and you can use it manually
5452

5553
#### Prerequisite
5654

57-
1. [yubikey-manager](https://github.com/Yubico/yubikey-manager)
55+
1. [yubikey-manager](https://github.com/Yubico/yubikey-manager)
5856

5957
To use `TOTP` from YubiKey set the following environment variable
6058

@@ -63,9 +61,10 @@ export LAZY_CONNECT_TOTP_GENERATOR=yubikey
6361
export LAZY_CONNECT_TOTP_QUERY=<name of the issuer>
6462
```
6563

66-
### Warning
64+
### Note
6765

68-
- The secret key to generate TOTP is stored as plain text in `~/.config/lazy-connect/secret`
66+
- The secret key to generate TOTP is stored in Keychain on Mac under default `login` keychain. You may need to
67+
enter your login password to allow access to Keychain.
6968
- You need to add your Termainal emulator app that invokes the function to `Security & Privacy -> Accessibility`. It is
7069
necesssary because the script interacts with the UI. There are other ways via CLI to avoid UI interaction but
7170
they are all broken in OS X 10.12+.

lazy-connect.sh renamed to lazy-connect

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ function _lazy_connect_init() {
1111
echo -n "Secret Key: "
1212
read -s secret_key
1313
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
1520
;;
1621
esac
1722
_lazy_connect_vpn_refresh
1823
}
1924

2025
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)
2227
[ -f $_lazy_connect_config_dir/vpns ] && cp $_lazy_connect_config_dir/vpns $backup_file
2328
osascript <<EOF |
2429
tell application "System Events"
@@ -40,8 +45,9 @@ function _lazy_connect_vpn_refresh() {
4045
end tell
4146
end tell
4247
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
4449

50+
echo "Storing the VPN list..."
4551
if [ -f $backup_file ]; then
4652
echo -e "\nDiff:\n$(diff -y $backup_file $_lazy_connect_config_dir/vpns)"
4753
else
@@ -59,8 +65,7 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
5965
and connect to it automatically.
6066
6167
-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
6469
-u - Update lazy-connect
6570
-r - Refresh vpn list in ~/.config/lazy-connect
6671
-h - Show this help
@@ -80,7 +85,7 @@ function _lazy_connect_get_totp() {
8085
exit 1
8186
fi
8287
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."
8489
exit 1
8590
else
8691
password=$(ykman oath code $LAZY_CONNECT_TOTP_QUERY 2>/dev/null | awk '{print $2}')
@@ -96,11 +101,11 @@ function _lazy_connect() {
96101
if [ -z "$password" ]; then
97102
case $TOTP_MODE in
98103
oathtool)
99-
echo "Error: Unable to generate otp using oathtool"
104+
echo "Error: Unable to generate otp using oathtool."
100105
return 1
101106
;;
102107
yubikey)
103-
echo "Error: No YubiKey found"
108+
echo "Error: No YubiKey found."
104109
return 1
105110
;;
106111
esac
@@ -187,8 +192,15 @@ function lazy-connect() {
187192
esac
188193
done
189194

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)
193203
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret"
194204
}
205+
206+
lazy-connect "$@"

0 commit comments

Comments
 (0)