# Copyright (c) 2007-2008 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: OTP.pm,v 1.7 2008/01/30 22:18:21 nagler Exp $ package Bivio::Util::OTP; use strict; use Bivio::Base 'Bivio::ShellUtil'; use Bivio::Biz::RFC2289; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.7 $ =~ /\d+/g); sub NULL_PASSPHRASE { return 'NULL_PASSPHRASE'; } sub USAGE { return <<'EOF'; usage: b-otp [options] command [args...] commands: hex_key [sequence_number seed [passphrase]] -- returns one time password in hex reset_user [sequence_number seed [passphrase]] -- reset auth_user's OTP record six_word_key [sequence_number seed [passphrase]] -- returns in six word format EOF } sub hex_key { my($self, @args) = _args(@_); $args[2] = '' if $args[2] eq $self->NULL_PASSPHRASE; return Bivio::Biz::RFC2289->compute(@args); } sub reset_user { my($self, $seq, $seed, $pass) = _args(@_); my($res) = Bivio::Biz::RFC2289->compute($seq + 1, $seed, $pass); $self->model('OTP')->reset_auth_user({ otp_md5 => $res, sequence => $seq, seed => $seed, }); return $res; } sub six_word_key { return Bivio::Biz::RFC2289->to_six_word_format(shift->hex_key(@_)); } sub _args { my($self) = shift; my($seq) = 1; return $self->name_args([ [sequence => OTPSequence => sub { $seq = 0; return $self->model('OTP')->get_field_type('sequence')->get_max; }], [qw(seed OTPSeed yourseed)], [passphrase => OTPPassphrase => sub { return $seq ? shift->use('Bivio::IO::TTY')->read_password('Passphrase: ') : shift->use('ShellUtil.SQL')->TEST_PASSWORD; }], ], \@_); } 1;