| 1 | package Lemonldap::NG::Portal::Auth::SSL; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use Mouse; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | PE_CERTIFICATEREQUIRED | ||||||||||||||||||||||||||||||||||||
| 7 | PE_ERROR | ||||||||||||||||||||||||||||||||||||
| 8 | PE_BADCERTIFICATE | ||||||||||||||||||||||||||||||||||||
| 9 | PE_FIRSTACCESS | ||||||||||||||||||||||||||||||||||||
| 10 | PE_OK | ||||||||||||||||||||||||||||||||||||
| 11 | 6 | ); | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 6 | our $VERSION = '2.23.0'; | |||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 6 | extends 'Lemonldap::NG::Portal::Main::Auth'; | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | # INITIALIZATION | ||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||
| 19 | 6 | has AjaxInitScript => ( is => 'rw', default => '' ); | |||||||||||||||||||||||||||||||||||
| 20 | 6 | has Name => ( is => 'ro', default => 'SSL' ); | |||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | 6 | has auth_id => ( is => 'ro', default => 'ssl' ); | |||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | has subject_var => | ||||||||||||||||||||||||||||||||||||
| 25 | 6 | ▶ | ( is => 'rw', lazy => 1, default => sub { $_[0]->conf->{SSLVar} } ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 26 | has issuer_var => | ||||||||||||||||||||||||||||||||||||
| 27 | 6 | ▶ | ( is => 'rw', lazy => 1, default => sub { $_[0]->conf->{SSLIssuerVar} } ); | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | 6 | with 'Lemonldap::NG::Portal::Auth::_Ajax'; | |||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||
| 31 | 26 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 32 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 33 | $self->AjaxInitScript( '<script type="application/init">{"sslHost":"' | ||||||||||||||||||||||||||||||||||||
| 34 | . $self->conf->{sslHost} | ||||||||||||||||||||||||||||||||||||
| 35 | . '"}</script>' ) | ||||||||||||||||||||||||||||||||||||
| 36 | 26 | ▶ | if $self->conf->{sslByAjax}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 37 | 26 | return 1; | |||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||
| 40 | # Create authentication token so you can use 2FA, notifications, etc, with Ajax | ||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | sub auth_route { | ||||||||||||||||||||||||||||||||||
|
Subroutine
auth_route: called CC=2 SCAR=7.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 42 | 4 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||
| 44 | 4 | my $ssl_user = $self->get_user_from_req($req); | |||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | if ($ssl_user) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 46 | return $self->ajax_success( | ||||||||||||||||||||||||||||||||||||
| 47 | $req, | ||||||||||||||||||||||||||||||||||||
| 48 | $ssl_user, | ||||||||||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||||||||||
| 50 | 4 | _Issuer => $req->env->{ $self->issuer_var }, | |||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||
| 54 | else { | ||||||||||||||||||||||||||||||||||||
| 55 | 0 | $req->wantErrorRender(1); | |||||||||||||||||||||||||||||||||||
| 56 | 0 | return $self->p->doPE( $req, PE_CERTIFICATEREQUIRED ); | |||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | sub get_user_from_req { | ||||||||||||||||||||||||||||||||||
|
Subroutine
get_user_from_req: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 61 | 12 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||
| 63 | 12 | my $field = $self->subject_var; | |||||||||||||||||||||||||||||||||||
| 64 | 12 | my $issuer_var = $self->issuer_var; | |||||||||||||||||||||||||||||||||||
| 65 | 12 | ▶ | if ( $req->env->{$issuer_var} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 66 | $self->logger->debug( | ||||||||||||||||||||||||||||||||||||
| 67 | 7 | 'Received SSL issuer ' . $req->env->{$issuer_var} ); | |||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||
| 69 | 7 | ▶ | if ( my $tmp = $self->conf->{SSLVarIf}->{ $req->env->{$issuer_var} } ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 70 | 2 | $field = $tmp; | |||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||
| 73 | 12 | my $value = $req->env->{$field}; | |||||||||||||||||||||||||||||||||||
| 74 | 12 | ▶ | if ($value) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 75 | 11 | $self->logger->debug("Using SSL environment variable $field"); | |||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||
| 77 | else { | ||||||||||||||||||||||||||||||||||||
| 78 | 1 | $self->logger->notice( | |||||||||||||||||||||||||||||||||||
| 79 | "No name found in certificate, check your configuration"); | ||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||
| 82 | 12 | return $value; | |||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||
| 85 | # Read username in SSL environment variables, or return an error | ||||||||||||||||||||||||||||||||||||
| 86 | # @return Lemonldap::NG::Portal constant | ||||||||||||||||||||||||||||||||||||
| 87 | 10 | ▶ | sub extractFormInfo { | ||||||||||||||||||||||||||||||||||
|
Subroutine
extractFormInfo: called CC=12 SCAR=28.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 88 | 10 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||
| 90 | # If this is the ajax query, allow response to contain HTML code | ||||||||||||||||||||||||||||||||||||
| 91 | # to update the portal error message | ||||||||||||||||||||||||||||||||||||
| 92 | 10 | ▶ | if ( $req->wantJSON ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 93 | 7 | $req->wantErrorRender(1); | |||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | 10 | ▶ | if ( $self->conf->{sslByAjax} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 97 | 5 | my $token_id = $req->param('ajax_auth_token'); | |||||||||||||||||||||||||||||||||||
| 98 | 5 | ▶ | if ($token_id) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 99 | 2 | my $token = $self->get_auth_token( $req, $token_id ); | |||||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | if ( $token->{user} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 101 | 2 | my $user = $token->{user}; | |||||||||||||||||||||||||||||||||||
| 102 | 2 | $self->userLogger->notice( | |||||||||||||||||||||||||||||||||||
| 103 | "Good SSL authentication for " . $user ); | ||||||||||||||||||||||||||||||||||||
| 104 | 2 | $req->user($user); | |||||||||||||||||||||||||||||||||||
| 105 | 2 | $req->data->{_Issuer} = $token->{extraInfo}->{_Issuer}; | |||||||||||||||||||||||||||||||||||
| 106 | 2 | return PE_OK; | |||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||
| 108 | else { | ||||||||||||||||||||||||||||||||||||
| 109 | 0 | return PE_ERROR; | |||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||
| 114 | 8 | my $ssl_user = $self->get_user_from_req($req); | |||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | 8 | ▶ | if ( $ssl_user and $req->user($ssl_user) ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$ssl_user and $req->user($ssl_user)
MC/DC50%1/2
$ssl_user and $req->user($ssl_user)
$ssl_user
$req->user($ssl_user)
Truth table66%2/3
A and B
A= $ssl_userB= $req->user($ssl_user)
| |||||||||||||||||||||||||||||||||||||
| 117 | 7 | $self->userLogger->notice( | |||||||||||||||||||||||||||||||||||
| 118 | "Good SSL authentication for " . $req->user ); | ||||||||||||||||||||||||||||||||||||
| 119 | 7 | $req->data->{_Issuer} = $req->env->{ $self->issuer_var }; | |||||||||||||||||||||||||||||||||||
| 120 | 7 | return PE_OK; | |||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||
| 122 | elsif ( $req->env->{SSL_CLIENT_S_DN} ) { | ||||||||||||||||||||||||||||||||||||
| 123 | 0 | return PE_BADCERTIFICATE; | |||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||
| 125 | ▶ | elsif ( $self->conf->{sslByAjax} and not $req->param('nossl') ) { | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->conf->{"sslByAjax"} and not $req->param("nossl")
MC/DC0%0/2
$self->conf->{"sslByAjax"} and not $req->param("nossl")
$self->conf->{"sslByAjax"}
not $req->param("nossl")
Truth table33%1/3
A and not(B)
A= $self->conf->{"sslByAjax"}B= not $req->param("nossl")
| |||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | # If this is the AJAX query | ||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | if ( $req->wantJSON ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 129 | 0 | return PE_CERTIFICATEREQUIRED; | |||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||
| 132 | 1 | $self->initDisplay($req); | |||||||||||||||||||||||||||||||||||
| 133 | 1 | $req->data->{waitingMessage} = 1; | |||||||||||||||||||||||||||||||||||
| 134 | 1 | return PE_FIRSTACCESS; | |||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if ( $self->conf->{sslByAjax} ) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 138 | 0 | $self->initDisplay($req); | |||||||||||||||||||||||||||||||||||
| 139 | 0 | return PE_BADCERTIFICATE; | |||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||
| 141 | 0 | $self->userLogger->warn('No certificate found'); | |||||||||||||||||||||||||||||||||||
| 142 | 0 | return PE_CERTIFICATEREQUIRED; | |||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||
| 146 | 8 | ▶ | sub authenticate { | ||||||||||||||||||||||||||||||||||
|
Subroutine
authenticate: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 147 | 8 | return PE_OK; | |||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||
| 150 | 8 | ▶ | sub setAuthSessionInfo { | ||||||||||||||||||||||||||||||||||
|
Subroutine
setAuthSessionInfo: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 151 | 8 | my ( $self, $req ) = @_; | |||||||||||||||||||||||||||||||||||
| 152 | 8 | $req->sessionInfo->{authenticationLevel} = $self->conf->{SSLAuthnLevel}; | |||||||||||||||||||||||||||||||||||
| 153 | 8 | $req->sessionInfo->{_Issuer} = $req->data->{_Issuer}; | |||||||||||||||||||||||||||||||||||
| 154 | 8 | return PE_OK; | |||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||
| 157 | 4 | ▶ | sub getDisplayType { | ||||||||||||||||||||||||||||||||||
|
Subroutine
getDisplayType: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 158 | 4 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||
| 159 | 4 | ▶ | return ( $self->{conf}->{sslByAjax} ? "sslform" : "logo" ); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub authLogout { | ||||||||||||||||||||||||||||||||||
|
Subroutine
authLogout: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 163 | 0 | return PE_OK; | |||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||
| 166 | 6 | 1; | |||||||||||||||||||||||||||||||||||