65

How do YubiKeys work? Are there any alternatives?

Here is a picture of one: yubikey

mentallurg
  • 8,536
  • 4
  • 26
  • 41
Gabriel Fair
  • 1,495
  • 2
  • 13
  • 23

5 Answers5

47

As I understand it, Yubikey acts like a USB keyboard. You plug it in your computer, place the cursor in a form field, press the button on the Yubikey, and it sends out a text string of 44 characters to the computer like you are typing those 44 characters. The computer doesn't know the difference between you typing it or the Yubikey generating it.

A website like a Wordpress site with Yubikey plugin, or the Lastpass addon in Firefox, or any other website that has a Yubikey option, has a login form with username, password, and Yubikey password. You enter your username and password, place the cursor in the Yubikey field, then press the Yubikey button, and it enters the Yubikey password into the field.

Then the form is submitted, and the Yubikey is validated in the Yubicloud. The website checks if the entered Yubikey password is valid. The Yubikey itself does not connect to the Yubicloud. It's just a device generating a string sending it out acting like a keyboard, and it does not connect to the internet or anything except as that keyboard.

Before all this works, you need to update your account on the website to use Yubikey. That means you need to link your key to the account. That way the Yubicloud can check the generated code and validate it against your account.

The website of course needs to implement the Yubikey functionality, which is available as a free service for website owners.

If the Yubikey gets lost, you can use the normal recovery methods the website has to recover your account and disable the Yubikey. Normally this means that you get a password recovery link via email, and that link disables the Yubikey function in your account.

I mailed Yubikey support to see if this answer is correct. They said this explanation was correct, except that it explained only one part of the way the key works.

The other answers here don't give any real explanation. Even the Linuxjournal article doesn't explain it this way. The accepted answer gives a black-box answer - not what I was looking for when I opened this page. I hope this answer gives a better explanation and writing it made me understand the Yubikey better.

SPRBRN
  • 7,379
  • 6
  • 33
  • 37
  • Awesome, thank you. Do you know how it generates the code, and how the Ubicloud validates it? – vcardillo Jan 06 '17 at 22:25
  • I don't know, but this is a good guess. You create or update your account on the website. When the submit button is pushed, the website contacts the Ubicloud. It sends the string you just entered, maybe along with a (by the website generated) identification string. The Ubicloud then registers this somehow and gives the website a reply (or maybe another code) saying all is OK. Next time when the user logs in, it contacts the Ubicloud again, using the given IDs, and the Ubicloud replies that used key is linked to this account or not. – SPRBRN Sep 18 '17 at 15:36
  • While this answer certainly touches on one specific aspect of the Yubikeys: U2F, it completely misses the other relevant functions a Yubikey also offers. It's being used as a HID device because generally posing as a HID device means no extra drivers are required for the device to interact with the OS. – 0xC0000022L Feb 13 '21 at 21:45
20

I have one, and I'd recommend them! I actually got it for free from the Yubico guys, when I was attending BSidesLondon.

Think of it as an RSA secure-key, except much smaller, cheaper and without a battery. You get (essentially) the same security, though YubiKeys have a signficantly larger keyspace than the RSA ones. They're also incredibly sturdy, and can be fully immersed in water without damage.

Here's mine:

YubiKey

I know this sounds like an advert, but they really are great. Compared to carrying around a bunch of those secure-keys, they're almost unnoticeable on a keyring.

As for how they work, they validate against a cloud service that Yubico run, and provide two-factor authentication. All the server software is open-source, and they're happy for you to run your own authentication servers. It's entirely transparent.

Have a dig around on their website, there's plenty of technical info and descriptions on there.

Polynomial
  • 132,208
  • 43
  • 298
  • 379
  • 1
    Is a subscription service required? Does one have to pay a monthly fee? – Gabriel Fair Jul 31 '12 at 18:00
  • 3
    @GabrielFair Nope, it's free. From their website: *"Provided with free hosted validation service, YubiCloud"* – Polynomial Aug 01 '12 at 08:18
  • 1
    Since you mention "Think of it as an RSA secure-key", one important difference to be aware of is the fact that it uses the symmetrical AES encryption, so _theoretically_ someone stealing their HSM (without being detected) could obtain your key and claim being you, which an asymmetric encryption like RSA would _not_ permit due to the server then only storing a public key... – Tobias Kienzler Sep 04 '13 at 14:25
  • How is this better than a USB key with a keyfile? If a Yubikey gets stolen, then the attacker can still use it. – Celeritas Dec 13 '15 at 02:43
  • 1
    @Celeritas Malware or exploitation of the system cannot trivially "trick" the YubiKey into giving up its password, as you need to press the physical button to type it. A value on a USB stick can just be read off. – Polynomial Dec 14 '15 at 20:21
  • Ya but you don't necessarily know a file is a keyfile on a USB stick or what password/username it goes with. Could you elaborate on this attack vector about how USB sticks are easy to read so that would compromise the key file? – Celeritas Dec 15 '15 at 02:40
  • @Celeritas Many RATs allow an attacker to browse the filesystem manually. Others will just dump removable drive contents for common document types (txt, doc, xls, docx, xlsx, mdb, etc.) and send them off to the C&C. You also have to keep in mind that the YubiKey offers CHAP-style authentication for 2FA, rather than just static-key auth, which is entirely superior to saving a password to a USB stick. – Polynomial Dec 15 '15 at 12:18
  • And the round contact on it is for Nuke or Nurse? Or what? – ott-- Jan 09 '16 at 21:51
  • @ott The round contact is for you to press. It's what triggers it to type its stored data. – Polynomial Jan 12 '16 at 11:05
19

The YubiKey comes in different variants, for example the YubiKey 4 and the YubiKey U2F. All YubiKeys are hardware tokens and are connected to a USB port. Most feature an inductive button and one model also has NFC (the YubiKey Neo). The variants differ regarding form factor and the number of supported features.

The YubiKey 4 provides several functions:

  • OTP generation
  • OATH compatible OTP generation (i.e. HOTP and TOTP)
  • emulate a chipcard reader with inserted OpenPGP chipcard (up to 4K bit RSA or 256 bit ECC private key size)
  • act as PIV device (up to 2K bit RSA or 256 bit ECC private key size)
  • act as U2F device
  • replay a static password

For some of its features it presents itself as a USB HID device.

There are alternative solutions available that provide similar or a subset of the multi-feature YubiKey 4. For example, classic hardware chipcard readers (perhaps even featuring a keypad) in combination with an OpenPGP compatible chipcard.

The YubiKey U2F is only a U2F device, i.e. a device that is able to generate a origin specific public/private key pair and returns a key handle and a public key to the caller. Like other inexpensive U2F devices, the private keys are not stored, instead they are symmetrically encrypted (with an internal key) and returned as the key handle. Using the key-handle, the U2f device is then able to sign a challenge, thus creating a response as part of a multi factor authentication.

Since U2F is an open standard (that is also pushed by corporations like Google), there are several alternative inexpensive U2F hardware tokens available (search for 'FIDO U2F key').

maxschlepzig
  • 550
  • 4
  • 10
  • 4
    FYI: The OpenPGP implementation on the Yubikey 4 [is not Open Source](https://github.com/Yubico/ykneo-openpgp/issues/2#issuecomment-218446368) - this is a significant departure from previous Yubikey NEO devices. – Jonathan Cross May 11 '16 at 13:02
  • @JonathanCross That's a pity. Also something worth knowing: Newer Yubikey NEOs can apparently no longer be customized with own applets unless one specifically orders a developer edition (which I didn't find anywhere) – Tobias Kienzler Nov 30 '16 at 08:07
11

Have a look over here http://www.linuxjournal.com/magazine/yubikey-one-time-password-authentication

The following outtake is written by Dirk Merkel, author of the previously linked article:

Each time you press the button on the device, it generates a one-time password and sends it to the host machine as if you had entered it on a keyboard. This password then can be used by the service to authenticate you as a user.

I suggest you read through the 5 page article as this is too much to take over here.

Lucas Kauffman
  • 54,169
  • 17
  • 112
  • 196
  • 21
    My edit was [rejected](http://security.stackexchange.com/review/suggested-edits/66637) by Lucas Kauffman with 'This edit does not make the post even a little bit easier to read, easier to find, more accurate or more accessible. Changes are either completely superfluous or actively harm readability.' - although it removes several errors and improves the layout. Most importantly, it fixes the name of the referenced author. The name currently contains two spelling errors: 'Drik Mekel' should read 'Dirk Merkel'. – maxschlepzig Jan 01 '16 at 16:43
2

From what I understand, the one-time password is made up of several different pieces of information, such as a timestamp (how long the key has been in your computer), a Yubikey session stamp (how many times you plugged it into your computer), a randomized special code, a stamp for how may times you have generated a password etc. then it encrypts it. Then it slaps on a special code assigned to that specific Yubikey, of which it encrypts again. Then it gets sent to Yubikey themselves (because they know all the special codes), and they verify that your key is correct and whatever. Then it tells whoever you are trying to sign into, like Google, that you are the right person, then Google lets you in.

There are other features like it just saves a string or password on the device and when you click it gives a password. Pretty straight forward.

schroeder
  • 123,438
  • 55
  • 284
  • 319
  • Welcome to Security StackExchange. This answer really doesn't provide more details than the other answers, and lacks the source data to explain what is actually going on like the other answers. Did you intend to say something different from the other answers? – schroeder Mar 06 '17 at 07:51
  • I'm also not sure about your claim about what the timestamp is (it's UTC, not "how long the key was inserted": https://developers.yubico.com/yubikey-val/Validation_Protocol_V2.0.html) – schroeder Mar 06 '17 at 07:55