| 1 | package Lemonldap::NG::Portal::Plugins::OIDC::DynamicRegistration; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use String::Random qw/random_string/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | PE_OK | ||||||||||||||||||||||||||||||||||||||||||
| 8 | PE_SENDRESPONSE | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | extends qw( | |||||||||||||||||||||||||||||||||||||||||
| 14 | Lemonldap::NG::Portal::Lib::OIDCPlugin | ||||||||||||||||||||||||||||||||||||||||||
| 15 | Lemonldap::NG::Common::Conf::AccessLib | ||||||||||||||||||||||||||||||||||||||||||
| 16 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | # random_string mask for auto-registration client-id/secret | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use constant RS_MSK => 's' x 30; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | has configStorage => ( | ||||||||||||||||||||||||||||||||||||||||||
| 22 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 23 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | $_[0]->{p}->HANDLER->localConfig->{configStorage}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=14.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | return 0 unless $self->SUPER::init; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | my $uri = $self->conf->{oidcServiceMetaDataRegistrationURI} || 'register'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->conf->{'oidcServiceMetaDataRegistrationURI'} || 'register'
MC/DC0%0/1
$self->conf->{'oidcServiceMetaDataRegistrationURI'} || 'register'
$self->conf->{'oidcServiceMetaDataRegistrationURI'}
Truth table50%1/2
A
A= $self->conf->{'oidcServiceMetaDataRegistrationURI'}
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | # Avoid warning if loading modules twice | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | return 1 if $self->p->unAuthRoutes->{GET}->{ $self->path }->{$uri}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | $self->addUnauthRoute( | |||||||||||||||||||||||||||||||||||||||||
| 38 | $self->path => { $uri => 'registration' }, | ||||||||||||||||||||||||||||||||||||||||||
| 39 | [ 'GET', 'POST' ] | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | $self->addAuthRoute( | |||||||||||||||||||||||||||||||||||||||||
| 42 | $self->path => { $uri => 'registration' }, | ||||||||||||||||||||||||||||||||||||||||||
| 43 | [ 'GET', 'POST' ] | ||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # Handle register endpoint | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ▶ | sub registration { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
registration: called CC=53 SCAR=48.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 4 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 4 | ▶ | $req->data->{dropCsp} = 1 if $self->conf->{oidcDropCspHeaders}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | $self->logger->debug("URL detected as an OpenID Connect REGISTRATION URL"); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # TODO: check Initial Access Token | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | # Specific message to allow DOS detection | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 4 | my $source_ip = $req->address; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 4 | $self->logger->notice( | |||||||||||||||||||||||||||||||||||||||||
| 59 | "OpenID Connect Registration request from $source_ip"); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | # Get client metadata first (needed for hook) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 4 | my $client_metadata_json = $req->content; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | ▶ | return $self->p->sendError( $req, 'Missing POST data', 400 ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | unless ($client_metadata_json); | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | $self->logger->debug("Client metadata received: $client_metadata_json"); | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | ▶ | my $client_metadata = $self->oidc->decodeJSON($client_metadata_json) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | or return $self->p->sendError( $req, 'invalid_client_metadata', 400 ); | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | my $registration_response = {}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # Check dynamic registration is allowed | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 4 | ▶ | unless ( $self->conf->{oidcServiceAllowDynamicRegistration} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $self->logger->error("Dynamic registration is not allowed"); | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return $self->p->sendError( $req, 'server_error' ); | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # Let hooks filter registration requests | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # PE_SENDRESPONSE means the hook took over the response | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 4 | my $h = $self->p->processHook( $req, 'oidcGotRegistrationRequest', | |||||||||||||||||||||||||||||||||||||||||
| 81 | $client_metadata ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 4 | ▶ | return $req->response if $h == PE_SENDRESPONSE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | if ( $h != PE_OK ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $self->logger->error("oidcGotRegistrationRequest hook failed"); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return $self->p->sendError( $req, 'invalid_request', 400 ); | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | # Check redirect_uris | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 4 | my $redirect_uris = $client_metadata->{redirect_uris}; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 4 | ▶ | unless ( $redirect_uris and ref($redirect_uris) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$redirect_uris and ref $redirect_uris eq "ARRAY"
MC/DC0%0/2
$redirect_uris and ref $redirect_uris eq "ARRAY"
$redirect_uris
ref $redirect_uris eq "ARRAY"
Truth table33%1/3
A and B
A= $redirect_urisB= ref $redirect_uris eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $self->logger->error("Field redirect_uris (array) is mandatory"); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | return $self->p->sendError( $req, 'invalid_client_metadata', 400 ); | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 4 | foreach (@$redirect_uris) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | if ( /^\s*((?:java|vb)script|data):/i | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
/^\s*((?:java|vb)script|data):/i or $self->p->checkXSSAttack("redirect_uri", $_)
MC/DC0%0/2
/^\s*((?:java|vb)script|data):/i or $self->p->checkXSSAttack("redirect_uri", $_)
/^\s*((?:java|vb)script|data):/i
$self->p->checkXSSAttack("redirect_uri", $_)
Truth table33%1/3
A or B
A= /^\s*((?:java|vb)script|data):/iB= $self->p->checkXSSAttack("redirect_uri", $_)
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | or $self->p->checkXSSAttack( 'redirect_uri', $_ ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $self->userLogger->error( | |||||||||||||||||||||||||||||||||||||||||
| 100 | "Registration tried with a forbidden redirect_uri: $_"); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return $self->p->sendError( $req, 'invalid_client_metadata', | |||||||||||||||||||||||||||||||||||||||||
| 102 | 400 ); | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # RP identifier | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | my $registration_time = time; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | my $rp = "register-$registration_time"; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | # Handle token_endpoint_auth_method | ||||||||||||||||||||||||||||||||||||||||||
| 112 | my $token_endpoint_auth_method = | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | ▶ | $client_metadata->{token_endpoint_auth_method} || 'client_secret_basic'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$client_metadata->{'token_endpoint_auth_method'} || 'client_secret_basic'
MC/DC0%0/1
$client_metadata->{'token_endpoint_auth_method'} || 'client_secret_basic'
$client_metadata->{'token_endpoint_auth_method'}
Truth table50%1/2
A
A= $client_metadata->{'token_endpoint_auth_method'}
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | my $is_public = ( $token_endpoint_auth_method eq 'none' ); | |||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | my $needs_secret = | |||||||||||||||||||||||||||||||||||||||||
| 116 | $token_endpoint_auth_method =~ /^client_secret_(?:basic|post|jwt)$/; | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | # Validate token_endpoint_auth_method value | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | unless ( $is_public | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$is_public or $needs_secret or $token_endpoint_auth_method eq "private_key_jwt"
$is_public or $needs_secret
MC/DC0%0/3
$is_public or $needs_secret or $token_endpoint_auth_method eq "private_key_jwt"
$is_public
$needs_secret
$token_endpoint_auth_method eq "private_key_jwt"
Truth table75%3/4
A or B or C
A= $is_publicB= $needs_secretC= $token_endpoint_auth_method eq "private_key_jwt"
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | or $needs_secret | ||||||||||||||||||||||||||||||||||||||||||
| 121 | or $token_endpoint_auth_method eq 'private_key_jwt' ) | ||||||||||||||||||||||||||||||||||||||||||
| 122 | { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||
| 124 | "Unsupported token_endpoint_auth_method: $token_endpoint_auth_method" | ||||||||||||||||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return $self->p->sendError( $req, 'invalid_client_metadata', 400 ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # Reject public clients when only confidential clients are allowed | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | if ( !$needs_secret | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $needs_secret and $self->conf->{"oidcServiceAllowDynamicRegistration"} < 2
MC/DC0%0/2
not $needs_secret and $self->conf->{"oidcServiceAllowDynamicRegistration"} < 2
not $needs_secret
$self->conf->{"oidcServiceAllowDynamicRegistration"} < 2
Truth table66%2/3
not(A) and B
A= not $needs_secretB= $self->conf->{"oidcServiceAllowDynamicRegistration"} < 2
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | and $self->conf->{oidcServiceAllowDynamicRegistration} < 2 ) | ||||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->logger->error( "Public client registration is not allowed " | |||||||||||||||||||||||||||||||||||||||||
| 134 | . "(token_endpoint_auth_method=$token_endpoint_auth_method)" ); | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return $self->p->sendError( $req, 'invalid_client_metadata', 400 ); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | # private_key_jwt requires jwks_uri | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | ▶ | if ( $token_endpoint_auth_method eq 'private_key_jwt' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$token_endpoint_auth_method eq "private_key_jwt" and not $client_metadata->{"jwks_uri"}
MC/DC100%2/2
$token_endpoint_auth_method eq "private_key_jwt" and not $client_metadata->{"jwks_uri"}
$token_endpoint_auth_method eq "private_key_jwt"
not $client_metadata->{"jwks_uri"}
Truth table100%3/3
A and not(B)
A= $token_endpoint_auth_method eq "private_key_jwt"B= not $client_metadata->{"jwks_uri"}
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | and not $client_metadata->{jwks_uri} ) | ||||||||||||||||||||||||||||||||||||||||||
| 141 | { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||
| 143 | "private_key_jwt requires jwks_uri in registration request"); | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return $self->p->sendError( $req, 'invalid_client_metadata', 400 ); | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # Generate Client ID and secret | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | my $client_id = random_string(RS_MSK); | |||||||||||||||||||||||||||||||||||||||||
| 149 | 3 | ▶ | my $client_secret = $needs_secret ? random_string(RS_MSK) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | my $default_signing_key_type = $self->oidc->_getKeyType( | |||||||||||||||||||||||||||||||||||||||||
| 152 | $self->oidc->get_public_key("default-oidc-sig") ); | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | # Register known parameters | ||||||||||||||||||||||||||||||||||||||||||
| 155 | my $client_name = | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | $client_metadata->{client_name} || "Self registered client"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$client_metadata->{'client_name'} || 'Self registered client'
MC/DC0%0/1
$client_metadata->{'client_name'} || 'Self registered client'
$client_metadata->{'client_name'}
Truth table50%1/2
A
A= $client_metadata->{'client_name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | my $logo_uri = $client_metadata->{logo_uri}; | |||||||||||||||||||||||||||||||||||||||||
| 158 | my $id_token_signed_response_alg = | ||||||||||||||||||||||||||||||||||||||||||
| 159 | $client_metadata->{id_token_signed_response_alg} | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | ▶ | || ( $default_signing_key_type eq 'EC' ? 'ES256' : 'RS256' ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$client_metadata->{'id_token_signed_response_alg'} || ($default_signing_key_type eq 'EC' ? 'ES256' : 'RS256')
MC/DC0%0/2
$client_metadata->{'id_token_signed_response_alg'} || ($default_signing_key_type eq 'EC' ? 'ES256' : 'RS256')
$client_metadata->{'id_token_signed_response_alg'}
($default_signing_key_type eq 'EC' ? 'ES256' : 'RS256')
Truth table33%1/3
A || B
A= $client_metadata->{'id_token_signed_response_alg'}B= ($default_signing_key_type eq 'EC' ? 'ES256' : 'RS256')
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | my $userinfo_signed_response_alg = | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | $client_metadata->{userinfo_signed_response_alg}; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | my $request_uris = $client_metadata->{request_uris}; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 3 | my $backchannel_logout_uri = $client_metadata->{backchannel_logout_uri}; | |||||||||||||||||||||||||||||||||||||||||
| 165 | my $backchannel_logout_session_required = | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | $client_metadata->{backchannel_logout_session_required}; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | my $frontchannel_logout_uri = $client_metadata->{frontchannel_logout_uri}; | |||||||||||||||||||||||||||||||||||||||||
| 168 | my $frontchannel_logout_session_required = | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 3 | $client_metadata->{frontchannel_logout_session_required}; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | my $jwksUri = $client_metadata->{jwks_uri}; | |||||||||||||||||||||||||||||||||||||||||
| 171 | my $encryptedResponseAlg = | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | $client_metadata->{id_token_encrypted_response_alg}; | |||||||||||||||||||||||||||||||||||||||||
| 173 | my $encryptedResponseEnc = | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 3 | $client_metadata->{id_token_encrypted_response_enc}; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 3 | my $userInfoEncAlg = $client_metadata->{userinfo_encrypted_response_alg}; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 3 | my $userInfoEncEnc = $client_metadata->{userinfo_encrypted_response_enc}; | |||||||||||||||||||||||||||||||||||||||||
| 177 | my $introspectionSignAlg = | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | $client_metadata->{introspection_signed_response_alg}; | |||||||||||||||||||||||||||||||||||||||||
| 179 | my $introspectionEncAlg = | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 3 | $client_metadata->{introspection_encrypted_response_alg}; | |||||||||||||||||||||||||||||||||||||||||
| 181 | my $introspectionEncEnc = | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | $client_metadata->{introspection_encrypted_response_enc}; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # Register RP in global configuration | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 3 | my $conf = $self->confAcc->getConf( { raw => 1, noCache => 1 } ); | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 3 | $conf->{cfgAuthor} = "OpenID Connect Registration ($client_name)"; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | $conf->{cfgAuthorIP} = $source_ip; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | $conf->{cfgVersion} = $VERSION; | |||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # Build RP options from client metadata | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | my $rp_options = { | |||||||||||||||||||||||||||||||||||||||||
| 193 | oidcRPMetaDataOptionsClientID => $client_id, | ||||||||||||||||||||||||||||||||||||||||||
| 194 | oidcRPMetaDataOptionsDisplayName => $client_name, | ||||||||||||||||||||||||||||||||||||||||||
| 195 | oidcRPMetaDataOptionsIcon => $logo_uri, | ||||||||||||||||||||||||||||||||||||||||||
| 196 | oidcRPMetaDataOptionsIDTokenSignAlg => $id_token_signed_response_alg, | ||||||||||||||||||||||||||||||||||||||||||
| 197 | oidcRPMetaDataOptionsRedirectUris => join( ' ', @$redirect_uris ), | ||||||||||||||||||||||||||||||||||||||||||
| 198 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 3 | ▶ | $rp_options->{oidcRPMetaDataOptionsClientSecret} = $client_secret | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | if defined $client_secret; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 3 | ▶ | $rp_options->{oidcRPMetaDataOptionsPublic} = 1 if $is_public; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | $rp_options->{oidcRPMetaDataOptionsRequirePKCE} = 2; | |||||||||||||||||||||||||||||||||||||||||
| 203 | $rp_options->{oidcRPMetaDataOptionsRequestUris} = | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | ▶ | join( ' ', @$request_uris ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$request_uris and @$request_uris
MC/DC0%0/2
$request_uris and @$request_uris
$request_uris
@$request_uris
Truth table33%1/3
A and B
A= $request_urisB= @$request_uris
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | if $request_uris and @$request_uris; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | $rp_options->{oidcRPMetaDataOptionsUserInfoSignAlg} = | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 3 | ▶ | $userinfo_signed_response_alg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | if defined $userinfo_signed_response_alg; | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 3 | ▶ | if ($backchannel_logout_uri) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $rp_options->{oidcRPMetaDataOptionsLogoutType} = 'back'; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $rp_options->{oidcRPMetaDataOptionsLogoutUrl} = $backchannel_logout_uri; | |||||||||||||||||||||||||||||||||||||||||
| 213 | $rp_options->{oidcRPMetaDataOptionsLogoutSessionRequired} = | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $backchannel_logout_session_required; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | elsif ($frontchannel_logout_uri) { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | $rp_options->{oidcRPMetaDataOptionsLogoutType} = 'front'; | |||||||||||||||||||||||||||||||||||||||||
| 218 | $rp_options->{oidcRPMetaDataOptionsLogoutUrl} = | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $frontchannel_logout_uri; | |||||||||||||||||||||||||||||||||||||||||
| 220 | $rp_options->{oidcRPMetaDataOptionsLogoutSessionRequired} = | ||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $frontchannel_logout_session_required; | |||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 3 | ▶ | $rp_options->{oidcRPMetaDataOptionsJwksUri} = $jwksUri | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | if $jwksUri; | ||||||||||||||||||||||||||||||||||||||||||
| 225 | $rp_options->{oidcRPMetaDataOptionsIdTokenEncKeyMgtAlg} = | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | $encryptedResponseAlg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | if $encryptedResponseAlg; | ||||||||||||||||||||||||||||||||||||||||||
| 228 | $rp_options->{oidcRPMetaDataOptionsIdTokenEncContentEncAlg} = | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 3 | ▶ | $encryptedResponseEnc | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | if $encryptedResponseEnc; | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 3 | ▶ | $rp_options->{oidcRPMetaDataOptionsUserInfoEncKeyMgtAlg} = $userInfoEncAlg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | if $userInfoEncAlg; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | $rp_options->{oidcRPMetaDataOptionsUserInfoEncContentEncAlg} = | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 3 | ▶ | $userInfoEncEnc | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | if $userInfoEncEnc; | ||||||||||||||||||||||||||||||||||||||||||
| 236 | $rp_options->{oidcRPMetaDataOptionsIntrospectionSignAlg} = | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 3 | ▶ | $introspectionSignAlg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | if $introspectionSignAlg; | ||||||||||||||||||||||||||||||||||||||||||
| 239 | $rp_options->{oidcRPMetaDataOptionsIntrospectionEncKeyMgtAlg} = | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 3 | ▶ | $introspectionEncAlg | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | if $introspectionEncAlg; | ||||||||||||||||||||||||||||||||||||||||||
| 242 | $rp_options->{oidcRPMetaDataOptionsIntrospectionEncContentEncAlg} = | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 3 | ▶ | $introspectionEncEnc | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | if $introspectionEncEnc; | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | # TODO "jwks" support (when jwks_uri isn't available | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | # Exported Vars | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 3 | my $exported_vars = {}; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | ref( $self->conf->{oidcServiceDynamicRegistrationExportedVars} ) eq | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||||||||||
| 254 | $exported_vars = | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 3 | $self->conf->{oidcServiceDynamicRegistrationExportedVars}; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | # Extra claims | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 3 | my $extra_claims = {}; | |||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | ref( $self->conf->{oidcServiceDynamicRegistrationExtraClaims} ) eq | ||||||||||||||||||||||||||||||||||||||||||
| 262 | 'HASH' ) | ||||||||||||||||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | $extra_claims = | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 3 | $self->conf->{oidcServiceDynamicRegistrationExtraClaims}; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | # Build newRp structure (same shape as getOidcRpConfig) | ||||||||||||||||||||||||||||||||||||||||||
| 269 | # Hooks can modify this to adjust the RP config before save | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | my $newRp = { | |||||||||||||||||||||||||||||||||||||||||
| 271 | confKey => $rp, | ||||||||||||||||||||||||||||||||||||||||||
| 272 | options => $rp_options, | ||||||||||||||||||||||||||||||||||||||||||
| 273 | attributes => $exported_vars, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | macros => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 275 | scopeRules => {}, | ||||||||||||||||||||||||||||||||||||||||||
| 276 | extraClaims => $extra_claims, | ||||||||||||||||||||||||||||||||||||||||||
| 277 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | # Allow hooks to modify the new RP config before saving | ||||||||||||||||||||||||||||||||||||||||||
| 280 | # $client_metadata is passed for read-only context | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | $h = $self->p->processHook( $req, 'oidcRegisterClient', | |||||||||||||||||||||||||||||||||||||||||
| 282 | $newRp, $client_metadata ); | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | ▶ | if ( $h != PE_OK ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $self->logger->error("oidcRegisterClient hook failed"); | |||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | return $self->p->sendError( $req, 'server_error', 500 ); | |||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | # Apply newRp to configuration | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 3 | $rp = $newRp->{confKey}; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 3 | $client_id = $newRp->{options}->{oidcRPMetaDataOptionsClientID}; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 3 | $client_secret = $newRp->{options}->{oidcRPMetaDataOptionsClientSecret}; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | $conf->{oidcRPMetaDataOptions}->{$rp} = $newRp->{options}; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | $conf->{oidcRPMetaDataExportedVars}->{$rp} = $newRp->{attributes}; | |||||||||||||||||||||||||||||||||||||||||
| 295 | $conf->{oidcRPMetaDataMacros}->{$rp} = $newRp->{macros} | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 3 | ▶ | if %{ $newRp->{macros} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | $conf->{oidcRPMetaDataScopeRules}->{$rp} = $newRp->{scopeRules} | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | ▶ | if %{ $newRp->{scopeRules} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | $conf->{oidcRPMetaDataOptionsExtraClaims}->{$rp} = $newRp->{extraClaims} | ||||||||||||||||||||||||||||||||||||||||||
| 300 | 3 | ▶ | if %{ $newRp->{extraClaims} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | ▶ | if ( $self->confAcc->saveConf($conf) > 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | # Send registration response | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 3 | $registration_response->{'client_id'} = $client_id; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | ▶ | $registration_response->{'client_secret'} = $client_secret | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | if defined $client_secret; | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 3 | $registration_response->{'token_endpoint_auth_method'} = | |||||||||||||||||||||||||||||||||||||||||
| 309 | $token_endpoint_auth_method; | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 3 | $registration_response->{'client_id_issued_at'} = $registration_time; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 3 | $registration_response->{'client_id_expires_at'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 3 | $registration_response->{'client_name'} = $client_name; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 3 | $registration_response->{'logo_uri'} = $logo_uri; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 3 | $registration_response->{'id_token_signed_response_alg'} = | |||||||||||||||||||||||||||||||||||||||||
| 315 | $id_token_signed_response_alg; | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 3 | $registration_response->{'redirect_uris'} = $redirect_uris; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 3 | ▶ | $registration_response->{'request_uris'} = $request_uris | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$request_uris and @$request_uris
MC/DC0%0/2
$request_uris and @$request_uris
$request_uris
@$request_uris
Truth table33%1/3
A and B
A= $request_urisB= @$request_uris
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | if $request_uris and @$request_uris; | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 3 | ▶ | $registration_response->{'userinfo_signed_response_alg'} = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | $userinfo_signed_response_alg | ||||||||||||||||||||||||||||||||||||||||||
| 321 | if defined $userinfo_signed_response_alg; | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | ▶ | $registration_response->{'introspection_signed_response_alg'} = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | $introspectionSignAlg | ||||||||||||||||||||||||||||||||||||||||||
| 324 | if defined $introspectionSignAlg; | ||||||||||||||||||||||||||||||||||||||||||
| 325 | 3 | ▶ | $registration_response->{'introspection_encrypted_response_alg'} = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 326 | $introspectionEncAlg | ||||||||||||||||||||||||||||||||||||||||||
| 327 | if defined $introspectionEncAlg; | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 3 | ▶ | $registration_response->{'introspection_encrypted_response_enc'} = | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | $introspectionEncEnc | ||||||||||||||||||||||||||||||||||||||||||
| 330 | if defined $introspectionEncEnc; | ||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $self->logger->error( | |||||||||||||||||||||||||||||||||||||||||
| 334 | "Configuration not saved: $Lemonldap::NG::Common::Conf::msg"); | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | return $self->p->sendError( $req, 'server_error', 500 ); | |||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 3 | $self->logger->debug("Registration response sent"); | |||||||||||||||||||||||||||||||||||||||||
| 339 | 3 | return $self->p->sendJSONresponse( $req, $registration_response, | |||||||||||||||||||||||||||||||||||||||||
| 340 | code => 201 ); | ||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||