commit 1c1024dade63180dfb0dae96d26f9dbd7c62bb8c Author: Alexandre Dulaunoy Date: Sun Jun 6 19:24:09 2010 +0200 First version of paper token - an application to make paper-based HOTP tokens. diff --git a/README.md b/README.md new file mode 100644 index 0000000..68b67fc --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +paper token +=========== + +paper token is a PDF generator to create paper-based OTP token. + +perl requirements +----------------- + +* Authen::HOTP +* PDF::API2 +* PDF::Table +* Getopt::Compact + +how to use it +============= + +perl paper-token.pl --output test.pdf --counter 0 --end 200 --secret 3132333435363738393031323334353637383930 --digits 6 + +OpenOTP server installation +=========================== + +* For more information - http://www.foo.be/cgi-bin/wiki.pl/SettingOOTP + +LICENSE +======= + +Copyright (C) 2010 Alexandre Dulaunoy, http://www.foo.be/ + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program 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 General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + diff --git a/examples/test.pdf b/examples/test.pdf new file mode 100644 index 0000000..08b1430 Binary files /dev/null and b/examples/test.pdf differ diff --git a/paper-token.pl b/paper-token.pl new file mode 100644 index 0000000..ad45444 --- /dev/null +++ b/paper-token.pl @@ -0,0 +1,152 @@ +#!/usr/bin/perl -w +# +# paper token is a software to generate paper-based OTP +# +# Copyright (C) 2010 Alexandre Dulaunoy, http://www.foo.be/ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. + +# You should have received a copy of the GNU General Public License + +use Authen::HOTP qw(hotp); +use PDF::API2; +use PDF::Table; +use Data::Dumper; +use Getopt::Compact; + +# default value is the test vector from RFC 4226 +my $secret = "3132333435363738393031323334353637383930"; + +# starting counter +my $counter = 0; + +# ending counter +my $end = 500; + +my $digits = 6; +my @tokentable = []; + +# window value (shown on one line and window of accepted token) +my $window = 14; + +my $when = localtime(); + +my $opt = new Getopt::Compact( + name => 'paper token - http://www.foo.be/paper-token/', + modes => '', + version => '0.1', + struct => [ + [ + [qw(s secret)], +qq(secret of the token in hex format - default is RFC 4226 test vector), + ':s' + ], + [ [qw(o output)], qq(output filename), ':s' ], + [ [qw(c counter)], qq(starting counter - default is 0), ':i' ], + [ [qw(e end)], qq(ending counter - default is 500), ':i' ], + [ + [qw(w window)], + qq(window of authentication (one line) - default is 14), ':i' + ], + [ + [qw(d digits)], + qq(digits showed per OTP value - default is 6 - dec31.6), ':i' + ], + ] +); + +my $opts = $opt->opts; + +if ( !( defined( $opts->{output} ) ) ) { + print $opt->usage; + exit(); +} + +if ( defined( $opts->{counter} ) ) { + $counter = $opts->{counter}; +} + +if ( defined( $opts->{end} ) ) { + $end = $opts->{end}; +} + +if ( defined( $opts->{window} ) ) { + $window = $opts->{window}; +} + +if ( defined( $opts->{secret} ) ) { + $secret = $opts->{secret}; +} + +my $sn = substr( $secret, 0, 10 ); + +if ( defined( $opts->{digits} ) ) { + $digits = $opts->{digits}; +} + +for ( $count = $counter ; $count < $counter + $end ; $count = $count + $window ) +{ + my @tj; + for ( $j = $count ; $j < $count + $window ; $j = $j + 1 ) { + my $pass = hotp( $secret, $j, $digits ); + push( @tj, "$pass" ); + } + @val = ["@tj"]; + push( @{ $tokentable[0] }, @val ); +} + +my $pdftable = new PDF::Table; +my $pdf = new PDF::API2( -file => $opts->{output} ); +my $page = $pdf->page; +my $gfx = $page->gfx; + +my $tokeninfo = "Paper token for HOTP token S/N : " . $sn; +my $tokenhowto = +"How to use? Read from left to right and when you use a token, strikethrough the used value."; +my $tokenadv = + "Generated by paper token - http://www.foo.be/paper-token/ at " . $when; + +$pdf->info( + 'Author' => "Alexandre Dulaunoy - http://www.foo.be/", + 'Creator' => "Paper Token - http://www.foo.be/paper-token/", + 'Producer' => "PDF::API2", + 'Title' => $tokeninfo, +); + +$fnt = $pdf->corefont('Helvetica-Bold'); +$fntlow = $pdf->corefont('Helvetica'); + +$gfx->textlabel( 10, 750, $fnt, 11, $tokeninfo ); +$gfx->textlabel( 10, 739, $fntlow, 11, $tokenhowto ); +$gfx->textlabel( 10, 728, $fntlow, 11, $tokenadv ); + +$pdftable->table( + $pdf, + $page, + @tokentable, + -x => 1, + -w => 40, + -start_y => 700, + -next_y => 700, + -start_h => 700, + -next_h => 700, + -w => 600, + -padding => 2, + -padding_right => 1, + -background_color_odd => "lightgray", + -background_color_even => "gray", + font => $pdf->corefont( "Helvetica", -encoding => "utf8" ), + font_size => 11, + border => 0 +); + +$pdf->save(); +