blib/lib/Lemonldap/NG/Portal/Plugins/TrustedBrowser.pm

filter: Statementstmt 28.9% 59 / 204 Branchbran 11.3% 10 / 88 Conditioncond 4.1% 1 / 24 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 40.6% 13 / 32 Podpod 6.2% 1 / 16 totaltotal 22.1% 84 / 379 CC 55 SCAR 29.2
CC
55
Cov
22%
checkFingerprint
56.0
storeBrowser
35.4
getTrustedBrowserSession
30.0
CRAP 18.5
« blib/lib/Lemonldap/NG/Portal/Main/Menu.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/ClientCredentialsGrant.pm »
1 # Trusted Browser service
2 # This package provides the ability to remember a browser across SSO logins
3 # It is meant to be used by multiple features
4 # - Auto-login (StayConnected)
5 # - 2FA bypass
6 #
7 # Browser registration is entirely handled by this plugin, and trigger by setting
8 # $req->param('stayconnected'), usually by the user clicking a checkbox.
9 # Request state is handled automatically during browser registration.
10 #
11 # This plugin sets a _trustedBrowser session variable that can be used in 2FA
12 # activation rules or other Portal features and plugins
13  
14 package Lemonldap::NG::Portal::Plugins::TrustedBrowser;
15  
16 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
19 PE_OK
20 PE_ERROR
21 PE_SENDRESPONSE
22 8 );
23  
24 8 our $VERSION = '2.23.0';
25  
26 8 extends qw(
27 Lemonldap::NG::Portal::Main::Plugin
28 Lemonldap::NG::Portal::Lib::OtherSessions
29 Lemonldap::NG::Common::TOTP
30 );
31  
32 # INTERFACE
33  
34 8 ▶use constant beforeAuth => 'checkAlreadyTrusted';
Subroutine BEGIN: called CC=1 SCAR=0.0
35 8 ▶use constant beforeLogout => 'logout';
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 # INITIALIZATION
38 has ott => (
39 is => 'rw',
40 lazy => 1,
41 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 my $ott =
43 0 $_[0]->{p}->loadModule('Lemonldap::NG::Portal::Lib::OneTimeToken');
44 0 $ott->timeout( $_[0]->conf->{formTimeout} );
45 0 return $ott;
46 }
47 8 );
48 has cookieName => (
49 is => 'ro',
50 lazy => 1,
51 1 ▶ default => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
52 1 ▶ $_[0]->conf->{stayConnectedCookieName} || 'llngconnection';
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->conf->{"stayConnectedCookieName"} or "llngconnection" 1 0 1
53 }
54 8 );
55 has singleSession => (
56 is => 'ro',
57 lazy => 1,
58 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 $_[0]->conf->{stayConnectedSingleSession};
60 }
61 8 );
62  
63 # Default timeout: 1 month
64 has timeout => (
65 is => 'ro',
66 lazy => 1,
67 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
68 0 ▶ $_[0]->conf->{stayConnectedTimeout} || 2592000;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->conf->{"stayConnectedTimeout"} or 2592000 0 0 0
69 }
70 8 );
71  
72 has use_totp => (
73 is => 'ro',
74 lazy => 1,
75 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
76 0 ▶ $_[0]->conf->{trustedBrowserUseTotp} || 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->conf->{"trustedBrowserUseTotp"} or 0 0 0 0
77 }
78 8 );
79  
80 has rule => (
81 is => 'rw',
82 8 ▶ default => sub {
Subroutine __ANON__: called CC=1 SCAR=1.2
83 0 ▶ sub { 0 }
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 8 }
85 8 );
86  
87 8 ▶sub init {
Subroutine init: called CC=4 SCAR=14.1
Pod undocumented
88 8 my ($self) = @_;
89 8 $self->addUnauthRoute( registerbrowser => 'storeBrowser', ['POST'] );
90 8 $self->addAuthRoute( registerbrowser => 'storeBrowser', ['POST'] );
91 8 $self->addUnauthRoute( checkbrowser => 'checkBrowserReturn', ['POST'] );
92 8 $self->addAuthRoute( checkbrowser => 'checkBrowserReturn', ['POST'] );
93  
94 # Parse activation rule
95 8 ▶ if ( $self->conf->{trustedBrowserRule} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->conf->{'trustedBrowserRule'}) { } 1 7 8
elsif ($self->conf->{'stayConnected'}) { } 7 0 7
96 $self->rule(
97 $self->p->buildRule(
98 $self->conf->{trustedBrowserRule},
99 1 'trustedBrowserRule'
100 )
101 );
102 1 ▶ return 0 unless $self->rule;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->rule 0 1 1
103 }
104  
105 # Enable with an all-allowing rule if stayConnected is used,
106 # for backward-compatibility
107 elsif ( $self->conf->{stayConnected} ) {
108 0 ▶ $self->rule( sub { 1 } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
109 }
110  
111 8 return 1;
112 }
113  
114 # RUNNING METHODS
115  
116 # Check if browser is trusted before auth
117 0 ▶sub checkAlreadyTrusted {
Subroutine checkAlreadyTrusted: not called CC=2 SCAR=17.9
Pod undocumented
118 0 my ( $self, $req ) = @_;
119  
120 0 my $session = $self->getTrustedBrowserSessionFromReq($req);
121  
122 0 ▶ if ($session) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session) 0 0 0
123 0 $req->data->{browserAlreadyTrusted} = 1;
124 }
125  
126 0 return PE_OK;
127 }
128  
129 # This method is called by the portal in standard auth flows
130  
131 0 ▶sub newDevice {
Subroutine newDevice: not called CC=4 SCAR=30.0
Pod undocumented
132 0 my ( $self, $req ) = @_;
133  
134 0 ▶ if ( $req->param('stayconnected') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->param("stayconnected")) 0 0 0
135  
136 0 ▶ if ( $req->sessionInfo->{_trustedBrowser} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->sessionInfo->{"_trustedBrowser"}) 0 0 0
137 $self->logger->debug( "User "
138 . $req->sessionInfo->{ $self->conf->{whatToTrace} }
139 0 . "asked to trust his web browser but is already trusted" );
140 0 return PE_OK;
141 }
142  
143 0 ▶ if ( $self->rule->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rule->($req, $req->sessionInfo)) { } 0 0 0
144 0 my $totpSecret = $self->newSecret;
145  
146 0 my $state = $self->_getRegisterStateTplParams( $req, $totpSecret );
147 0 $req->response(
148 $self->p->sendHtml(
149 $req,
150 'registerBrowser',
151 params => {
152 TOTPSEC => $totpSecret,
153 USETOTP => $self->use_totp,
154 ACTION => '/registerbrowser',
155 %$state,
156 }
157 )
158 );
159 0 return PE_SENDRESPONSE;
160 }
161 else {
162 $self->userLogger->info( "User "
163 . $req->sessionInfo->{ $self->conf->{whatToTrace} }
164 0 . "asked to trust his web browser but was denied by rule" );
165 }
166 }
167 0 return PE_OK;
168 }
169  
170 # Store TOTP secret + request state into a temporary session
171 # and return relevant template parameters
172 0 ▶sub _getRegisterStateTplParams {
Subroutine _getRegisterStateTplParams: not called CC=2 SCAR=17.9
173 0 my ( $self, $req, $totpSecret ) = @_;
174  
175 0 ▶ my $checkLogins = $req->param('checkLogins') || 0;
Condition0%0/2
$req->param('checkLogins') || 0
l!l
00
MC/DC0%0/1
$req->param('checkLogins') || 0
$req->param('checkLogins')
Truth table0%0/2
A
A= $req->param('checkLogins')
Aresult
11
00
176 0 my $url = $req->urldc;
177 0 my $token = $self->ott->createToken( {
178 id => $req->id,
179 sessionInfo => $req->sessionInfo,
180 totpSecret => $totpSecret,
181 }
182 );
183 0 my %state = (
184 CHECKLOGINS => $checkLogins,
185 URL => $url,
186 TOKEN => $token,
187 );
188 0 return \%state;
189 }
190  
191 # This method handles the browser response to the registerBrowser JS code
192 # and persists the registration
193 18 ▶sub storeBrowser {
Subroutine storeBrowser: called CC=7 SCAR=35.7
Pod undocumented
194 18 my ( $self, $req ) = @_;
195  
196 18 ▶ if ( my $totpSecret = $self->_restoreRegisterState($req) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $totpSecret = $self->_restoreRegisterState($req)) { } 0 18 18
197 0 my $name = $req->sessionInfo->{ $self->conf->{whatToTrace} };
198 0 my $authnLevel = $req->sessionInfo->{authenticationLevel};
199 0 ▶ if ( my $fg = $req->param('fg') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fg = $req->param('fg')) { } 0 0 0
200 0 ▶ my $isTotp = ( $fg =~ s/^TOTP_// ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$fg =~ s/^TOTP_// ? : 0 0 0
201 0 ▶ if ( $isTotp
Branch: 1 branch
BranchTrueFalseTotal
if ($isTotp and not $self->verifyCode(30, 1, 6, $totpSecret, $fg)) { } 0 0 0
Condition0%0/3
$isTotp and not $self->verifyCode(30, 1, 6, $totpSecret, $fg)
!ll&&!rl&&r
000
MC/DC0%0/2
$isTotp and not $self->verifyCode(30, 1, 6, $totpSecret, $fg)
$isTotp not $self->verifyCode(30, 1, 6, $totpSecret, $fg)
Truth table0%0/3
A and not(B)
A= $isTotpB= not $self->verifyCode(30, 1, 6, $totpSecret, $fg)
ABresult
0X0
100
111
202 and !$self->verifyCode( 30, 1, 6, $totpSecret, $fg ) )
203 {
204 0 $self->logger->warn( "Failed to register device, bad TOTP, "
205 . "device will not be remembered" );
206 }
207 else {
208 0 ▶ my $ps = $self->newConnectionSession( { (
Branch: 1 branch
BranchTrueFalseTotal
$isTotp ? : 0 0 0
209 _session_uid => $name,
210 authenticationLevel => $authnLevel,
211 $isTotp
212 ? ( totpSecret => $totpSecret )
213 : ( fingerprint => $fg )
214 ),
215 },
216 );
217  
218 # Cookie available 30 days by default
219 $req->addCookie(
220 $self->p->cookie(
221 name => $self->cookieName,
222 value => $ps->id,
223 max_age => $self->timeout,
224 secure => $self->conf->{securedCookie},
225 )
226 0 );
227  
228 # Store connection ID in current session
229 0 $self->p->updateSession( $req,
230 { _stayConnectedSession => $ps->id } );
231 }
232 }
233 else {
234 0 $self->logger->warn( "Browser did not return fingerprint, "
235 . "browser will not be remembered" );
236 }
237 }
238 else {
239 18 $self->userLogger->error(
240 "Cannot restore trusted browser registration state");
241 18 return $self->p->doPE( $req, PE_ERROR );
242 }
243  
244 # Resume normal login flow
245 0 $req->mustRedirect(1);
246 return $self->p->do( $req,
247 0 [ 'buildCookie', @{ $self->p->endAuth }, [ returnPE => PE_OK ] ] );
248 }
249  
250 18 ▶sub _restoreRegisterState {
Subroutine _restoreRegisterState: called CC=3 SCAR=16.8
251 18 my ( $self, $req ) = @_;
252  
253 18 ▶ if ( my $token = $req->param('token') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = $req->param('token')) { } 0 18 18
254 0 ▶ if ( my $saved_state = $self->ott->getToken($token) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $saved_state = $self->ott->getToken($token)) { } 0 0 0
255  
256 # checkLogins is restored automatically as a request parameter
257 0 $req->urldc( $req->param('url') );
258 0 $req->sessionInfo( $saved_state->{sessionInfo} );
259 0 $req->id( $saved_state->{id} );
260 0 return $saved_state->{totpSecret};
261 }
262 else {
263 0 $self->userLogger->error("Invalid trusted browser state token");
264 }
265 }
266 else {
267 18 $self->userLogger->error('Missing trusted browser state token');
268 }
269 18 return;
270  
271 }
272  
273 2 ▶sub getTrustedBrowserSessionFromReq {
Subroutine getTrustedBrowserSessionFromReq: called CC=3 SCAR=16.3
Pod undocumented
274 2 my ( $self, $req ) = @_;
275  
276 2 ▶ if ( my $cid = $req->cookies->{ $self->cookieName } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cid = $req->cookies->{$self->cookieName}) { } 0 2 2
277 0 my $session = $self->getTrustedBrowserSession($cid);
278 0 ▶ if ($session) {
Branch: 1 branch
BranchTrueFalseTotal
if ($session) { } 0 0 0
279 0 return $session;
280 }
281 else {
282 0 $self->removeCookie($req);
283 0 return;
284 }
285 }
286 else {
287 2 $self->logger->debug("No trusted browser cookie was sent");
288 }
289 2 return;
290 }
291  
292 0 ▶sub getTrustedBrowserSession {
Subroutine getTrustedBrowserSession: not called CC=5 SCAR=34.0
Pod undocumented
293 0 my ( $self, $cid, $raw ) = @_;
294 my $ps = Lemonldap::NG::Common::Session->new(
295 hashStore => $raw ? 0 : $self->{conf}->{hashedSessionStore},
296 storageModule => $self->conf->{globalStorage},
297 storageModuleOptions => $self->conf->{globalStorageOptions},
298 0 ▶ kind => "SSO",
Branch: 1 branch
BranchTrueFalseTotal
$raw ? : 0 0 0
299 id => $cid,
300 );
301 0 ▶ if ( $ps->data->{_session_uid} and ( time() < $ps->data->{_utime} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ps->data->{'_session_uid'} and &CORE::GLOBAL::time() < $ps->data->{'_utime'}) { } 0 0 0
Condition0%0/3
$ps->data->{"_session_uid"} and &CORE::GLOBAL::time() < $ps->data->{"_utime"}
!ll&&!rl&&r
000
MC/DC0%0/2
$ps->data->{"_session_uid"} and &CORE::GLOBAL::time() < $ps->data->{"_utime"}
$ps->data->{"_session_uid"} &CORE::GLOBAL::time() < $ps->data->{"_utime"}
Truth table0%0/3
A and B
A= $ps->data->{"_session_uid"}B= &CORE::GLOBAL::time() < $ps->data->{"_utime"}
ABresult
0X0
100
111
302 0 $self->logger->debug('Persistent connection found');
303 0 return $ps;
304 }
305 else {
306 0 $self->userLogger->notice('Persistent connection expired');
307 0 ▶ unless ( $ps->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ps->{"error"}) 0 0 0
308 $self->logger->debug(
309 0 'Persistent connection session id = ' . $ps->{id} );
310 $self->logger->debug( 'Persistent connection session _utime = '
311 0 . $ps->data->{_utime} );
312 0 $ps->remove;
313 }
314 }
315 0 return;
316 }
317  
318 0 ▶sub _hasFingerprintParams {
Subroutine _hasFingerprintParams: not called CC=2 SCAR=17.9
319 0 my ( $self, $req ) = @_;
320 0 ▶ return ( $req->param('fg') and $req->param('token') );
Condition0%0/3
$req->param('fg') && $req->param('token')
!ll&&!rl&&r
000
MC/DC0%0/2
$req->param('fg') && $req->param('token')
$req->param('fg') $req->param('token')
Truth table0%0/3
A && B
A= $req->param('fg')B= $req->param('token')
ABresult
0X0
100
111
321 }
322  
323 0 ▶sub mustChallenge {
Subroutine mustChallenge: not called CC=5 SCAR=34.0
Pod undocumented
324 0 my ( $self, $req, $expected_user ) = @_;
325  
326 0 my $ps = $self->getTrustedBrowserSessionFromReq($req);
327 0 ▶ if ( $ps and not( $self->_hasFingerprintParams($req) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ps and not $self->_hasFingerprintParams($req)) 0 0 0
Condition0%0/3
$ps and not $self->_hasFingerprintParams($req)
!ll&&!rl&&r
000
MC/DC0%0/2
$ps and not $self->_hasFingerprintParams($req)
$ps not $self->_hasFingerprintParams($req)
Truth table0%0/3
A and not(B)
A= $psB= not $self->_hasFingerprintParams($req)
ABresult
0X0
100
111
328 0 ▶ if ($expected_user) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expected_user) { } 0 0 0
329 return ( $ps->data->{_session_uid}
330 0 ▶ and $ps->data->{_session_uid} eq $expected_user );
Condition0%0/3
$ps->data->{'_session_uid'} && $ps->data->{'_session_uid'} eq $expected_user
!ll&&!rl&&r
000
MC/DC0%0/2
$ps->data->{'_session_uid'} && $ps->data->{'_session_uid'} eq $expected_user
$ps->data->{'_session_uid'} $ps->data->{'_session_uid'} eq $expected_user
Truth table0%0/3
A && B
A= $ps->data->{'_session_uid'}B= $ps->data->{'_session_uid'} eq $expected_user
ABresult
0X0
100
111
331 }
332 else {
333 0 return 1;
334 }
335 }
336 0 return 0;
337 }
338  
339 2 ▶sub getKnownBrowserState {
Subroutine getKnownBrowserState: called CC=5 SCAR=26.6
Pod undocumented
340 2 my ( $self, $req ) = @_;
341  
342 2 my $ps = $self->getTrustedBrowserSessionFromReq($req);
343 2 ▶ if ( $ps and $self->_hasFingerprintParams($req) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ps and $self->_hasFingerprintParams($req)) { } 0 2 2
Condition33%1/3
$ps and $self->_hasFingerprintParams($req)
!ll&&!rl&&r
200
MC/DC0%0/2
$ps and $self->_hasFingerprintParams($req)
$ps $self->_hasFingerprintParams($req)
Truth table33%1/3
A and B
A= $psB= $self->_hasFingerprintParams($req)
ABresult
0X0
100
111
344 0 my $fg = $req->param('fg');
345 0 my $token = $req->param('token');
346 0 my $uid = $ps->data->{_session_uid};
347 0 my $authnLevel = $ps->data->{authenticationLevel};
348  
349 0 my $token_data = $self->ott->getToken($token);
350 0 ▶ return unless $token_data;
Branch: 1 branch
BranchTrueFalseTotal
unless $token_data 0 0 0
351  
352 0 ▶ if ( $self->checkFingerprint( $req, $ps, $uid, $fg ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->checkFingerprint($req, $ps, $uid, $fg)) { } 0 0 0
353 return {
354 0 _trustedUser => $uid,
355 _trustedAuthnLevel => $authnLevel,
356 _stayConnectedSession => $ps->id,
357 data => $token_data,
358 };
359 }
360 else {
361 0 $self->userLogger->warn("Fingerprint changed for $uid");
362 0 $ps->remove;
363 0 $self->logout($req);
364 }
365 }
366 else {
367 2 $self->logger->debug("No fingerprint or token parameter was sent");
368 }
369 2 return;
370 }
371  
372 0 ▶sub checkFingerprint {
Subroutine checkFingerprint: not called CC=7 SCAR=40.3
Pod undocumented
373 0 my ( $self, $req, $ps, $uid, $fg ) = @_;
374 0 $self->logger->debug('Persistent connection found');
375 0 ▶ if ( $self->conf->{stayConnectedBypassFG} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->conf->{"stayConnectedBypassFG"}) 0 0 0
376 0 return 1;
377 }
378  
379 0 ▶ if ( $ps->data->{totpSecret} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ps->data->{'totpSecret'}) { } 0 0 0
elsif ($ps->data->{'fingerprint'}) { } 0 0 0
380 0 ▶ if ( $fg =~ s/^TOTP_// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fg =~ s/^TOTP_//) 0 0 0
381 return 1
382 if (
383 0 ▶ $self->verifyCode( 30, 1, 6, $ps->data->{totpSecret}, $fg ) >
Branch: 1 branch
BranchTrueFalseTotal
if $self->verifyCode(30, 1, 6, $ps->data->{"totpSecret"}, $fg) > 0 0 0 0
384 0 );
385 }
386 }
387 elsif ( $ps->data->{fingerprint} ) {
388 0 ▶ return 1 if ( $fg eq $ps->data->{fingerprint} );
Branch: 1 branch
BranchTrueFalseTotal
if $fg eq $ps->data->{"fingerprint"} 0 0 0
389 }
390 0 return 0;
391 }
392  
393 0 ▶sub challenge {
Subroutine challenge: not called CC=1 SCAR=6.9
Pod undocumented
394 0 my ( $self, $req, $action, $info ) = @_;
395 0 my $token = $self->ott->createToken($info);
396 0 $req->response(
397 $self->p->sendHtml(
398 $req,
399 'registerBrowser',
400 params => {
401 TOKEN => $token,
402 USETOTP => $self->use_totp,
403 ACTION => $action,
404 }
405 )
406 );
407 0 return PE_SENDRESPONSE;
408 }
409  
410 0 ▶sub logout {
Subroutine logout: not called CC=3 SCAR=24.8
Pod documented
411 0 my ( $self, $req ) = @_;
412 0 $self->removeCookie($req);
413  
414 # Try to clean stayconnected cookie
415 0 my $cid = $req->sessionInfo->{_stayConnectedSession};
416 0 ▶ if ($cid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cid) 0 0 0
417 0 my $ps = $self->getTrustedBrowserSession($cid);
418 0 ▶ if ($ps) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ps) 0 0 0
419 0 $self->logger->debug("Cleaning up StayConnected session $cid");
420 0 $ps->remove;
421 }
422 }
423  
424 0 return PE_OK;
425 }
426  
427 0 ▶sub removeCookie {
Subroutine removeCookie: not called CC=1 SCAR=6.9
Pod undocumented
428 0 my ( $self, $req ) = @_;
429  
430 $req->addCookie(
431 $self->p->cookie(
432 name => $self->cookieName,
433 value => 0,
434 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
435 secure => $self->conf->{securedCookie},
436 )
437 0 );
438  
439 # Avoid regressions with #3228
440 $req->addCookie(
441 $self->p->genDomainCookie(
442 $req,
443 name => $self->cookieName,
444 value => 0,
445 expires => 'Wed, 21 Oct 2015 00:00:00 GMT',
446 secure => $self->conf->{securedCookie},
447 )
448 0 );
449 }
450  
451 0 ▶sub removeExistingSessions {
Subroutine removeExistingSessions: not called CC=5 SCAR=34.0
Pod undocumented
452 0 my ( $self, $uid ) = @_;
453 0 $self->logger->debug("StayConnected: removing all sessions for $uid");
454  
455 0 my $sessions =
456 $self->module->searchOn( $self->moduleOpts, '_session_uid', $uid );
457  
458 # searchOn() returns sessions indexed by their storage ID, then
459 # it is required to use hashed ID
460 0 ▶ foreach ( keys %{ $sessions || {} } ) {
Condition0%0/2
$sessions || {}
l!l
00
MC/DC0%0/1
$sessions || {}
$sessions
Truth table0%0/2
A
A= $sessions
Aresult
11
00
461 0 ▶ if ( my $ps = $self->getTrustedBrowserSession( $_, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ps = $self->getTrustedBrowserSession($_, 1)) { } 0 0 0
462  
463 # If this is a StayConnected session, remove it
464 0 ▶ $ps->remove if $ps->{data}->{_connectedSince};
Branch: 1 branch
BranchTrueFalseTotal
if $ps->{"data"}{"_connectedSince"} 0 0 0
465 0 $self->logger->debug("StayConnected removed session $_");
466 }
467 else {
468 0 $self->logger->debug("StayConnected session $_ expired");
469 }
470 }
471 }
472  
473 0 ▶sub newConnectionSession {
Subroutine newConnectionSession: not called CC=3 SCAR=24.8
Pod undocumented
474 0 my ( $self, $info ) = @_;
475  
476 0 ▶ $info ||= {};
Condition0%0/2
$info ||= {}
l!l
00
MC/DC0%0/1
$info ||= {}
$info
Truth table0%0/2
A
A= $info
Aresult
11
00
477  
478 # Remove existing sessions
479 0 ▶ if ( $self->singleSession ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->singleSession) 0 0 0
480 0 $self->removeExistingSessions( $info->{_session_uid} );
481 }
482  
483 return Lemonldap::NG::Common::Session->new(
484 hashStore => $self->{conf}->{hashedSessionStore},
485 storageModule => $self->conf->{globalStorage},
486 storageModuleOptions => $self->conf->{globalStorageOptions},
487 0 kind => "SSO",
488 info => {
489 _utime => time + $self->timeout,
490 _connectedSince => time,
491 %$info,
492 }
493 );
494 }
495  
496 0 ▶sub check {
Subroutine check: not called CC=2 SCAR=17.9
Pod undocumented
497 0 my ( $self, $req ) = @_;
498  
499 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->mustChallenge($req, $req->sessionInfo->{$self->conf->{"whatToTrace"}})) 0 0 0
500 $self->mustChallenge(
501 $req, $req->sessionInfo->{ $self->conf->{whatToTrace} }
502 )
503 )
504 {
505 0 return $self->challenge(
506 $req,
507 '/checkbrowser',
508 {
509 _challenge_session_info => $req->sessionInfo,
510 _challenge_urldc => $req->urldc
511 }
512 );
513 }
514 0 return PE_OK;
515 }
516  
517 2 ▶sub checkBrowserReturn {
Subroutine checkBrowserReturn: called CC=6 SCAR=31.4
Pod undocumented
518 2 my ( $self, $req ) = @_;
519 2 my $state = $self->getKnownBrowserState($req);
520  
521 2 ▶ if ($state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state) { } 0 2 2
522  
523 # Restore state
524 0 my $sessionInfo = $state->{data}->{_challenge_session_info};
525 0 my $urldc = $state->{data}->{_challenge_urldc};
526 0 ▶ return $self->p->doPE( $req, PE_ERROR )
Branch: 1 branch
BranchTrueFalseTotal
unless $sessionInfo 0 0 0
527 unless $sessionInfo;
528 0 ▶ $req->urldc($urldc) if $urldc;
Branch: 1 branch
BranchTrueFalseTotal
if $urldc 0 0 0
529 0 $req->sessionInfo($sessionInfo);
530  
531 0 $req->sessionInfo->{_trustedBrowser} = 1;
532 $req->sessionInfo->{_stayConnectedSession} =
533 0 $state->{_stayConnectedSession};
534 0 my $authn_level_from_trusted = $state->{_trustedAuthnLevel};
535 0 my $authn_level_from_auth = $sessionInfo->{authenticationLevel};
536 0 ▶ my $new_authn_level =
Branch: 1 branch
BranchTrueFalseTotal
$authn_level_from_trusted > $authn_level_from_auth ? : 0 0 0
537 ( $authn_level_from_trusted > $authn_level_from_auth )
538 ? $authn_level_from_trusted
539 : undef;
540  
541 0 ▶ if ($new_authn_level) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_authn_level) 0 0 0
542 0 $req->sessionInfo->{authenticationLevel} = $new_authn_level;
543 }
544  
545 0 $req->mustRedirect(1);
546  
547 # Resume login
548 return $self->p->do(
549 $req,
550 [
551 'store', 'secondFactor',
552 0 @{ $self->p->afterData }, $self->p->validSession,
553 0 @{ $self->p->endAuth }, [ returnPE => PE_OK ],
554 ]
555 );
556  
557 }
558 else {
559 2 $self->logger->error("Trusted browser failed fingerprint challenge");
560 }
561 2 $req->noLoginDisplay(1);
562 2 return $self->p->doPE( $req, PE_ERROR );
563 }
564  
565 8 1;
« blib/lib/Lemonldap/NG/Portal/Main/Menu.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/ClientCredentialsGrant.pm »