Skip to content

Commit 18da9e2

Browse files
Merge pull request #9 from caalberts/keychain
Store secret in keychain
2 parents 42b09e3 + f33b5db commit 18da9e2

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export LAZY_CONNECT_TOTP_QUERY=<name of the issuer>
5656

5757
### Warning
5858

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

lazy-connect.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ 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+
security add-generic-password -a lazy-connect -p "$secret_key" -s lazy-connect
1517
;;
1618
esac
1719
_lazy_connect_vpn_refresh
@@ -171,7 +173,13 @@ function lazy-connect() {
171173
esac
172174
done
173175

174-
secret=$(cat $_lazy_connect_config_dir/secret)
176+
local secret=$(security find-generic-password -a lazy-connect -w 2> /dev/null | tr -d '\n')
177+
if [ -z "$secret" ];
178+
then
179+
echo "Secret not found in keychain. Initialize lazy-connect and try again."
180+
return 1
181+
fi
182+
175183
vpn_name=$(cat $_lazy_connect_config_dir/vpns \
176184
| fzf --height=10 --ansi --reverse --query "$*" --select-1)
177185
[ -z "$vpn_name" ] || _lazy_connect "$vpn_name" "$secret"

0 commit comments

Comments
 (0)