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