X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=lib%2FFile%2FKDBX%2FKey%2FYubiKey.pm;h=e86b6e786a5246b3b2d21189f4e7a112312bb16a;hb=0d19b6cdca02d43bb5c6bdf7b2617ae5e54f2953;hp=7a7e23893313d2b4ff184e3df98509f57e8925e7;hpb=f63182fc62b25269b1c38588dca2b3535ed1a1a2;p=chaz%2Fp5-File-KDBX diff --git a/lib/File/KDBX/Key/YubiKey.pm b/lib/File/KDBX/Key/YubiKey.pm index 7a7e238..e86b6e7 100644 --- a/lib/File/KDBX/Key/YubiKey.pm +++ b/lib/File/KDBX/Key/YubiKey.pm @@ -8,6 +8,7 @@ use File::KDBX::Constants qw(:yubikey); use File::KDBX::Error; use File::KDBX::Util qw(pad_pkcs7); use IPC::Open3; +use Ref::Util qw(is_arrayref); use Scope::Guard; use Symbol qw(gensym); use namespace::clean; @@ -38,7 +39,7 @@ sub challenge { $hook->($self, $challenge); } - my @cmd = ($self->ykchalresp, "-n$device", "-$slot", qw{-H -i-}, $timeout == 0 ? '-N' : ()); + my @cmd = ($self->_program('ykchalresp'), "-n$device", "-$slot", qw{-H -i-}, $timeout == 0 ? '-N' : ()); my ($pid, $child_in, $child_out, $child_err) = _run_ykpers(@cmd); push @cleanup, Scope::Guard->new(sub { kill $pid if defined $pid }); @@ -310,7 +311,7 @@ sub _get_yubikey_info { my $self = shift; my $device = shift; - my @cmd = ($self->ykinfo, "-n$device", qw{-a}); + my @cmd = ($self->_program('ykinfo'), "-n$device", qw{-a}); my $try = 0; TRY: @@ -361,12 +362,22 @@ sub _set_yubikey_info { @$self{keys %info} = values %info; } +sub _program { + my $self = shift; + my $name = shift; + my @cmd = $self->$name // $name; + my $name_uc = uc($name); + my $flags = $ENV{"${name_uc}_FLAGS"}; + push @cmd, split(/\h+/, $flags) if $flags; + return @cmd; +} + sub _run_ykpers { my ($child_err, $child_in, $child_out) = (gensym); my $pid = eval { open3($child_in, $child_out, $child_err, @_) }; if (my $err = $@) { throw "Failed to run $_[0] - Make sure you have the YubiKey Personalization Tool (CLI) package installed.\n", - error => $err; + error => $err; } return ($pid, $child_in, $child_out, $child_err); } @@ -436,9 +447,11 @@ See L for more information. =for :list * C - Path to the L program +* C - Extra arguments to the B program * C - Path to the L program +* C - Extra arguments to the B program -C searches for these programs in the same way perl typically searches for executables (using the +B searches for these programs in the same way perl typically searches for executables (using the C 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.