| 1 | package OpenID::Lite::Provider::AssociationBuilder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Any::Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Digest::SHA; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use String::Random; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use OpenID::Lite::Association; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use OpenID::Lite::SignatureMethods; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | with 'OpenID::Lite::Role::ErrorHandler'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | has 'server_secret' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | default => q{secret}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | has 'secret_lifetime' => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | default => 86400, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | #has 'secret_gen_interval' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # default => 86400, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | #); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | #has 'get_server_secret' => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # isa => 'CodeRef', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # my $sec_time = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # my $secret = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # return $secret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | #); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 12 | ▶ | sub build_association { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_association: called CC=6 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 12 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 12 | my $type = $opts{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 12 | ▶ | my $dumb = $opts{dumb} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts{'dumb'} || 0
MC/DC100%1/1
$opts{'dumb'} || 0
$opts{'dumb'}
Truth table100%2/2
A
A= $opts{'dumb'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 12 | ▶ | my $lifetime = $opts{lifetime} || $self->secret_lifetime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts{'lifetime'} || $self->secret_lifetime
MC/DC0%0/2
$opts{'lifetime'} || $self->secret_lifetime
$opts{'lifetime'}
$self->secret_lifetime
Truth table33%1/3
A || B
A= $opts{'lifetime'}B= $self->secret_lifetime
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 12 | ▶ | my $signature_method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | = OpenID::Lite::SignatureMethods->select_method($type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | or return $self->ERROR( sprintf q{Invalid assoc_type "%s"}, $type ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 12 | my $now = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | #my $sec_time = $now - ( $now % $self->secret_gen_interval ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | #my $s_sec = $self->get_server_secret->($sec_time) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # || $self->server_secret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | my $s_sec = $self->server_secret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 12 | my $random = String::Random->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 12 | my $nonce = $random->randregex( sprintf '[a-zA-Z0-9]{%d}', 20 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | $nonce = sprintf( q{STLS.%s}, $nonce ) if $dumb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | my $handle = sprintf( q{%d:%s:%s}, $now, $type, $nonce ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 12 | $handle | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | .= ":" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | . substr( $signature_method->hmac_hash_hex( $handle, $s_sec ), 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 10 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 12 | ▶ | my $c_sec = $self->secret_of_handle( $handle, $dumb, 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 12 | my $assoc = OpenID::Lite::Association->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | secret => $c_sec, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | handle => $handle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | expires_in => $lifetime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | issued => $now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 12 | return $assoc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | ▶ | sub build_from_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_from_handle: called CC=8 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 4 | my ( $self, $handle, $opts ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | my $dumb = $opts->{dumb} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opts->{'dumb'} || 0
MC/DC100%1/1
$opts->{'dumb'} || 0
$opts->{'dumb'}
Truth table100%2/2
A
A= $opts->{'dumb'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | ▶ | my $lifetime = $opts->{lifetime} || $self->secret_lifetime; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->{'lifetime'} || $self->secret_lifetime
MC/DC0%0/2
$opts->{'lifetime'} || $self->secret_lifetime
$opts->{'lifetime'}
$self->secret_lifetime
Truth table33%1/3
A || B
A= $opts->{'lifetime'}B= $self->secret_lifetime
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | my ( $time, $type, $nonce, $nonce_sig80 ) = split( /:/, $handle ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | ▶ | return $self->ERROR(q{not found proper time,type,nonce and nonce_sig80}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
$time =~ /^\d+$/ and $type and $nonce
$time =~ /^\d+$/ and $type
MC/DC0%0/4
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
$time =~ /^\d+$/
$type
$nonce
$nonce_sig80
Truth table20%1/5
A and B and C and D
A= $time =~ /^\d+$/B= $typeC= $nonceD= $nonce_sig80
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | unless $time =~ /^\d+$/ && $type && $nonce && $nonce_sig80; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | ▶ | my $secret = $self->secret_of_handle( $handle, $dumb ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 4 | return OpenID::Lite::Association->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | secret => $secret, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | handle => $handle, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | issued => $time, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | expires_in => $lifetime, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 20 | ▶ | sub secret_of_handle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
secret_of_handle: called CC=13 SCAR=30.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 20 | my ( $self, $handle, $dumb, $no_verify ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 20 | my ( $time, $type, $nonce, $nonce_sig80 ) = split( /:/, $handle ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 20 | ▶ | return $self->ERROR(q{not found proper time,type,nonce and nonce_sig80}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
$time =~ /^\d+$/ and $type and $nonce
$time =~ /^\d+$/ and $type
MC/DC0%0/4
$time =~ /^\d+$/ and $type and $nonce and $nonce_sig80
$time =~ /^\d+$/
$type
$nonce
$nonce_sig80
Truth table20%1/5
A and B and C and D
A= $time =~ /^\d+$/B= $typeC= $nonceD= $nonce_sig80
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | unless $time =~ /^\d+$/ && $type && $nonce && $nonce_sig80; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 20 | ▶ | return $self->ERROR(q{nonce is invalid for dumb-mode}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dumb and not $nonce =~ /^STLS\./
MC/DC0%0/2
$dumb and not $nonce =~ /^STLS\./
$dumb
not $nonce =~ /^STLS\./
Truth table66%2/3
A and not(B)
A= $dumbB= not $nonce =~ /^STLS\./
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | if $dumb && $nonce !~ /^STLS\./; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 20 | ▶ | my $signature_method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | = OpenID::Lite::SignatureMethods->select_method($type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | or return $self->ERROR( sprintf q{Invalid assoc_type, "%s"}, $type ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | #my $sec_time = $time - ( $time % $self->secret_gen_interval ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | #my $s_sec = $self->get_server_secret->($sec_time) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # || $self->server_secret; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 20 | my $s_sec = $self->server_secret; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 20 | ▶ | length($nonce) == ( $dumb ? 25 : 20 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | or return $self->ERROR(q{Invalid nonce length}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 20 | ▶ | length($nonce_sig80) == 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | or return $self->ERROR(q{Invalid nonce_sig80 length}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 20 | ▶ | return $self->ERROR(q{Failed to verify nonce_sig80.}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$no_verify or $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
MC/DC0%0/2
$no_verify or $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
$no_verify
$nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
Truth table66%2/3
A or B
A= $no_verifyB= $nonce_sig80 eq substr($signature_method->hmac_hash_hex(sprintf("%d:%s:%s", $time, $type, $nonce), $s_sec), 0, 10)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | unless $no_verify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | || $nonce_sig80 eq substr( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | $signature_method->hmac_hash_hex( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | sprintf( q{%d:%s:%s}, $time, $type, $nonce ), $s_sec | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0, 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 20 | return $signature_method->hmac_hash( $handle, $s_sec ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | no Any::Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||