| 1 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | ############################################################################ | ||||||||||||||||||||||||||||
| 5 | package Net::OpenID::ClaimedIdentity; | ||||||||||||||||||||||||||||
| 6 | BEGIN { | ||||||||||||||||||||||||||||
| 7 | 5 | ▶ | $Net::OpenID::ClaimedIdentity::VERSION = '1.100099_002'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | } | ||||||||||||||||||||||||||||
| 9 | use fields ( | ||||||||||||||||||||||||||||
| 10 | 5 | 'identity', # the canonical URL that was found, following redirects | |||||||||||||||||||||||||||
| 11 | 'server', # author-identity identity provider endpoint | ||||||||||||||||||||||||||||
| 12 | 'consumer', # ref up to the Net::OpenID::Consumer which generated us | ||||||||||||||||||||||||||||
| 13 | 'delegate', # the delegated URL actually asserted by the provider | ||||||||||||||||||||||||||||
| 14 | 'protocol_version', # The version of the OpenID Authentication Protocol that is used | ||||||||||||||||||||||||||||
| 15 | 'semantic_info', # Stuff that we've discovered in the identifier page's metadata | ||||||||||||||||||||||||||||
| 16 | 'extension_args', # Extension arguments that the caller wants to add to the request | ||||||||||||||||||||||||||||
| 17 | 5 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 5 | ▶ | use Digest::SHA qw(hmac_sha1_hex); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $self = fields::new( $self ) unless ref $self; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | my %opts = @_; | |||||||||||||||||||||||||||
| 25 | 0 | for my $f (qw( identity server consumer delegate protocol_version semantic_info )) { | |||||||||||||||||||||||||||
| 26 | 0 | $self->{$f} = delete $opts{$f}; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | ▶ | $self->{protocol_version} ||= 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"protocol_version"} ||= 1
MC/DC0%0/1
$self->{"protocol_version"} ||= 1
$self->{"protocol_version"}
Truth table0%0/2
A
A= $self->{"protocol_version"}
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | unless ($self->{protocol_version} == 1 || $self->{protocol_version} == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"protocol_version"} == 1 or $self->{"protocol_version"} == 2
MC/DC0%0/2
$self->{"protocol_version"} == 1 or $self->{"protocol_version"} == 2
$self->{"protocol_version"} == 1
$self->{"protocol_version"} == 2
Truth table0%0/3
A or B
A= $self->{"protocol_version"} == 1B= $self->{"protocol_version"} == 2
| |||||||||||||||||||||||||||||
| 31 | 0 | Carp::croak("Unsupported protocol version"); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | # lowercase the scheme and hostname | ||||||||||||||||||||||||||||
| 35 | 0 | $self->{'identity'} =~ s!^(https?://.+?)(/(?:.*))?$!lc($1) . $2!ie; | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | $self->{extension_args} = {}; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | Carp::croak("unknown options: " . join(", ", keys %opts)) if %opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub claimed_url { | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
claimed_url: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | Carp::croak("Too many parameters") if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | return $self->{'identity'}; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub delegated_url { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delegated_url: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | Carp::croak("Too many parameters") if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | return $self->{'delegate'}; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub identity_server { | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
identity_server: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | Carp::croak("Too many parameters") if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | return $self->{server}; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | sub protocol_version { | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
protocol_version: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | Carp::croak("Too many parameters") if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | return $self->{protocol_version}; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub semantic_info { | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
semantic_info: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | Carp::croak("Too many parameters") if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | return $self->{semantic_info} if $self->{semantic_info}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | my $final_url = ''; | |||||||||||||||||||||||||||
| 72 | 0 | my $info = $self->{consumer}->_find_semantic_info($self->claimed_url, \$final_url); | |||||||||||||||||||||||||||
| 73 | # Don't return anything if the URL has changed. Something bad may be happening. | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $info = {} if $final_url ne $self->claimed_url; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | return $self->{semantic_info} = $info; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub set_extension_args { | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
set_extension_args: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my $ext_uri = shift; | |||||||||||||||||||||||||||
| 81 | 0 | my $args = shift; | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | Carp::croak("Too many parameters") if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | Carp::croak("No extension URI given") unless $ext_uri; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | Carp::croak("Expecting hashref of args") if defined($args) && ref $args ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args and ref $args ne "HASH"
MC/DC0%0/2
defined $args and ref $args ne "HASH"
defined $args
ref $args ne "HASH"
Truth table0%0/3
A and B
A= defined $argsB= ref $args ne "HASH"
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | $self->{extension_args}{$ext_uri} = $args; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | sub check_url { | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my Net::OpenID::ClaimedIdentity $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
check_url: not called CC=22 SCAR=62.3
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | my (%opts) = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | my $return_to = delete $opts{'return_to'}; | |||||||||||||||||||||||||||
| 94 | 0 | my $trust_root = delete $opts{'trust_root'}; | |||||||||||||||||||||||||||
| 95 | 0 | my $delayed_ret = delete $opts{'delayed_return'}; | |||||||||||||||||||||||||||
| 96 | 0 | my $force_reassociate = delete $opts{'force_reassociate'}; | |||||||||||||||||||||||||||
| 97 | 0 | my $use_assoc_handle = delete $opts{'use_assoc_handle'}; | |||||||||||||||||||||||||||
| 98 | 0 | my $actually_return_association = delete $opts{'actually_return_association'}; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | Carp::croak("Unknown options: " . join(", ", keys %opts)) if %opts; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | Carp::croak("Invalid/missing return_to") unless $return_to =~ m!^https?://!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my $csr = $self->{consumer}; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | my $ident_server = $self->{server} or | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | Carp::croak("No identity server"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # get an assoc (or undef for dumb mode) | ||||||||||||||||||||||||||||
| 109 | 0 | my $assoc; | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($use_assoc_handle) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | 0 | $assoc = Net::OpenID::Association::handle_assoc($csr, $ident_server, $use_assoc_handle); | |||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||
| 113 | $assoc = Net::OpenID::Association::server_assoc($csr, $ident_server, $force_reassociate, ( | ||||||||||||||||||||||||||||
| 114 | 0 | %{$csr->assoc_options}, | |||||||||||||||||||||||||||
| 115 | protocol_version => $self->protocol_version, | ||||||||||||||||||||||||||||
| 116 | )); | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # for the openid-test project: (doing interop testing) | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($actually_return_association) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | 0 | return $assoc; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | my $identity_arg = $self->{'delegate'} || $self->{'identity'}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'delegate'} || $self->{'identity'}
MC/DC0%0/2
$self->{'delegate'} || $self->{'identity'}
$self->{'delegate'}
$self->{'identity'}
Truth table0%0/3
A || B
A= $self->{'delegate'}B= $self->{'identity'}
| |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # make a note back to ourselves that we're using a delegate | ||||||||||||||||||||||||||||
| 127 | # but only in the 1.1 case because 2.0 has a core field for this | ||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ($self->{'delegate'} && $self->protocol_version == 1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"delegate"} and $self->protocol_version == 1
MC/DC0%0/2
$self->{"delegate"} and $self->protocol_version == 1
$self->{"delegate"}
$self->protocol_version == 1
Truth table0%0/3
A and B
A= $self->{"delegate"}B= $self->protocol_version == 1
| |||||||||||||||||||||||||||||
| 129 | OpenID::util::push_url_arg(\$return_to, | ||||||||||||||||||||||||||||
| 130 | 0 | "oic.identity", $self->{identity}); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # add a HMAC-signed time so we can verify the return_to URL wasn't spoofed | ||||||||||||||||||||||||||||
| 134 | 0 | my $sig_time = time(); | |||||||||||||||||||||||||||
| 135 | 0 | my $c_secret = $csr->_get_consumer_secret($sig_time); | |||||||||||||||||||||||||||
| 136 | 0 | my $sig = substr(hmac_sha1_hex($sig_time, $c_secret), 0, 20); | |||||||||||||||||||||||||||
| 137 | 0 | OpenID::util::push_url_arg(\$return_to, | |||||||||||||||||||||||||||
| 138 | "oic.time", "${sig_time}-$sig"); | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | my $curl = $ident_server; | |||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ($self->protocol_version == 1) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | OpenID::util::push_url_arg(\$curl, | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 143 | "openid.mode" => ($delayed_ret ? "checkid_setup" : "checkid_immediate"), | ||||||||||||||||||||||||||||
| 144 | "openid.identity" => $identity_arg, | ||||||||||||||||||||||||||||
| 145 | "openid.return_to" => $return_to, | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | ($trust_root ? ( | ||||||||||||||||||||||||||||
| 148 | "openid.trust_root" => $trust_root | ||||||||||||||||||||||||||||
| 149 | ) : ()), | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | ($assoc ? ( | ||||||||||||||||||||||||||||
| 152 | "openid.assoc_handle" => $assoc->handle | ||||||||||||||||||||||||||||
| 153 | ) : ()), | ||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | elsif ($self->protocol_version == 2) { | ||||||||||||||||||||||||||||
| 157 | # NOTE: OpenID Auth 2.0 uses different terminology for a bunch | ||||||||||||||||||||||||||||
| 158 | # of things than 1.1 did. This library still uses the 1.1 terminology | ||||||||||||||||||||||||||||
| 159 | # in its API. | ||||||||||||||||||||||||||||
| 160 | 0 | ▶ | OpenID::util::push_openid2_url_arg(\$curl, | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 161 | "mode" => ($delayed_ret ? "checkid_setup" : "checkid_immediate"), | ||||||||||||||||||||||||||||
| 162 | "claimed_id" => $self->claimed_url, | ||||||||||||||||||||||||||||
| 163 | "identity" => $identity_arg, | ||||||||||||||||||||||||||||
| 164 | "return_to" => $return_to, | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | ($trust_root ? ( | ||||||||||||||||||||||||||||
| 167 | "realm" => $trust_root | ||||||||||||||||||||||||||||
| 168 | ) : ()), | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | ($assoc ? ( | ||||||||||||||||||||||||||||
| 171 | "assoc_handle" => $assoc->handle | ||||||||||||||||||||||||||||
| 172 | ) : ()), | ||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # Finally we add in the extension arguments, if any | ||||||||||||||||||||||||||||
| 177 | 0 | my %ext_url_args = (); | |||||||||||||||||||||||||||
| 178 | 0 | my $ext_idx = 1; | |||||||||||||||||||||||||||
| 179 | 0 | foreach my $ext_uri (keys %{$self->{extension_args}}) { | |||||||||||||||||||||||||||
| 180 | 0 | my $ext_alias; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ($ext_uri eq "http://openid.net/extensions/sreg/1.1") { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 183 | # For OpenID 1.1 only the "SREG" extension is allowed, | ||||||||||||||||||||||||||||
| 184 | # and it must use the "openid.sreg." prefix. | ||||||||||||||||||||||||||||
| 185 | 0 | $ext_alias = "sreg"; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | elsif ($self->protocol_version < 2) { | ||||||||||||||||||||||||||||
| 188 | 0 | next; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | else { | ||||||||||||||||||||||||||||
| 191 | 0 | $ext_alias = 'e'.($ext_idx++); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 0 | $ext_url_args{'openid.ns.'.$ext_alias} = $ext_uri; | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | foreach my $k (keys %{$self->{extension_args}{$ext_uri}}) { | |||||||||||||||||||||||||||
| 196 | 0 | $ext_url_args{'openid.'.$ext_alias.'.'.$k} = $self->{extension_args}{$ext_uri}{$k}; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | OpenID::util::push_url_arg(\$curl, %ext_url_args) if %ext_url_args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | $self->{consumer}->_debug("check_url for (del=$self->{delegate}, id=$self->{identity}) = $curl"); | |||||||||||||||||||||||||||
| 202 | 0 | return $curl; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 5 | 1; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||