Skip to content

Instantly share code, notes, and snippets.

@sshimko
Last active January 9, 2024 23:25
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sshimko/9e0472f0f0b5d49a8ec19e1d2afb3199 to your computer and use it in GitHub Desktop.
Save sshimko/9e0472f0f0b5d49a8ec19e1d2afb3199 to your computer and use it in GitHub Desktop.
Yubikey + FreeIPA Manual Setup
In Yubikey tool:
1. Click OATH+HOTP tab
2. Click Advanced
3. Deselect token identifier.
4. Press Generate to create a new random seed.
5. Press the Write Configuration button to store the seed on the yubikey
6. Now, we need to convert the 20 byte that the yubi tool needs to the base 32 that FreeIPA (actually otpauth:// URIs need):
6a. Select all of the content the Secret Key field in the yubi app and copy it.
6b. At a command-line, run this replacing the hex string parameter with the hex string you just copied out of the yubi tool. Note: copying and pasting the following into a terminal may result in incorrect quotes being present leading to syntax errors. Check the quotes to ensure the double quotes are simply vertical quotes.
python -c 'import base64 as base64;print(base64.b32encode(base64.b16decode("0a 0b 0c 0d 0e 0f 01 08 0c 04 08 0e 06 0d 06 03 05 01 0b 08".upper().replace(" ",""))).decode("ascii"))'
6c. Have the resulting string output available for the next steps.
In FreeIPA web UI, logged in as an administrator (by default unprivileged users can't do this):
0. Goto -> Authentication -> OTP Tokens. Click Add.
1. Select Counter-Based (HOTP) a unique ID (username-HOTP).
2. In the “Key” field enter the base 32 encoding of the Yubikey tool’s 20 hex byte field (see python command above)
3. Set the appropriate user as the Owner.
4. Optional: save QR code for use in auth app. This isn’t that useful for HOTP, as the yubikey and other device will not have counters in-sync.
5. Click Add.
6. Go to the specified user in IPA GUI and change their User Authentication Type to Two Factor auth. Ensure that Two Factor auth is the only checkbox selected and save the change.
7. Have the user test it.
@sshimko
Copy link
Author

sshimko commented Sep 21, 2018

This gist provides basic guidance in configuring Yubico's Yubikeys for use with FreeIPA and maybe Red Hat's Identity Manager (though I haven't used it).

While there is an IPA plugin for configuring Yubikey's for IPA, it requires the admin to have physical access to the IPA server as the Yubikeys need to be inserted into the IPA host during the provisioning process. Additionally, I was never successful in using USB pass-through with ESXi with the Yubikey's HID features. The instructions in this Gist allow you to configure Yubikeys remotely without physical access.

@CameronNemo
Copy link

Thanks!

@goldyfruit
Copy link

goldyfruit commented Oct 18, 2019

Python command is working only with Python 2.7 not Python 3.x.
And the key is only available as administrator not as a simple user.

Thanks for the guide!!

@sshimko
Copy link
Author

sshimko commented Oct 18, 2019

@goldyfruit thanks. I updated the gist to reflect the need for admin privs and modified the python command to behave the same in both python 2 and 3.

@goldyfruit
Copy link

@goldyfruit thanks. I updated the gist to reflect the need for admin privs and modified the python command to behave the same in both python 2 and 3.

👍

@sshimko
Copy link
Author

sshimko commented Jan 27, 2020

Step six for the yubi tool mentions a 20 byte value and the Secret Key field. There is only one of those :) I will clarify that it is for the personalization tool though because there are a number of tools and it is helpful to know which one is needed.

I did not describe fields whose default values are appropriate, such as the SHA value, as opposed to fields that must be changed from their default value, like the token identifier.

Screenshots like you posted would have been helpful from the outset. I didn't even think about it since I pretty much cope/paste a brain dump from a text file ina git repo ;) I'll have to add some next time I run through the process.

Thanks for the feedback!

@EsWees
Copy link

EsWees commented May 6, 2020

I did a few tests with my YubiKey and OTP. For some reason the OTP is not working for from the HOTP but works with FreeOTP app.
Screenshot from 2020-05-07 00-23-58
Screenshot from 2020-05-06 15-31-00
@sshimko could you please show me what I did wrong?

@sshimko
Copy link
Author

sshimko commented May 6, 2020

@EsWees your moving factor is non-zero. I don't think IPA has a way to set a custom value for the moving factor. Try zero or one and give it another shot.

@EsWees
Copy link

EsWees commented May 7, 2020

@EsWees your moving factor is non-zero. I don't think IPA has a way to set a custom value for the moving factor. Try zero or one and give it another shot.

Thank you alot. It works.
Screenshot from 2020-05-07 11-21-53

@zhanko73
Copy link

zhanko73 commented Jan 9, 2024

For me it keeps asking first then second factor. But this is not the biggest issue. The key generate numbers that are actually keystrokes. If 0 is actually ö (hungarian) character - or anything else you configure for keyboard - then it may not work. I changed back to UK layout but it still not accept the second factor.
Also first slot may have special role so when choosing slot the second is suggested to be selected. As far as I know second slot available for longer touch (1.5-2 secs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment