Skip to content

Suport hardware keys #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
-h - Show this help
```

### YubiKey Support

#### Prerequisite

1. [yubikey-manager](https://github.com/Yubico/yubikey-manager)

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

```sh
export LAZY_CONNECT_TOTP_GENERATOR=yubikey
export LAZY_CONNECT_TOTP_QUERY=<name of the issuer>
```

### Warning

- The secret key to generate TOTP is stored as plain text in `~/.config/lazy-connect/secret`
Expand Down
52 changes: 46 additions & 6 deletions lazy-connect.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#!/bin/bash

TOTP_MODE=${LAZY_CONNECT_TOTP_GENERATOR:-oathtool}

_lazy_connect_config_dir=~/.config/lazy-connect
_lazy_connect_project_dir=~/.lazy-connect

function _lazy_connect_init() {
echo -n "Secret Key: "
read -s secret_key
echo "**********"
echo $secret_key > $_lazy_connect_config_dir/secret
case $TOTP_MODE in
oathtool)
echo -n "Secret Key: "
read -s secret_key
echo "**********"
echo $secret_key >$_lazy_connect_config_dir/secret
;;
esac
_lazy_connect_vpn_refresh
}

Expand Down Expand Up @@ -60,10 +66,44 @@ lazy-connect - Shell function to fuzzy search an IPSec VPN by name
EOF
}

function _lazy_connect_get_totp() {
secret_key=$1
case $TOTP_MODE in
oathtool)
password=$(oathtool --totp --base32 $secret_key)
return 0
;;
yubikey)
if ! [ -x "$(command -v ykman)" ]; then
echo 'Error: ykman tool not installed.' >&2
exit 1
fi
if [ -z "$LAZY_CONNECT_TOTP_QUERY" ]; then
echo "Error: LAZY_CONNECT_TOTP_QUERY not set"
exit 1
else
password=$(ykman oath code $LAZY_CONNECT_TOTP_QUERY 2>/dev/null | awk '{print $2}')
fi
;;
esac
}

function _lazy_connect() {
vpn_name=$1
secret_key=$2
password=$(oathtool --totp --base32 $secret_key)
_lazy_connect_get_totp $2

if [ -z "$password" ]; then
case $TOTP_MODE in
oathtool)
echo "Error: Unable to generate otp using oathtool"
return 1
;;
yubikey)
echo "Error: No YubiKey found"
return 1
;;
esac
fi

osascript <<EOF
on connectVpn(vpnName, password)
Expand Down