]> git.proxmox.com Git - pve-access-control.git/commitdiff
oathkeygen: modernize and improve error handling slightly
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 21 May 2023 10:34:19 +0000 (12:34 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 21 May 2023 10:37:11 +0000 (12:37 +0200)
Note that this could also just be documented doing:

 dd if=/dev/urandom bs=1 count=10 2>/dev/null | base32

And using TOTP apps that can scan QR codes is much better UX anyway,
but its to trivial to bother deprecating it now and we'd still depend
on libmime-base32-perl, so really nothing gained in removing or
rewriting in shell..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/oathkeygen

index 574b0c715882051b6e6e0afcc6754bfd58a6e365..fa73f05c72dd05a1cafc74edba2b7a6925e0df50 100755 (executable)
@@ -2,10 +2,13 @@
 
 use strict;
 use warnings;
-use MIME::Base32; #libmime-base32-perl
 
-my $test;
-open(my $RND_FH, '<', "/dev/urandom");
-sysread($RND_FH, $test, 10) == 10 || die "read random data failed - $!\n";
-print MIME::Base32::encode_rfc3548($test) . "\n";
+use MIME::Base32; # libmime-base32-perl
 
+open(my $RND_FH, '<', "/dev/urandom") or die "Unable to open '/dev/urandom' - $!";
+sysread($RND_FH, my $random_data, 10) == 10 or die "read random data failed - $!\n";
+close $RND_FH or warn "Unable to close '/dev/urandom' - $!";
+
+print MIME::Base32::encode_rfc3548($random_data) . "\n";
+
+exit(0);