totp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env perl
  2. use 5.040;
  3. use re '/aa';
  4. use FindBin::libs;
  5. use Trog::Auth;
  6. use Trog::Config;
  7. =head1 SYNOPSIS
  8. Print a user's TOTP enrollment details, so that they can set up 2FA without
  9. going through the web UI -- or get back in when they've lost their
  10. authenticator and you need to read them the current code.
  11. =head2 USAGE
  12. bin/totp username
  13. Prints the otpauth:// URI (what a QR code would encode), the base32 secret to
  14. type into an authenticator by hand, and the code which is valid right now.
  15. Note that this hands out everything needed to generate that user's codes
  16. forever, so treat the output like a password.
  17. =head2 CAVEATS
  18. Requires general.hostname to be set in the tCMS configuration, as the domain is
  19. part of what an authenticator shows the user. Set it with bin/tcms-hostname.
  20. =cut
  21. my $user = shift @ARGV;
  22. my $domain = Trog::Config->get()->param('general.hostname');
  23. die "Must provide a user" unless $user;
  24. die "Must Set domain in configuration file" unless $domain;
  25. my ( $uri, $qr, $failure, $message, $totp ) = Trog::Auth::totp( $user, $domain );
  26. print "TOTP URI: $uri\n";
  27. print "Secret: " . $totp->base32secret() . "\n";
  28. print "Current Auth code: " . $totp->expected_totp_code(time) . "\n";