Debian Codegraph @

lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Conf/Tests.pm

raw
1 package Lemonldap::NG::Manager::Conf::Tests;
2
3 use strict;
4 use utf8;
5 use strict;
6 use Lemonldap::NG::Common::Regexp;
7 use Lemonldap::NG::Handler::Main;
8 use Lemonldap::NG::Common::Util qw(getSameSite);
9 use URI;
10
11 our $VERSION = '2.23.3';
12
13 use constant validPartnerName => qr/^[\w-]+$/;
14
15 ## @method hashref tests(hashref conf)
16 # Return a hash ref where keys are the names of the tests and values
17 # subroutines to execute.
18 #
19 # Subroutines can return one of the followings :
20 # - (1) : everything is OK
21 # - (1,message) : OK with a warning
22 # - (0,message) : NOK
23 # - (-1,message) : OK, but must be confirmed (ignored if confirm parameter is
24 # set)
25 #
26 # Those subroutines can also modify configuration.
27 #
28 # @param $conf Configuration to test
29 # @return hash ref where keys are the names of the tests and values
30 sub tests {
31 my $conf = shift;
32 return {
33
34 # 1. CHECKS
35
36 # Check if portal is in domain
37 portalIsInDomain => sub {
38
39 # Looks like a sub, user knows what they are doing
40 if ( $conf->{portal} =~ /[\$\(&\|"']/ ) {
41 return 1;
42 }
43
44 return (
45 1,
46 (
47 index( $conf->{portal}, $conf->{domain} ) > 0
48 ? ''
49 : "Portal seems not to be in the domain $conf->{domain}"
50 )
51 );
52 },
53
54 # Check if portal URL is well formated
55 portalURL => sub {
56 my $url = $conf->{portal};
57
58 # Looks like a sub, user knows what they are doing
59 if ( $url =~ /[\$\(&\|"']/ ) {
60 return 1;
61 }
62 else {
63 return (
64 1,
65 (
66 ( $url =~ m%/$% )
67 ? ''
68 : "Portal URL should end with a /"
69 )
70 );
71 }
72 },
73
74 # Check if virtual hosts are in the domain
75 vhostInDomainOrCDA => sub {
76 return 1 if ( $conf->{cda} );
77 my @pb;
78 foreach my $vh ( keys %{ $conf->{locationRules} } ) {
79 push @pb, $vh unless ( index( $vh, $conf->{domain} ) >= 0 );
80 }
81 return (
82 1,
83 (
84 @pb
85 ? 'Virtual hosts '
86 . join( ', ', @pb )
87 . " are not in $conf->{domain} and cross-domain-authentication is not set"
88 : undef
89 )
90 );
91 },
92
93 # Check if automatically displayed menu applications have VH configuration
94 menuAutoDisplayedVhostsHaveConf => sub {
95 my @pb;
96
97 # Known hosts: locationRules keys + every vhostAliases entry
98 my %known;
99 $known{ lc $_ } = 1 for keys %{ $conf->{locationRules} || {} };
100 foreach my $vh ( keys %{ $conf->{vhostOptions} || {} } ) {
101 my $aliases = $conf->{vhostOptions}->{$vh}->{vhostAliases};
102 next unless defined $aliases and length $aliases;
103 $known{ lc $_ } = 1 for split /\s+/, $aliases;
104 }
105
106 # Walk applicationList recursively (categories may be nested)
107 my %entries;
108 my $walk;
109 $walk = sub {
110 my $node = shift;
111 return unless ref $node eq 'HASH';
112 foreach my $key ( keys %$node ) {
113 next if $key =~ /^(?:catname|type|options|order)$/;
114 my $child = $node->{$key};
115 next unless ref $child eq 'HASH';
116 if ( ( $child->{type} // '' ) eq 'category' ) {
117 $walk->($child);
118 }
119 elsif ( ( $child->{options}->{display} // '' ) eq 'auto' ) {
120 my $uri = $child->{options}->{uri};
121 next unless defined $uri and length $uri;
122 my $u = URI->new($uri);
123 next unless $u->can('host');
124 my $h = $u->host;
125 $entries{ lc $h } = 1 if defined $h and length $h;
126 }
127 }
128 };
129 $walk->( $conf->{applicationList} );
130
131 foreach ( sort keys %entries ) {
132 push @pb, $_ unless $known{$_};
133 }
134
135 return (
136 1,
137 (
138 @pb
139 ? 'Menu applications '
140 . join( ', ', @pb )
141 . ' are automatically displayed but have no configuration'
142 : undef
143 )
144 );
145 },
146
147 # Check if virtual host do not contain a port
148 vhostWithPort => sub {
149 my @pb;
150 foreach my $vh ( keys %{ $conf->{locationRules} } ) {
151 push @pb, $vh if ( $vh =~ /:/ );
152 }
153 return @pb
154 ? (
155 0,
156 'Virtual hosts '
157 . join( ', ', @pb )
158 . ' contain a port, this is not allowed'
159 )
160 : 1;
161 },
162
163 # Force vhost to be lowercase
164 vhostUpperCase => sub {
165 my @pb;
166 foreach my $vh ( keys %{ $conf->{locationRules} } ) {
167 push @pb, $vh if ( $vh ne lc $vh );
168 }
169 return @pb
170 ? (
171 0,
172 'Virtual hosts ' . join( ', ', @pb ) . ' must be in lower case'
173 )
174 : 1;
175 },
176
177 vhostNotAnAlias => sub {
178 my ( @pb, @aliases, @all_aliases );
179
180 @aliases =
181 map { $conf->{vhostOptions}->{$_}->{vhostAliases} }
182 keys %{ $conf->{vhostOptions} };
183
184 foreach my $alias (@aliases) {
185 push @all_aliases, split( /\s+/, $alias );
186 }
187
188 foreach my $vh ( keys %{ $conf->{locationRules} } ) {
189 push @pb, $vh if ( grep { lc($_) eq lc($vh) } @all_aliases );
190 }
191 return @pb
192 ? ( 0, 'Virtual hosts ' . join( ', ', @pb ) . ' match an alias' )
193 : 1;
194 },
195
196 # Check if "userDB" and "authentication" are consistent
197 authAndUserDBConsistency => sub {
198 foreach
199 my $type (qw(Facebook Google OpenID OpenIDConnect SAML WebID))
200 {
201 return ( 0,
202 "\"$type\" can not be used as user database without using \"$type\" for authentication"
203 )
204 if ( $conf->{userDB} =~ /$type/
205 and $conf->{authentication} !~ /$type/ );
206 }
207 return 1;
208 },
209
210 checkSelfReferentialMacros => sub {
211 my @tmp;
212 foreach my $macro ( keys %{$conf->{macros}} ) {
213 my $code = $conf->{macros}->{$macro};
214 push @tmp, $macro if $code =~ /\$\Q$macro\E\b/;
215 }
216 return (
217 1,
218 (
219 @tmp
220 ? 'Macro definitions for "'
221 . join( ', ', @tmp )
222 . '" refer to themselves'
223 : ''
224 )
225 );
226 },
227
228 # Check that OpenID macros exists
229 checkAttrAndMacros => sub {
230 my @tmp;
231 foreach my $k ( keys %$conf ) {
232 if ( $k =~
233 /^(?:openIdSreg_(?:(?:(?:full|nick)nam|languag|postcod|timezon)e|country|gender|email|dob)|whatToTrace)$/
234 )
235 {
236 my $v = $conf->{$k};
237 $v =~ s/^$//;
238 next if ( $v =~ /^_/ );
239 push @tmp,
240 $k
241 unless (
242 defined(
243 $conf->{exportedVars}->{$v}
244 or defined( $conf->{macros}->{$v} )
245 )
246 );
247 }
248 }
249 return (
250 1,
251 (
252 @tmp
253 ? 'Values of parameter(s) "'
254 . join( ', ', @tmp )
255 . '" are not defined in exported attributes or macros'
256 : ''
257 )
258 );
259 },
260
261 # Test that variables are exported if Google is used as UserDB
262 checkUserDBGoogleAXParams => sub {
263 my @tmp;
264 if ( $conf->{userDB} =~ /^Google$/ ) {
265 foreach my $k ( keys %{ $conf->{exportedVars} } ) {
266 my $v = $conf->{exportedVars}->{$k};
267 if ( $v !~ Lemonldap::NG::Common::Regexp::GOOGLEAXATTR() ) {
268 push @tmp, $v;
269 }
270 }
271 }
272 return (
273 1,
274 (
275 @tmp
276 ? 'Values of parameter(s) "'
277 . join( ', ', @tmp )
278 . '" are not exported by Google'
279 : ''
280 )
281 );
282 },
283
284 # Test that variables are exported if OpenID is used as UserDB
285 checkUserDBOpenIDParams => sub {
286 my @tmp;
287 if ( $conf->{userDB} =~ /^OpenID$/ ) {
288 foreach my $k ( keys %{ $conf->{exportedVars} } ) {
289 my $v = $conf->{exportedVars}->{$k};
290 if ( $v !~ Lemonldap::NG::Common::Regexp::OPENIDSREGATTR() )
291 {
292 push @tmp, $v;
293 }
294 }
295 }
296 return (
297 1,
298 (
299 @tmp
300 ? 'Values of parameter(s) "'
301 . join( ', ', @tmp )
302 . '" are not exported by OpenID SREG'
303 : ''
304 )
305 );
306 },
307
308 # Try to use Apache::Session module
309 testApacheSession => sub {
310 my ( $id, %h );
311 my $gc = Lemonldap::NG::Handler::Main->tsv->{sessionStorageModule};
312 return 1
313 if ( ( $gc and $gc eq $conf->{globalStorage} )
314 or $conf->{globalStorage} =~
315 /^Lemonldap::NG::Common::Apache::Session::/ );
316 eval "use $conf->{globalStorage}";
317 return ( -1, "Unknown package $conf->{globalStorage}" ) if ($@);
318 eval {
319 tie %h, 'Lemonldap::NG::Common::Apache::Session', undef,
320 {
321 %{ $conf->{globalStorageOptions} },
322 backend => $conf->{globalStorage}
323 };
324 };
325 return ( -1, "Unable to create a session ($@)" )
326 if ( $@ or not tied(%h) );
327 eval {
328 $h{a} = 1;
329 $id = $h{_session_id} or return ( -1, 'No _session_id' );
330 untie(%h);
331 tie %h, 'Lemonldap::NG::Common::Apache::Session', $id,
332 {
333 %{ $conf->{globalStorageOptions} },
334 backend => $conf->{globalStorage}
335 };
336 };
337 return ( -1, "Unable to insert data ($@)" ) if ($@);
338 return ( -1, "Unable to recover data stored" )
339 unless ( $h{a} == 1 );
340 eval { tied(%h)->delete; };
341 return ( -1, "Unable to delete session ($@)" ) if ($@);
342 return ( -1,
343 'All sessions may be lost and you must restart all your web servers'
344 ) if ( $gc and $conf->{globalStorage} ne $gc );
345 return 1;
346 },
347
348 # Warn if cookie name has changed
349 cookieNameChanged => sub {
350 my $cn = Lemonldap::NG::Handler::Main->tsv->{cookieName};
351 return (
352 1,
353 (
354 $cn
355 and $cn ne $conf->{cookieName}
356 ? 'Cookie name has changed, you must restart all your web servers'
357 : ()
358 )
359 );
360 },
361
362 # Warn if cookie TTL is equal or lower than one hour
363 cookieTTL => sub {
364 return 1 unless ( defined $conf->{cookieExpiration} );
365 return ( 0, "Cookie TTL must be higher than one minute" )
366 unless ( $conf->{cookieExpiration} == 0
367 || $conf->{cookieExpiration} > 60 );
368 return ( 1, "Cookie TTL should be higher or equal than one hour" )
369 unless ( $conf->{cookieExpiration} >= 3600
370 || $conf->{cookieExpiration} == 0 );
371 return 1;
372 },
373
374 # Warn if session timeout is lower than 10 minutes
375 sessionTimeout => sub {
376 return 1 unless ( defined $conf->{timeout} );
377 return ( -1, "Session timeout should be higher than ten minutes" )
378 unless ( $conf->{timeout} > 600
379 || $conf->{timeout} == 0 );
380 return 1;
381 },
382
383 # Error if session Activity Timeout is equal or lower than one minute
384 sessionTimeoutActivity => sub {
385 return 1 unless ( defined $conf->{timeoutActivity} );
386 return ( 0,
387 "Session activity timeout must be higher or equal than one minute"
388 )
389 unless ( $conf->{timeoutActivity} > 59
390 || $conf->{timeoutActivity} == 0 );
391 return 1;
392 },
393
394 # Error if activity timeout interval is higher than session activity timeout
395 timeoutActivityInterval => sub {
396 return 1 unless ( defined $conf->{timeoutActivityInterval} );
397 return ( 0,
398 "Activity timeout interval must be lower than session activity timeout"
399 )
400 if ( $conf->{timeoutActivity}
401 and $conf->{timeoutActivity} <=
402 $conf->{timeoutActivityInterval} );
403 return 1;
404 },
405
406 # Warn if manager seems to be unprotected
407 managerProtection => sub {
408 return (
409 1,
410 (
411 $conf->{cfgAuthor} eq 'anonymous'
412 ? 'Your manager seems to be unprotected'
413 : ''
414 )
415 );
416 },
417
418 # Test support of timeouts for LDAPS connections
419 ldapsNoTimeout => sub {
420
421 # Skip test if no SMTP configuration
422 return (1) unless ( $conf->{ldapServer} );
423
424 if ( $conf->{ldapServer} =~ /ldaps:/ ) {
425
426 if ( eval "require IO::Socket::SSL; require IO::Socket::IP;" ) {
427 if ( IO::Socket::SSL->isa('IO::Socket::IP') ) {
428 unless ( eval { IO::Socket::IP->VERSION(0.31) } ) {
429 return ( 1,
430 "Your version of IO::Socket::IP is too old to enforce "
431 . "connection timeouts on ldaps:// URLs. Use ldap+tls:// instead"
432 );
433 }
434 }
435 }
436 }
437 return (1);
438 },
439
440 # Test SMTP connection and authentication (warning only)
441 smtpConfiguration => sub {
442
443 # Skip test if no SMTP configuration
444 return 1 unless ( $conf->{SMTPServer} );
445
446 # Use SMTP
447 eval "use Lemonldap::NG::Common::EmailTransport";
448 return ( 1, "Could not load Lemonldap::NG::Common::EmailTransport" )
449 if ($@);
450
451 return Lemonldap::NG::Common::EmailTransport->configTest($conf);
452 },
453
454 # SAML entity ID must be unique
455 samlIDPEntityIdUniqueness => sub {
456 return 1
457 unless ( $conf->{samlIDPMetaDataXML}
458 and %{ $conf->{samlIDPMetaDataXML} } );
459 my @msg;
460 my $res = 1;
461 my %entityIds;
462 foreach my $idpId ( keys %{ $conf->{samlIDPMetaDataXML} } ) {
463 if (
464 $conf->{samlIDPMetaDataXML}->{$idpId}->{samlIDPMetaDataXML}
465 =~ /entityID=(['"])(.+?)\1/si )
466 {
467 my $eid = $2;
468 if ( defined $entityIds{$eid} ) {
469 push @msg,
470 "$idpId and $entityIds{$eid} have the same SAML EntityID";
471 $res = 0;
472 next;
473 }
474 $entityIds{$eid} = $idpId;
475 }
476 }
477 return ( $res, join( ', ', @msg ) );
478 },
479 samlSPEntityIdUniqueness => sub {
480 return 1
481 unless ( $conf->{samlSPMetaDataXML}
482 and %{ $conf->{samlSPMetaDataXML} } );
483 my @msg;
484 my $res = 1;
485 my %entityIds;
486 foreach my $spId ( keys %{ $conf->{samlSPMetaDataXML} } ) {
487 if (
488 $conf->{samlSPMetaDataXML}->{$spId}->{samlSPMetaDataXML} =~
489 /entityID=(['"])(.+?)\1/si )
490 {
491 my $eid = $2;
492 if ( defined $entityIds{$eid} ) {
493 push @msg,
494 "$spId and $entityIds{$eid} have the same SAML EntityID";
495 $res = 0;
496 next;
497 }
498 $entityIds{$eid} = $spId;
499 }
500 }
501 return ( $res, join( ', ', @msg ) );
502 },
503
504 # Test if SAML private and public keys signature keys are set
505 samlSecretKeys => sub {
506 return 1 unless ( $conf->{issuerDBSAMLActivation} );
507
508 if ( $conf->{samlServicePrivateKeySig}
509 && $conf->{samlServicePublicKeySig} )
510 {
511 return 1;
512 }
513 else {
514 my ($key) = split( /\s*,\s*/,
515 ( $conf->{samlServiceSignatureKey} || "" ) );
516 if ( $conf->{keys}->{$key} ) {
517 return 1;
518 }
519 }
520
521 return ( 0,
522 'SAML service private and public keys signature must be set' );
523 },
524
525 samlSignatureUnsupportedAlg => sub {
526 return 1 unless $conf->{issuerDBSAMLActivation};
527 return 1
528 unless eval
529 'use Lasso; Lasso::check_version( 2, 5, 1, Lasso::Constants::CHECK_VERSION_NUMERIC) ? 0 : 1';
530
531 my $allsha1 = 1;
532 undef $allsha1
533 unless $conf->{samlServiceSignatureMethod} eq "RSA_SHA1";
534
535 for my $idp ( keys %{ $conf->{samlIDPMetaDataOptions} } ) {
536 if ( $conf->{samlIDPMetaDataOptions}->{$idp}
537 ->{samlIDPMetaDataOptionsSignatureMethod} )
538 {
539 if ( $conf->{samlIDPMetaDataOptions}->{$idp}
540 ->{samlIDPMetaDataOptionsSignatureMethod} ne
541 "RSA_SHA1" )
542 {
543 undef $allsha1;
544 last;
545 }
546 }
547 }
548 for my $sp ( keys %{ $conf->{samlSPMetaDataOptions} } ) {
549 if ( $conf->{samlSPMetaDataOptions}->{$sp}
550 ->{samlSPMetaDataOptionsSignatureMethod} )
551 {
552 if ( $conf->{samlSPMetaDataOptions}->{$sp}
553 ->{samlSPMetaDataOptionsSignatureMethod} ne "RSA_SHA1" )
554 {
555 undef $allsha1;
556 last;
557 }
558 }
559 }
560 return $allsha1
561 ? 1
562 : (
563 0,
564 "Algorithms other than SHA1 are only supported on Lasso>=2.5.1"
565 );
566 },
567
568 samlIssuerNotEnabled => sub {
569 if ( keys %{ $conf->{samlSPMetaDataXML} || {} } ) {
570 if ( $conf->{issuerDBSAMLActivation} ) {
571 return 1;
572 }
573 else {
574 return ( 1,
575 "SAML service providers require enabling the SAML Issuer in General Parameters"
576 );
577 }
578 }
579 return 1;
580 },
581
582 # Try to parse combination with declared modules
583 checkCombinations => sub {
584 return 1 unless ( $conf->{authentication} eq 'Combination' );
585 require Lemonldap::NG::Common::Combination::Parser;
586 return ( 0, 'No module declared for combination' )
587 unless ( $conf->{combModules} and %{ $conf->{combModules} } );
588 my $moduleList;
589 foreach my $md ( keys %{ $conf->{combModules} } ) {
590 my $entry = $conf->{combModules}->{$md};
591 $moduleList->{$md} = (
592 $entry->{for} == 2 ? [ undef, {} ]
593 : $entry->{for} == 1 ? [ {}, undef ]
594 : [ {}, {} ]
595 );
596 }
597 eval {
598 Lemonldap::NG::Common::Combination::Parser->parse( $moduleList,
599 $conf->{combination} );
600 };
601 return ( 0, $@ ) if ($@);
602
603 # Return
604 return 1;
605 },
606
607 # Check Combination parameters
608 combinationParameters => sub {
609 return 1 unless ( $conf->{authentication} eq "Combination" );
610 return ( 0, "Combination rule must be defined" )
611 unless ( $conf->{combination} );
612 return ( 0, 'userDB must be set to "Same" to enable Combination' )
613 unless ( $conf->{userDB} eq "Same" );
614 return 1;
615 },
616
617 # Warn if 2F dependencies seem missing
618 sfaDependencies => sub {
619 my $ok = 0;
620 foreach (qw(totp yubikey)) {
621 $ok ||= $conf->{ $_ . '2fActivation' };
622 last if ($ok);
623 }
624 return 1 unless ($ok);
625
626 # Use TOTP
627 if ( $conf->{totp2fActivation} ) {
628 eval "use Convert::Base32";
629 return ( 1,
630 "Convert::Base32 module is required to enable TOTP" )
631 if ($@);
632 }
633
634 # Use WebAuthn
635 if ( $conf->{webauthn2fActivation} ) {
636 eval "use Authen::WebAuthn";
637 return ( 1,
638 "Authen::WebAuthn module is required to enable WebAuthn" )
639 if ($@);
640 }
641
642 # WebAuthn requires https://
643 if ( $conf->{webauthn2fActivation} ) {
644 my $portal_uri = URI->new( $conf->{portal} );
645 unless ( $portal_uri->scheme eq "https" ) {
646 return ( 1, "WebAuthn requires HTTPS" );
647 }
648 }
649
650 # Use Yubikey
651 if ( $conf->{yubikey2fActivation} ) {
652 eval "use Auth::Yubikey_WebClient";
653 return ( 1,
654 "Auth::Yubikey_WebClient module is required to enable Yubikey"
655 ) if ($@);
656 }
657 return 1;
658 },
659
660 # Warn if TOTP not 6 or 8 digits long
661 totp2fDigits => sub {
662 return 1 unless ( $conf->{totp2fActivation} );
663 return 1 unless ( defined $conf->{totp2fDigits} );
664 return (
665 1,
666 ( (
667 $conf->{totp2fDigits} == 6
668 or $conf->{totp2fDigits} == 8
669 )
670 ? ''
671 : 'TOTP should be 6 or 8 digits long'
672 )
673 );
674 },
675
676 # Test TOTP params
677 totp2fParams => sub {
678 return 1 unless ( $conf->{totp2fActivation} );
679 return ( 0, 'TOTP range must be defined' )
680 unless ( $conf->{totp2fRange} );
681 return ( 1, "TOTP interval should be higher than 10s" )
682 unless ( $conf->{totp2fInterval} > 10 );
683 return 1;
684 },
685
686 # Error if Yubikey client ID and secret key are missing
687 # Warn if Yubikey public ID size is not 12 digits long
688 yubikey2fParams => sub {
689 return 1 unless ( $conf->{yubikey2fActivation} );
690 return ( 0, "Yubikey client ID and secret key must be set" )
691 unless ( defined $conf->{yubikey2fSecretKey}
692 && defined $conf->{yubikey2fClientID} );
693 return (
694 1,
695 (
696 ( $conf->{yubikey2fPublicIDSize} == 12 )
697 ? ''
698 : 'Yubikey public ID size should be 12 digits long'
699 )
700 );
701 },
702
703 # Error if REST 2F verify URL is missing
704 rest2fVerifyUrl => sub {
705 return 1 unless ( $conf->{rest2fActivation} );
706 return ( 0, "REST 2F Verify URL must be set" )
707 unless ( defined $conf->{rest2fVerifyUrl} );
708
709 # Return
710 return 1;
711 },
712
713 # Warn if 2FA is required without a registrable 2F module enabled
714 required2FA => sub {
715 return 1 unless ( $conf->{sfRequired} );
716
717 my $msg = '';
718 my $ok = 0;
719 foreach (qw(u totp yubikey webauthn)) {
720 $ok ||= $conf->{ $_ . '2fActivation' }
721 && $conf->{ $_ . '2fSelfRegistration' };
722 last if ($ok);
723 }
724 return ( 1, $msg );
725 },
726
727 # Error if external 2F Send or Validate command is missing
728 ext2fCommands => sub {
729 return 1 unless ( $conf->{ext2fActivation} );
730 return ( 0, "External 2F Send command must be set" )
731 unless ( defined $conf->{ext2FSendCommand} );
732 unless ( defined $conf->{ext2fCodeActivation} ) {
733 return ( 0, "External 2F Validate command must be set" )
734 unless ( defined $conf->{ext2FValidateCommand} );
735 }
736 return 1;
737 },
738
739 # Warn if XSRF token TTL is higher than 30s
740 formTimeout => sub {
741 return 1 unless ( defined $conf->{formTimeout} );
742 return ( 0, "XSRF form token TTL must be higher than 30s" )
743 unless ( $conf->{formTimeout} > 30 );
744 return ( 1, "XSRF form token TTL should not be higher than 2mn" )
745 if ( $conf->{formTimeout} > 120 );
746 return 1;
747 },
748
749 # Warn if issuers token TTL is higher than 30s
750 issuersTimeout => sub {
751 return 1 unless ( defined $conf->{issuersTimeout} );
752 return ( 0, "Issuers token TTL must be higher than 30s" )
753 unless ( $conf->{issuersTimeout} > 30 );
754
755 # because of issue #2186
756 return ( 1, "Issuers token TTL should not be higher than 10mn" )
757 if ( $conf->{issuersTimeout} > 600 );
758 return 1;
759 },
760
761 # Warn if number of password reset retries is null
762 passwordResetRetries => sub {
763 return 1 unless ( $conf->{portalDisplayResetPassword} );
764 return ( 1, "Number of reset password retries should not be null" )
765 unless ( $conf->{passwordResetAllowedRetries} );
766 return 1;
767 },
768
769 # Warn if ldapPpolicyControl is used with AD (#2007)
770 ppolicyAd => sub {
771 return ( 1,
772 "LDAP password policy control should be disabled when using AD authentication"
773 )
774 if ( $conf->{ldapPpolicyControl}
775 and $conf->{authentication} eq "AD" );
776 return 1;
777 },
778
779 # Warn if bruteForceProtection enabled without History
780 bruteForceProtection => sub {
781 my @lockTimes =
782 sort { $a <=> $b }
783 map { abs(s/\D//r) }
784 grep { /\d+/ }
785 split /\s*,\s*/, $conf->{bruteForceProtectionLockTimes} || '';
786 $conf->{bruteForceProtectionLockTimes} = join ', ', @lockTimes
787 if scalar @lockTimes;
788 return 1 unless ( $conf->{bruteForceProtection} );
789 return ( 0,
790 '"History" plugin is required to enable "BruteForceProtection" plugin'
791 ) unless ( $conf->{loginHistoryEnabled} );
792 return ( 0,
793 'Number of failed logins must be higher than 1 to enable "BruteForceProtection" plugin'
794 ) unless ( $conf->{failedLoginNumber} > 1 );
795 return ( 0,
796 'Number of allowed failed logins must be higher than 0 to enable "BruteForceProtection" plugin'
797 ) unless ( $conf->{bruteForceProtectionMaxFailed} > 0 );
798 return ( 0,
799 'Number of failed logins history must be higher or equal than allowed failed logins plus lock time values'
800 )
801 if ( $conf->{bruteForceProtectionIncrementalTempo}
802 && $conf->{failedLoginNumber} <
803 $conf->{bruteForceProtectionMaxFailed} + scalar @lockTimes );
804 return ( 0,
805 'Number of failed logins history must be higher or equal than allowed failed logins'
806 )
807 unless ( $conf->{failedLoginNumber} >=
808 $conf->{bruteForceProtectionMaxFailed} );
809 return 1;
810 },
811
812 # Warn if Mailrest plugin is enabled without Token or Captcha
813 checkMailResetSecurity => sub {
814 return 1 unless ( $conf->{portalDisplayResetPassword} );
815 return ( -1,
816 '"passwordMailReset" plugin is enabled without CSRF Token neither Captcha required'
817 )
818 unless ( $conf->{requireToken}
819 or $conf->{captcha_mail_enabled} );
820 return 1;
821 },
822
823 # Warn if Impersonation and ContextSwitching are simultaneously enabled
824 impersonation => sub {
825 return ( 1,
826 "Impersonation and ContextSwitching are simultaneously enabled"
827 )
828 if ( $conf->{impersonationRule}
829 and $conf->{contextSwitchingRule} );
830 return 1;
831 },
832
833 # Warn if persistent storage is disabled with 2FA, History, OIDCConsents, Notifications or BruteForce protection
834 persistentStorage => sub {
835 return 1 unless ( $conf->{disablePersistentStorage} );
836 return ( 1, "2FA enabled WITHOUT persistent session storage" )
837 if ( $conf->{totp2fActivation}
838 || $conf->{yubikey2fActivation} );
839 return ( 1,
840 "History plugin enabled WITHOUT persistent session storage" )
841 if ( $conf->{loginHistoryEnabled} );
842 return ( 1,
843 "OIDC consents enabled WITHOUT persistent session storage" )
844 if ( $conf->{portalDisplayOidcConsents} );
845 return ( 1,
846 "Notifications enabled WITHOUT persistent session storage" )
847 if ( $conf->{notification} );
848 return ( 1,
849 "BruteForceProtection plugin enabled WITHOUT persistent session storage"
850 ) if ( $conf->{bruteForceProtection} );
851 return 1;
852 },
853
854 # Warn if XML dependencies seem missing
855 xmlDependencies => sub {
856 return 1 unless ( $conf->{oldNotifFormat} );
857 eval "use XML::LibXML";
858 return ( 1,
859 "XML::LibXML module is required to enable old format notifications"
860 ) if ($@);
861 eval "use XML::LibXSLT";
862 return ( 1,
863 "XML::LibXSLT module is required to enable old format notifications"
864 ) if ($@);
865 return 1;
866 },
867
868 # Warn if CertificateResetByMail dependencies seem missing
869 certResetByMailDependencies => sub {
870 return 1 unless ( $conf->{portalDisplayCertificateResetByMail} );
871 return ( 0,
872 "LDAP RegisterDB is required to enable CertificateResetByMail plugin"
873 ) unless ( $conf->{registerDB} eq 'LDAP' );
874 eval "use DateTime::Format::RFC3339";
875 return ( 1,
876 "DateTime::Format::RFC3339 module is required to enable CertificateResetByMail plugin"
877 ) if ($@);
878 return 1;
879 },
880
881 # OIDC redirect URI must not be empty
882 oidcRPRedirectURINotEmpty => sub {
883 return 1
884 unless ( $conf->{oidcRPMetaDataOptions}
885 and %{ $conf->{oidcRPMetaDataOptions} } );
886 my @msg;
887 my $res = 1;
888 foreach my $oidcRpId ( keys %{ $conf->{oidcRPMetaDataOptions} } ) {
889 unless ( $conf->{oidcRPMetaDataOptions}->{$oidcRpId}
890 ->{oidcRPMetaDataOptionsRedirectUris} )
891 {
892 push @msg,
893 "$oidcRpId: OIDC Relying Party has no redirect URI defined";
894 $res = 0;
895 next;
896 }
897 }
898 return ( $res, join( ', ', @msg ) );
899 },
900
901 # OIDC public RP should implement PKCE
902 oidcRPpublicClientWithPKCE => sub {
903 return 1
904 unless ( $conf->{oidcRPMetaDataOptions}
905 and %{ $conf->{oidcRPMetaDataOptions} } );
906 my @msg;
907 foreach my $oidcRpId ( keys %{ $conf->{oidcRPMetaDataOptions} } ) {
908 if ( $conf->{oidcRPMetaDataOptions}->{$oidcRpId}
909 ->{oidcRPMetaDataOptionsPublic} )
910 {
911 push @msg,
912 "$oidcRpId: requiring PKCE is recommended for public OIDC Relying Parties"
913 unless $conf->{oidcRPMetaDataOptions}->{$oidcRpId}
914 ->{oidcRPMetaDataOptionsRequirePKCE};
915 next;
916 }
917 }
918 return ( 1, join( ', ', @msg ) );
919 },
920
921 # Test if OIDC private and public keys signature keys are set
922 oidcSecretKeys => sub {
923 return 1 unless ( $conf->{issuerDBOpenIDConnectActivation} );
924
925 if ( $conf->{oidcServicePrivateKeySig}
926 && $conf->{oidcServicePublicKeySig} )
927 {
928 return 1;
929 }
930 else {
931 my ($key) = split( /\s*,\s*/,
932 ( $conf->{oidcServiceSignatureKey} || "" ) );
933 if ( $conf->{keys}->{$key} ) {
934 return 1;
935 }
936 }
937
938 return ( 1,
939 'OIDC service private and public keys signature should be set'
940 );
941 },
942
943 # RS* OIDC algs require a signing key
944 oidcRPNeedRSAKey => sub {
945 return 1
946 unless ( $conf->{oidcRPMetaDataOptions}
947 and %{ $conf->{oidcRPMetaDataOptions} } );
948 my @usingRSA =
949 grep {
950 $conf->{oidcRPMetaDataOptions}->{$_}
951 ->{oidcRPMetaDataOptionsIDTokenSignAlg}
952 and $conf->{oidcRPMetaDataOptions}->{$_}
953 ->{oidcRPMetaDataOptionsIDTokenSignAlg} =~ /^RS/
954 } keys %{ $conf->{oidcRPMetaDataOptions} }, grep {
955 $conf->{oidcRPMetaDataOptions}->{$_}
956 ->{oidcRPMetaDataOptionsAccessTokenSignAlg}
957 and $conf->{oidcRPMetaDataOptions}->{$_}
958 ->{oidcRPMetaDataOptionsAccessTokenSignAlg} =~ /^RS/
959 and $conf->{oidcRPMetaDataOptions}->{$_}
960 ->{oidcRPMetaDataOptionsAccessTokenJWT}
961 } keys %{ $conf->{oidcRPMetaDataOptions} };
962
963 if (
964 @usingRSA
965 and not( $conf->{oidcServicePrivateKeySig}
966 or %{ $conf->{keys} || {} } )
967 )
968 {
969 my $msg =
970 join( ", ", @usingRSA )
971 . ": using RS-type encryption, but no RSA key is defined in global OIDC configuration";
972 return ( 0, $msg );
973 }
974 return 1;
975 },
976
977 # Public OIDC clients require a public key algorithm
978 oidcRPPublicNeedPubAlg => sub {
979 return 1
980 unless ( $conf->{oidcRPMetaDataOptions}
981 and %{ $conf->{oidcRPMetaDataOptions} || {} } );
982 my @clients;
983 for ( keys %{ $conf->{oidcRPMetaDataOptions} || {} } ) {
984 if ( $conf->{oidcRPMetaDataOptions}->{$_}
985 ->{oidcRPMetaDataOptionsPublic}
986 and $conf->{oidcRPMetaDataOptions}->{$_}
987 ->{oidcRPMetaDataOptionsIDTokenSignAlg} =~ /^HS/ )
988 {
989 push @clients, $_;
990 }
991 }
992 if (@clients) {
993 my $msg =
994 join( ", ", @clients )
995 . ": public clients should use a public key algorithm"
996 . " for ID token signature";
997 return 1, $msg;
998 }
999 else {
1000 return 1;
1001 }
1002 },
1003
1004 # OIDC RP Client ID must exist and be unique
1005 oidcRPClientIdUniqueness => sub {
1006 return 1
1007 unless ( $conf->{oidcRPMetaDataOptions}
1008 and %{ $conf->{oidcRPMetaDataOptions} } );
1009 my @msg;
1010 my $res = 1;
1011 my %clientIds;
1012 foreach
1013 my $clientConfKey ( keys %{ $conf->{oidcRPMetaDataOptions} } )
1014 {
1015 my $clientId =
1016 $conf->{oidcRPMetaDataOptions}->{$clientConfKey}
1017 ->{oidcRPMetaDataOptionsClientID};
1018 unless ($clientId) {
1019 push @msg,
1020 "$clientConfKey: OIDC Relying Party has no Client ID";
1021 $res = 0;
1022 next;
1023 }
1024
1025 if ( defined $clientIds{$clientId} ) {
1026 push @msg,
1027 "$clientConfKey and $clientIds{$clientId} have the same Client ID";
1028 $res = 0;
1029 next;
1030 }
1031 $clientIds{$clientId} = $clientConfKey;
1032 }
1033 return ( $res, join( ', ', @msg ) );
1034 },
1035
1036 oidcIssuerNotEnabled => sub {
1037 if ( keys %{ $conf->{oidcRPMetaDataOptions} || {} } ) {
1038 if ( $conf->{issuerDBOpenIDConnectActivation} ) {
1039 return 1;
1040 }
1041 else {
1042 return ( 1,
1043 "OIDC relying parties require enabling the OpenID Connect Issuer in General Parameters"
1044 );
1045 }
1046 }
1047 return 1;
1048 },
1049
1050 # CAS APP URL must be defined and unique
1051 casAppHostnameUniqueness => sub {
1052 return 1
1053 unless ( $conf->{casAppMetaDataOptions}
1054 and %{ $conf->{casAppMetaDataOptions} } );
1055 my @msg;
1056 my $res = 1;
1057 my %casUrl;
1058 foreach my $casConfKey ( keys %{ $conf->{casAppMetaDataOptions} } )
1059 {
1060 for my $appUrl (
1061 split(
1062 /\s+/,
1063 $conf->{casAppMetaDataOptions}->{$casConfKey}
1064 ->{casAppMetaDataOptionsService}
1065 )
1066 )
1067 {
1068 $appUrl ||= "";
1069 my ($appHost) = $appUrl =~ m#^(https?://[^/]+)(/.*)?$#;
1070 unless ($appHost) {
1071 push @msg,
1072 "$casConfKey: CAS Application has no Service URL";
1073 $res = 0;
1074 next;
1075 }
1076
1077 if ( defined $casUrl{$appUrl} ) {
1078 push @msg,
1079 "$casConfKey and $casUrl{$appUrl} have the same Service URL";
1080 $res = 0;
1081 next;
1082 }
1083 $casUrl{$appUrl} = $casConfKey;
1084 }
1085 }
1086 return ( $res, join( ', ', @msg ) );
1087 },
1088
1089 casIssuerNotEnabled => sub {
1090 if ( keys %{ $conf->{casAppMetaDataOptions} || {} } ) {
1091 if ( $conf->{issuerDBCASActivation} ) {
1092 return 1;
1093 }
1094 else {
1095 return ( 1,
1096 "CAS applications require enabling the CAS Issuer in General Parameters"
1097 );
1098 }
1099 }
1100 return 1;
1101 },
1102
1103 # Relying Party / Service Provider / CAS Application names must
1104 # contain only word characters (letters, digits, underscore)
1105 spNameNoWhitespace => sub {
1106 my @msg;
1107 foreach my $rpId ( keys %{ $conf->{oidcRPMetaDataOptions} || {} } )
1108 {
1109 if ( $rpId !~ validPartnerName ) {
1110 push @msg,
1111 "OIDC Relying Party name '$rpId' must contain only word characters (letters, digits, underscore)";
1112 }
1113 }
1114 foreach my $spId ( keys %{ $conf->{samlSPMetaDataXML} || {} } ) {
1115 if ( $spId !~ validPartnerName ) {
1116 push @msg,
1117 "SAML Service Provider name '$spId' must contain only word characters (letters, digits, underscore)";
1118 }
1119 }
1120 foreach my $casId ( keys %{ $conf->{casAppMetaDataOptions} || {} } )
1121 {
1122 if ( $casId !~ validPartnerName ) {
1123 push @msg,
1124 "CAS Application name '$casId' must contain only word characters (letters, digits, underscore)";
1125 }
1126 }
1127 return @msg ? ( 0, join( ', ', @msg ) ) : 1;
1128 },
1129
1130 # Identity Provider / OpenID Provider / CAS Server names must
1131 # contain only word characters (letters, digits, underscore)
1132 idpNameNoWhitespace => sub {
1133 my @msg;
1134 foreach my $idpId ( keys %{ $conf->{samlIDPMetaDataXML} || {} } ) {
1135 if ( $idpId !~ validPartnerName ) {
1136 push @msg,
1137 "SAML Identity Provider name '$idpId' must contain only word characters (letters, digits, underscore)";
1138 }
1139 }
1140 foreach my $opId ( keys %{ $conf->{oidcOPMetaDataOptions} || {} } )
1141 {
1142 if ( $opId !~ validPartnerName ) {
1143 push @msg,
1144 "OIDC OpenID Provider name '$opId' must contain only word characters (letters, digits, underscore)";
1145 }
1146 }
1147 foreach
1148 my $casSrvId ( keys %{ $conf->{casSrvMetaDataOptions} || {} } )
1149 {
1150 if ( $casSrvId !~ validPartnerName ) {
1151 push @msg,
1152 "CAS Server name '$casSrvId' must contain only word characters (letters, digits, underscore)";
1153 }
1154 }
1155 return @msg ? ( 0, join( ', ', @msg ) ) : 1;
1156 },
1157
1158 # Notification system required with removed SF notification
1159 sfRemovedNotification => sub {
1160 return 1 unless ( $conf->{sfRemovedMsgRule} );
1161 return ( 1,
1162 'Notification system must be enabled to display a notification if a SF is removed'
1163 )
1164 if ( $conf->{sfRemovedUseNotif}
1165 and not $conf->{notification} );
1166 return 1;
1167 },
1168
1169 # noAjaxHook and krbByJs are incompatible (#2237)
1170 noAjaxHookwithKrb => sub {
1171 return ( 1,
1172 'noAjaxHook is not compatible with'
1173 . ' AJAX Kerberos authentication' )
1174 if ( $conf->{noAjaxHook} and $conf->{krbByJs} );
1175 return 1;
1176 },
1177
1178 # Cookie SameSite=None requires Secure flag
1179 # Same with SameSite=(auto) and SAML issuer in use
1180 SameSiteNoneWithSecure => sub {
1181 return ( -1, 'SameSite value = None requires the secured flag' )
1182 if ( getSameSite($conf) eq 'None'
1183 and !$conf->{securedCookie} );
1184 return 1;
1185 },
1186
1187 # Secure cookies require HTTPS
1188 SecureCookiesRequireHttps => sub {
1189 return ( -1, 'Secure cookies require a HTTPS portal URL' )
1190 if ( $conf->{securedCookie} == 1
1191 and $conf->{portal}
1192 and $conf->{portal} !~ /^https:/ );
1193 return 1;
1194 },
1195
1196 # Password module requires a password backend
1197 passwordModuleNeedsBackend => sub {
1198 return ( -1, 'Password module is enabled without password backend' )
1199 if ( $conf->{portalDisplayChangePassword}
1200 and $conf->{passwordDB} eq 'Null' );
1201 if ( $conf->{portalDisplayChangePassword}
1202 and $conf->{passwordDB} eq 'Choice'
1203 and $conf->{authChoiceModules} )
1204 {
1205 my $hasPwdBE = 0;
1206 foreach ( keys %{ $conf->{authChoiceModules} } ) {
1207 my @mods = split /;\s*/, $conf->{authChoiceModules}->{$_};
1208 $hasPwdBE ||= 1 unless $mods[2] eq 'Null';
1209 }
1210 return ( -1,
1211 'Password module is enabled without AuthChoice password backend'
1212 ) unless $hasPwdBE;
1213 }
1214 return 1;
1215 },
1216
1217 webAuthnRequiresToken => sub {
1218 if (
1219 grep { $_->[0] eq "WebAuthn" }
1220 map { [ split( /;\s*/, $_ ) ] }
1221 values %{ $conf->{authChoiceModules} }
1222 )
1223 {
1224 if ( $conf->{requireToken} == 0 ) {
1225 return ( 0,
1226 "WebAuthn authentication requires using a token" );
1227 }
1228 elsif ( $conf->{requireToken} == 1 ) {
1229 return 1;
1230 }
1231 else {
1232 return ( 1,
1233 "WebAuthn authentication requires a token"
1234 . " but a rule was defined for token use."
1235 . " WebAuthn might not work in some situations" );
1236 }
1237 }
1238 return 1;
1239 },
1240
1241 # FindUser requires Impersonation and attributes
1242 findUserWithoutImpersonationOrAttributes => sub {
1243 return ( -1,
1244 '"Impersonation" plugin is required to enable "FindUser" plugin'
1245 )
1246 if ( $conf->{findUser}
1247 and !$conf->{impersonationRule} );
1248 return ( 1,
1249 '"FindUser" plugin enabled without searching attributes' )
1250 if ( $conf->{findUser}
1251 and scalar
1252 keys %{ $conf->{findUserSearchingAttributes} } == 0 );
1253 return 1;
1254 },
1255
1256 # FindUser wildcard must be allowed
1257 findUserWildcard => sub {
1258 return 1
1259 unless ( $conf->{findUser}
1260 and $conf->{findUserWildcard}
1261 and $conf->{findUserControl} );
1262 return ( 1,
1263 'FindUser wildcard should be allowed by parameters control' )
1264 unless (
1265 $conf->{findUserWildcard} =~ /$conf->{findUserControl}/ );
1266 return 1;
1267 },
1268
1269 # AuthChoice parameters must exist
1270 AuthChoiceParams => sub {
1271 return 1
1272 unless ( $conf->{authChoiceModules}
1273 and %{ $conf->{authChoiceModules} }
1274 and $conf->{authentication} eq 'Choice' );
1275 foreach (qw(AuthBasic FindUser)) {
1276 if ( $conf->{"authChoice$_"} ) {
1277 my $test = $conf->{"authChoice$_"};
1278 my $param = grep /^$test$/,
1279 keys %{ $conf->{authChoiceModules} };
1280 return ( -1, "Choice $_ parameter does not exist" )
1281 unless $param;
1282 }
1283 }
1284 foreach my $k ( sort keys %{ $conf->{authChoiceModules} } ) {
1285 my $v = $conf->{authChoiceModules}->{$k};
1286 my ( $a, $u, $p, $url ) = split ';', $v;
1287 return ( 0, "Choice $k has an invalid URL" )
1288 if $url and $url !~ m#^https?://#;
1289 }
1290 return 1;
1291 },
1292
1293 # When auth is choice, userDB should be choice also
1294 userdbChoice => sub {
1295 return 1
1296 unless ( $conf->{authChoiceModules}
1297 and %{ $conf->{authChoiceModules} }
1298 and $conf->{authentication} eq 'Choice' );
1299 return ( 1, 'UserDB should be Same when authentication is Choice' )
1300 unless $conf->{userDB} eq 'Same'
1301 or $conf->{userDB} eq 'Choice';
1302 return 1;
1303 },
1304
1305 # FindUser authChoice parameter must be defined
1306 findUserChoiceParam => sub {
1307 return ( -1, 'FindUser choice parameter must be defined' )
1308 if ( $conf->{findUser}
1309 and $conf->{impersonationRule}
1310 and $conf->{authentication} eq 'Choice'
1311 and !$conf->{authChoiceFindUser} );
1312 return 1;
1313 },
1314
1315 # Chain must be defined with AuthChoice
1316 authChoiceChains => sub {
1317 return ( -1, 'Authentication choice enabled without chain' )
1318 if ( $conf->{authentication} eq 'Choice'
1319 and scalar keys %{ $conf->{authChoiceModules} } == 0 );
1320 return 1;
1321 },
1322
1323 # Internal portal URL must be defined with Proxy authentication
1324 authProxy => sub {
1325 return ( 0,
1326 'Proxy authentication enabled without internal portal URL' )
1327 if ( $conf->{authentication} eq 'Proxy'
1328 and !$conf->{proxyAuthService} );
1329 return 1;
1330 },
1331
1332 # Warn if Impersonation and proxyAuthServiceImpersonation are simultaneously enabled
1333 impersonationProxy => sub {
1334 return ( -1,
1335 'Impersonation and internal portal Impersonation are simultaneously enabled'
1336 )
1337 if ( $conf->{impersonationRule}
1338 and $conf->{proxyAuthServiceImpersonation} );
1339 return 1;
1340 },
1341
1342 # CheckDevOps requires Safe jail
1343 checkDevOpsWithSafeJail => sub {
1344 return ( 0, 'Safe jail must be enabled with CheckDevOps plugin' )
1345 if ( $conf->{checkDevOps}
1346 and !$conf->{useSafeJail} );
1347 return 1;
1348 },
1349
1350 # Work around for #1740
1351 corruptApplicationConfig => sub {
1352 for my $cat ( keys %{ $conf->{applicationList} || {} } ) {
1353 if ( ref( $conf->{applicationList}->{$cat} ) eq "HASH" ) {
1354 for my $app (
1355 keys %{ $conf->{applicationList}->{$cat} || {} } )
1356 {
1357 if (
1358 ref( $conf->{applicationList}->{$cat}->{$app} ) eq
1359 "HASH"
1360 and
1361 $conf->{applicationList}->{$cat}->{$app}->{type} eq
1362 "menuApp" )
1363 {
1364 return ( 0,
1365 'Error saving application list.'
1366 . ' Reload the manager and try again' );
1367 }
1368 }
1369 }
1370 }
1371 return 1;
1372 },
1373
1374 # Warn if both oidcRPMetaDataOptionsJwks and oidcRPMetaDataOptionsJwksUri is set
1375 noJwksDuplication => sub {
1376 return 1
1377 unless $conf->{oidcRPMetaDataOptions}
1378 and ref $conf->{oidcRPMetaDataOptions};
1379 my @pb;
1380 for my $rp ( keys %{ $conf->{oidcRPMetaDataOptions} } ) {
1381 push @pb, $rp
1382 if $conf->{oidcRPMetaDataOptions}->{$rp}
1383 ->{oidcRPMetaDataOptionsJwks}
1384 and $conf->{oidcRPMetaDataOptions}->{$rp}
1385 ->{oidcRPMetaDataOptionsJwksUri};
1386 }
1387 return 1 unless @pb;
1388 return ( 1,
1389 "JWKS URI defined while JWKS document is fixed: "
1390 . join( ', ', @pb ) );
1391 },
1392
1393 # If oidcRPMetaDataOptionsAuthRequiredForAuthorize is set, oidcRPMetaDataOptionsAuthMethod should be compatible
1394 oidcCompatAuth => sub {
1395 return 1
1396 unless $conf->{oidcRPMetaDataOptions}
1397 and ref $conf->{oidcRPMetaDataOptions};
1398 my @pb;
1399 for my $rp ( keys %{ $conf->{oidcRPMetaDataOptions} } ) {
1400 push @pb, $rp
1401 if $conf->{oidcRPMetaDataOptions}->{$rp}
1402 ->{oidcRPMetaDataOptionsAuthRequiredForAuthorize}
1403 and $conf->{oidcRPMetaDataOptions}->{$rp}
1404 ->{oidcRPMetaDataOptionsAuthMethod}
1405 and $conf->{oidcRPMetaDataOptions}->{$rp}
1406 ->{oidcRPMetaDataOptionsAuthMethod} !~
1407 /^(?:client_secret|private_key)_jwt$/;
1408 }
1409 return 1 unless @pb;
1410 return ( 1,
1411 'Incompatible required authentication methods in RP '
1412 . '(only client_secret_jwt and private_key_jwt are allowed '
1413 . 'when authentication is required on authorization endpoint: '
1414 . join( ', ', @pb ) );
1415 },
1416
1417 # Test password length policy if enabled
1418 ppMaxSizeGreaterThanMinSize => sub {
1419 return ( 1,
1420 'Password maximum size should be greater than minimal size' )
1421 if ( (
1422 $conf->{passwordPolicyMinSize} >=
1423 $conf->{passwordPolicyMaxSize}
1424 )
1425 and $conf->{passwordPolicyMaxSize}
1426 and $conf->{passwordPolicyActivation}
1427 );
1428 return 1;
1429 },
1430
1431 # Test password minimal size policy if enabled
1432 ppMinSize => sub {
1433 my $total;
1434 foreach (qw(Lower Upper Digit SpeChar)) {
1435 $total += $conf->{"passwordPolicyMin$_"}
1436 if $conf->{"passwordPolicyMin$_"} > 0;
1437 }
1438 return ( 1,
1439 'Password minimal size should be greater than total of minimal sizes'
1440 )
1441 if ( ( $conf->{passwordPolicyMinSize} < $total )
1442 and $conf->{passwordPolicyMinSize}
1443 and $conf->{passwordPolicyActivation} );
1444 return 1;
1445 },
1446 accessTokenConsistency => sub {
1447 return 1
1448 unless $conf->{issuerDBOpenIDConnectActivation};
1449 my @pb;
1450 foreach my $rp ( keys %{ $conf->{oidcRPMetaDataOptions} || {} } ) {
1451 my $opts = $conf->{oidcRPMetaDataOptions}->{$rp};
1452 push @pb, $rp
1453 if $opts->{oidcRPMetaDataOptionsAccessTokenClaims}
1454 and not $opts->{oidcRPMetaDataOptionsAccessTokenJWT};
1455 }
1456 return 1 unless @pb;
1457 return ( 0,
1458 'access_token cannot be opaque with claims in access_token ('
1459 . join( ', ', @pb )
1460 . ')' );
1461 },
1462 oidcNoneConsistency => sub {
1463 my @pb;
1464 return 1 unless $conf->{oidcServiceMetaDataDisallowNoneAlg};
1465 foreach my $rp ( keys %{ $conf->{oidcRPMetaDataOptions} || {} } ) {
1466 my $opts = $conf->{oidcRPMetaDataOptions}->{$rp};
1467 push @pb, $rp
1468 if $opts->{oidcRPMetaDataOptionsIDTokenSignAlg} eq 'none'
1469 or $opts->{oidcRPMetaDataOptionsUserInfoSignAlg} eq 'none';
1470 }
1471 return 1 unless @pb;
1472 return ( 1,
1473 'Signature algorithm is not allowed but set for: '
1474 . join( ', ', @pb ) );
1475 },
1476 crowdSecBouncer => sub {
1477 return 1 unless $conf->{crowdsec};
1478 return 1 if $conf->{crowdsecKey};
1479 return ( 0, 'Crowdsec Bouncer enabled without API key' );
1480 },
1481 crowdSecAgent => sub {
1482 return 1 unless $conf->{crowdsecAgent};
1483 return 1
1484 if $conf->{crowdsecMachineId} and $conf->{crowdsecPassword};
1485 return ( 0,
1486 'Crowdsec Agent enabled without machine_id and password' );
1487 },
1488
1489 # External menu URL must be a valid URL
1490 externalMenuUrl => sub {
1491 return 1 unless $conf->{externalMenu};
1492 return ( 0, 'External menu URL looks invalid' )
1493 unless $conf->{externalMenu} =~ m#^(\w+)://#;
1494 return 1;
1495 },
1496 };
1497 }
1498
1499 1;