File::KDBX::Key::YubiKey(3pm) | User Contributed Perl Documentation | File::KDBX::Key::YubiKey(3pm) |
File::KDBX::Key::YubiKey - A Yubico challenge-response key
version 0.906
use File::KDBX::Key::YubiKey; use File::KDBX; my $yubikey = File::KDBX::Key::YubiKey->new(%attributes); my $kdbx = File::KDBX->load_file('database.kdbx', $yubikey); # OR my $kdbx = File::KDBX->load_file('database.kdbx', ['password', $yubikey]); # Scan for USB YubiKeys: my ($first_key, @other_keys) = File::KDBX::Key::YubiKey->scan; my $response = $first_key->challenge('hello');
A File::KDBX::Key::YubiKey is a type of challenge-response key. This module follows the KeePassXC-style challenge-response implementation, so this might not work at all with incompatible challenge-response implementations (e.g. KeeChallenge).
Inherets methods and attributes from File::KDBX::Key::ChallengeResponse.
To use this type of key to secure a File::KDBX database, you also need to install the YubiKey Personalization Tool (CLI) <https://developers.yubico.com/yubikey-personalization/> and configure at least one of the slots on your YubiKey for HMAC-SHA1 challenge response mode. You can use the YubiKey Personalization Tool GUI to do this.
See <https://keepassxc.org/docs/#faq-yubikey-howto> for more information.
$device = $key->device($device);
Get or set the device number, which is the index number starting and incrementing from zero assigned to the YubiKey device. If there is only one detected YubiKey device, its number is 0.
Defaults to 0.
$slot = $key->slot($slot);
Get or set the slot number, which is a number starting and incrementing from one. A YubiKey can have multiple slots (often just two) which can be independently configured.
Defaults to 1.
$timeout = $key->timeout($timeout);
Get or set the timeout, in seconds. If the challenge takes longer than this, the challenge will be cancelled and an error is thrown.
If the timeout is zero, the challenge is non-blocking; an error is thrown if the challenge would block. If the timeout is negative, timeout is disabled and the challenge will block forever or until a response is received.
Defaults to 0.
$callback = $key->pre_challenge($callback);
Get or set a callback function that will be called immediately before any challenge is issued. This might be used to prompt the user so they are aware that they are expected to interact with their YubiKey.
$key->pre_challenge(sub { my ($key, $challenge) = @_; if ($key->requires_interaction) { say 'Please touch your key device to proceed with decrypting your KDBX file.'; } say 'Key: ', $key->name; if (0 < $key->timeout) { say 'Key access request expires: ' . localtime(time + $key->timeout); } });
You can throw from this subroutine to abort the challenge. If the challenge is part of loading or dumping a KDBX database, the entire load/dump will be aborted.
$callback = $key->post_challenge($callback);
Get or set a callback function that will be called immediately after a challenge response has been received.
You can throw from this subroutine to abort the challenge. If the challenge is part of loading or dumping a KDBX database, the entire load/dump will be aborted.
$program = $key->ykchalresp;
Get or set the ykchalresp(1) program name or filepath. Defaults to $ENV{YKCHALRESP} or "ykchalresp".
$program = $key->ykinfo;
Get or set the ykinfo(1) program name or filepath. Defaults to $ENV{YKINFO} or "ykinfo".
@keys = File::KDBX::Key::YubiKey->scan(%options);
Find connected, configured YubiKeys that are capable of responding to a challenge. This can take several seconds.
Options:
Other options are passed as-is as attributes to the key constructors of found keys (if any).
Get the device serial number, as a number, or "undef" if there is no such device.
Get the device firmware version (or "undef").
Get the "touch level" value for the device associated with this key (or "undef").
Get the vendor ID or product ID for the device associated with this key (or "undef").
$name = $key->name;
Get a human-readable string identifying the YubiKey (or "undef").
Get whether or not the key requires interaction (e.g. a touch) to provide a challenge response (or "undef").
YubiKey searches for these programs in the same way perl typically searches for executables (using the "PATH" environment variable on many platforms). If the programs aren't installed normally, or if you want to override the default programs, these environment variables can be used.
This doesn't work yet on Windows, probably. The hangup is pretty silly: IPC. Theoretically it would work if "run_forked" from IPC::Cmd worked in Windows, but it probably doesn't. I spent a couple hours applying various quirks to IPC::Open3 and IPC::Cmd implementations but never quite got it to worked reliably without deadlocks. Maybe I'll revisit this later. Hit me up so I know if there's interest.
It would also be possible to implement this as an XS module that incorporated ykcore, using libusb-1 which would probably make it more portable with Windows. Perhaps if I get around to it.
Please report any bugs or feature requests on the bugtracker website <https://github.com/chazmcgarvey/File-KDBX/issues>
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
Charles McGarvey <ccm@cpan.org>
This software is copyright (c) 2022 by Charles McGarvey.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2022-11-20 | perl v5.36.0 |