I'm using OpenVPN's "auth-user-pass-verify" executable call-out, which forces the OpenVPN client to prompt for a user/password which is verified on the OpenVPN server side. I use this callout in combination with the "ykclient" that comes with the libyubikey-client-1.1 package. (You could also use the other clients, as well.)
First, I had to modify the code for ykclient. As of version 1.1, the last three code lines in ykclient.c look like this:
Code:
ret = yubikey_client_simple_request (token, atoi (client_id), 0, NULL);
printf ("Verification output (%d): %s\n", ret, yubikey_client_strerror (ret));
return EXIT_FAILURE;
I recommend modifying the final line to this:
Code:
return ret;
...which appears to return a zero (0) value upon success, and non-zero for failure.
After compiling ykclient and putting it into /usr/local/bin, I wrote the following script called /usr/local/bin/openvpn-yubikey-verify:
Code:
#!/bin/sh
CLIENT_ID=###
/usr/local/bin/ykclient ${CLIENT_ID} "${password}"
exit $?
(Be sure to replace ### with your Yubico client ID.)
Next, I added this line to openvpn.conf on the server:
Code:
auth-user-pass-verify /usr/local/bin/openvpn-yubikey-verify via-env
And finally, I added this line to openvpn.conf on the client:
Code:
auth-user-pass
A restart of both the OpenVPN client and server is required.
This code will "get you going," but it's recommended that a more robust script be used to check for proper usernames (the above example ignores the ${username} variable entirely) and bounds-check the password (perhaps using a filter to consider only ModHex characters).
Be sure to use proper permissions to secure all of your files.