| 1 | package OpenID::Lite::Nonce; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use String::Random; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use POSIX; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Time::Local; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | my $SKEW = 60 * 60 * 5; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 10 | ▶ | sub gen_nonce { | ||||||||||||||||||||||||||
|
Subroutine
gen_nonce: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 10 | my $class = shift; | |||||||||||||||||||||||||||
| 14 | 10 | my $t = shift; | |||||||||||||||||||||||||||
| 15 | 10 | ▶ | $t = time() unless defined $t; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 10 | my $time = POSIX::strftime( q{%FT%TZ}, gmtime($t) ); | |||||||||||||||||||||||||||
| 17 | 10 | my $random = String::Random->new; | |||||||||||||||||||||||||||
| 18 | 10 | my $salt = $random->randregex('[a-zA-Z0-9]{6}'); | |||||||||||||||||||||||||||
| 19 | 10 | return $time . $salt; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 30 | ▶ | sub split_nonce { | ||||||||||||||||||||||||||
|
Subroutine
split_nonce: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 30 | my $class = shift; | |||||||||||||||||||||||||||
| 24 | 30 | my $nonce = shift; | |||||||||||||||||||||||||||
| 25 | 30 | my $pos = length(q{0000-00-00T00:00:00Z}); | |||||||||||||||||||||||||||
| 26 | 30 | my $timestamp = substr( $nonce, 0, $pos ); | |||||||||||||||||||||||||||
| 27 | 30 | ▶ | return if length($timestamp) < $pos; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 27 | ▶ | return unless $timestamp =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 24 | my $time; | |||||||||||||||||||||||||||
| 30 | 24 | eval { $time = Time::Local::timegm($6, $5, $4, $3, $2 - 1, $1); }; | |||||||||||||||||||||||||||
| 31 | 24 | ▶ | if ($@) { return; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 23 | my $rest = substr( $nonce, $pos ); | |||||||||||||||||||||||||||
| 33 | 23 | return ( $time, $rest ); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 27 | ▶ | sub skew { | ||||||||||||||||||||||||||
|
Subroutine
skew: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 37 | 27 | my ( $class, $new_skew ) = @_; | |||||||||||||||||||||||||||
| 38 | 27 | ▶ | $SKEW = $new_skew if $new_skew; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 27 | return $SKEW; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 8 | ▶ | sub check_timestamp { | ||||||||||||||||||||||||||
|
Subroutine
check_timestamp: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 43 | 8 | my ( $class, $nonce_str, $allowed_skew, $now ) = @_; | |||||||||||||||||||||||||||
| 44 | 8 | ▶ | $allowed_skew = $class->skew() unless defined $allowed_skew; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 8 | ▶ | $now = time() unless defined $now; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 8 | ▶ | my ( $stamp, $foo ) = $class->split_nonce($nonce_str) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | or return 0; | ||||||||||||||||||||||||||||
| 48 | 7 | my $past = $now - $allowed_skew; | |||||||||||||||||||||||||||
| 49 | 7 | my $future = $now + $allowed_skew; | |||||||||||||||||||||||||||
| 50 | 7 | ▶ | return ( $past <= $stamp && $stamp <= $future ) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$past <= $stamp and $stamp <= $future
MC/DC100%2/2
$past <= $stamp and $stamp <= $future
$past <= $stamp
$stamp <= $future
Truth table100%3/3
A and B
A= $past <= $stampB= $stamp <= $future
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | 1; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||