Rubikey is another Ruby (2.1+) library for decoding, decrypting, parsing, and verifying YubiKey OTPs against Yubico Validation Protocol Version 2.0.
Add this line to your application's Gemfile:
gem 'rubikey', git: '[email protected]:sigfrid/rubikey.git'
And then execute:
$ bundle
Once you have instantiated a Rubikey::OTP object by passing to it your otp, you can get the YubiKey configuration by calling config
and passing to it your Yubikey secret_key
.
It returns a Rubikey::KeyConfig object that provides:
- public_id: Yubikey identifier.
- secret_it: hexadecimal identifier that is encrypted in OTP.
- insert_counter: integer that represents how many time the YubiKey has been plugged in a device.
unique_passcode = 'ccccccbtcvvhkbkvkdrbbjjlkvgvtvrvibekdcentbti'
secret_key = 'ecde18dbe76fbd0c33330f1c354871db'
opt = Rubikey::OTP.new(unique_passcode)
keyconfig = opt.config(secret_key) #=> Rubikey::KeyConfig
keyconfig.public_id #=> 'ccccccbtcvvh'
keyconfig.secret_id #=> '8792ebfe26cc'
keyconfig.insert_counter #=> 1
Once you have instantiated a Rubikey::OTP object by passing to it your otp, you can validate it by calling authenticate
and passing to it your Yubikey api_id
and api_key
.
If you use YubiCloud you can get your API id and key at yubico.com/getapykey
It returns a Rubikey::ApiAuthentication object that provides:
- status: Authentication outcome.
unique_passcode = 'ccccccbtcvvhkbkvkdrbbjjlkvgvtvrvibekdcentbti'
api_id = 1234
api_key = 'n2AS3oMbInqZ7BbxN/vrFayYUaQ='
opt = Rubikey::OTP.new(unique_passcode)
authentication = opt.authenticate(api_id: api_id, api_key: api_key) #=> Rubikey::ApiAuthentication
authentication.status #=> THE STATUS
Refer to Yubico Validation Protocol Version 2.0 documentation for all the possible statuses and their meanings.
Rubikey is specified with RSpec.
To successfully run the specs you must first add spec/authentication_fixtures.yml
with the following:
api_id: 'YOUR YUBIKEY API ID'
api_key: 'YOUR YUBIKEY API KEY '
unique_passcode: 'A NEVER USED YUBIKEY OTP'
The gem uses semantic versioning.
Teh gem has been inspired by yubikey
- Fork it ( http://github.com//rubikey/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request