Securing KeePass databases with OTP codes generated on a Fidesmo device

June 3rd, 2016

Securing your KeePass 2.x password database with OTP codes generated from a seed safely kept on a Fidesmo device is really simple. We do however recommend that you have gone through our instructions on how to use basic OTP functions with your Fidesmo device before trying this. If you feel ready then read on!

Warning

If you lose your Fidesmo device and have not kept a copy of the seed somewhere safe you will no longer be able to access the contents of the database. Be smart; keep a backup.

Prerequisites

  1. KeePass 2.x installed wherever you want. We tested it on Windows 10.
  2. An Android device with Yubico Authenticator installed and a Fidesmo device with OTP installed (or similar setup). As we mentioned above this blog post will get you there.

Setting up OtpKeyProv

  1. Download the KeePass 2.x plugin OtpKeyProv from the plugin list on the KeePass website: http://keepass.info/plugins.html#otpkeyprov
    Download
  2. Find the installation folder of your KeePass 2.x program. For me that was ‘C:\Program Files (x86)\KeePass Password Safe 2’ Create a folder there called Plugins.
    install folder
  3. Unzip the content of the downloaded OtpKeyProv .zip-file into our newly created Plugins folder. (If you ever want to stop using the plugin simply deleting the two files will do that.)

Create master key

To avoid making this blog post too long we’ll simply set up a new database but the option to use the plugin should show up when changing the master key of an existing database as well.

  1. Launch the KeePass 2.x program and choose the option ‘New…’ under ‘File’ in the menu.
    create new database
  2. Next choose a fitting location and name for the database. We’ll just keep it as is for now.
  3. Make sure the master password option is checked and add a password to the field (and repeat it). We’ll just make the password ‘notthatsecure’ for now.
  4. Check the option ‘Key file / provider’ and choose the option ‘One-Time Passwords (OATH HOTP)’ in the picker. See the image below for a closer look.
  5. Press ‘OK’

OneTimePasswordprovider

Configure OTP lock

The next screen ‘Configure OTP lock’ should pop up automatically.

  1. Set ‘length of passwords generated by the token’ to 6. This is always necessary for this to work with Yubico Authenticator.
  2. Set the ‘Secret key’ to ‘abitmoresecurity’ for now. When you actually set this up the key has to conform to the following Base32 requirements plus some random rules:
    1. Only a-z, 2-7 characters are allowed.
    2. ‘=’ is not allowed.
    3. The key length has to be divisible by 8.
  3. Set the secret key picker to ‘Base32’
  4. Set ‘Counter’ to 0. This is the number of generated tokens so far.
  5. Set ‘Number of OTPs required to open the database’ to 3. This is the minimum requirement by OtpKeyProv. Together with a strong master password this should be fine.
  6. Set ‘Look ahead-count’ to 9. This is how far “into the future” KeePass will look for matching OTP codes. 
  7. Make sure it looks the same as below and then press ‘OK’
    configure otp lock
  8. Click OK in the ‘Create new database’ screen that pop ups.
  9. Save the database by pressing Ctrl + S or the save icon.
  10. Exit KeePass.

Generating codes on Android

  1. Launch the Yubikey Authenticator app on your Android device.
  2. Press the menu button in the top right corner and choose the option ‘Add account manually’
    Screenshot_20160603-011524
  3. Enter ‘KeePass code test’ in the credential name field
  4. Enter the same secret key as before, which in this case was ‘abitmoresecurity’ into the field ‘Enter secret key’
  5. Choose ‘Counter based (HOTP)’ in the picker.
  6. Ensure that everything looks similar to the below picture and press add.
    Screenshot_20160603-012010
  7. Tap your Fidesmo device to save the seed.

Using OtpKeyProv

  1. Open the keystore database that we saved before.
  2. Enter our ‘Master Password’ ‘notthatsecure’
  3. Make sure that the ‘Key file’ option is picked and ‘One-Time Passwords (OATH HOTP)’ is selected.
    logging in
  4. Press ‘OK’
  5. A window that allows you to enter three OTP codes should show up. Fill the three fields with the codes generated by pressing the refresh button in Yubico Authenticator and tapping the Fidesmo device.
    Screenshot_20160603-013734 
  6. When you are done it should look like below. Press ‘OK’
    Enter OTPs
  7. If everything worked out you should now have access to your database! If it didn’t work the first time you have two more tries because we set the ‘Look-ahead count’ to 9. Just make sure to replace all three codes with new ones, because the old ones are already used.

Good to know

The seed is what is important

If somebody had/has access to the seed all is lost. They can always create the same OTP codes as you can as well as use the recovery feature. Don’t set this up in a public setting like a café or on the subway.

HOTP

The codes differ from the TOTP codes that we used in the first tutorial. The codes that KeePass supports are HOTP codes. One part of HOTP codes is a counter which has to match between the place where you generate the code and the place you are trying to use the code. This means that if you are out of sync with OtpKeyProv because you just had to show of the code generation a couple of times to your best buddies you might be locked out. Use the recovery feature to get access again.

Recovery

If you are locked out you can use the recovery feature in OtpKeyProv that is available in the same window where you input generated OTP codes. This requires you to input the seed which is why you should keep it around but in a safe place. As it is counter based you probably will be locked out sooner or later. Again: Be smart; keep a backup.

Inspiration

This is nothing new but the information that was available was lacking in many ways. Therefore we wrote this blog post. The inspiration came from @jdsmithies on twitter asking us:

While looking around for an answer the plugin OtpKeyProv showed up. The following tutorials and discussions were used as base for the post:

https://sourceforge.net/p/keepass/discussion/329220/thread/be102635/#e37a
http://mx.thirdvisit.co.uk/2014/01/02/getting-the-otpkeyprov-hotp-plug-in-to-work-with-google-authenitcator/
https://www.yubico.com/why-yubico/for-individuals/password-managers/keepass/

A huge thanks to them and as well as the developers of KeePass, OtpKeyProv and Yubico Authenticator for making this possible! If we missed something important or have misunderstood something please do tell us on Twitter @fidesmo or via email info@fidesmo.com

Thanks for reading and see you next time!