« blib/lib/Lemonldap/NG/Portal/Lib/CrowdSecFilter.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Lib/OpenIDConnect.pm »
| 1 | package Lemonldap::NG::Portal::Lib::SAML; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Mouse; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Lemonldap::NG::Common::Conf::SAML::Metadata; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Lemonldap::NG::Common::Session; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Lemonldap::NG::Common::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Lemonldap::NG::Common::FormEncode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use HTML::Entities qw(decode_entities encode_entities); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use HTTP::Request; # SOAP call | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use POSIX qw(strftime); # Convert SAML2 date into timestamp | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Time::Local; # Convert SAML2 date into timestamp | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Encode; # Encode attribute values | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use URI; # Get metadata URL path | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | use Lemonldap::NG::Portal::Main::Constants qw( | |||||||||||||||||||||||||||
| 18 | PE_OK | ||||||||||||||||||||||||||||
| 19 | PE_REDIRECT | ||||||||||||||||||||||||||||
| 20 | PE_LOGOUT_OK | ||||||||||||||||||||||||||||
| 21 | PE_SLO_ERROR | ||||||||||||||||||||||||||||
| 22 | 3 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | with 'Lemonldap::NG::Portal::Lib::LazyLoadedConfiguration'; | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | our $VERSION = '2.22.0'; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # PROPERTIES | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | has lassoServer => ( is => 'rw' ); | ||||||||||||||||||||||||||||
| 31 | has idpList => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 32 | has idpRules => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 33 | has idpAttributes => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 34 | has idpOptions => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 35 | has spList => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 36 | has spRules => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 37 | has spLevelRules => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 38 | has spMacros => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 39 | has spAttributes => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 40 | has spOptions => ( is => 'rw', default => sub { {} } ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # XML parser | ||||||||||||||||||||||||||||
| 43 | has parser => ( | ||||||||||||||||||||||||||||
| 44 | is => 'rw', | ||||||||||||||||||||||||||||
| 45 | builder => sub { | ||||||||||||||||||||||||||||
| 46 | return XML::LibXML->new( load_ext_dtd => 0, expand_entities => 0 ); | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # return LWP::UserAgent object | ||||||||||||||||||||||||||||
| 51 | has ua => ( | ||||||||||||||||||||||||||||
| 52 | is => 'rw', | ||||||||||||||||||||||||||||
| 53 | lazy => 1, | ||||||||||||||||||||||||||||
| 54 | builder => sub { | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # TODO : LWP options to use a proxy for example | ||||||||||||||||||||||||||||
| 57 | my $ua = Lemonldap::NG::Common::UserAgent->new( $_[0]->{conf} ); | ||||||||||||||||||||||||||||
| 58 | $ua->env_proxy(); | ||||||||||||||||||||||||||||
| 59 | return $ua; | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # SAML storage | ||||||||||||||||||||||||||||
| 64 | has aModule => ( is => 'rw' ); | ||||||||||||||||||||||||||||
| 65 | has amOpts => ( is => 'rw' ); | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # INITIALIZATION | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | BEGIN { | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | # Load Glib if available | ||||||||||||||||||||||||||||
| 72 | 3 | ▶ | eval 'use Glib;'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 73 | 3 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 3 | print STDERR | |||||||||||||||||||||||||||
| 75 | "Glib Lasso messages will not be catched (require Glib module)\n"; | ||||||||||||||||||||||||||||
| 76 | 3 | ▶ | eval "use constant GLIB => 0"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | else { | ||||||||||||||||||||||||||||
| 79 | 0 | eval "use constant GLIB => 1"; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # Load Lasso.pm | ||||||||||||||||||||||||||||
| 83 | 3 | ▶ | eval 'use Lasso;'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 84 | 3 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 3 | print STDERR "Lasso.pm not loaded: $@"; | |||||||||||||||||||||||||||
| 86 | eval | ||||||||||||||||||||||||||||
| 87 | 3 | ▶ | 'use constant LASSO => 0;use constant BADLASSO => 0;use constant LASSOTHINSESSIONS => 0'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | else { | ||||||||||||||||||||||||||||
| 90 | 3 | ▶ | no strict 'subs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 91 | 0 | eval 'use constant LASSO => 1'; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # Check Lasso version >= 2.3.0 | ||||||||||||||||||||||||||||
| 94 | 0 | my $lasso_check_version_mode = | |||||||||||||||||||||||||||
| 95 | eval 'Lasso::Constants::CHECK_VERSION_NUMERIC'; | ||||||||||||||||||||||||||||
| 96 | 0 | my $check_version = | |||||||||||||||||||||||||||
| 97 | Lasso::check_version( 2, 3, 0, $lasso_check_version_mode ); | ||||||||||||||||||||||||||||
| 98 | 0 | ▶ | unless ($check_version) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | eval 'use constant BADLASSO => 1'; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||
| 102 | 0 | eval 'use constant BADLASSO => 0'; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # Try to set thin-sessions flag | ||||||||||||||||||||||||||||
| 106 | 0 | eval 'Lasso::set_flag("thin-sessions");'; | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | eval 'use constant LASSOTHINSESSIONS => 0'; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | else { | ||||||||||||||||||||||||||||
| 111 | 0 | eval 'use constant LASSOTHINSESSIONS => 1'; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | sub init { | ||||||||||||||||||||||||||||
| 118 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | # Initialize SAML storage | ||||||||||||||||||||||||||||
| 121 | 0 | my $moduleOptions; | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ( $self->conf->{samlStorage} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $moduleOptions = $self->conf->{samlStorageOptions} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->conf->{'samlStorageOptions'} || {}
MC/DC0%0/1
$self->conf->{'samlStorageOptions'} || {}
$self->conf->{'samlStorageOptions'}
Truth table0%0/2
A
A= $self->conf->{'samlStorageOptions'}
| |||||||||||||||||||||||||||||
| 124 | 0 | $moduleOptions->{backend} = $self->conf->{samlStorage}; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | else { | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | $moduleOptions = $self->conf->{globalStorageOptions} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->conf->{'globalStorageOptions'} || {}
MC/DC0%0/1
$self->conf->{'globalStorageOptions'} || {}
$self->conf->{'globalStorageOptions'}
Truth table0%0/2
A
A= $self->conf->{'globalStorageOptions'}
| |||||||||||||||||||||||||||||
| 128 | 0 | $moduleOptions->{backend} = $self->conf->{globalStorage}; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | $self->aModule( $moduleOptions->{backend} ); | |||||||||||||||||||||||||||
| 131 | 0 | $self->amOpts($moduleOptions); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | # Check for Lasso errors/messages (see BEGIN) | ||||||||||||||||||||||||||||
| 134 | 0 | unless (LASSO) { | |||||||||||||||||||||||||||
| 135 | 0 | $self->logger->error("Module Lasso not loaded (see below)"); | |||||||||||||||||||||||||||
| 136 | 0 | return 0; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | if (BADLASSO) { | |||||||||||||||||||||||||||
| 140 | $self->logger->error('Lasso version >= 2.3.0 required'); | ||||||||||||||||||||||||||||
| 141 | return 0; | ||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | unless (LASSOTHINSESSIONS) { | |||||||||||||||||||||||||||
| 145 | 0 | $self->logger->warn('Lasso thin-sessions flag could not be set'); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | else { | ||||||||||||||||||||||||||||
| 148 | $self->logger->debug('Lasso thin-sessions flag set'); | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | if (GLIB) { | |||||||||||||||||||||||||||
| 151 | Glib::Log->set_handler( | ||||||||||||||||||||||||||||
| 152 | "Lasso", | ||||||||||||||||||||||||||||
| 153 | [qw/ error critical warning message info debug /], | ||||||||||||||||||||||||||||
| 154 | sub { | ||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $self->logger->debug( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 156 | $_[0] . " error " . $_[1] . ": " . $_[2] ); | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | ); | ||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | # Conf initialization | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | return 0 unless ( $self->lassoServer( $self->loadService ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | $self->addUnauthRoute( | ||||||||||||||||||||||||||||
| 165 | 0 | ▶ | ( $self->{path} || 'saml' ) => | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'path'} || 'saml'
MC/DC0%0/1
$self->{'path'} || 'saml'
$self->{'path'}
Truth table0%0/2
A
A= $self->{'path'}
| |||||||||||||||||||||||||||||
| 166 | { 'metadata' => { ':type' => 'metadata' } }, | ||||||||||||||||||||||||||||
| 167 | ['GET'] | ||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||
| 169 | $self->addAuthRoute( | ||||||||||||||||||||||||||||
| 170 | 0 | ▶ | ( $self->{path} || 'saml' ) => | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'path'} || 'saml'
MC/DC0%0/1
$self->{'path'} || 'saml'
$self->{'path'}
Truth table0%0/2
A
A= $self->{'path'}
| |||||||||||||||||||||||||||||
| 171 | { 'metadata' => { ':type' => 'metadata' } }, | ||||||||||||||||||||||||||||
| 172 | ['GET'] | ||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||
| 174 | 0 | return 1; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # METHODS | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | sub loadService { | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
loadService: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # Check if certificate is available | ||||||||||||||||||||||||||||
| 183 | 0 | my $signing_key = | |||||||||||||||||||||||||||
| 184 | $self->get_private_key( $self->_get_default_signing_key_name ); | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | unless ($signing_key) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 187 | 'SAML private and public key not found in configuration'); | ||||||||||||||||||||||||||||
| 188 | 0 | return 0; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | my $serviceCertificate; | |||||||||||||||||||||||||||
| 192 | 0 | ▶ | if ( $self->conf->{samlServiceUseCertificateInResponse} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->conf->{"samlServiceUseCertificateInResponse"} and $signing_key->{"public"} =~ /CERTIFICATE/
MC/DC0%0/2
$self->conf->{"samlServiceUseCertificateInResponse"} and $signing_key->{"public"} =~ /CERTIFICATE/
$self->conf->{"samlServiceUseCertificateInResponse"}
$signing_key->{"public"} =~ /CERTIFICATE/
Truth table0%0/3
A and B
A= $self->conf->{"samlServiceUseCertificateInResponse"}B= $signing_key->{"public"} =~ /CERTIFICATE/
| |||||||||||||||||||||||||||||
| 193 | and $signing_key->{public} =~ /CERTIFICATE/ ) | ||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||
| 195 | 0 | $serviceCertificate = $signing_key->{public}; | |||||||||||||||||||||||||||
| 196 | 0 | $self->logger->debug('Certificate will be used in SAML responses'); | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # Get metadata from configuration | ||||||||||||||||||||||||||||
| 201 | 0 | $self->logger->debug("Get Metadata for this service"); | |||||||||||||||||||||||||||
| 202 | 0 | my $metadata = $self->_get_metadata_xml( undef, "all" ); | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | $self->logger->debug("Create Lasso server"); | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | my $encryption_key = | |||||||||||||||||||||||||||
| 207 | $self->get_private_key( $self->_get_default_encryption_key_name ); | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # Create Lasso server with service metadata | ||||||||||||||||||||||||||||
| 210 | my $server = $self->createServer( | ||||||||||||||||||||||||||||
| 211 | $metadata, | ||||||||||||||||||||||||||||
| 212 | $signing_key->{private}, | ||||||||||||||||||||||||||||
| 213 | $signing_key->{password}, | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # use signature cert for encryption unless defined | ||||||||||||||||||||||||||||
| 216 | ( | ||||||||||||||||||||||||||||
| 217 | $encryption_key | ||||||||||||||||||||||||||||
| 218 | ? ( $encryption_key->{private}, $encryption_key->{password}, ) | ||||||||||||||||||||||||||||
| 219 | : ( $signing_key->{private}, $signing_key->{password}, ) | ||||||||||||||||||||||||||||
| 220 | 0 | ▶ | ), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | $serviceCertificate | ||||||||||||||||||||||||||||
| 222 | ); | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | unless ($server) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | $self->logger->error('Unable to create Lasso server'); | |||||||||||||||||||||||||||
| 226 | 0 | return 0; | |||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | # Signature method | ||||||||||||||||||||||||||||
| 230 | 0 | my $method = $self->getDefaultSignatureMethod(); | |||||||||||||||||||||||||||
| 231 | 0 | $server->signature_method( $self->getSignatureMethod($method) ); | |||||||||||||||||||||||||||
| 232 | 0 | $self->logger->debug("Set $method as SAML server signature method "); | |||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | # Log | ||||||||||||||||||||||||||||
| 235 | 0 | $self->logger->debug("Service created"); | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 0 | return $server; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | sub loadIDPs { | ||||||||||||||||||||||||||||
| 241 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
loadIDPs: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # Load identity provider metadata | ||||||||||||||||||||||||||||
| 244 | # IDP metadata are listed in $self->{samlIDPMetaDataXML} | ||||||||||||||||||||||||||||
| 245 | # Each key is the IDP name | ||||||||||||||||||||||||||||
| 246 | # Build IDP list for later use in extractFormInfo | ||||||||||||||||||||||||||||
| 247 | 0 | foreach ( keys %{ $self->conf->{samlIDPMetaDataXML} } ) { | |||||||||||||||||||||||||||
| 248 | 0 | $self->loadIDP($_); | |||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | 0 | return 1; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | sub loadIDP { | ||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my ( $self, $idpConfKey ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
loadIDP: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | $self->logger->debug("Get Metadata for IDP $idpConfKey"); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | # If XML metadata has been set in conf, load this provider from conf | ||||||||||||||||||||||||||||
| 259 | my $idp_metadata = | ||||||||||||||||||||||||||||
| 260 | 0 | $self->conf->{samlIDPMetaDataXML}->{$idpConfKey}->{samlIDPMetaDataXML}; | |||||||||||||||||||||||||||
| 261 | 0 | ▶ | if ($idp_metadata) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if ( $self->load_idp_from_conf( $idpConfKey, $idp_metadata ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 0 | $self->logger->debug("IDP $idpConfKey added"); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | else { | ||||||||||||||||||||||||||||
| 266 | 0 | $self->logger->warn("Ignoring IDP $idpConfKey"); | |||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | sub load_idp_from_conf { | ||||||||||||||||||||||||||||
| 272 | 0 | ▶ | my ( $self, $idpConfKey, $idp_metadata ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
load_idp_from_conf: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | # Check metadata format | ||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ( ref $idp_metadata eq "HASH" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 277 | "Metadata for IDP $idpConfKey is in old format. Please reload them from Manager" | ||||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||
| 279 | 0 | return; | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if ( $self->conf->{samlMetadataForceUTF8} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | 0 | $idp_metadata = encode( "utf8", $idp_metadata ); | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | # Store IDP entityID and Organization Name | ||||||||||||||||||||||||||||
| 287 | 0 | my ( $tmp, $entityID ) = ( $idp_metadata =~ /entityID=(['"])(.+?)\1/si ); | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | # Decode HTML entities from entityID | ||||||||||||||||||||||||||||
| 290 | # TODO: see Lasso comment above | ||||||||||||||||||||||||||||
| 291 | 0 | decode_entities($entityID); | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | return $self->load_idp_metadata( | ||||||||||||||||||||||||||||
| 294 | $idpConfKey, | ||||||||||||||||||||||||||||
| 295 | $idp_metadata, | ||||||||||||||||||||||||||||
| 296 | $entityID, | ||||||||||||||||||||||||||||
| 297 | $self->conf->{samlIDPMetaDataExportedAttributes}->{$idpConfKey}, | ||||||||||||||||||||||||||||
| 298 | 0 | $self->conf->{samlIDPMetaDataOptions}->{$idpConfKey}, | |||||||||||||||||||||||||||
| 299 | ); | ||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | sub load_idp_metadata { | ||||||||||||||||||||||||||||
| 303 | 0 | ▶ | my ( $self, $idpConfKey, $idp_metadata, $entityID, $attributes, $options ) | ||||||||||||||||||||||||||
|
Subroutine
load_idp_metadata: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 304 | = @_; | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | # Add this IDP to Lasso::Server | ||||||||||||||||||||||||||||
| 307 | 0 | my $result = $self->addIDP( $self->lassoServer, $idp_metadata ); | |||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | unless ($result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | $self->logger->error("Fail to use IDP $idpConfKey Metadata"); | |||||||||||||||||||||||||||
| 311 | 0 | return; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 0 | ▶ | my $name = $self->getOrganizationName( $self->lassoServer, $entityID ) | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->getOrganizationName($self->lassoServer, $entityID) || ucfirst $idpConfKey
MC/DC0%0/2
$self->getOrganizationName($self->lassoServer, $entityID) || ucfirst $idpConfKey
$self->getOrganizationName($self->lassoServer, $entityID)
ucfirst $idpConfKey
Truth table0%0/3
A || B
A= $self->getOrganizationName($self->lassoServer, $entityID)B= ucfirst $idpConfKey
| |||||||||||||||||||||||||||||
| 315 | || ucfirst($idpConfKey); | ||||||||||||||||||||||||||||
| 316 | 0 | $self->idpList->{$entityID}->{confKey} = $idpConfKey; | |||||||||||||||||||||||||||
| 317 | 0 | $self->idpList->{$entityID}->{name} = $name; | |||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | # Set encryption mode | ||||||||||||||||||||||||||||
| 320 | my $encryption_mode = | ||||||||||||||||||||||||||||
| 321 | 0 | ▶ | $options->{samlIDPMetaDataOptionsEncryptionMode} || "none"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$options->{'samlIDPMetaDataOptionsEncryptionMode'} || 'none'
MC/DC0%0/1
$options->{'samlIDPMetaDataOptionsEncryptionMode'} || 'none'
$options->{'samlIDPMetaDataOptionsEncryptionMode'}
Truth table0%0/2
A
A= $options->{'samlIDPMetaDataOptionsEncryptionMode'}
| |||||||||||||||||||||||||||||
| 322 | 0 | my $lasso_encryption_mode = $self->getEncryptionMode($encryption_mode); | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | unless ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | $self->setProviderEncryptionMode( | ||||||||||||||||||||||||||||
| 326 | $self->lassoServer->get_provider($entityID), | ||||||||||||||||||||||||||||
| 327 | $lasso_encryption_mode | ||||||||||||||||||||||||||||
| 328 | ) | ||||||||||||||||||||||||||||
| 329 | ) | ||||||||||||||||||||||||||||
| 330 | { | ||||||||||||||||||||||||||||
| 331 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 332 | "Unable to set encryption mode $encryption_mode on IDP $idpConfKey" | ||||||||||||||||||||||||||||
| 333 | ); | ||||||||||||||||||||||||||||
| 334 | 0 | delete $self->idpList->{$entityID}; | |||||||||||||||||||||||||||
| 335 | 0 | return; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 338 | 0 | "Set encryption mode $encryption_mode on IDP $idpConfKey"); | |||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | # Set signature method if overridden | ||||||||||||||||||||||||||||
| 341 | 0 | my $signature_method = $options->{samlIDPMetaDataOptionsSignatureMethod}; | |||||||||||||||||||||||||||
| 342 | 0 | my $signature_key = $options->{samlIDPMetaDataOptionsSignatureKey}; | |||||||||||||||||||||||||||
| 343 | 0 | $self->_override_signature_or_key( $entityID, "IDP $idpConfKey", | |||||||||||||||||||||||||||
| 344 | $signature_method, $signature_key ); | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | # Set display options | ||||||||||||||||||||||||||||
| 347 | $self->idpList->{$entityID}->{displayName} = | ||||||||||||||||||||||||||||
| 348 | 0 | $options->{samlIDPMetaDataOptionsDisplayName}; | |||||||||||||||||||||||||||
| 349 | $self->idpList->{$entityID}->{icon} = | ||||||||||||||||||||||||||||
| 350 | 0 | $options->{samlIDPMetaDataOptionsIcon}; | |||||||||||||||||||||||||||
| 351 | $self->idpList->{$entityID}->{tooltip} = | ||||||||||||||||||||||||||||
| 352 | 0 | $options->{samlIDPMetaDataOptionsTooltip}; | |||||||||||||||||||||||||||
| 353 | $self->idpList->{$entityID}->{order} = | ||||||||||||||||||||||||||||
| 354 | 0 | $options->{samlIDPMetaDataOptionsSortNumber}; | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | # Set rule | ||||||||||||||||||||||||||||
| 357 | 0 | my $cond = $options->{samlIDPMetaDataOptionsResolutionRule}; | |||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ( length $cond ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | 0 | $cond = $self->p->HANDLER->substitute($cond); | |||||||||||||||||||||||||||
| 360 | 0 | ▶ | unless ( $cond = $self->p->HANDLER->buildSub($cond) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | $self->logger->error( 'SAML IdP rule error: ' | ||||||||||||||||||||||||||||
| 362 | 0 | . $self->p->HANDLER->tsv->{jail}->error ); | |||||||||||||||||||||||||||
| 363 | 0 | delete $self->idpList->{$entityID}; | |||||||||||||||||||||||||||
| 364 | 0 | return; | |||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | 0 | $self->idpRules->{$entityID} = $cond; | |||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | $self->idpAttributes->{$entityID} = { %{ $attributes || {} } }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 370 | 0 | ▶ | $self->idpOptions->{$entityID} = { %{ $options || {} } }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | return 1; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | sub loadSPs { | ||||||||||||||||||||||||||||
| 376 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
loadSPs: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | # Load service provider metadata | ||||||||||||||||||||||||||||
| 379 | # SP metadata are listed in $self->{samlSPMetaDataXML} | ||||||||||||||||||||||||||||
| 380 | # Each key is the SP name | ||||||||||||||||||||||||||||
| 381 | # Build SP list for later use in extractFormInfo | ||||||||||||||||||||||||||||
| 382 | 0 | foreach ( keys %{ $self->conf->{samlSPMetaDataXML} } ) { | |||||||||||||||||||||||||||
| 383 | 0 | $self->loadSP($_); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | 0 | return 1; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | # This loads either a single SP or a federation | ||||||||||||||||||||||||||||
| 389 | sub loadSP { | ||||||||||||||||||||||||||||
| 390 | 0 | ▶ | my ( $self, $spConfKey ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
loadSP: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 0 | $self->logger->debug("Get Metadata for SP $spConfKey"); | |||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | # If XML metadata has been set in conf, load this provider from conf | ||||||||||||||||||||||||||||
| 395 | my $sp_metadata = | ||||||||||||||||||||||||||||
| 396 | 0 | $self->conf->{samlSPMetaDataXML}->{$spConfKey}->{samlSPMetaDataXML}; | |||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ($sp_metadata) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 398 | 0 | $self->load_sp_from_conf( $spConfKey, $sp_metadata ); | |||||||||||||||||||||||||||
| 399 | 0 | $self->logger->debug("SP $spConfKey added"); | |||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | sub load_sp_from_conf { | ||||||||||||||||||||||||||||
| 404 | 0 | ▶ | my ( $self, $spConfKey, $sp_metadata ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
load_sp_from_conf: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | # Check metadata format | ||||||||||||||||||||||||||||
| 407 | 0 | ▶ | if ( ref $sp_metadata eq "HASH" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 409 | "Metadata for SP $spConfKey is in old format. Please reload them from Manager" | ||||||||||||||||||||||||||||
| 410 | ); | ||||||||||||||||||||||||||||
| 411 | 0 | return; | |||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if ( $self->conf->{samlMetadataForceUTF8} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 0 | $sp_metadata = encode( "utf8", $sp_metadata ); | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | # Get SP entityID | ||||||||||||||||||||||||||||
| 419 | # TODO: when Lasso issue #35061 is fixed in all distros, | ||||||||||||||||||||||||||||
| 420 | # we could load the metadata into a new LassoProvider, extract the | ||||||||||||||||||||||||||||
| 421 | # parsed-and-decoded entityID from this Provider, and then add the | ||||||||||||||||||||||||||||
| 422 | # Provider into the server with $server->add_provider2, instead of | ||||||||||||||||||||||||||||
| 423 | # extracting and decoding HTML entities ourselves here | ||||||||||||||||||||||||||||
| 424 | 0 | my ( $tmp, $entityID ) = ( $sp_metadata =~ /entityID=(['"])(.+?)\1/si ); | |||||||||||||||||||||||||||
| 425 | 0 | decode_entities($entityID); | |||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | return $self->load_sp_metadata( | ||||||||||||||||||||||||||||
| 428 | $spConfKey, | ||||||||||||||||||||||||||||
| 429 | $sp_metadata, | ||||||||||||||||||||||||||||
| 430 | $entityID, | ||||||||||||||||||||||||||||
| 431 | $self->conf->{samlSPMetaDataExportedAttributes}->{$spConfKey}, | ||||||||||||||||||||||||||||
| 432 | $self->conf->{samlSPMetaDataOptions}->{$spConfKey}, | ||||||||||||||||||||||||||||
| 433 | 0 | $self->conf->{samlSPMetaDataMacros}->{$spConfKey}, | |||||||||||||||||||||||||||
| 434 | ); | ||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | sub load_sp_metadata { | ||||||||||||||||||||||||||||
| 438 | 0 | ▶ | my ( $self, $spConfKey, $sp_metadata, $entityID, $attributes, $options, | ||||||||||||||||||||||||||
|
Subroutine
load_sp_metadata: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||
| 439 | $macros ) | ||||||||||||||||||||||||||||
| 440 | = @_; | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | 0 | my $valid = 1; | |||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | # Access Rule | ||||||||||||||||||||||||||||
| 445 | 0 | my $rule = $options->{samlSPMetaDataOptionsRule}; | |||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ( length $rule ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 447 | 0 | $rule = $self->p->buildRule( $rule, "access rule for SP $spConfKey" ); | |||||||||||||||||||||||||||
| 448 | 0 | ▶ | unless ($rule) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 449 | 0 | $valid = 0; | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | # Required authentication level rule | ||||||||||||||||||||||||||||
| 454 | 0 | ▶ | my $levelrule = $options->{samlSPMetaDataOptionsAuthnLevel} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$options->{'samlSPMetaDataOptionsAuthnLevel'} || 0
MC/DC0%0/1
$options->{'samlSPMetaDataOptionsAuthnLevel'} || 0
$options->{'samlSPMetaDataOptionsAuthnLevel'}
Truth table0%0/2
A
A= $options->{'samlSPMetaDataOptionsAuthnLevel'}
| |||||||||||||||||||||||||||||
| 455 | 0 | $levelrule = $self->p->buildRule( $levelrule, | |||||||||||||||||||||||||||
| 456 | "required authentication level rule for SP $spConfKey" ); | ||||||||||||||||||||||||||||
| 457 | 0 | ▶ | unless ($levelrule) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | 0 | $valid = 0; | |||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | # Load per-SP macros | ||||||||||||||||||||||||||||
| 462 | 0 | my $compiledMacros = {}; | |||||||||||||||||||||||||||
| 463 | 0 | for my $macroAttr ( keys %{$macros} ) { | |||||||||||||||||||||||||||
| 464 | 0 | my $macroRule = $macros->{$macroAttr}; | |||||||||||||||||||||||||||
| 465 | 0 | ▶ | if ( length $macroRule ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 466 | 0 | $macroRule = $self->p->HANDLER->substitute($macroRule); | |||||||||||||||||||||||||||
| 467 | 0 | ▶ | if ( $macroRule = $self->p->HANDLER->buildSub($macroRule) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 468 | 0 | $compiledMacros->{$macroAttr} = $macroRule; | |||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||
| 470 | else { | ||||||||||||||||||||||||||||
| 471 | 0 | $valid = 0; | |||||||||||||||||||||||||||
| 472 | $self->logger->error( | ||||||||||||||||||||||||||||
| 473 | "Error processing macro $macroAttr for SAML SP $spConfKey" | ||||||||||||||||||||||||||||
| 474 | 0 | . $self->p->HANDLER->tsv->{jail}->error ); | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | 0 | ▶ | if ($valid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 480 | 0 | $self->spRules->{$spConfKey} = $rule; | |||||||||||||||||||||||||||
| 481 | 0 | $self->spLevelRules->{$spConfKey} = $levelrule; | |||||||||||||||||||||||||||
| 482 | 0 | $self->spMacros->{$spConfKey} = $compiledMacros; | |||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | else { | ||||||||||||||||||||||||||||
| 485 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 486 | "SAML SP $spConfKey has errors and will be ignored"); | ||||||||||||||||||||||||||||
| 487 | 0 | return; | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||
| 490 | 0 | ▶ | $self->spAttributes->{$entityID} = { %{ $attributes || {} } }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | 0 | ▶ | $self->spOptions->{$entityID} = { %{ $options || {} } }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||
| 494 | # Add this SP to Lasso::Server | ||||||||||||||||||||||||||||
| 495 | 0 | my $result = $self->addSP( $self->lassoServer, $sp_metadata ); | |||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | 0 | ▶ | unless ($result) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 498 | 0 | $self->logger->error("Fail to use SP $spConfKey Metadata"); | |||||||||||||||||||||||||||
| 499 | 0 | return; | |||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | # Store Org name | ||||||||||||||||||||||||||||
| 503 | 0 | ▶ | my $name = $self->getOrganizationName( $self->lassoServer, $entityID ) | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->getOrganizationName($self->lassoServer, $entityID) || ucfirst $spConfKey
MC/DC0%0/2
$self->getOrganizationName($self->lassoServer, $entityID) || ucfirst $spConfKey
$self->getOrganizationName($self->lassoServer, $entityID)
ucfirst $spConfKey
Truth table0%0/3
A || B
A= $self->getOrganizationName($self->lassoServer, $entityID)B= ucfirst $spConfKey
| |||||||||||||||||||||||||||||
| 504 | || ucfirst($spConfKey); | ||||||||||||||||||||||||||||
| 505 | 0 | $self->spList->{$entityID}->{confKey} = $spConfKey; | |||||||||||||||||||||||||||
| 506 | 0 | $self->spList->{$entityID}->{name} = $name; | |||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | # Set encryption mode | ||||||||||||||||||||||||||||
| 509 | my $encryption_mode = | ||||||||||||||||||||||||||||
| 510 | 0 | ▶ | $options->{samlSPMetaDataOptionsEncryptionMode} || "none"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$options->{'samlSPMetaDataOptionsEncryptionMode'} || 'none'
MC/DC0%0/1
$options->{'samlSPMetaDataOptionsEncryptionMode'} || 'none'
$options->{'samlSPMetaDataOptionsEncryptionMode'}
Truth table0%0/2
A
A= $options->{'samlSPMetaDataOptionsEncryptionMode'}
| |||||||||||||||||||||||||||||
| 511 | 0 | my $lasso_encryption_mode = $self->getEncryptionMode($encryption_mode); | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 0 | ▶ | unless ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | $self->setProviderEncryptionMode( | ||||||||||||||||||||||||||||
| 515 | $self->lassoServer->get_provider($entityID), | ||||||||||||||||||||||||||||
| 516 | $lasso_encryption_mode | ||||||||||||||||||||||||||||
| 517 | ) | ||||||||||||||||||||||||||||
| 518 | ) | ||||||||||||||||||||||||||||
| 519 | { | ||||||||||||||||||||||||||||
| 520 | 0 | $self->logger->error( | |||||||||||||||||||||||||||
| 521 | "Unable to set encryption mode $encryption_mode on SP $spConfKey"); | ||||||||||||||||||||||||||||
| 522 | 0 | return; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 525 | 0 | "Set encryption mode $encryption_mode on SP $spConfKey"); | |||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||
| 527 | # Set signature method if overridden | ||||||||||||||||||||||||||||
| 528 | 0 | my $signature_method = $options->{samlSPMetaDataOptionsSignatureMethod}; | |||||||||||||||||||||||||||
| 529 | 0 | my $signature_key = $options->{samlSPMetaDataOptionsSignatureKey}; | |||||||||||||||||||||||||||
| 530 | 0 | $self->_override_signature_or_key( $entityID, "SP $spConfKey", | |||||||||||||||||||||||||||
| 531 | $signature_method, $signature_key ); | ||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||
| 534 | sub lazy_load_message { | ||||||||||||||||||||||||||||
| 535 | 0 | ▶ | my ( $self, $message ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lazy_load_message: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 536 | 0 | ▶ | return unless $message; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 537 | 0 | my $entityID = $self->getIssuer($message); | |||||||||||||||||||||||||||
| 538 | 0 | ▶ | if ($entityID) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 539 | 0 | $self->logger->debug("Found entityID $entityID in message"); | |||||||||||||||||||||||||||
| 540 | 0 | return $self->lazy_load_entityid($entityID); | |||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | sub lazy_load_entityid { | ||||||||||||||||||||||||||||
| 545 | 0 | ▶ | my ( $self, $entityID ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
lazy_load_entityid: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 546 | 0 | ▶ | return unless $entityID; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 547 | 0 | my $provider = $self->lassoServer->get_provider($entityID); | |||||||||||||||||||||||||||
| 548 | 0 | ▶ | unless ($provider) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 549 | 0 | $self->logger->debug("Lazy loading provider $entityID"); | |||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | 0 | return $self->lazy_load_config($entityID); | |||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||
| 555 | sub load_config { | ||||||||||||||||||||||||||||
| 556 | 0 | ▶ | my ( $self, $entityID ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
load_config: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | 0 | my $config = {}; | |||||||||||||||||||||||||||
| 559 | 0 | my $res = $self->p->processHook( {}, 'getSamlConfig', $entityID, $config ); | |||||||||||||||||||||||||||
| 560 | 0 | ▶ | if ( $res != PE_OK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 561 | 0 | return; | |||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||
| 564 | 0 | my $info; | |||||||||||||||||||||||||||
| 565 | 0 | ▶ | if ( $config->{sp_metadata} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 566 | 0 | $info->{sp_confKey} = $config->{sp_confKey}; | |||||||||||||||||||||||||||
| 567 | $self->load_sp_metadata( | ||||||||||||||||||||||||||||
| 568 | $config->{sp_confKey}, $config->{sp_metadata}, | ||||||||||||||||||||||||||||
| 569 | $entityID, $config->{sp_attributes}, | ||||||||||||||||||||||||||||
| 570 | $config->{sp_options}, $config->{sp_macros}, | ||||||||||||||||||||||||||||
| 571 | 0 | ); | |||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 0 | ▶ | if ( $config->{idp_metadata} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 576 | 0 | $info->{idp_confKey} = $config->{idp_confKey}; | |||||||||||||||||||||||||||
| 577 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 578 | $self->load_idp_metadata( | ||||||||||||||||||||||||||||
| 579 | $config->{idp_confKey}, $config->{idp_metadata}, | ||||||||||||||||||||||||||||
| 580 | $entityID, $config->{idp_attributes}, | ||||||||||||||||||||||||||||
| 581 | $config->{idp_options} | ||||||||||||||||||||||||||||
| 582 | ) | ||||||||||||||||||||||||||||
| 583 | ) | ||||||||||||||||||||||||||||
| 584 | { | ||||||||||||||||||||||||||||
| 585 | 0 | $self->logger->debug("IDP $config->{idp_confKey} added from hook"); | |||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||
| 587 | else { | ||||||||||||||||||||||||||||
| 588 | 0 | $self->logger->warn("Ignoring IDP $config->{idp_confKey}"); | |||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||
| 591 | 0 | my $ttl = $config->{ttl}; | |||||||||||||||||||||||||||
| 592 | 0 | ▶ | return { ( $ttl ? ( ttl => $ttl ) : () ), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 593 | ( $info ? ( info => $info ) : () ) }; | ||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||
| 596 | # This method returns the configuration info for the given provider | ||||||||||||||||||||||||||||
| 597 | # Returns a hashref or undef | ||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | # Check SAML requests and responses | ||||||||||||||||||||||||||||
| 600 | sub checkMessage { | ||||||||||||||||||||||||||||
| 601 | 0 | ▶ | my ( $self, $req, $url, $request_method, $content_type, $profile_type ) = | ||||||||||||||||||||||||||
|
Subroutine
checkMessage: not called CC=16 SCAR=56.1
| |||||||||||||||||||||||||||||
| 602 | @_; | ||||||||||||||||||||||||||||
| 603 | 0 | ▶ | $profile_type ||= "login"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$profile_type ||= "login"
MC/DC0%0/1
$profile_type ||= "login"
$profile_type
Truth table0%0/2
A
A= $profile_type
| |||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||
| 605 | # Create Profile object | ||||||||||||||||||||||||||||
| 606 | 0 | my $profile; | |||||||||||||||||||||||||||
| 607 | 0 | ▶ | $profile = $self->createLogin( $self->lassoServer ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 608 | if ( $profile_type eq "login" ); | ||||||||||||||||||||||||||||
| 609 | 0 | ▶ | $profile = $self->createLogout( $self->lassoServer ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 610 | if ( $profile_type eq "logout" ); | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | # Get relayState | ||||||||||||||||||||||||||||
| 613 | 0 | my $relaystate = $req->param('RelayState'); | |||||||||||||||||||||||||||
| 614 | 0 | my ( $method, $request, $response, $artifact, $message ); | |||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | # 2.1. HTTP REDIRECT | ||||||||||||||||||||||||||||
| 617 | 0 | ▶ | if ( $request_method eq 'GET' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||
| 619 | 0 | $method = Lasso::Constants::HTTP_METHOD_REDIRECT; | |||||||||||||||||||||||||||
| 620 | 0 | $self->logger->debug("SAML method: HTTP-REDIRECT"); | |||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | 0 | ▶ | if ( $req->param('SAMLResponse') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | # Response in query string | ||||||||||||||||||||||||||||
| 625 | 0 | $response = $self->getQueryString($req); | |||||||||||||||||||||||||||
| 626 | 0 | $self->logger->debug("HTTP-REDIRECT: SAML Response $response"); | |||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | 0 | ▶ | if ( $req->param('SAMLRequest') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | # Request in query string | ||||||||||||||||||||||||||||
| 633 | 0 | $request = $self->getQueryString($req); | |||||||||||||||||||||||||||
| 634 | 0 | $self->logger->debug("HTTP-REDIRECT: SAML Request $request"); | |||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 0 | ▶ | if ( $req->param('SAMLart') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||
| 640 | # Artifact in query string | ||||||||||||||||||||||||||||
| 641 | 0 | $artifact = $self->getQueryString($req); | |||||||||||||||||||||||||||
| 642 | 0 | $self->logger->debug("HTTP-REDIRECT: SAML Artifact $artifact"); | |||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||
| 644 | # Resolve Artifact | ||||||||||||||||||||||||||||
| 645 | 0 | $method = Lasso::Constants::HTTP_METHOD_ARTIFACT_GET; | |||||||||||||||||||||||||||
| 646 | 0 | $message = $self->resolveArtifact( $profile, $artifact, $method ); | |||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||
| 648 | # Request or response ? | ||||||||||||||||||||||||||||
| 649 | 0 | ▶ | if ( $self->_isArtifactSamlResponse($message) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 650 | 0 | $response = $message; | |||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | else { | ||||||||||||||||||||||||||||
| 653 | 0 | $request = $message; | |||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||
| 659 | # 2.2. HTTP POST AND SOAP | ||||||||||||||||||||||||||||
| 660 | elsif ( $request_method =~ /^POST$/ ) { | ||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||
| 662 | # 2.2.1. POST | ||||||||||||||||||||||||||||
| 663 | 0 | ▶ | if ( $content_type !~ /xml/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | 0 | $method = Lasso::Constants::HTTP_METHOD_POST; | |||||||||||||||||||||||||||
| 666 | 0 | $self->logger->debug("SAML method: HTTP-POST"); | |||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||
| 668 | 0 | ▶ | if ( $req->param('SAMLResponse') ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||
| 670 | # Response in body part | ||||||||||||||||||||||||||||
| 671 | 0 | $response = $req->param('SAMLResponse'); | |||||||||||||||||||||||||||
| 672 | 0 | $response =~ s/ /+/gs; | |||||||||||||||||||||||||||
| 673 | 0 | $self->logger->debug("HTTP-POST: SAML Response $response"); | |||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | elsif ( $req->param('SAMLRequest') ) { | ||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | # Request in body part | ||||||||||||||||||||||||||||
| 680 | 0 | $request = $req->param('SAMLRequest'); | |||||||||||||||||||||||||||
| 681 | 0 | $self->logger->debug("HTTP-POST: SAML Request $request"); | |||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||
| 685 | elsif ( $req->param('SAMLart') ) { | ||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||
| 687 | # Artifact in SAMLart param | ||||||||||||||||||||||||||||
| 688 | 0 | $artifact = $req->param('SAMLart'); | |||||||||||||||||||||||||||
| 689 | 0 | $self->logger->debug("HTTP-POST: SAML Artifact $artifact"); | |||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | # Resolve Artifact | ||||||||||||||||||||||||||||
| 692 | 0 | $method = Lasso::Constants::HTTP_METHOD_ARTIFACT_POST; | |||||||||||||||||||||||||||
| 693 | 0 | $message = | |||||||||||||||||||||||||||
| 694 | $self->resolveArtifact( $profile, $artifact, $method ); | ||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | # Request or response ? | ||||||||||||||||||||||||||||
| 697 | 0 | ▶ | if ( $self->_isArtifactSamlResponse($message) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 698 | 0 | $response = $message; | |||||||||||||||||||||||||||
| 699 | } | ||||||||||||||||||||||||||||
| 700 | else { | ||||||||||||||||||||||||||||
| 701 | 0 | $request = $message; | |||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||
| 704 | } | ||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||
| 708 | # 2.2.2. SOAP | ||||||||||||||||||||||||||||
| 709 | else { | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | 0 | $method = Lasso::Constants::HTTP_METHOD_SOAP; | |||||||||||||||||||||||||||
| 712 | 0 | $self->logger->debug("SAML method: HTTP-SOAP"); | |||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||
| 714 | # SOAP is always a request | ||||||||||||||||||||||||||||
| 715 | 0 | $request = $req->content; | |||||||||||||||||||||||||||
| 716 | 0 | $self->logger->debug("HTTP-SOAP: SAML Request $request"); | |||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||
| 722 | # 4. Return values | ||||||||||||||||||||||||||||
| 723 | 0 | ▶ | return ( $request, $response, $method, $relaystate, $artifact ? 1 : 0 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | sub _isArtifactSamlResponse { | ||||||||||||||||||||||||||||
| 727 | my ( $self, $message ) = @_; | ||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||
| 729 | my $type = eval { | ||||||||||||||||||||||||||||
| 730 | my $resp = Lasso::Samlp2ArtifactResponse->new; | ||||||||||||||||||||||||||||
| 731 | $resp->init_from_message($message); | ||||||||||||||||||||||||||||
| 732 | $resp->any->get_name; | ||||||||||||||||||||||||||||
| 733 | }; | ||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||
| 735 | if ($@) { | ||||||||||||||||||||||||||||
| 736 | $self->logger->warn("Could not detect type of Artifact response"); | ||||||||||||||||||||||||||||
| 737 | return; | ||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||
| 740 | $self->logger->debug("Artifact response type is $type"); | ||||||||||||||||||||||||||||
| 741 | if ( $type eq "Response" ) { | ||||||||||||||||||||||||||||
| 742 | return 1; | ||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||
| 744 | else { | ||||||||||||||||||||||||||||
| 745 | return 0; | ||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||
| 749 | ## @method boolean checkLassoError(Lasso::Error error, string level) | ||||||||||||||||||||||||||||
| 750 | # Log Lasso error code and message if this is actually a Lasso::Error with code > 0 | ||||||||||||||||||||||||||||
| 751 | # @param error Lasso error object | ||||||||||||||||||||||||||||
| 752 | # @param level optional log level (debug by default) | ||||||||||||||||||||||||||||
| 753 | # @return 1 if no error | ||||||||||||||||||||||||||||
| 754 | sub checkLassoError { | ||||||||||||||||||||||||||||
| 755 | my ( $self, $error, $level ) = @_; | ||||||||||||||||||||||||||||
| 756 | my ( $lasso_result, $lasso_error_code ) = | ||||||||||||||||||||||||||||
| 757 | $self->getLassoError( $error, $level ); | ||||||||||||||||||||||||||||
| 758 | return $lasso_result; | ||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||
| 761 | ## @method boolean getLassoError(Lasso::Error error, string level) | ||||||||||||||||||||||||||||
| 762 | # Log Lasso error code and message if this is actually a Lasso::Error with code > 0 | ||||||||||||||||||||||||||||
| 763 | # @param error Lasso error object | ||||||||||||||||||||||||||||
| 764 | # @param level optional log level (debug by default) | ||||||||||||||||||||||||||||
| 765 | # @return (success status, lasso error code) | ||||||||||||||||||||||||||||
| 766 | sub getLassoError { | ||||||||||||||||||||||||||||
| 767 | my ( $self, $error, $level ) = @_; | ||||||||||||||||||||||||||||
| 768 | $level ||= 'error'; | ||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||
| 770 | # If $error is not a Lasso::Error object, display error string | ||||||||||||||||||||||||||||
| 771 | unless ( ref($error) and $error->isa("Lasso::Error") ) { | ||||||||||||||||||||||||||||
| 772 | return ( 1, undef ) unless $error; | ||||||||||||||||||||||||||||
| 773 | $self->p->lmLog( "Lasso error: $error", $level ); | ||||||||||||||||||||||||||||
| 774 | return ( 0, undef ); | ||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||
| 776 | |||||||||||||||||||||||||||||
| 777 | # Else check error code and error message | ||||||||||||||||||||||||||||
| 778 | if ( $error->{code} ) { | ||||||||||||||||||||||||||||
| 779 | $self->p->lmLog( | ||||||||||||||||||||||||||||
| 780 | "Lasso error code " . $error->{code} . ": " . $error->{message}, | ||||||||||||||||||||||||||||
| 781 | $level ); | ||||||||||||||||||||||||||||
| 782 | return ( 0, $error->{code} ); | ||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||
| 785 | return ( 1, undef ); | ||||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||
| 788 | ## @method Lasso::Server createServer(string metadata, string private_key, string private_key_password, string private_key_enc, string private_key_enc_password, string certificate) | ||||||||||||||||||||||||||||
| 789 | # Load service metadata and create Lasso::Server object | ||||||||||||||||||||||||||||
| 790 | # @param metadata SAML metadata | ||||||||||||||||||||||||||||
| 791 | # @param private_key private key | ||||||||||||||||||||||||||||
| 792 | # @param private_key_password optional private key password | ||||||||||||||||||||||||||||
| 793 | # @param private_key_enc optional private key for encryption | ||||||||||||||||||||||||||||
| 794 | # @param private_key_enc_password optional private key password for encryption | ||||||||||||||||||||||||||||
| 795 | # @param certificate optional certificate | ||||||||||||||||||||||||||||
| 796 | # @return Lasso::Server object | ||||||||||||||||||||||||||||
| 797 | sub createServer { | ||||||||||||||||||||||||||||
| 798 | my ( $self, $metadata, $private_key, $private_key_password, | ||||||||||||||||||||||||||||
| 799 | $private_key_enc, $private_key_enc_password, $certificate ) | ||||||||||||||||||||||||||||
| 800 | = @_; | ||||||||||||||||||||||||||||
| 801 | my $server; | ||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||
| 803 | # https://dev.entrouvert.org/issues/51415 | ||||||||||||||||||||||||||||
| 804 | my $save_env = $ENV{'SSL_CERT_FILE'}; | ||||||||||||||||||||||||||||
| 805 | $ENV{'SSL_CERT_FILE'} = "/dev/null"; | ||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||
| 807 | eval { | ||||||||||||||||||||||||||||
| 808 | $server = Lasso::Server::new_from_buffers( $metadata, $private_key, | ||||||||||||||||||||||||||||
| 809 | $private_key_password, $certificate ); | ||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||
| 811 | # Set private key for encryption | ||||||||||||||||||||||||||||
| 812 | if ( $server && $private_key_enc ) { | ||||||||||||||||||||||||||||
| 813 | Lasso::Server::set_encryption_private_key_with_password( $server, | ||||||||||||||||||||||||||||
| 814 | $private_key_enc, $private_key_enc_password ); | ||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||
| 816 | }; | ||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||
| 818 | if ( defined $save_env ) { | ||||||||||||||||||||||||||||
| 819 | $ENV{'SSL_CERT_FILE'} = $save_env; | ||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||
| 821 | else { | ||||||||||||||||||||||||||||
| 822 | delete $ENV{'SSL_CERT_FILE'}; | ||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||
| 825 | if ($@) { | ||||||||||||||||||||||||||||
| 826 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 827 | return; | ||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||
| 830 | return $server; | ||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||
| 833 | ## @method boolean addIDP(Lasso::Server server, string metadata, string public_key, string ca_cert_chain) | ||||||||||||||||||||||||||||
| 834 | # Add IDP to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 835 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 836 | # @param metadata IDP metadata | ||||||||||||||||||||||||||||
| 837 | # @param public_key optional public key | ||||||||||||||||||||||||||||
| 838 | # @param ca_cert_chain optional ca cert chain | ||||||||||||||||||||||||||||
| 839 | # @return boolean result | ||||||||||||||||||||||||||||
| 840 | sub addIDP { | ||||||||||||||||||||||||||||
| 841 | my ( $self, $server, $metadata, $public_key, $ca_cert_chain ) = @_; | ||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||
| 843 | return 0 unless ( $server->isa("Lasso::Server") and defined $metadata ); | ||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||
| 845 | return $self->addProvider( $server, Lasso::Constants::PROVIDER_ROLE_IDP, | ||||||||||||||||||||||||||||
| 846 | $metadata, $public_key, $ca_cert_chain ); | ||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||
| 849 | ## @method boolean addSP(Lasso::Server server, string metadata, string public_key, string ca_cert_chain) | ||||||||||||||||||||||||||||
| 850 | # Add SP to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 851 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 852 | # @param metadata SP metadata | ||||||||||||||||||||||||||||
| 853 | # @param public_key optional public key | ||||||||||||||||||||||||||||
| 854 | # @param ca_cert_chain optional ca cert chain | ||||||||||||||||||||||||||||
| 855 | # @return boolean result | ||||||||||||||||||||||||||||
| 856 | sub addSP { | ||||||||||||||||||||||||||||
| 857 | my ( $self, $server, $metadata, $public_key, $ca_cert_chain ) = @_; | ||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||
| 859 | return 0 unless ( $server->isa("Lasso::Server") and defined $metadata ); | ||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||
| 861 | return $self->addProvider( $server, Lasso::Constants::PROVIDER_ROLE_SP, | ||||||||||||||||||||||||||||
| 862 | $metadata, $public_key, $ca_cert_chain ); | ||||||||||||||||||||||||||||
| 863 | } | ||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||
| 865 | ## @method boolean addAA(Lasso::Server server, string metadata, string public_key, string ca_cert_chain) | ||||||||||||||||||||||||||||
| 866 | # Add Attribute Authority to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 867 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 868 | # @param metadata AA metadata | ||||||||||||||||||||||||||||
| 869 | # @param public_key optional public key | ||||||||||||||||||||||||||||
| 870 | # @param ca_cert_chain optional ca cert chain | ||||||||||||||||||||||||||||
| 871 | # @return boolean result | ||||||||||||||||||||||||||||
| 872 | sub addAA { | ||||||||||||||||||||||||||||
| 873 | my ( $self, $server, $metadata, $public_key, $ca_cert_chain ) = @_; | ||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||
| 875 | return 0 unless ( $server->isa("Lasso::Server") and defined $metadata ); | ||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||
| 877 | return $self->addProvider( $server, | ||||||||||||||||||||||||||||
| 878 | Lasso::Constants::PROVIDER_ROLE_ATTRIBUTE_AUTHORITY, | ||||||||||||||||||||||||||||
| 879 | $metadata, $public_key, $ca_cert_chain ); | ||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||
| 882 | ## @method boolean addProvider(Lasso::Server server, int role, string metadata, string public_key, string ca_cert_chain) | ||||||||||||||||||||||||||||
| 883 | # Add provider to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 884 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 885 | # @param role (IDP, SP or Both) | ||||||||||||||||||||||||||||
| 886 | # @param metadata IDP metadata | ||||||||||||||||||||||||||||
| 887 | # @param public_key optional public key | ||||||||||||||||||||||||||||
| 888 | # @param ca_cert_chain optional ca cert chain | ||||||||||||||||||||||||||||
| 889 | # @return boolean result | ||||||||||||||||||||||||||||
| 890 | sub addProvider { | ||||||||||||||||||||||||||||
| 891 | my ( $self, $server, $role, $metadata, $public_key, $ca_cert_chain ) = @_; | ||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||
| 893 | return 0 | ||||||||||||||||||||||||||||
| 894 | unless ( $server->isa("Lasso::Server") | ||||||||||||||||||||||||||||
| 895 | and defined $role | ||||||||||||||||||||||||||||
| 896 | and defined $metadata ); | ||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||
| 898 | # https://dev.entrouvert.org/issues/51415 | ||||||||||||||||||||||||||||
| 899 | my $save_env = $ENV{'SSL_CERT_FILE'}; | ||||||||||||||||||||||||||||
| 900 | $ENV{'SSL_CERT_FILE'} = "/dev/null"; | ||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||
| 902 | eval { | ||||||||||||||||||||||||||||
| 903 | Lasso::Server::add_provider_from_buffer( $server, $role, $metadata, | ||||||||||||||||||||||||||||
| 904 | $public_key, $ca_cert_chain ); | ||||||||||||||||||||||||||||
| 905 | }; | ||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||
| 907 | if ( defined $save_env ) { | ||||||||||||||||||||||||||||
| 908 | $ENV{'SSL_CERT_FILE'} = $save_env; | ||||||||||||||||||||||||||||
| 909 | } | ||||||||||||||||||||||||||||
| 910 | else { | ||||||||||||||||||||||||||||
| 911 | delete $ENV{'SSL_CERT_FILE'}; | ||||||||||||||||||||||||||||
| 912 | } | ||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||
| 914 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||
| 917 | ## @method string getOrganizationName(Lasso::Server server, string idp) | ||||||||||||||||||||||||||||
| 918 | # Return name of organization picked up from metadata | ||||||||||||||||||||||||||||
| 919 | #@param server Lasso::Server object | ||||||||||||||||||||||||||||
| 920 | #@param idp entity ID | ||||||||||||||||||||||||||||
| 921 | #@return string organization name | ||||||||||||||||||||||||||||
| 922 | sub getOrganizationName { | ||||||||||||||||||||||||||||
| 923 | my ( $self, $server, $idp ) = @_; | ||||||||||||||||||||||||||||
| 924 | my ( $provider, $node ); | ||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||
| 926 | # Get provider from server | ||||||||||||||||||||||||||||
| 927 | eval { $provider = Lasso::Server::get_provider( $server, $idp ); }; | ||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||
| 929 | if ($@) { | ||||||||||||||||||||||||||||
| 930 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 931 | return; | ||||||||||||||||||||||||||||
| 932 | } | ||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||
| 934 | # Get organization node | ||||||||||||||||||||||||||||
| 935 | eval { $node = Lasso::Provider::get_organization($provider); }; | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | if ($@) { | ||||||||||||||||||||||||||||
| 938 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 939 | return; | ||||||||||||||||||||||||||||
| 940 | } | ||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||
| 942 | # Return if node is empty | ||||||||||||||||||||||||||||
| 943 | return unless $node; | ||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||
| 945 | # Extract organization name | ||||||||||||||||||||||||||||
| 946 | my $data = eval { $self->parser->parse_string($node)->documentElement }; | ||||||||||||||||||||||||||||
| 947 | if ( my $exception = $@ ) { | ||||||||||||||||||||||||||||
| 948 | $self->logger->warn("Could not parse Organization for $idp: $@"); | ||||||||||||||||||||||||||||
| 949 | } | ||||||||||||||||||||||||||||
| 950 | return unless $data; | ||||||||||||||||||||||||||||
| 951 | return $data->getElementsByTagNameNS( | ||||||||||||||||||||||||||||
| 952 | "urn:oasis:names:tc:SAML:2.0:metadata", | ||||||||||||||||||||||||||||
| 953 | 'OrganizationName' )->string_value; | ||||||||||||||||||||||||||||
| 954 | } | ||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||
| 956 | ## @method string getNextProviderId(Lasso::Logout logout) | ||||||||||||||||||||||||||||
| 957 | # Returns the provider id from providerID_index in list of providerIDs in | ||||||||||||||||||||||||||||
| 958 | # principal session with the exception of initial service provider ID. | ||||||||||||||||||||||||||||
| 959 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 960 | # @return string | ||||||||||||||||||||||||||||
| 961 | sub getNextProviderId { | ||||||||||||||||||||||||||||
| 962 | my $self = shift; | ||||||||||||||||||||||||||||
| 963 | my $logout = shift; | ||||||||||||||||||||||||||||
| 964 | my $providerId; | ||||||||||||||||||||||||||||
| 965 | |||||||||||||||||||||||||||||
| 966 | eval { $providerId = Lasso::Logout::get_next_providerID($logout); }; | ||||||||||||||||||||||||||||
| 967 | if ($@) { | ||||||||||||||||||||||||||||
| 968 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 969 | return; | ||||||||||||||||||||||||||||
| 970 | } | ||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||
| 972 | return $providerId; | ||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||
| 974 | |||||||||||||||||||||||||||||
| 975 | ## @method boolean resetProviderIdIndex(Lasso::Logout logout) | ||||||||||||||||||||||||||||
| 976 | # Reset the providerID_index attribute in Lasso::Logout object | ||||||||||||||||||||||||||||
| 977 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 978 | # @return boolean | ||||||||||||||||||||||||||||
| 979 | sub resetProviderIdIndex { | ||||||||||||||||||||||||||||
| 980 | my $self = shift; | ||||||||||||||||||||||||||||
| 981 | my $logout = shift; | ||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||
| 983 | eval { Lasso::Logout::reset_providerID_index($logout); }; | ||||||||||||||||||||||||||||
| 984 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 985 | } | ||||||||||||||||||||||||||||
| 986 | |||||||||||||||||||||||||||||
| 987 | ## @method Lasso::Login createAuthnRequest(Lasso::Server server, string idp, int method, boolean forceAuthn, boolean isPassive, string nameIDFormat, boolean allowProxiedAuthn, boolean signSSOMessage, string requestedAuthnContext) | ||||||||||||||||||||||||||||
| 988 | # Create authentication request for selected IDP | ||||||||||||||||||||||||||||
| 989 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 990 | # @param idp IDP entityID | ||||||||||||||||||||||||||||
| 991 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 992 | # @param forceAuthn force authentication on IDP | ||||||||||||||||||||||||||||
| 993 | # @param isPassive require passive authentication | ||||||||||||||||||||||||||||
| 994 | # @param nameIDFormat SAML2 NameIDFormat | ||||||||||||||||||||||||||||
| 995 | # @param allowProxiedAuthn allow proxy on IDP // Not used anymore but kept to avoid API break | ||||||||||||||||||||||||||||
| 996 | # @param signSSOMessage sign request | ||||||||||||||||||||||||||||
| 997 | # @param requestedAuthnContext authentication context | ||||||||||||||||||||||||||||
| 998 | # @return Lasso::Login object | ||||||||||||||||||||||||||||
| 999 | sub createAuthnRequest { | ||||||||||||||||||||||||||||
| 1000 | my ( | ||||||||||||||||||||||||||||
| 1001 | $self, $req, $server, | ||||||||||||||||||||||||||||
| 1002 | $idp, $method, $forceAuthn, | ||||||||||||||||||||||||||||
| 1003 | $isPassive, $nameIDFormat, $allowProxiedAuthn, | ||||||||||||||||||||||||||||
| 1004 | $signSSOMessage, $requestedAuthnContext | ||||||||||||||||||||||||||||
| 1005 | ) = @_; | ||||||||||||||||||||||||||||
| 1006 | my $proxyCount; | ||||||||||||||||||||||||||||
| 1007 | my $proxyRequestedAuthnContext; | ||||||||||||||||||||||||||||
| 1008 | |||||||||||||||||||||||||||||
| 1009 | # Create Lasso Login | ||||||||||||||||||||||||||||
| 1010 | my $login = $self->createLogin($server); | ||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||
| 1012 | unless ($login) { | ||||||||||||||||||||||||||||
| 1013 | $self->logger->error('Unable to create Lasso login'); | ||||||||||||||||||||||||||||
| 1014 | return; | ||||||||||||||||||||||||||||
| 1015 | } | ||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||
| 1017 | # Init authentication request | ||||||||||||||||||||||||||||
| 1018 | unless ( $self->initAuthnRequest( $login, $idp, $method ) ) { | ||||||||||||||||||||||||||||
| 1019 | $self->logger->error( | ||||||||||||||||||||||||||||
| 1020 | "Could not initiate authentication request on $idp"); | ||||||||||||||||||||||||||||
| 1021 | return; | ||||||||||||||||||||||||||||
| 1022 | } | ||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||
| 1024 | # Set RelayState | ||||||||||||||||||||||||||||
| 1025 | if ( my $relaystate = $self->storeRelayState( $req, 'urldc' ) ) { | ||||||||||||||||||||||||||||
| 1026 | $login->msg_relayState($relaystate); | ||||||||||||||||||||||||||||
| 1027 | $self->logger->debug("Set $relaystate in RelayState"); | ||||||||||||||||||||||||||||
| 1028 | } | ||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||
| 1030 | # Customize request | ||||||||||||||||||||||||||||
| 1031 | my $request = $login->request(); | ||||||||||||||||||||||||||||
| 1032 | |||||||||||||||||||||||||||||
| 1033 | # Maybe we are in IDP proxy mode (SAML request received on IDP side) | ||||||||||||||||||||||||||||
| 1034 | # In this case: | ||||||||||||||||||||||||||||
| 1035 | # * Check proxy conditions | ||||||||||||||||||||||||||||
| 1036 | # * Forward some authn constraints | ||||||||||||||||||||||||||||
| 1037 | if ( $req->data->{_proxiedSamlRequest} ) { | ||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||
| 1039 | $self->logger->debug("IDP Proxy mode detected"); | ||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||
| 1041 | # Get ProxyCount value | ||||||||||||||||||||||||||||
| 1042 | eval { | ||||||||||||||||||||||||||||
| 1043 | $proxyCount = | ||||||||||||||||||||||||||||
| 1044 | $req->data->{_proxiedSamlRequest}->Scoping()->ProxyCount(); | ||||||||||||||||||||||||||||
| 1045 | }; | ||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||
| 1047 | # Deny request if ProxyCount eq 0 | ||||||||||||||||||||||||||||
| 1048 | if ( defined $proxyCount ) { | ||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||
| 1050 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 1051 | "Found proxyCount $proxyCount in proxied request"); | ||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||
| 1053 | if ( $proxyCount eq 0 ) { | ||||||||||||||||||||||||||||
| 1054 | $self->userLogger->error( | ||||||||||||||||||||||||||||
| 1055 | "SAML request cannot be proxied (ProxyCount 0)"); | ||||||||||||||||||||||||||||
| 1056 | return; | ||||||||||||||||||||||||||||
| 1057 | } | ||||||||||||||||||||||||||||
| 1058 | else { | ||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||
| 1060 | # Decrease ProxyCount | ||||||||||||||||||||||||||||
| 1061 | my $scoping = $req->data->{_proxiedSamlRequest}->Scoping(); | ||||||||||||||||||||||||||||
| 1062 | $scoping->ProxyCount( $proxyCount-- ); | ||||||||||||||||||||||||||||
| 1063 | eval { $request->Scoping($scoping); }; | ||||||||||||||||||||||||||||
| 1064 | } | ||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||
| 1067 | # isPassive | ||||||||||||||||||||||||||||
| 1068 | eval { $isPassive = $req->data->{_proxiedSamlRequest}->IsPassive(); }; | ||||||||||||||||||||||||||||
| 1069 | |||||||||||||||||||||||||||||
| 1070 | # forceAuthn | ||||||||||||||||||||||||||||
| 1071 | eval { $forceAuthn = $req->data->{_proxiedSamlRequest}->ForceAuthn(); }; | ||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||
| 1073 | # requestedAuthnContext | ||||||||||||||||||||||||||||
| 1074 | eval { | ||||||||||||||||||||||||||||
| 1075 | $proxyRequestedAuthnContext = | ||||||||||||||||||||||||||||
| 1076 | $req->data->{_proxiedSamlRequest}->RequestedAuthnContext(); | ||||||||||||||||||||||||||||
| 1077 | }; | ||||||||||||||||||||||||||||
| 1078 | } | ||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||
| 1080 | # NameIDFormat | ||||||||||||||||||||||||||||
| 1081 | if ($nameIDFormat) { | ||||||||||||||||||||||||||||
| 1082 | $self->logger->debug("Use NameIDFormat $nameIDFormat"); | ||||||||||||||||||||||||||||
| 1083 | $request->NameIDPolicy()->Format($nameIDFormat); | ||||||||||||||||||||||||||||
| 1084 | } | ||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||
| 1086 | # Always allow NameID creation | ||||||||||||||||||||||||||||
| 1087 | $request->NameIDPolicy()->AllowCreate(1); | ||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||
| 1089 | # Force authentication | ||||||||||||||||||||||||||||
| 1090 | if ($forceAuthn) { | ||||||||||||||||||||||||||||
| 1091 | $self->logger->debug("Force authentication on IDP"); | ||||||||||||||||||||||||||||
| 1092 | $request->ForceAuthn(1); | ||||||||||||||||||||||||||||
| 1093 | } | ||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||
| 1095 | # Passive authentication | ||||||||||||||||||||||||||||
| 1096 | if ($isPassive) { | ||||||||||||||||||||||||||||
| 1097 | $self->logger->debug("Passive authentication on IDP"); | ||||||||||||||||||||||||||||
| 1098 | $request->IsPassive(1); | ||||||||||||||||||||||||||||
| 1099 | } | ||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||
| 1101 | # Signature | ||||||||||||||||||||||||||||
| 1102 | if ( $signSSOMessage == 0 ) { | ||||||||||||||||||||||||||||
| 1103 | $self->logger->debug("SSO request will not be signed"); | ||||||||||||||||||||||||||||
| 1104 | $self->disableSignature($login); | ||||||||||||||||||||||||||||
| 1105 | } | ||||||||||||||||||||||||||||
| 1106 | elsif ( $signSSOMessage == 1 ) { | ||||||||||||||||||||||||||||
| 1107 | $self->logger->debug("SSO request will be signed"); | ||||||||||||||||||||||||||||
| 1108 | $self->forceSignature($login); | ||||||||||||||||||||||||||||
| 1109 | } | ||||||||||||||||||||||||||||
| 1110 | else { | ||||||||||||||||||||||||||||
| 1111 | $self->logger->debug("SSO request signature according to metadata"); | ||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||
| 1114 | # Requested authentication context | ||||||||||||||||||||||||||||
| 1115 | if ($proxyRequestedAuthnContext) { | ||||||||||||||||||||||||||||
| 1116 | $self->logger->debug("Use RequestedAuthnContext from proxied request"); | ||||||||||||||||||||||||||||
| 1117 | $request->RequestedAuthnContext($proxyRequestedAuthnContext); | ||||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||
| 1119 | elsif ($requestedAuthnContext) { | ||||||||||||||||||||||||||||
| 1120 | $self->logger->debug("Request $requestedAuthnContext context"); | ||||||||||||||||||||||||||||
| 1121 | eval { | ||||||||||||||||||||||||||||
| 1122 | my $context = Lasso::Samlp2RequestedAuthnContext->new(); | ||||||||||||||||||||||||||||
| 1123 | $context->AuthnContextClassRef($requestedAuthnContext); | ||||||||||||||||||||||||||||
| 1124 | $context->Comparison("minimum"); | ||||||||||||||||||||||||||||
| 1125 | $request->RequestedAuthnContext($context); | ||||||||||||||||||||||||||||
| 1126 | }; | ||||||||||||||||||||||||||||
| 1127 | if ($@) { | ||||||||||||||||||||||||||||
| 1128 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1129 | return; | ||||||||||||||||||||||||||||
| 1130 | } | ||||||||||||||||||||||||||||
| 1131 | } | ||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||
| 1133 | # Call samlGenerateAuthnRequest hook | ||||||||||||||||||||||||||||
| 1134 | my $h = | ||||||||||||||||||||||||||||
| 1135 | $self->p->processHook( $req, 'samlGenerateAuthnRequest', $idp, $login ); | ||||||||||||||||||||||||||||
| 1136 | return if ( $h != PE_OK ); | ||||||||||||||||||||||||||||
| 1137 | |||||||||||||||||||||||||||||
| 1138 | # Build authentication request | ||||||||||||||||||||||||||||
| 1139 | unless ( $self->buildAuthnRequestMsg($login) ) { | ||||||||||||||||||||||||||||
| 1140 | $self->logger->error("Could not build authentication request on $idp"); | ||||||||||||||||||||||||||||
| 1141 | return; | ||||||||||||||||||||||||||||
| 1142 | } | ||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||
| 1144 | # Artifact | ||||||||||||||||||||||||||||
| 1145 | if ( $method == $self->getHttpMethod("artifact-get") | ||||||||||||||||||||||||||||
| 1146 | or $method == $self->getHttpMethod("artifact-post") ) | ||||||||||||||||||||||||||||
| 1147 | { | ||||||||||||||||||||||||||||
| 1148 | |||||||||||||||||||||||||||||
| 1149 | # Get artifact ID and Content, and store them | ||||||||||||||||||||||||||||
| 1150 | my $artifact_id = $login->get_artifact; | ||||||||||||||||||||||||||||
| 1151 | my $artifact_message = $login->get_artifact_message; | ||||||||||||||||||||||||||||
| 1152 | |||||||||||||||||||||||||||||
| 1153 | $self->storeArtifact( $artifact_id, $artifact_message ); | ||||||||||||||||||||||||||||
| 1154 | } | ||||||||||||||||||||||||||||
| 1155 | return $login; | ||||||||||||||||||||||||||||
| 1156 | } | ||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||
| 1158 | ## @method Lasso::Login createLogin(Lasso::Server server, string dump) | ||||||||||||||||||||||||||||
| 1159 | # Create Lasso::Login object | ||||||||||||||||||||||||||||
| 1160 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 1161 | # @param dump optional XML dump | ||||||||||||||||||||||||||||
| 1162 | # @return Lasso::Login object | ||||||||||||||||||||||||||||
| 1163 | sub createLogin { | ||||||||||||||||||||||||||||
| 1164 | my ( $self, $server, $dump ) = @_; | ||||||||||||||||||||||||||||
| 1165 | my $login; | ||||||||||||||||||||||||||||
| 1166 | |||||||||||||||||||||||||||||
| 1167 | if ($dump) { | ||||||||||||||||||||||||||||
| 1168 | eval { $login = Lasso::Login::new_from_dump( $server, $dump ); }; | ||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||
| 1170 | else { | ||||||||||||||||||||||||||||
| 1171 | eval { $login = Lasso::Login->new($server); }; | ||||||||||||||||||||||||||||
| 1172 | } | ||||||||||||||||||||||||||||
| 1173 | |||||||||||||||||||||||||||||
| 1174 | if ($@) { | ||||||||||||||||||||||||||||
| 1175 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1176 | return; | ||||||||||||||||||||||||||||
| 1177 | } | ||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||
| 1179 | return $login; | ||||||||||||||||||||||||||||
| 1180 | } | ||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||
| 1182 | ## @method boolean initAuthnRequest(Lasso::Login login, string idp, int method) | ||||||||||||||||||||||||||||
| 1183 | # Init authentication request | ||||||||||||||||||||||||||||
| 1184 | # @param login Lasso::Login | ||||||||||||||||||||||||||||
| 1185 | # @param idp entityID | ||||||||||||||||||||||||||||
| 1186 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 1187 | # @return boolean result | ||||||||||||||||||||||||||||
| 1188 | sub initAuthnRequest { | ||||||||||||||||||||||||||||
| 1189 | my ( $self, $login, $idp, $method ) = @_; | ||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||
| 1191 | eval { Lasso::Login::init_authn_request( $login, $idp, $method ); }; | ||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||
| 1193 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||
| 1196 | ## @method boolean initIdpInitiatedAuthnRequest(Lasso::Login login, string idp) | ||||||||||||||||||||||||||||
| 1197 | # Init authentication request | ||||||||||||||||||||||||||||
| 1198 | # @param login Lasso::Login | ||||||||||||||||||||||||||||
| 1199 | # @param idp entityID | ||||||||||||||||||||||||||||
| 1200 | # @return boolean result | ||||||||||||||||||||||||||||
| 1201 | sub initIdpInitiatedAuthnRequest { | ||||||||||||||||||||||||||||
| 1202 | my ( $self, $login, $idp ) = @_; | ||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||
| 1204 | eval { Lasso::Login::init_idp_initiated_authn_request( $login, $idp ); }; | ||||||||||||||||||||||||||||
| 1205 | |||||||||||||||||||||||||||||
| 1206 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1207 | } | ||||||||||||||||||||||||||||
| 1208 | |||||||||||||||||||||||||||||
| 1209 | ## @method boolean buildAuthnRequestMsg(Lasso::Login login) | ||||||||||||||||||||||||||||
| 1210 | # Build authentication request message | ||||||||||||||||||||||||||||
| 1211 | # @param login Lasso::Login | ||||||||||||||||||||||||||||
| 1212 | # @return boolean result | ||||||||||||||||||||||||||||
| 1213 | sub buildAuthnRequestMsg { | ||||||||||||||||||||||||||||
| 1214 | my ( $self, $login ) = @_; | ||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||
| 1216 | eval { Lasso::Login::build_authn_request_msg($login); }; | ||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||
| 1218 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1219 | } | ||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||
| 1221 | ## @method boolean processAuthnRequestMsg(Lasso::Login login, string request) | ||||||||||||||||||||||||||||
| 1222 | # Process authentication request message | ||||||||||||||||||||||||||||
| 1223 | # processAuthnRequestMsgWithError is preferred, but this function is kept for | ||||||||||||||||||||||||||||
| 1224 | # API compatibility in 2.0 | ||||||||||||||||||||||||||||
| 1225 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1226 | # @param request SAML request | ||||||||||||||||||||||||||||
| 1227 | # @return result | ||||||||||||||||||||||||||||
| 1228 | sub processAuthnRequestMsg { | ||||||||||||||||||||||||||||
| 1229 | my ( $self, $login, $request, $level ) = @_; | ||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||
| 1231 | $self->lazy_load_message($request); | ||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||
| 1233 | eval { Lasso::Login::process_authn_request_msg( $login, $request ); }; | ||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||
| 1235 | return $self->checkLassoError( $@, $level ); | ||||||||||||||||||||||||||||
| 1236 | } | ||||||||||||||||||||||||||||
| 1237 | |||||||||||||||||||||||||||||
| 1238 | ## @method boolean processAuthnRequestMsgWithError(Lasso::Login login, string request) | ||||||||||||||||||||||||||||
| 1239 | # Process authentication request message | ||||||||||||||||||||||||||||
| 1240 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1241 | # @param request SAML request | ||||||||||||||||||||||||||||
| 1242 | # @return result, Lasso error code | ||||||||||||||||||||||||||||
| 1243 | sub processAuthnRequestMsgWithError { | ||||||||||||||||||||||||||||
| 1244 | my ( $self, $login, $request, $level ) = @_; | ||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||
| 1246 | $self->lazy_load_message($request); | ||||||||||||||||||||||||||||
| 1247 | |||||||||||||||||||||||||||||
| 1248 | eval { Lasso::Login::process_authn_request_msg( $login, $request ); }; | ||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||
| 1250 | return $self->getLassoError( $@, $level ); | ||||||||||||||||||||||||||||
| 1251 | } | ||||||||||||||||||||||||||||
| 1252 | |||||||||||||||||||||||||||||
| 1253 | ## @method boolean validateRequestMsg(Lasso::Login login, boolean auth, boolean consent) | ||||||||||||||||||||||||||||
| 1254 | # Validate request message | ||||||||||||||||||||||||||||
| 1255 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1256 | # @param auth is user authenticated? | ||||||||||||||||||||||||||||
| 1257 | # @param consent is consent obtained? | ||||||||||||||||||||||||||||
| 1258 | # @return result | ||||||||||||||||||||||||||||
| 1259 | sub validateRequestMsg { | ||||||||||||||||||||||||||||
| 1260 | my ( $self, $login, $auth, $consent ) = @_; | ||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||
| 1262 | eval { Lasso::Login::validate_request_msg( $login, $auth, $consent ); }; | ||||||||||||||||||||||||||||
| 1263 | |||||||||||||||||||||||||||||
| 1264 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1265 | } | ||||||||||||||||||||||||||||
| 1266 | |||||||||||||||||||||||||||||
| 1267 | ## @method boolean buildAuthnResponseMsg(Lasso::Login login) | ||||||||||||||||||||||||||||
| 1268 | # Build authentication response message | ||||||||||||||||||||||||||||
| 1269 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1270 | # @return boolean result | ||||||||||||||||||||||||||||
| 1271 | sub buildAuthnResponseMsg { | ||||||||||||||||||||||||||||
| 1272 | my ( $self, $login ) = @_; | ||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||
| 1274 | eval { Lasso::Login::build_authn_response_msg($login); }; | ||||||||||||||||||||||||||||
| 1275 | |||||||||||||||||||||||||||||
| 1276 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1277 | } | ||||||||||||||||||||||||||||
| 1278 | |||||||||||||||||||||||||||||
| 1279 | ## @method boolean buildArtifactMsg(Lasso::Login login, int method) | ||||||||||||||||||||||||||||
| 1280 | # Build artifact message | ||||||||||||||||||||||||||||
| 1281 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1282 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 1283 | # @return boolean result | ||||||||||||||||||||||||||||
| 1284 | sub buildArtifactMsg { | ||||||||||||||||||||||||||||
| 1285 | my ( $self, $login, $method ) = @_; | ||||||||||||||||||||||||||||
| 1286 | |||||||||||||||||||||||||||||
| 1287 | eval { Lasso::Login::build_artifact_msg( $login, $method ); }; | ||||||||||||||||||||||||||||
| 1288 | |||||||||||||||||||||||||||||
| 1289 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1290 | } | ||||||||||||||||||||||||||||
| 1291 | |||||||||||||||||||||||||||||
| 1292 | ## @method boolean buildAssertion(Lasso::Login login, string authn_context, int notOnOrAfterTimeout) | ||||||||||||||||||||||||||||
| 1293 | # Build assertion | ||||||||||||||||||||||||||||
| 1294 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1295 | # @param authn_context SAML2 authentication context | ||||||||||||||||||||||||||||
| 1296 | # @param notOnOrAfterTimeout Timeout to apply to notOnOrAfter | ||||||||||||||||||||||||||||
| 1297 | # @return boolean result | ||||||||||||||||||||||||||||
| 1298 | sub buildAssertion { | ||||||||||||||||||||||||||||
| 1299 | my ( $self, $req, $login, $authn_context, $notOnOrAfterTimeout ) = @_; | ||||||||||||||||||||||||||||
| 1300 | $notOnOrAfterTimeout ||= $self->conf->{timeout}; | ||||||||||||||||||||||||||||
| 1301 | |||||||||||||||||||||||||||||
| 1302 | # Dates | ||||||||||||||||||||||||||||
| 1303 | my $time = $req->sessionInfo->{_utime} || time(); | ||||||||||||||||||||||||||||
| 1304 | my $timeout = $time + $notOnOrAfterTimeout; | ||||||||||||||||||||||||||||
| 1305 | my $authenticationInstant = $self->timestamp2samldate($time); | ||||||||||||||||||||||||||||
| 1306 | my $reauthenticateOnOrAfter = $self->timestamp2samldate($timeout); | ||||||||||||||||||||||||||||
| 1307 | my $issued_time = time; | ||||||||||||||||||||||||||||
| 1308 | my $notBefore = $self->timestamp2samldate($issued_time); | ||||||||||||||||||||||||||||
| 1309 | my $notOnOrAfter = | ||||||||||||||||||||||||||||
| 1310 | $self->timestamp2samldate( $issued_time + $notOnOrAfterTimeout ); | ||||||||||||||||||||||||||||
| 1311 | |||||||||||||||||||||||||||||
| 1312 | eval { | ||||||||||||||||||||||||||||
| 1313 | Lasso::Login::build_assertion( $login, $authn_context, | ||||||||||||||||||||||||||||
| 1314 | $authenticationInstant, $reauthenticateOnOrAfter, $notBefore, | ||||||||||||||||||||||||||||
| 1315 | $notOnOrAfter ); | ||||||||||||||||||||||||||||
| 1316 | }; | ||||||||||||||||||||||||||||
| 1317 | |||||||||||||||||||||||||||||
| 1318 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1319 | } | ||||||||||||||||||||||||||||
| 1320 | |||||||||||||||||||||||||||||
| 1321 | ## @method boolean processAuthnResponseMsg(Lasso::Login login, string response) | ||||||||||||||||||||||||||||
| 1322 | # Process authentication response message | ||||||||||||||||||||||||||||
| 1323 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1324 | # @param response SAML response | ||||||||||||||||||||||||||||
| 1325 | # @return result | ||||||||||||||||||||||||||||
| 1326 | sub processAuthnResponseMsg { | ||||||||||||||||||||||||||||
| 1327 | my ( $self, $login, $response ) = @_; | ||||||||||||||||||||||||||||
| 1328 | |||||||||||||||||||||||||||||
| 1329 | $self->lazy_load_message($response); | ||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||
| 1331 | eval { Lasso::Login::process_authn_response_msg( $login, $response ); }; | ||||||||||||||||||||||||||||
| 1332 | |||||||||||||||||||||||||||||
| 1333 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1334 | } | ||||||||||||||||||||||||||||
| 1335 | |||||||||||||||||||||||||||||
| 1336 | # UNUSED | ||||||||||||||||||||||||||||
| 1337 | ### @method Lasso::Saml2NameID getNameIdentifer(Lasso::Profile profile) | ||||||||||||||||||||||||||||
| 1338 | ## Get NameID from Lasso Profile | ||||||||||||||||||||||||||||
| 1339 | ## @param profile Lasso::Profile object | ||||||||||||||||||||||||||||
| 1340 | ## @return result or NULL if error | ||||||||||||||||||||||||||||
| 1341 | #sub getNameIdentifier { | ||||||||||||||||||||||||||||
| 1342 | # my ( $self, $profile ) = @_; | ||||||||||||||||||||||||||||
| 1343 | # my $nameid; | ||||||||||||||||||||||||||||
| 1344 | # | ||||||||||||||||||||||||||||
| 1345 | # eval { $nameid = Lasso::Profile::get_nameIdentifier($profile); }; | ||||||||||||||||||||||||||||
| 1346 | # | ||||||||||||||||||||||||||||
| 1347 | # if ($@) { | ||||||||||||||||||||||||||||
| 1348 | # $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1349 | # return; | ||||||||||||||||||||||||||||
| 1350 | # } | ||||||||||||||||||||||||||||
| 1351 | # | ||||||||||||||||||||||||||||
| 1352 | # return $nameid; | ||||||||||||||||||||||||||||
| 1353 | #} | ||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||
| 1355 | # UNUSED | ||||||||||||||||||||||||||||
| 1356 | ### @method Lasso::Identity createIdentity(string dump) | ||||||||||||||||||||||||||||
| 1357 | ## Create Lasso::Identity object | ||||||||||||||||||||||||||||
| 1358 | ## @param dump optional Identity dump | ||||||||||||||||||||||||||||
| 1359 | ## @return Lasso::Identity object | ||||||||||||||||||||||||||||
| 1360 | #sub createIdentity { | ||||||||||||||||||||||||||||
| 1361 | # my ( $self, $dump ) = @_; | ||||||||||||||||||||||||||||
| 1362 | # my $identity; | ||||||||||||||||||||||||||||
| 1363 | # | ||||||||||||||||||||||||||||
| 1364 | # if ($dump) { | ||||||||||||||||||||||||||||
| 1365 | # eval { $identity = Lasso::Identity::new_from_dump($dump); }; | ||||||||||||||||||||||||||||
| 1366 | # } | ||||||||||||||||||||||||||||
| 1367 | # else { | ||||||||||||||||||||||||||||
| 1368 | # eval { $identity = Lasso::Identity->new(); }; | ||||||||||||||||||||||||||||
| 1369 | # } | ||||||||||||||||||||||||||||
| 1370 | # | ||||||||||||||||||||||||||||
| 1371 | # if ($@) { | ||||||||||||||||||||||||||||
| 1372 | # $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1373 | # return; | ||||||||||||||||||||||||||||
| 1374 | # } | ||||||||||||||||||||||||||||
| 1375 | # | ||||||||||||||||||||||||||||
| 1376 | # return $identity; | ||||||||||||||||||||||||||||
| 1377 | #} | ||||||||||||||||||||||||||||
| 1378 | |||||||||||||||||||||||||||||
| 1379 | ## UNUSED | ||||||||||||||||||||||||||||
| 1380 | ### @method Lasso::Session createSession(string dump) | ||||||||||||||||||||||||||||
| 1381 | ## Create Lasso::Session object | ||||||||||||||||||||||||||||
| 1382 | ## @param dump optional Session dump | ||||||||||||||||||||||||||||
| 1383 | ## @return Lasso::Session object | ||||||||||||||||||||||||||||
| 1384 | #sub createSession { | ||||||||||||||||||||||||||||
| 1385 | # my ( $self, $dump ) = @_; | ||||||||||||||||||||||||||||
| 1386 | # my $session; | ||||||||||||||||||||||||||||
| 1387 | # | ||||||||||||||||||||||||||||
| 1388 | # if ($dump) { | ||||||||||||||||||||||||||||
| 1389 | # eval { $session = Lasso::Session::new_from_dump($dump); }; | ||||||||||||||||||||||||||||
| 1390 | # } | ||||||||||||||||||||||||||||
| 1391 | # else { | ||||||||||||||||||||||||||||
| 1392 | # eval { $session = Lasso::Session->new(); }; | ||||||||||||||||||||||||||||
| 1393 | # } | ||||||||||||||||||||||||||||
| 1394 | # | ||||||||||||||||||||||||||||
| 1395 | # if ($@) { | ||||||||||||||||||||||||||||
| 1396 | # $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1397 | # return; | ||||||||||||||||||||||||||||
| 1398 | # } | ||||||||||||||||||||||||||||
| 1399 | # | ||||||||||||||||||||||||||||
| 1400 | # return $session; | ||||||||||||||||||||||||||||
| 1401 | #} | ||||||||||||||||||||||||||||
| 1402 | |||||||||||||||||||||||||||||
| 1403 | ## @method boolean acceptSSO(Lasso::Login login) | ||||||||||||||||||||||||||||
| 1404 | # Accept SSO from IDP | ||||||||||||||||||||||||||||
| 1405 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1406 | # @return result | ||||||||||||||||||||||||||||
| 1407 | sub acceptSSO { | ||||||||||||||||||||||||||||
| 1408 | my ( $self, $login ) = @_; | ||||||||||||||||||||||||||||
| 1409 | |||||||||||||||||||||||||||||
| 1410 | eval { Lasso::Login::accept_sso($login); }; | ||||||||||||||||||||||||||||
| 1411 | |||||||||||||||||||||||||||||
| 1412 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1413 | } | ||||||||||||||||||||||||||||
| 1414 | |||||||||||||||||||||||||||||
| 1415 | ## @method string getIssuer(string msg) | ||||||||||||||||||||||||||||
| 1416 | # Get issuer from message | ||||||||||||||||||||||||||||
| 1417 | # @param msg SAML message | ||||||||||||||||||||||||||||
| 1418 | # @return issuer | ||||||||||||||||||||||||||||
| 1419 | sub getIssuer { | ||||||||||||||||||||||||||||
| 1420 | my ( $self, $message ) = @_; | ||||||||||||||||||||||||||||
| 1421 | |||||||||||||||||||||||||||||
| 1422 | # Work around lasso bug (https://dev.entrouvert.org/issues/97575) | ||||||||||||||||||||||||||||
| 1423 | $message =~ s/&RelayState=$//g; | ||||||||||||||||||||||||||||
| 1424 | my $issuer = eval { Lasso::profile_get_issuer($message) }; | ||||||||||||||||||||||||||||
| 1425 | if ($@) { | ||||||||||||||||||||||||||||
| 1426 | $self->logger->debug("lasso_profile_get_issuer: $@"); | ||||||||||||||||||||||||||||
| 1427 | } | ||||||||||||||||||||||||||||
| 1428 | if ( !$issuer ) { | ||||||||||||||||||||||||||||
| 1429 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 1430 | "lasso_profile_get_issuer could not find entityID" | ||||||||||||||||||||||||||||
| 1431 | . " in incoming message" ); | ||||||||||||||||||||||||||||
| 1432 | return; | ||||||||||||||||||||||||||||
| 1433 | } | ||||||||||||||||||||||||||||
| 1434 | return $issuer; | ||||||||||||||||||||||||||||
| 1435 | } | ||||||||||||||||||||||||||||
| 1436 | |||||||||||||||||||||||||||||
| 1437 | ## @method string storeRelayState(hashref infos) | ||||||||||||||||||||||||||||
| 1438 | # Store information in relayState database and return | ||||||||||||||||||||||||||||
| 1439 | # corresponding session_id | ||||||||||||||||||||||||||||
| 1440 | # @param infos HASH reference of information | ||||||||||||||||||||||||||||
| 1441 | sub storeRelayState { | ||||||||||||||||||||||||||||
| 1442 | my ( $self, $req, @data ) = @_; | ||||||||||||||||||||||||||||
| 1443 | |||||||||||||||||||||||||||||
| 1444 | # check if there are data to store | ||||||||||||||||||||||||||||
| 1445 | my $infos; | ||||||||||||||||||||||||||||
| 1446 | foreach (@data) { | ||||||||||||||||||||||||||||
| 1447 | $infos->{$_} = $req->{$_} if $req->{$_}; | ||||||||||||||||||||||||||||
| 1448 | } | ||||||||||||||||||||||||||||
| 1449 | return unless ($infos); | ||||||||||||||||||||||||||||
| 1450 | |||||||||||||||||||||||||||||
| 1451 | # Session type | ||||||||||||||||||||||||||||
| 1452 | $infos->{_type} = "relaystate"; | ||||||||||||||||||||||||||||
| 1453 | |||||||||||||||||||||||||||||
| 1454 | # Set _utime for session autoremove | ||||||||||||||||||||||||||||
| 1455 | # Use default session timeout and relayState session timeout to compute it | ||||||||||||||||||||||||||||
| 1456 | my $time = time(); | ||||||||||||||||||||||||||||
| 1457 | my $timeout = $self->conf->{timeout}; | ||||||||||||||||||||||||||||
| 1458 | my $samlRelayStateTimeout = | ||||||||||||||||||||||||||||
| 1459 | $self->conf->{samlRelayStateTimeout} || $timeout; | ||||||||||||||||||||||||||||
| 1460 | |||||||||||||||||||||||||||||
| 1461 | $infos->{_utime} = $time + ( $samlRelayStateTimeout - $timeout ); | ||||||||||||||||||||||||||||
| 1462 | |||||||||||||||||||||||||||||
| 1463 | # Create relaystate session and store infos in relaystate session | ||||||||||||||||||||||||||||
| 1464 | my $samlSessionInfo = $self->getSamlSession( undef, $infos ) | ||||||||||||||||||||||||||||
| 1465 | or return undef; | ||||||||||||||||||||||||||||
| 1466 | |||||||||||||||||||||||||||||
| 1467 | # Session ID | ||||||||||||||||||||||||||||
| 1468 | my $relaystate_id = $samlSessionInfo->id; | ||||||||||||||||||||||||||||
| 1469 | |||||||||||||||||||||||||||||
| 1470 | # Return session ID | ||||||||||||||||||||||||||||
| 1471 | return $relaystate_id; | ||||||||||||||||||||||||||||
| 1472 | } | ||||||||||||||||||||||||||||
| 1473 | |||||||||||||||||||||||||||||
| 1474 | ## @method boolean extractRelayState(string relaystate, boolean relayStateURL) | ||||||||||||||||||||||||||||
| 1475 | # Extract RelayState information into $self | ||||||||||||||||||||||||||||
| 1476 | # @param relaystate Relay state value | ||||||||||||||||||||||||||||
| 1477 | # @param relayStateURL Allow Relay state value to be the redirection URL | ||||||||||||||||||||||||||||
| 1478 | # @return result | ||||||||||||||||||||||||||||
| 1479 | sub extractRelayState { | ||||||||||||||||||||||||||||
| 1480 | my ( $self, $req, $relaystate, $relayStateURL ) = @_; | ||||||||||||||||||||||||||||
| 1481 | |||||||||||||||||||||||||||||
| 1482 | return 0 unless $relaystate; | ||||||||||||||||||||||||||||
| 1483 | if ( $relayStateURL and $relaystate =~ /^https?:\/\// ) { | ||||||||||||||||||||||||||||
| 1484 | $self->logger->debug("RelayState is a redirection URL: $relaystate"); | ||||||||||||||||||||||||||||
| 1485 | $req->{urldc} = $relaystate; | ||||||||||||||||||||||||||||
| 1486 | return 1; | ||||||||||||||||||||||||||||
| 1487 | } | ||||||||||||||||||||||||||||
| 1488 | else { | ||||||||||||||||||||||||||||
| 1489 | |||||||||||||||||||||||||||||
| 1490 | # Open relaystate session | ||||||||||||||||||||||||||||
| 1491 | my $samlSessionInfo = $self->getSamlSession($relaystate); | ||||||||||||||||||||||||||||
| 1492 | |||||||||||||||||||||||||||||
| 1493 | return 0 unless $samlSessionInfo; | ||||||||||||||||||||||||||||
| 1494 | |||||||||||||||||||||||||||||
| 1495 | # Push values in $self | ||||||||||||||||||||||||||||
| 1496 | foreach ( keys %{ $samlSessionInfo->data } ) { | ||||||||||||||||||||||||||||
| 1497 | next if $_ =~ /(type|_session_id|_utime|issuerNextUrl)/; | ||||||||||||||||||||||||||||
| 1498 | $req->{$_} = $samlSessionInfo->data->{$_}; | ||||||||||||||||||||||||||||
| 1499 | } | ||||||||||||||||||||||||||||
| 1500 | |||||||||||||||||||||||||||||
| 1501 | # issuerNextUrl has priority over urldc if both are set | ||||||||||||||||||||||||||||
| 1502 | if ( $samlSessionInfo->data->{issuerNextUrl} ) { | ||||||||||||||||||||||||||||
| 1503 | $req->urldc( $samlSessionInfo->data->{issuerNextUrl} ); | ||||||||||||||||||||||||||||
| 1504 | } | ||||||||||||||||||||||||||||
| 1505 | |||||||||||||||||||||||||||||
| 1506 | # delete relaystate session | ||||||||||||||||||||||||||||
| 1507 | if ( $samlSessionInfo->remove ) { | ||||||||||||||||||||||||||||
| 1508 | $self->logger->debug("Relaystate $relaystate was deleted"); | ||||||||||||||||||||||||||||
| 1509 | } | ||||||||||||||||||||||||||||
| 1510 | else { | ||||||||||||||||||||||||||||
| 1511 | $self->logger->error("Unable to delete relaystate $relaystate"); | ||||||||||||||||||||||||||||
| 1512 | $self->logger->error( $samlSessionInfo->error ); | ||||||||||||||||||||||||||||
| 1513 | } | ||||||||||||||||||||||||||||
| 1514 | |||||||||||||||||||||||||||||
| 1515 | } | ||||||||||||||||||||||||||||
| 1516 | |||||||||||||||||||||||||||||
| 1517 | return 1; | ||||||||||||||||||||||||||||
| 1518 | } | ||||||||||||||||||||||||||||
| 1519 | |||||||||||||||||||||||||||||
| 1520 | ## @method Lasso::Node getAssertion(Lasso::Login login) | ||||||||||||||||||||||||||||
| 1521 | # Get assertion in Lasso::Login object | ||||||||||||||||||||||||||||
| 1522 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 1523 | # @return assertion Lasso::Node object | ||||||||||||||||||||||||||||
| 1524 | sub getAssertion { | ||||||||||||||||||||||||||||
| 1525 | my ( $self, $login ) = @_; | ||||||||||||||||||||||||||||
| 1526 | my $assertion; | ||||||||||||||||||||||||||||
| 1527 | |||||||||||||||||||||||||||||
| 1528 | eval { $assertion = Lasso::Login::get_assertion($login); }; | ||||||||||||||||||||||||||||
| 1529 | |||||||||||||||||||||||||||||
| 1530 | if ($@) { | ||||||||||||||||||||||||||||
| 1531 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1532 | return; | ||||||||||||||||||||||||||||
| 1533 | } | ||||||||||||||||||||||||||||
| 1534 | |||||||||||||||||||||||||||||
| 1535 | return $assertion; | ||||||||||||||||||||||||||||
| 1536 | } | ||||||||||||||||||||||||||||
| 1537 | |||||||||||||||||||||||||||||
| 1538 | ## @method string getAttributeValue(string name, string format, string friendly_name, arrayref attributes, boolean force_utf8) | ||||||||||||||||||||||||||||
| 1539 | # Get SAML attribute value corresponding to name, format and friendly_name | ||||||||||||||||||||||||||||
| 1540 | # Multivaluated values are separated by multiValuesSeparator | ||||||||||||||||||||||||||||
| 1541 | # If force_utf8 flag is set, value is encoded in UTF-8 | ||||||||||||||||||||||||||||
| 1542 | # @param name SAML attribute name | ||||||||||||||||||||||||||||
| 1543 | # @param format optional SAML attribute format | ||||||||||||||||||||||||||||
| 1544 | # @param friendly_name optional SAML attribute friendly name | ||||||||||||||||||||||||||||
| 1545 | # @param attributes Attributes | ||||||||||||||||||||||||||||
| 1546 | # @param force_utf8 optional flag to force value in UTF-8 | ||||||||||||||||||||||||||||
| 1547 | # @return attribute value | ||||||||||||||||||||||||||||
| 1548 | sub getAttributeValue { | ||||||||||||||||||||||||||||
| 1549 | my ( $self, $name, $format, $friendly_name, $attributes, $force_utf8 ) = @_; | ||||||||||||||||||||||||||||
| 1550 | my $value; | ||||||||||||||||||||||||||||
| 1551 | |||||||||||||||||||||||||||||
| 1552 | # Loop on attributes | ||||||||||||||||||||||||||||
| 1553 | foreach (@$attributes) { | ||||||||||||||||||||||||||||
| 1554 | my $attr_name = $_->Name(); | ||||||||||||||||||||||||||||
| 1555 | my $attr_format = $_->NameFormat(); | ||||||||||||||||||||||||||||
| 1556 | my $attr_fname = $_->FriendlyName(); | ||||||||||||||||||||||||||||
| 1557 | |||||||||||||||||||||||||||||
| 1558 | # Skip if name does not correspond to attribute name | ||||||||||||||||||||||||||||
| 1559 | next if ( $name ne $attr_name ); | ||||||||||||||||||||||||||||
| 1560 | |||||||||||||||||||||||||||||
| 1561 | # Verify format and friendly name if given | ||||||||||||||||||||||||||||
| 1562 | next if ( $format and $format ne $attr_format ); | ||||||||||||||||||||||||||||
| 1563 | next if ( $friendly_name and $friendly_name ne $attr_fname ); | ||||||||||||||||||||||||||||
| 1564 | |||||||||||||||||||||||||||||
| 1565 | # Attribute is found, return its content | ||||||||||||||||||||||||||||
| 1566 | my @attr_values = $_->AttributeValue(); | ||||||||||||||||||||||||||||
| 1567 | |||||||||||||||||||||||||||||
| 1568 | $value = join( | ||||||||||||||||||||||||||||
| 1569 | $self->{conf}->{multiValuesSeparator}, | ||||||||||||||||||||||||||||
| 1570 | map { | ||||||||||||||||||||||||||||
| 1571 | eval { $_->any->content } | ||||||||||||||||||||||||||||
| 1572 | || () | ||||||||||||||||||||||||||||
| 1573 | } @attr_values | ||||||||||||||||||||||||||||
| 1574 | ); | ||||||||||||||||||||||||||||
| 1575 | } | ||||||||||||||||||||||||||||
| 1576 | |||||||||||||||||||||||||||||
| 1577 | return $value; | ||||||||||||||||||||||||||||
| 1578 | } | ||||||||||||||||||||||||||||
| 1579 | |||||||||||||||||||||||||||||
| 1580 | ## @method boolean validateConditions(Lasso::Saml2::Assertion assertion, string entityID, boolean checkTime, boolean checkAudience) | ||||||||||||||||||||||||||||
| 1581 | # Validate conditions | ||||||||||||||||||||||||||||
| 1582 | # @param assertion SAML2 assertion | ||||||||||||||||||||||||||||
| 1583 | # @param entityID relying party entity ID | ||||||||||||||||||||||||||||
| 1584 | # @param checkTime Enable time conditions check | ||||||||||||||||||||||||||||
| 1585 | # @param checkAudience Enable audience conditions check | ||||||||||||||||||||||||||||
| 1586 | # @return result | ||||||||||||||||||||||||||||
| 1587 | sub validateConditions { | ||||||||||||||||||||||||||||
| 1588 | my ( $self, $assertion, $entityID, $checkTime, $checkAudience ) = @_; | ||||||||||||||||||||||||||||
| 1589 | my $tolerance = 10; | ||||||||||||||||||||||||||||
| 1590 | my $status; | ||||||||||||||||||||||||||||
| 1591 | $checkTime = 1 unless defined $checkTime; | ||||||||||||||||||||||||||||
| 1592 | $checkAudience = 1 unless defined $checkAudience; | ||||||||||||||||||||||||||||
| 1593 | |||||||||||||||||||||||||||||
| 1594 | # Time | ||||||||||||||||||||||||||||
| 1595 | if ($checkTime) { | ||||||||||||||||||||||||||||
| 1596 | eval { | ||||||||||||||||||||||||||||
| 1597 | $status = Lasso::Saml2Assertion::validate_time_checks( $assertion, | ||||||||||||||||||||||||||||
| 1598 | $tolerance ); | ||||||||||||||||||||||||||||
| 1599 | }; | ||||||||||||||||||||||||||||
| 1600 | |||||||||||||||||||||||||||||
| 1601 | if ($@) { | ||||||||||||||||||||||||||||
| 1602 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1603 | return 0; | ||||||||||||||||||||||||||||
| 1604 | } | ||||||||||||||||||||||||||||
| 1605 | |||||||||||||||||||||||||||||
| 1606 | unless ( $status eq Lasso::Constants::SAML2_ASSERTION_VALID ) { | ||||||||||||||||||||||||||||
| 1607 | $self->logger->error("Time conditions validation failed ($status)"); | ||||||||||||||||||||||||||||
| 1608 | return 0; | ||||||||||||||||||||||||||||
| 1609 | } | ||||||||||||||||||||||||||||
| 1610 | |||||||||||||||||||||||||||||
| 1611 | $self->logger->debug("Time conditions validated"); | ||||||||||||||||||||||||||||
| 1612 | } | ||||||||||||||||||||||||||||
| 1613 | else { | ||||||||||||||||||||||||||||
| 1614 | $self->logger->debug("Time conditions not checked"); | ||||||||||||||||||||||||||||
| 1615 | } | ||||||||||||||||||||||||||||
| 1616 | |||||||||||||||||||||||||||||
| 1617 | # Audience | ||||||||||||||||||||||||||||
| 1618 | if ($checkAudience) { | ||||||||||||||||||||||||||||
| 1619 | eval { | ||||||||||||||||||||||||||||
| 1620 | $status = | ||||||||||||||||||||||||||||
| 1621 | Lasso::Saml2Assertion::validate_audience( $assertion, $entityID ); | ||||||||||||||||||||||||||||
| 1622 | }; | ||||||||||||||||||||||||||||
| 1623 | |||||||||||||||||||||||||||||
| 1624 | if ($@) { | ||||||||||||||||||||||||||||
| 1625 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1626 | return 0; | ||||||||||||||||||||||||||||
| 1627 | } | ||||||||||||||||||||||||||||
| 1628 | |||||||||||||||||||||||||||||
| 1629 | unless ( $status eq Lasso::Constants::SAML2_ASSERTION_VALID ) { | ||||||||||||||||||||||||||||
| 1630 | $self->logger->error( | ||||||||||||||||||||||||||||
| 1631 | "Audience conditions validations result: $status"); | ||||||||||||||||||||||||||||
| 1632 | return 0; | ||||||||||||||||||||||||||||
| 1633 | } | ||||||||||||||||||||||||||||
| 1634 | |||||||||||||||||||||||||||||
| 1635 | $self->logger->debug("Audience conditions validated"); | ||||||||||||||||||||||||||||
| 1636 | } | ||||||||||||||||||||||||||||
| 1637 | else { | ||||||||||||||||||||||||||||
| 1638 | $self->logger->debug("Audience conditions not checked"); | ||||||||||||||||||||||||||||
| 1639 | } | ||||||||||||||||||||||||||||
| 1640 | |||||||||||||||||||||||||||||
| 1641 | return 1; | ||||||||||||||||||||||||||||
| 1642 | } | ||||||||||||||||||||||||||||
| 1643 | |||||||||||||||||||||||||||||
| 1644 | ## @method Lasso::Logout createLogoutRequest(Lasso::Server server, string session_dump, int method, boolean signSLOMessage) | ||||||||||||||||||||||||||||
| 1645 | # Create logout request for selected entity | ||||||||||||||||||||||||||||
| 1646 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 1647 | # @param session_dump Lasso::Session dump | ||||||||||||||||||||||||||||
| 1648 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 1649 | # @param signSLOMessage sign request | ||||||||||||||||||||||||||||
| 1650 | # @return Lasso::Login object | ||||||||||||||||||||||||||||
| 1651 | sub createLogoutRequest { | ||||||||||||||||||||||||||||
| 1652 | my ( $self, $req, $server, $session_dump, $method, $signSLOMessage ) = @_; | ||||||||||||||||||||||||||||
| 1653 | my $session; | ||||||||||||||||||||||||||||
| 1654 | |||||||||||||||||||||||||||||
| 1655 | # Create Lasso Logout | ||||||||||||||||||||||||||||
| 1656 | my $logout = $self->createLogout($server); | ||||||||||||||||||||||||||||
| 1657 | |||||||||||||||||||||||||||||
| 1658 | unless ( $self->setSessionFromDump( $logout, $session_dump ) ) { | ||||||||||||||||||||||||||||
| 1659 | $self->logger->error("Could not fill Lasso::Logout with session dump"); | ||||||||||||||||||||||||||||
| 1660 | return; | ||||||||||||||||||||||||||||
| 1661 | } | ||||||||||||||||||||||||||||
| 1662 | |||||||||||||||||||||||||||||
| 1663 | # Init logout request | ||||||||||||||||||||||||||||
| 1664 | unless ( $self->initLogoutRequest( $logout, undef, $method ) ) { | ||||||||||||||||||||||||||||
| 1665 | $self->logger->error("Could not initiate logout request"); | ||||||||||||||||||||||||||||
| 1666 | return; | ||||||||||||||||||||||||||||
| 1667 | } | ||||||||||||||||||||||||||||
| 1668 | |||||||||||||||||||||||||||||
| 1669 | # Set RelayState | ||||||||||||||||||||||||||||
| 1670 | if ( my $relaystate = | ||||||||||||||||||||||||||||
| 1671 | $self->storeRelayState( $req, 'urldc', 'issuerNextUrl' ) ) | ||||||||||||||||||||||||||||
| 1672 | { | ||||||||||||||||||||||||||||
| 1673 | $logout->msg_relayState($relaystate); | ||||||||||||||||||||||||||||
| 1674 | $self->logger->debug("Set $relaystate in RelayState"); | ||||||||||||||||||||||||||||
| 1675 | } | ||||||||||||||||||||||||||||
| 1676 | |||||||||||||||||||||||||||||
| 1677 | # Signature | ||||||||||||||||||||||||||||
| 1678 | if ( $signSLOMessage == 0 ) { | ||||||||||||||||||||||||||||
| 1679 | $self->logger->debug("SLO request will not be signed"); | ||||||||||||||||||||||||||||
| 1680 | $self->disableSignature($logout); | ||||||||||||||||||||||||||||
| 1681 | } | ||||||||||||||||||||||||||||
| 1682 | elsif ( $signSLOMessage == 1 ) { | ||||||||||||||||||||||||||||
| 1683 | $self->logger->debug("SLO request will be signed"); | ||||||||||||||||||||||||||||
| 1684 | $self->forceSignature($logout); | ||||||||||||||||||||||||||||
| 1685 | } | ||||||||||||||||||||||||||||
| 1686 | else { | ||||||||||||||||||||||||||||
| 1687 | $self->logger->debug("SLO request signature according to metadata"); | ||||||||||||||||||||||||||||
| 1688 | } | ||||||||||||||||||||||||||||
| 1689 | |||||||||||||||||||||||||||||
| 1690 | # Build logout request | ||||||||||||||||||||||||||||
| 1691 | unless ( $self->buildLogoutRequestMsg($logout) ) { | ||||||||||||||||||||||||||||
| 1692 | $self->logger->error("Could not build logout request"); | ||||||||||||||||||||||||||||
| 1693 | return; | ||||||||||||||||||||||||||||
| 1694 | } | ||||||||||||||||||||||||||||
| 1695 | |||||||||||||||||||||||||||||
| 1696 | return $logout; | ||||||||||||||||||||||||||||
| 1697 | |||||||||||||||||||||||||||||
| 1698 | } | ||||||||||||||||||||||||||||
| 1699 | |||||||||||||||||||||||||||||
| 1700 | ## @method Lasso::Logout createLogout(Lasso::Server server, string dump) | ||||||||||||||||||||||||||||
| 1701 | # Create Lasso::Logout object | ||||||||||||||||||||||||||||
| 1702 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 1703 | # @param dump optional XML dump | ||||||||||||||||||||||||||||
| 1704 | # @return Lasso::Logout object | ||||||||||||||||||||||||||||
| 1705 | sub createLogout { | ||||||||||||||||||||||||||||
| 1706 | my ( $self, $server, $dump ) = @_; | ||||||||||||||||||||||||||||
| 1707 | my $logout; | ||||||||||||||||||||||||||||
| 1708 | |||||||||||||||||||||||||||||
| 1709 | if ($dump) { | ||||||||||||||||||||||||||||
| 1710 | eval { $logout = Lasso::Logout::new_from_dump( $server, $dump ); }; | ||||||||||||||||||||||||||||
| 1711 | } | ||||||||||||||||||||||||||||
| 1712 | else { | ||||||||||||||||||||||||||||
| 1713 | eval { $logout = Lasso::Logout->new($server); }; | ||||||||||||||||||||||||||||
| 1714 | } | ||||||||||||||||||||||||||||
| 1715 | |||||||||||||||||||||||||||||
| 1716 | if ($@) { | ||||||||||||||||||||||||||||
| 1717 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1718 | return; | ||||||||||||||||||||||||||||
| 1719 | } | ||||||||||||||||||||||||||||
| 1720 | |||||||||||||||||||||||||||||
| 1721 | return $logout; | ||||||||||||||||||||||||||||
| 1722 | } | ||||||||||||||||||||||||||||
| 1723 | |||||||||||||||||||||||||||||
| 1724 | ## @method boolean initLogoutRequest(Lasso::Logout logout, string entityID, int method) | ||||||||||||||||||||||||||||
| 1725 | # Init logout request | ||||||||||||||||||||||||||||
| 1726 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 1727 | # @param entityID Entity ID | ||||||||||||||||||||||||||||
| 1728 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 1729 | # @return result | ||||||||||||||||||||||||||||
| 1730 | sub initLogoutRequest { | ||||||||||||||||||||||||||||
| 1731 | my ( $self, $logout, $entityID, $method ) = @_; | ||||||||||||||||||||||||||||
| 1732 | |||||||||||||||||||||||||||||
| 1733 | eval { Lasso::Logout::init_request( $logout, $entityID, $method ); }; | ||||||||||||||||||||||||||||
| 1734 | |||||||||||||||||||||||||||||
| 1735 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1736 | } | ||||||||||||||||||||||||||||
| 1737 | |||||||||||||||||||||||||||||
| 1738 | ## @method boolean buildLogoutRequestMsg(Lasso::Logout logout) | ||||||||||||||||||||||||||||
| 1739 | # Build logout request message | ||||||||||||||||||||||||||||
| 1740 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 1741 | # @return result | ||||||||||||||||||||||||||||
| 1742 | sub buildLogoutRequestMsg { | ||||||||||||||||||||||||||||
| 1743 | my ( $self, $logout ) = @_; | ||||||||||||||||||||||||||||
| 1744 | |||||||||||||||||||||||||||||
| 1745 | eval { Lasso::Logout::build_request_msg($logout); }; | ||||||||||||||||||||||||||||
| 1746 | |||||||||||||||||||||||||||||
| 1747 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1748 | } | ||||||||||||||||||||||||||||
| 1749 | |||||||||||||||||||||||||||||
| 1750 | ## @method boolean setSessionFromDump(Lasso::Profile profile, string dump) | ||||||||||||||||||||||||||||
| 1751 | # Set session from dump in Lasso::Profile object | ||||||||||||||||||||||||||||
| 1752 | # @param profile Lasso::Profile object | ||||||||||||||||||||||||||||
| 1753 | # @param dump Lasso::Session XML dump | ||||||||||||||||||||||||||||
| 1754 | # @return result | ||||||||||||||||||||||||||||
| 1755 | sub setSessionFromDump { | ||||||||||||||||||||||||||||
| 1756 | my ( $self, $profile, $dump ) = @_; | ||||||||||||||||||||||||||||
| 1757 | |||||||||||||||||||||||||||||
| 1758 | $self->logger->debug("Loading Session dump: $dump") if $dump; | ||||||||||||||||||||||||||||
| 1759 | |||||||||||||||||||||||||||||
| 1760 | eval { Lasso::Profile::set_session_from_dump( $profile, $dump ); }; | ||||||||||||||||||||||||||||
| 1761 | |||||||||||||||||||||||||||||
| 1762 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1763 | } | ||||||||||||||||||||||||||||
| 1764 | |||||||||||||||||||||||||||||
| 1765 | ## @method boolean setIdentityFromDump(Lasso::Profile profile, string dump) | ||||||||||||||||||||||||||||
| 1766 | # Set identity from dump in Lasso::Profile object | ||||||||||||||||||||||||||||
| 1767 | # @param profile Lasso::Profile object | ||||||||||||||||||||||||||||
| 1768 | # @param dump Lasso::Identity XML dump | ||||||||||||||||||||||||||||
| 1769 | # @return result | ||||||||||||||||||||||||||||
| 1770 | sub setIdentityFromDump { | ||||||||||||||||||||||||||||
| 1771 | my ( $self, $profile, $dump ) = @_; | ||||||||||||||||||||||||||||
| 1772 | |||||||||||||||||||||||||||||
| 1773 | eval { Lasso::Profile::set_identity_from_dump( $profile, $dump ); }; | ||||||||||||||||||||||||||||
| 1774 | |||||||||||||||||||||||||||||
| 1775 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1776 | } | ||||||||||||||||||||||||||||
| 1777 | |||||||||||||||||||||||||||||
| 1778 | ## @method string getMetaDataURL(string key, int index) | ||||||||||||||||||||||||||||
| 1779 | # Get URL stored in a service metadata configuration key | ||||||||||||||||||||||||||||
| 1780 | # Replace #PORTAL# macro | ||||||||||||||||||||||||||||
| 1781 | # @param key Metadata configuration key | ||||||||||||||||||||||||||||
| 1782 | # @param index field index containing URL | ||||||||||||||||||||||||||||
| 1783 | # @param full Return full URL instead of path | ||||||||||||||||||||||||||||
| 1784 | # @return url | ||||||||||||||||||||||||||||
| 1785 | sub getMetaDataURL { | ||||||||||||||||||||||||||||
| 1786 | my ( $self, $key, $index, $full ) = @_; | ||||||||||||||||||||||||||||
| 1787 | $index = 3 unless defined $index; | ||||||||||||||||||||||||||||
| 1788 | $full = 0 unless defined $full; | ||||||||||||||||||||||||||||
| 1789 | |||||||||||||||||||||||||||||
| 1790 | return '' unless defined $self->conf->{$key}; | ||||||||||||||||||||||||||||
| 1791 | |||||||||||||||||||||||||||||
| 1792 | my $url = ( split( /;/, $self->conf->{$key} ) )[$index] || ''; | ||||||||||||||||||||||||||||
| 1793 | |||||||||||||||||||||||||||||
| 1794 | # Get default portal value | ||||||||||||||||||||||||||||
| 1795 | my $portal = $self->p->buildUrl; | ||||||||||||||||||||||||||||
| 1796 | $portal =~ s/\/$//; | ||||||||||||||||||||||||||||
| 1797 | |||||||||||||||||||||||||||||
| 1798 | # Replace #PORTAL# macro | ||||||||||||||||||||||||||||
| 1799 | $url =~ s/#PORTAL#/$portal/g; | ||||||||||||||||||||||||||||
| 1800 | |||||||||||||||||||||||||||||
| 1801 | # Return Full URL | ||||||||||||||||||||||||||||
| 1802 | return $url if $full; | ||||||||||||||||||||||||||||
| 1803 | |||||||||||||||||||||||||||||
| 1804 | # Return only path | ||||||||||||||||||||||||||||
| 1805 | my $uri = URI->new($url); | ||||||||||||||||||||||||||||
| 1806 | return $uri->path(); | ||||||||||||||||||||||||||||
| 1807 | } | ||||||||||||||||||||||||||||
| 1808 | |||||||||||||||||||||||||||||
| 1809 | sub getRouteFromMetaDataURL { | ||||||||||||||||||||||||||||
| 1810 | my ( $self, $key, $index, $sub ) = @_; | ||||||||||||||||||||||||||||
| 1811 | my $uri = $self->getMetaDataURL( $key, $index, 0 ); | ||||||||||||||||||||||||||||
| 1812 | unless ( $uri =~ m#^/\w# ) { | ||||||||||||||||||||||||||||
| 1813 | $self->logger->debug("$key has no index $index"); | ||||||||||||||||||||||||||||
| 1814 | return (); | ||||||||||||||||||||||||||||
| 1815 | } | ||||||||||||||||||||||||||||
| 1816 | my @t = grep /\w/, split( /\//, $uri ); | ||||||||||||||||||||||||||||
| 1817 | my $h = { pop(@t) => $sub }; | ||||||||||||||||||||||||||||
| 1818 | while ( my $s = pop @t ) { | ||||||||||||||||||||||||||||
| 1819 | $h = { $s => $h }; | ||||||||||||||||||||||||||||
| 1820 | } | ||||||||||||||||||||||||||||
| 1821 | return %$h; | ||||||||||||||||||||||||||||
| 1822 | } | ||||||||||||||||||||||||||||
| 1823 | |||||||||||||||||||||||||||||
| 1824 | sub addRouteFromMetaDataURL { | ||||||||||||||||||||||||||||
| 1825 | my ( $self, @args ) = @_; | ||||||||||||||||||||||||||||
| 1826 | $self->addAuthRouteFromMetaDataURL(@args); | ||||||||||||||||||||||||||||
| 1827 | $self->addUnauthRouteFromMetaDataURL(@args); | ||||||||||||||||||||||||||||
| 1828 | } | ||||||||||||||||||||||||||||
| 1829 | |||||||||||||||||||||||||||||
| 1830 | sub addAuthRouteFromMetaDataURL { | ||||||||||||||||||||||||||||
| 1831 | my ( $self, $key, $index, $sub, $methods ) = @_; | ||||||||||||||||||||||||||||
| 1832 | my %route = $self->getRouteFromMetaDataURL( $key, $index, $sub ); | ||||||||||||||||||||||||||||
| 1833 | return unless (%route); | ||||||||||||||||||||||||||||
| 1834 | $self->addAuthRoute( %route, $methods ); | ||||||||||||||||||||||||||||
| 1835 | } | ||||||||||||||||||||||||||||
| 1836 | |||||||||||||||||||||||||||||
| 1837 | sub addUnauthRouteFromMetaDataURL { | ||||||||||||||||||||||||||||
| 1838 | my ( $self, $key, $index, $sub, $methods ) = @_; | ||||||||||||||||||||||||||||
| 1839 | my %route = $self->getRouteFromMetaDataURL( $key, $index, $sub ); | ||||||||||||||||||||||||||||
| 1840 | return unless (%route); | ||||||||||||||||||||||||||||
| 1841 | $self->addUnauthRoute( %route, $methods ); | ||||||||||||||||||||||||||||
| 1842 | } | ||||||||||||||||||||||||||||
| 1843 | |||||||||||||||||||||||||||||
| 1844 | ## @method boolean processLogoutResponseMsg(Lasso::Logout logout, string response) | ||||||||||||||||||||||||||||
| 1845 | # Process logout response message | ||||||||||||||||||||||||||||
| 1846 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 1847 | # @param response SAML response | ||||||||||||||||||||||||||||
| 1848 | # @return result | ||||||||||||||||||||||||||||
| 1849 | sub processLogoutResponseMsg { | ||||||||||||||||||||||||||||
| 1850 | my ( $self, $logout, $response ) = @_; | ||||||||||||||||||||||||||||
| 1851 | |||||||||||||||||||||||||||||
| 1852 | $self->lazy_load_message($response); | ||||||||||||||||||||||||||||
| 1853 | |||||||||||||||||||||||||||||
| 1854 | eval { Lasso::Logout::process_response_msg( $logout, $response ); }; | ||||||||||||||||||||||||||||
| 1855 | |||||||||||||||||||||||||||||
| 1856 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1857 | } | ||||||||||||||||||||||||||||
| 1858 | |||||||||||||||||||||||||||||
| 1859 | ## @method boolean processLogoutRequestMsg(Lasso::Logout logout, string request) | ||||||||||||||||||||||||||||
| 1860 | # Process logout request message | ||||||||||||||||||||||||||||
| 1861 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 1862 | # @param request SAML request | ||||||||||||||||||||||||||||
| 1863 | # @return result | ||||||||||||||||||||||||||||
| 1864 | sub processLogoutRequestMsg { | ||||||||||||||||||||||||||||
| 1865 | my ( $self, $logout, $request ) = @_; | ||||||||||||||||||||||||||||
| 1866 | |||||||||||||||||||||||||||||
| 1867 | $self->lazy_load_message($request); | ||||||||||||||||||||||||||||
| 1868 | |||||||||||||||||||||||||||||
| 1869 | # Process the request | ||||||||||||||||||||||||||||
| 1870 | eval { Lasso::Logout::process_request_msg( $logout, $request ); }; | ||||||||||||||||||||||||||||
| 1871 | |||||||||||||||||||||||||||||
| 1872 | return 0 unless $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1873 | |||||||||||||||||||||||||||||
| 1874 | # Check NotOnOrAfter optional attribute | ||||||||||||||||||||||||||||
| 1875 | my $notOnOrAfter; | ||||||||||||||||||||||||||||
| 1876 | |||||||||||||||||||||||||||||
| 1877 | eval { $notOnOrAfter = $logout->request()->NotOnOrAfter(); }; | ||||||||||||||||||||||||||||
| 1878 | |||||||||||||||||||||||||||||
| 1879 | return 1 if ( $@ or !$notOnOrAfter ); | ||||||||||||||||||||||||||||
| 1880 | |||||||||||||||||||||||||||||
| 1881 | $self->logger->debug("Found NotOnOrAfter $notOnOrAfter in logout request"); | ||||||||||||||||||||||||||||
| 1882 | |||||||||||||||||||||||||||||
| 1883 | my $expirationTime = $self->samldate2timestamp($notOnOrAfter); | ||||||||||||||||||||||||||||
| 1884 | |||||||||||||||||||||||||||||
| 1885 | return ( time < $expirationTime ); | ||||||||||||||||||||||||||||
| 1886 | } | ||||||||||||||||||||||||||||
| 1887 | |||||||||||||||||||||||||||||
| 1888 | ## @method boolean validateLogoutRequest(Lasso::Logout logout) | ||||||||||||||||||||||||||||
| 1889 | # Validate logout request | ||||||||||||||||||||||||||||
| 1890 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 1891 | # @return result | ||||||||||||||||||||||||||||
| 1892 | sub validateLogoutRequest { | ||||||||||||||||||||||||||||
| 1893 | my ( $self, $logout ) = @_; | ||||||||||||||||||||||||||||
| 1894 | |||||||||||||||||||||||||||||
| 1895 | eval { Lasso::Logout::validate_request($logout); }; | ||||||||||||||||||||||||||||
| 1896 | |||||||||||||||||||||||||||||
| 1897 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1898 | } | ||||||||||||||||||||||||||||
| 1899 | |||||||||||||||||||||||||||||
| 1900 | ## @method boolean buildLogoutResponseMsg(Lasso::Logout logout) | ||||||||||||||||||||||||||||
| 1901 | # Build logout response message | ||||||||||||||||||||||||||||
| 1902 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 1903 | # @return boolean result | ||||||||||||||||||||||||||||
| 1904 | sub buildLogoutResponseMsg { | ||||||||||||||||||||||||||||
| 1905 | my ( $self, $logout ) = @_; | ||||||||||||||||||||||||||||
| 1906 | |||||||||||||||||||||||||||||
| 1907 | eval { Lasso::Logout::build_response_msg($logout); }; | ||||||||||||||||||||||||||||
| 1908 | |||||||||||||||||||||||||||||
| 1909 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 1910 | } | ||||||||||||||||||||||||||||
| 1911 | |||||||||||||||||||||||||||||
| 1912 | ## @method boolean storeReplayProtection(string samlID, string samlData) | ||||||||||||||||||||||||||||
| 1913 | # Store ID of an SAML message in Replay Protection base | ||||||||||||||||||||||||||||
| 1914 | # @param samlID ID of SAML message | ||||||||||||||||||||||||||||
| 1915 | # @param samlData Optional data to store | ||||||||||||||||||||||||||||
| 1916 | # @return result | ||||||||||||||||||||||||||||
| 1917 | sub storeReplayProtection { | ||||||||||||||||||||||||||||
| 1918 | my ( $self, $samlID, $samlData ) = @_; | ||||||||||||||||||||||||||||
| 1919 | my $infos = { | ||||||||||||||||||||||||||||
| 1920 | type => 'assertion', # Session type | ||||||||||||||||||||||||||||
| 1921 | _utime => time(), # Creation time | ||||||||||||||||||||||||||||
| 1922 | _assert_id => $samlID, | ||||||||||||||||||||||||||||
| 1923 | }; | ||||||||||||||||||||||||||||
| 1924 | |||||||||||||||||||||||||||||
| 1925 | if ( defined $samlData && $samlData ) { | ||||||||||||||||||||||||||||
| 1926 | $infos->{data} = $samlData; | ||||||||||||||||||||||||||||
| 1927 | } | ||||||||||||||||||||||||||||
| 1928 | |||||||||||||||||||||||||||||
| 1929 | my $samlSessionInfo = $self->getSamlSession( undef, $infos ); | ||||||||||||||||||||||||||||
| 1930 | return 0 unless $samlSessionInfo; | ||||||||||||||||||||||||||||
| 1931 | |||||||||||||||||||||||||||||
| 1932 | my $session_id = $samlSessionInfo->id; | ||||||||||||||||||||||||||||
| 1933 | |||||||||||||||||||||||||||||
| 1934 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 1935 | "Keep request ID $samlID in assertion session $session_id"); | ||||||||||||||||||||||||||||
| 1936 | |||||||||||||||||||||||||||||
| 1937 | return 1; | ||||||||||||||||||||||||||||
| 1938 | } | ||||||||||||||||||||||||||||
| 1939 | |||||||||||||||||||||||||||||
| 1940 | ## @method boolean replayProtection(string samlID) | ||||||||||||||||||||||||||||
| 1941 | # Check if SAML message do not correspond to a previously responded message | ||||||||||||||||||||||||||||
| 1942 | # @param samlID ID of initial SAML message | ||||||||||||||||||||||||||||
| 1943 | # @return result | ||||||||||||||||||||||||||||
| 1944 | sub replayProtection { | ||||||||||||||||||||||||||||
| 1945 | my ( $self, $samlID ) = @_; | ||||||||||||||||||||||||||||
| 1946 | |||||||||||||||||||||||||||||
| 1947 | unless ($samlID) { | ||||||||||||||||||||||||||||
| 1948 | $self->userLogger->error( | ||||||||||||||||||||||||||||
| 1949 | "Cannot verify replay because no SAML ID given"); | ||||||||||||||||||||||||||||
| 1950 | return 0; | ||||||||||||||||||||||||||||
| 1951 | } | ||||||||||||||||||||||||||||
| 1952 | |||||||||||||||||||||||||||||
| 1953 | my $sessions = | ||||||||||||||||||||||||||||
| 1954 | Lemonldap::NG::Common::Apache::Session->searchOn( $self->amOpts, | ||||||||||||||||||||||||||||
| 1955 | "_assert_id", $samlID ); | ||||||||||||||||||||||||||||
| 1956 | |||||||||||||||||||||||||||||
| 1957 | if ( | ||||||||||||||||||||||||||||
| 1958 | my @keys = | ||||||||||||||||||||||||||||
| 1959 | grep { $sessions->{$_}->{_session_kind} eq $self->sessionKind } | ||||||||||||||||||||||||||||
| 1960 | keys %$sessions | ||||||||||||||||||||||||||||
| 1961 | ) | ||||||||||||||||||||||||||||
| 1962 | { | ||||||||||||||||||||||||||||
| 1963 | |||||||||||||||||||||||||||||
| 1964 | # A session was found | ||||||||||||||||||||||||||||
| 1965 | foreach (@keys) { | ||||||||||||||||||||||||||||
| 1966 | next | ||||||||||||||||||||||||||||
| 1967 | unless ( $sessions->{$_}->{_session_kind} eq $self->sessionKind ); | ||||||||||||||||||||||||||||
| 1968 | my $session = $_; | ||||||||||||||||||||||||||||
| 1969 | my $result = 1; | ||||||||||||||||||||||||||||
| 1970 | |||||||||||||||||||||||||||||
| 1971 | # Delete it | ||||||||||||||||||||||||||||
| 1972 | my $samlSessionInfo = $self->getSamlSession($_); | ||||||||||||||||||||||||||||
| 1973 | |||||||||||||||||||||||||||||
| 1974 | return 0 unless $samlSessionInfo; | ||||||||||||||||||||||||||||
| 1975 | |||||||||||||||||||||||||||||
| 1976 | if ( defined $samlSessionInfo->data->{data} ) { | ||||||||||||||||||||||||||||
| 1977 | $result = $samlSessionInfo->data->{data}; | ||||||||||||||||||||||||||||
| 1978 | } | ||||||||||||||||||||||||||||
| 1979 | |||||||||||||||||||||||||||||
| 1980 | if ( $samlSessionInfo->remove ) { | ||||||||||||||||||||||||||||
| 1981 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 1982 | "Assertion session $session (Message ID $samlID) was deleted" | ||||||||||||||||||||||||||||
| 1983 | ); | ||||||||||||||||||||||||||||
| 1984 | return $result; | ||||||||||||||||||||||||||||
| 1985 | } | ||||||||||||||||||||||||||||
| 1986 | else { | ||||||||||||||||||||||||||||
| 1987 | $self->logger->error( | ||||||||||||||||||||||||||||
| 1988 | "Unable to delete assertion session $session (Message ID $samlID)" | ||||||||||||||||||||||||||||
| 1989 | ); | ||||||||||||||||||||||||||||
| 1990 | $self->logger->error( $samlSessionInfo->error ); | ||||||||||||||||||||||||||||
| 1991 | return 0; | ||||||||||||||||||||||||||||
| 1992 | } | ||||||||||||||||||||||||||||
| 1993 | } | ||||||||||||||||||||||||||||
| 1994 | } | ||||||||||||||||||||||||||||
| 1995 | else { | ||||||||||||||||||||||||||||
| 1996 | $self->logger->warn( | ||||||||||||||||||||||||||||
| 1997 | "No assertion session found for request ID " . $samlID ); | ||||||||||||||||||||||||||||
| 1998 | } | ||||||||||||||||||||||||||||
| 1999 | |||||||||||||||||||||||||||||
| 2000 | return 0; | ||||||||||||||||||||||||||||
| 2001 | } | ||||||||||||||||||||||||||||
| 2002 | |||||||||||||||||||||||||||||
| 2003 | ## @method string resolveArtifact(Lasso::Profile profile, string artifact, int method) | ||||||||||||||||||||||||||||
| 2004 | # Resolve artifact to get real SAML message | ||||||||||||||||||||||||||||
| 2005 | # @param profile Lasso::Profile object | ||||||||||||||||||||||||||||
| 2006 | # @param artifact Artifact message | ||||||||||||||||||||||||||||
| 2007 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 2008 | # @return SAML message | ||||||||||||||||||||||||||||
| 2009 | sub resolveArtifact { | ||||||||||||||||||||||||||||
| 2010 | my ( $self, $profile, $artifact, $method ) = @_; | ||||||||||||||||||||||||||||
| 2011 | my $message; | ||||||||||||||||||||||||||||
| 2012 | |||||||||||||||||||||||||||||
| 2013 | # Login profile | ||||||||||||||||||||||||||||
| 2014 | if ( $profile->isa("Lasso::Login") ) { | ||||||||||||||||||||||||||||
| 2015 | |||||||||||||||||||||||||||||
| 2016 | # Init request message | ||||||||||||||||||||||||||||
| 2017 | eval { Lasso::Login::init_request( $profile, $artifact, $method ); }; | ||||||||||||||||||||||||||||
| 2018 | return unless $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2019 | |||||||||||||||||||||||||||||
| 2020 | # Build request message | ||||||||||||||||||||||||||||
| 2021 | eval { Lasso::Login::build_request_msg($profile); }; | ||||||||||||||||||||||||||||
| 2022 | return unless $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2023 | |||||||||||||||||||||||||||||
| 2024 | unless ( $profile->msg_url ) { | ||||||||||||||||||||||||||||
| 2025 | $self->logger->error("No artifact resolution URL found"); | ||||||||||||||||||||||||||||
| 2026 | return; | ||||||||||||||||||||||||||||
| 2027 | } | ||||||||||||||||||||||||||||
| 2028 | |||||||||||||||||||||||||||||
| 2029 | my $request = HTTP::Request->new( 'POST' => $profile->msg_url ); | ||||||||||||||||||||||||||||
| 2030 | $request->content_type('text/xml'); | ||||||||||||||||||||||||||||
| 2031 | $request->header( Accept => 'text/xml' ); | ||||||||||||||||||||||||||||
| 2032 | $request->content( $profile->msg_body ); | ||||||||||||||||||||||||||||
| 2033 | |||||||||||||||||||||||||||||
| 2034 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2035 | "Send message " . $profile->msg_body . " to " . $profile->msg_url ); | ||||||||||||||||||||||||||||
| 2036 | |||||||||||||||||||||||||||||
| 2037 | # SOAP call | ||||||||||||||||||||||||||||
| 2038 | my $soap_answer = $self->ua->request($request); | ||||||||||||||||||||||||||||
| 2039 | if ( $soap_answer->code() == "200" ) { | ||||||||||||||||||||||||||||
| 2040 | $message = $soap_answer->content(); | ||||||||||||||||||||||||||||
| 2041 | $self->logger->debug("Get message $message"); | ||||||||||||||||||||||||||||
| 2042 | } | ||||||||||||||||||||||||||||
| 2043 | else { | ||||||||||||||||||||||||||||
| 2044 | $self->logger->error( | ||||||||||||||||||||||||||||
| 2045 | "Error while sending message: " . $soap_answer->status_line ); | ||||||||||||||||||||||||||||
| 2046 | } | ||||||||||||||||||||||||||||
| 2047 | } | ||||||||||||||||||||||||||||
| 2048 | |||||||||||||||||||||||||||||
| 2049 | return $message; | ||||||||||||||||||||||||||||
| 2050 | } | ||||||||||||||||||||||||||||
| 2051 | |||||||||||||||||||||||||||||
| 2052 | ## @method boolean storeArtifact(string id, string message, string session_id) | ||||||||||||||||||||||||||||
| 2053 | # Store artifact | ||||||||||||||||||||||||||||
| 2054 | # @param id Artifact ID | ||||||||||||||||||||||||||||
| 2055 | # @param message Artifact content | ||||||||||||||||||||||||||||
| 2056 | # @param session_id Session ID | ||||||||||||||||||||||||||||
| 2057 | # @return result | ||||||||||||||||||||||||||||
| 2058 | sub storeArtifact { | ||||||||||||||||||||||||||||
| 2059 | my ( $self, $id, $message, $session_id ) = @_; | ||||||||||||||||||||||||||||
| 2060 | |||||||||||||||||||||||||||||
| 2061 | my $infos = { | ||||||||||||||||||||||||||||
| 2062 | type => 'artifact', # Session type | ||||||||||||||||||||||||||||
| 2063 | _utime => time(), # Creation time | ||||||||||||||||||||||||||||
| 2064 | _art_id => $id, | ||||||||||||||||||||||||||||
| 2065 | message => $message, | ||||||||||||||||||||||||||||
| 2066 | }; | ||||||||||||||||||||||||||||
| 2067 | $infos->{_saml_id} = $session_id if $session_id; | ||||||||||||||||||||||||||||
| 2068 | |||||||||||||||||||||||||||||
| 2069 | my $samlSessionInfo = $self->getSamlSession( undef, $infos ) or return 0; | ||||||||||||||||||||||||||||
| 2070 | return 0 unless $samlSessionInfo; | ||||||||||||||||||||||||||||
| 2071 | |||||||||||||||||||||||||||||
| 2072 | my $art_session_id = $samlSessionInfo->id; | ||||||||||||||||||||||||||||
| 2073 | |||||||||||||||||||||||||||||
| 2074 | $self->logger->debug("Keep artifact $id in session $art_session_id"); | ||||||||||||||||||||||||||||
| 2075 | |||||||||||||||||||||||||||||
| 2076 | return 1; | ||||||||||||||||||||||||||||
| 2077 | } | ||||||||||||||||||||||||||||
| 2078 | |||||||||||||||||||||||||||||
| 2079 | ## @method hashRef loadArtifact(string id) | ||||||||||||||||||||||||||||
| 2080 | # Load artifact | ||||||||||||||||||||||||||||
| 2081 | # @param id Artifact ID | ||||||||||||||||||||||||||||
| 2082 | # @return Artifact session content | ||||||||||||||||||||||||||||
| 2083 | sub loadArtifact { | ||||||||||||||||||||||||||||
| 2084 | my ( $self, $id ) = @_; | ||||||||||||||||||||||||||||
| 2085 | my $art_session; | ||||||||||||||||||||||||||||
| 2086 | |||||||||||||||||||||||||||||
| 2087 | unless ($id) { | ||||||||||||||||||||||||||||
| 2088 | $self->logger->error("Cannot load artifact because no id given"); | ||||||||||||||||||||||||||||
| 2089 | return; | ||||||||||||||||||||||||||||
| 2090 | } | ||||||||||||||||||||||||||||
| 2091 | |||||||||||||||||||||||||||||
| 2092 | my $sessions = | ||||||||||||||||||||||||||||
| 2093 | Lemonldap::NG::Common::Apache::Session->searchOn( $self->amOpts, | ||||||||||||||||||||||||||||
| 2094 | "_art_id", $id ); | ||||||||||||||||||||||||||||
| 2095 | |||||||||||||||||||||||||||||
| 2096 | if ( | ||||||||||||||||||||||||||||
| 2097 | my @keys = | ||||||||||||||||||||||||||||
| 2098 | grep { $sessions->{$_}->{_session_kind} eq $self->sessionKind } | ||||||||||||||||||||||||||||
| 2099 | keys %$sessions | ||||||||||||||||||||||||||||
| 2100 | ) | ||||||||||||||||||||||||||||
| 2101 | { | ||||||||||||||||||||||||||||
| 2102 | |||||||||||||||||||||||||||||
| 2103 | my $nb_sessions = $#keys + 1; | ||||||||||||||||||||||||||||
| 2104 | |||||||||||||||||||||||||||||
| 2105 | $self->logger->debug("Found $nb_sessions sessions for artifact $id"); | ||||||||||||||||||||||||||||
| 2106 | |||||||||||||||||||||||||||||
| 2107 | # There should only be 1 result | ||||||||||||||||||||||||||||
| 2108 | return if ( $nb_sessions != 1 ); | ||||||||||||||||||||||||||||
| 2109 | |||||||||||||||||||||||||||||
| 2110 | my $session_id = shift @keys; | ||||||||||||||||||||||||||||
| 2111 | my $session = $session_id; | ||||||||||||||||||||||||||||
| 2112 | |||||||||||||||||||||||||||||
| 2113 | # Open session | ||||||||||||||||||||||||||||
| 2114 | my $samlSessionInfo = $self->getSamlSession($session_id); | ||||||||||||||||||||||||||||
| 2115 | |||||||||||||||||||||||||||||
| 2116 | return unless $samlSessionInfo; | ||||||||||||||||||||||||||||
| 2117 | |||||||||||||||||||||||||||||
| 2118 | # Get session contents | ||||||||||||||||||||||||||||
| 2119 | foreach ( keys %{ $samlSessionInfo->data } ) { | ||||||||||||||||||||||||||||
| 2120 | $art_session->{$_} = $samlSessionInfo->data->{$_}; | ||||||||||||||||||||||||||||
| 2121 | } | ||||||||||||||||||||||||||||
| 2122 | |||||||||||||||||||||||||||||
| 2123 | # Delete session | ||||||||||||||||||||||||||||
| 2124 | if ( $samlSessionInfo->remove ) { | ||||||||||||||||||||||||||||
| 2125 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2126 | "Artifact session $session (ID $id) was deleted"); | ||||||||||||||||||||||||||||
| 2127 | |||||||||||||||||||||||||||||
| 2128 | return $art_session; | ||||||||||||||||||||||||||||
| 2129 | } | ||||||||||||||||||||||||||||
| 2130 | else { | ||||||||||||||||||||||||||||
| 2131 | $self->logger->error( | ||||||||||||||||||||||||||||
| 2132 | "Unable to delete artifact session $session (ID $id)"); | ||||||||||||||||||||||||||||
| 2133 | $self->logger->error( $samlSessionInfo->error ); | ||||||||||||||||||||||||||||
| 2134 | return; | ||||||||||||||||||||||||||||
| 2135 | } | ||||||||||||||||||||||||||||
| 2136 | } | ||||||||||||||||||||||||||||
| 2137 | |||||||||||||||||||||||||||||
| 2138 | return; | ||||||||||||||||||||||||||||
| 2139 | } | ||||||||||||||||||||||||||||
| 2140 | |||||||||||||||||||||||||||||
| 2141 | ## @method string createArtifactResponse(Lasso::Login login) | ||||||||||||||||||||||||||||
| 2142 | # Create artifact response | ||||||||||||||||||||||||||||
| 2143 | # @param login Lasso::Login object | ||||||||||||||||||||||||||||
| 2144 | # @return Artifact response | ||||||||||||||||||||||||||||
| 2145 | sub createArtifactResponse { | ||||||||||||||||||||||||||||
| 2146 | my ( $self, $req, $login ) = @_; | ||||||||||||||||||||||||||||
| 2147 | |||||||||||||||||||||||||||||
| 2148 | my $artifact_id = $login->assertionArtifact(); | ||||||||||||||||||||||||||||
| 2149 | |||||||||||||||||||||||||||||
| 2150 | # Load artifact message into login response | ||||||||||||||||||||||||||||
| 2151 | my $art_session = $self->loadArtifact($artifact_id); | ||||||||||||||||||||||||||||
| 2152 | utf8::decode( $art_session->{message} ); | ||||||||||||||||||||||||||||
| 2153 | eval { $login->set_artifact_message( $art_session->{message} ); }; | ||||||||||||||||||||||||||||
| 2154 | if ($@) { | ||||||||||||||||||||||||||||
| 2155 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2156 | $self->logger->error("Cannot load artifact message"); | ||||||||||||||||||||||||||||
| 2157 | return; | ||||||||||||||||||||||||||||
| 2158 | } | ||||||||||||||||||||||||||||
| 2159 | |||||||||||||||||||||||||||||
| 2160 | $self->logger->debug("Response loaded"); | ||||||||||||||||||||||||||||
| 2161 | |||||||||||||||||||||||||||||
| 2162 | # Try to get Lasso session | ||||||||||||||||||||||||||||
| 2163 | my $session_id = $art_session->{_saml_id}; | ||||||||||||||||||||||||||||
| 2164 | if ($session_id) { | ||||||||||||||||||||||||||||
| 2165 | $self->logger->debug("Find session_id $session_id in artifact session"); | ||||||||||||||||||||||||||||
| 2166 | |||||||||||||||||||||||||||||
| 2167 | my $session = $self->p->getApacheSession($session_id); | ||||||||||||||||||||||||||||
| 2168 | unless ($session) { | ||||||||||||||||||||||||||||
| 2169 | $self->logger->error("Unable to open session $session_id"); | ||||||||||||||||||||||||||||
| 2170 | return; | ||||||||||||||||||||||||||||
| 2171 | } | ||||||||||||||||||||||||||||
| 2172 | |||||||||||||||||||||||||||||
| 2173 | my $lassoSession = $session->data->{ $self->lsDump }; | ||||||||||||||||||||||||||||
| 2174 | |||||||||||||||||||||||||||||
| 2175 | if ($lassoSession) { | ||||||||||||||||||||||||||||
| 2176 | unless ( $self->setSessionFromDump( $login, $lassoSession ) ) { | ||||||||||||||||||||||||||||
| 2177 | $self->logger->error("Unable to load Lasso Session"); | ||||||||||||||||||||||||||||
| 2178 | return; | ||||||||||||||||||||||||||||
| 2179 | } | ||||||||||||||||||||||||||||
| 2180 | $self->logger->debug("Lasso Session loaded"); | ||||||||||||||||||||||||||||
| 2181 | } | ||||||||||||||||||||||||||||
| 2182 | |||||||||||||||||||||||||||||
| 2183 | } | ||||||||||||||||||||||||||||
| 2184 | else { | ||||||||||||||||||||||||||||
| 2185 | $self->logger->debug("No session_id in artifact session"); | ||||||||||||||||||||||||||||
| 2186 | } | ||||||||||||||||||||||||||||
| 2187 | |||||||||||||||||||||||||||||
| 2188 | # Build artifact response | ||||||||||||||||||||||||||||
| 2189 | eval { Lasso::Login::build_response_msg($login); }; | ||||||||||||||||||||||||||||
| 2190 | if ($@) { | ||||||||||||||||||||||||||||
| 2191 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2192 | $self->logger->error("Cannot build artifact response"); | ||||||||||||||||||||||||||||
| 2193 | return; | ||||||||||||||||||||||||||||
| 2194 | } | ||||||||||||||||||||||||||||
| 2195 | $self->logger->debug("Artifact response built"); | ||||||||||||||||||||||||||||
| 2196 | |||||||||||||||||||||||||||||
| 2197 | # Store Lasso session if session opened | ||||||||||||||||||||||||||||
| 2198 | if ( $session_id and $login->is_session_dirty ) { | ||||||||||||||||||||||||||||
| 2199 | $self->logger->debug("Save Lasso session in session"); | ||||||||||||||||||||||||||||
| 2200 | $self->updateSession( $req, | ||||||||||||||||||||||||||||
| 2201 | { $self->lsDump => $login->get_session->dump }, $session_id ); | ||||||||||||||||||||||||||||
| 2202 | } | ||||||||||||||||||||||||||||
| 2203 | |||||||||||||||||||||||||||||
| 2204 | # Return artifact message | ||||||||||||||||||||||||||||
| 2205 | return $login->msg_body; | ||||||||||||||||||||||||||||
| 2206 | } | ||||||||||||||||||||||||||||
| 2207 | |||||||||||||||||||||||||||||
| 2208 | ## @method boolean processArtRequestMsg(Lasso::Profile profile, string request) | ||||||||||||||||||||||||||||
| 2209 | # Process artifact request message | ||||||||||||||||||||||||||||
| 2210 | # @param profile Lasso::Profile object | ||||||||||||||||||||||||||||
| 2211 | # @param request SAML request | ||||||||||||||||||||||||||||
| 2212 | # @return result | ||||||||||||||||||||||||||||
| 2213 | sub processArtRequestMsg { | ||||||||||||||||||||||||||||
| 2214 | my ( $self, $profile, $request ) = @_; | ||||||||||||||||||||||||||||
| 2215 | |||||||||||||||||||||||||||||
| 2216 | # Login profile | ||||||||||||||||||||||||||||
| 2217 | if ( $profile->isa("Lasso::Login") ) { | ||||||||||||||||||||||||||||
| 2218 | |||||||||||||||||||||||||||||
| 2219 | eval { Lasso::Login::process_request_msg( $profile, $request ); }; | ||||||||||||||||||||||||||||
| 2220 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2221 | |||||||||||||||||||||||||||||
| 2222 | } | ||||||||||||||||||||||||||||
| 2223 | |||||||||||||||||||||||||||||
| 2224 | return 0; | ||||||||||||||||||||||||||||
| 2225 | } | ||||||||||||||||||||||||||||
| 2226 | |||||||||||||||||||||||||||||
| 2227 | ## @method boolean processArtResponseMsg(Lasso::Profile profile, string response) | ||||||||||||||||||||||||||||
| 2228 | # Process artifact response message | ||||||||||||||||||||||||||||
| 2229 | # @param profile Lasso::Profile object | ||||||||||||||||||||||||||||
| 2230 | # @param response SAML response | ||||||||||||||||||||||||||||
| 2231 | # @return result | ||||||||||||||||||||||||||||
| 2232 | sub processArtResponseMsg { | ||||||||||||||||||||||||||||
| 2233 | my ( $self, $profile, $response ) = @_; | ||||||||||||||||||||||||||||
| 2234 | |||||||||||||||||||||||||||||
| 2235 | # Login profile | ||||||||||||||||||||||||||||
| 2236 | if ( $profile->isa("Lasso::Login") ) { | ||||||||||||||||||||||||||||
| 2237 | |||||||||||||||||||||||||||||
| 2238 | eval { Lasso::Login::process_response_msg( $profile, $response ); }; | ||||||||||||||||||||||||||||
| 2239 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2240 | |||||||||||||||||||||||||||||
| 2241 | } | ||||||||||||||||||||||||||||
| 2242 | |||||||||||||||||||||||||||||
| 2243 | return 0; | ||||||||||||||||||||||||||||
| 2244 | } | ||||||||||||||||||||||||||||
| 2245 | |||||||||||||||||||||||||||||
| 2246 | ## @method string sendSOAPMessage(string endpoint, string message) | ||||||||||||||||||||||||||||
| 2247 | # Send SOAP message and get response | ||||||||||||||||||||||||||||
| 2248 | # @param endpoint SOAP End Point | ||||||||||||||||||||||||||||
| 2249 | # @param message SOAP message | ||||||||||||||||||||||||||||
| 2250 | # @return SOAP response | ||||||||||||||||||||||||||||
| 2251 | sub sendSOAPMessage { | ||||||||||||||||||||||||||||
| 2252 | my ( $self, $endpoint, $message ) = @_; | ||||||||||||||||||||||||||||
| 2253 | my $response; | ||||||||||||||||||||||||||||
| 2254 | |||||||||||||||||||||||||||||
| 2255 | my $request = HTTP::Request->new( 'POST' => $endpoint ); | ||||||||||||||||||||||||||||
| 2256 | $request->content_type('text/xml'); | ||||||||||||||||||||||||||||
| 2257 | $request->header( Accept => 'text/xml' ); | ||||||||||||||||||||||||||||
| 2258 | $request->content($message); | ||||||||||||||||||||||||||||
| 2259 | |||||||||||||||||||||||||||||
| 2260 | $self->logger->debug("Send SOAP message $message to $endpoint"); | ||||||||||||||||||||||||||||
| 2261 | |||||||||||||||||||||||||||||
| 2262 | # SOAP call | ||||||||||||||||||||||||||||
| 2263 | my $soap_answer = $self->ua()->request($request); | ||||||||||||||||||||||||||||
| 2264 | if ( $soap_answer->code() == "200" ) { | ||||||||||||||||||||||||||||
| 2265 | $response = $soap_answer->content(); | ||||||||||||||||||||||||||||
| 2266 | $self->logger->debug("Get response $response"); | ||||||||||||||||||||||||||||
| 2267 | } | ||||||||||||||||||||||||||||
| 2268 | else { | ||||||||||||||||||||||||||||
| 2269 | $self->logger->debug("No response to SOAP request"); | ||||||||||||||||||||||||||||
| 2270 | return; | ||||||||||||||||||||||||||||
| 2271 | } | ||||||||||||||||||||||||||||
| 2272 | |||||||||||||||||||||||||||||
| 2273 | return $response; | ||||||||||||||||||||||||||||
| 2274 | } | ||||||||||||||||||||||||||||
| 2275 | |||||||||||||||||||||||||||||
| 2276 | ## @method Lasso::AssertionQuery createAssertionQuery(Lasso::Server server) | ||||||||||||||||||||||||||||
| 2277 | # Create a new assertion query | ||||||||||||||||||||||||||||
| 2278 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 2279 | # @return assertion query | ||||||||||||||||||||||||||||
| 2280 | sub createAssertionQuery { | ||||||||||||||||||||||||||||
| 2281 | my ( $self, $server ) = @_; | ||||||||||||||||||||||||||||
| 2282 | my $query; | ||||||||||||||||||||||||||||
| 2283 | |||||||||||||||||||||||||||||
| 2284 | # Create assertion query | ||||||||||||||||||||||||||||
| 2285 | eval { $query = Lasso::AssertionQuery->new($server); }; | ||||||||||||||||||||||||||||
| 2286 | if ($@) { | ||||||||||||||||||||||||||||
| 2287 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2288 | return; | ||||||||||||||||||||||||||||
| 2289 | } | ||||||||||||||||||||||||||||
| 2290 | |||||||||||||||||||||||||||||
| 2291 | return $query; | ||||||||||||||||||||||||||||
| 2292 | } | ||||||||||||||||||||||||||||
| 2293 | |||||||||||||||||||||||||||||
| 2294 | ## @method Lasso::AssertionQuery createAttributeRequest(Lasso::Server server, string idp, hashref attributes, Lasso::Saml2NameID nameid) | ||||||||||||||||||||||||||||
| 2295 | # Create an attribute request | ||||||||||||||||||||||||||||
| 2296 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 2297 | # @param idp IDP entityID | ||||||||||||||||||||||||||||
| 2298 | # @param attributes List of requested attributes | ||||||||||||||||||||||||||||
| 2299 | # @param nameid Subject NameID | ||||||||||||||||||||||||||||
| 2300 | # @return attribute request | ||||||||||||||||||||||||||||
| 2301 | sub createAttributeRequest { | ||||||||||||||||||||||||||||
| 2302 | my ( $self, $server, $idp, $attributes, $nameid ) = @_; | ||||||||||||||||||||||||||||
| 2303 | my $query; | ||||||||||||||||||||||||||||
| 2304 | |||||||||||||||||||||||||||||
| 2305 | # Create assertion query | ||||||||||||||||||||||||||||
| 2306 | return unless ( $query = $self->createAssertionQuery($server) ); | ||||||||||||||||||||||||||||
| 2307 | |||||||||||||||||||||||||||||
| 2308 | $self->logger->debug("Assertion query created"); | ||||||||||||||||||||||||||||
| 2309 | |||||||||||||||||||||||||||||
| 2310 | # Init request | ||||||||||||||||||||||||||||
| 2311 | my $method = Lasso::Constants::HTTP_METHOD_SOAP; | ||||||||||||||||||||||||||||
| 2312 | my $type = Lasso::Constants::ASSERTION_QUERY_REQUEST_TYPE_ATTRIBUTE; | ||||||||||||||||||||||||||||
| 2313 | eval { | ||||||||||||||||||||||||||||
| 2314 | Lasso::AssertionQuery::init_request( $query, $idp, $method, $type ); | ||||||||||||||||||||||||||||
| 2315 | }; | ||||||||||||||||||||||||||||
| 2316 | if ($@) { | ||||||||||||||||||||||||||||
| 2317 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2318 | return; | ||||||||||||||||||||||||||||
| 2319 | } | ||||||||||||||||||||||||||||
| 2320 | |||||||||||||||||||||||||||||
| 2321 | $self->logger->debug("Assertion query request initiated"); | ||||||||||||||||||||||||||||
| 2322 | |||||||||||||||||||||||||||||
| 2323 | # Set NameID | ||||||||||||||||||||||||||||
| 2324 | eval { $query->request()->Subject()->NameID($nameid); }; | ||||||||||||||||||||||||||||
| 2325 | if ($@) { | ||||||||||||||||||||||||||||
| 2326 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2327 | return; | ||||||||||||||||||||||||||||
| 2328 | } | ||||||||||||||||||||||||||||
| 2329 | |||||||||||||||||||||||||||||
| 2330 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2331 | "Set NameID " . $nameid->dump . " in assertion query" ); | ||||||||||||||||||||||||||||
| 2332 | |||||||||||||||||||||||||||||
| 2333 | # Store attributes in request | ||||||||||||||||||||||||||||
| 2334 | my @requested_attributes; | ||||||||||||||||||||||||||||
| 2335 | foreach ( keys %$attributes ) { | ||||||||||||||||||||||||||||
| 2336 | |||||||||||||||||||||||||||||
| 2337 | # Create SAML2 Attribute | ||||||||||||||||||||||||||||
| 2338 | my $attribute; | ||||||||||||||||||||||||||||
| 2339 | |||||||||||||||||||||||||||||
| 2340 | eval { $attribute = Lasso::Saml2Attribute->new(); }; | ||||||||||||||||||||||||||||
| 2341 | if ($@) { | ||||||||||||||||||||||||||||
| 2342 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2343 | return; | ||||||||||||||||||||||||||||
| 2344 | } | ||||||||||||||||||||||||||||
| 2345 | |||||||||||||||||||||||||||||
| 2346 | # Set attribute properties | ||||||||||||||||||||||||||||
| 2347 | my ( $mandatory, $name, $format, $friendly_name ) = | ||||||||||||||||||||||||||||
| 2348 | split( /;/, $attributes->{$_} ); | ||||||||||||||||||||||||||||
| 2349 | |||||||||||||||||||||||||||||
| 2350 | $attribute->Name($name) if defined $name; | ||||||||||||||||||||||||||||
| 2351 | $attribute->NameFormat($format) if defined $format; | ||||||||||||||||||||||||||||
| 2352 | $attribute->FriendlyName($friendly_name) if defined $friendly_name; | ||||||||||||||||||||||||||||
| 2353 | |||||||||||||||||||||||||||||
| 2354 | # Store attribute | ||||||||||||||||||||||||||||
| 2355 | push @requested_attributes, $attribute; | ||||||||||||||||||||||||||||
| 2356 | } | ||||||||||||||||||||||||||||
| 2357 | |||||||||||||||||||||||||||||
| 2358 | # Set attributes in request | ||||||||||||||||||||||||||||
| 2359 | eval { $query->request()->Attribute(@requested_attributes); }; | ||||||||||||||||||||||||||||
| 2360 | if ($@) { | ||||||||||||||||||||||||||||
| 2361 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2362 | return; | ||||||||||||||||||||||||||||
| 2363 | } | ||||||||||||||||||||||||||||
| 2364 | |||||||||||||||||||||||||||||
| 2365 | # Build message | ||||||||||||||||||||||||||||
| 2366 | eval { Lasso::AssertionQuery::build_request_msg($query); }; | ||||||||||||||||||||||||||||
| 2367 | if ($@) { | ||||||||||||||||||||||||||||
| 2368 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2369 | return; | ||||||||||||||||||||||||||||
| 2370 | } | ||||||||||||||||||||||||||||
| 2371 | |||||||||||||||||||||||||||||
| 2372 | # Return query | ||||||||||||||||||||||||||||
| 2373 | return $query; | ||||||||||||||||||||||||||||
| 2374 | } | ||||||||||||||||||||||||||||
| 2375 | |||||||||||||||||||||||||||||
| 2376 | ## @method boolean validateAttributeRequest(Lasso::AssertionQuery query) | ||||||||||||||||||||||||||||
| 2377 | # Validate an attribute request | ||||||||||||||||||||||||||||
| 2378 | # @param query Lasso::AssertionQuery object | ||||||||||||||||||||||||||||
| 2379 | # @return result | ||||||||||||||||||||||||||||
| 2380 | sub validateAttributeRequest { | ||||||||||||||||||||||||||||
| 2381 | my ( $self, $query ) = @_; | ||||||||||||||||||||||||||||
| 2382 | |||||||||||||||||||||||||||||
| 2383 | eval { Lasso::AssertionQuery::validate_request($query); }; | ||||||||||||||||||||||||||||
| 2384 | |||||||||||||||||||||||||||||
| 2385 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2386 | } | ||||||||||||||||||||||||||||
| 2387 | |||||||||||||||||||||||||||||
| 2388 | ## @method Lasso::AssertionQuery processAttributeRequest(Lasso::Server server, string request) | ||||||||||||||||||||||||||||
| 2389 | # Process an attribute request | ||||||||||||||||||||||||||||
| 2390 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 2391 | # @param request Request content | ||||||||||||||||||||||||||||
| 2392 | # @return assertion query | ||||||||||||||||||||||||||||
| 2393 | sub processAttributeRequest { | ||||||||||||||||||||||||||||
| 2394 | my ( $self, $server, $request ) = @_; | ||||||||||||||||||||||||||||
| 2395 | my $query; | ||||||||||||||||||||||||||||
| 2396 | |||||||||||||||||||||||||||||
| 2397 | # Create assertion query | ||||||||||||||||||||||||||||
| 2398 | return unless ( $query = $self->createAssertionQuery($server) ); | ||||||||||||||||||||||||||||
| 2399 | |||||||||||||||||||||||||||||
| 2400 | $self->logger->debug("Assertion query created"); | ||||||||||||||||||||||||||||
| 2401 | |||||||||||||||||||||||||||||
| 2402 | # Process response | ||||||||||||||||||||||||||||
| 2403 | eval { Lasso::AssertionQuery::process_request_msg( $query, $request ); }; | ||||||||||||||||||||||||||||
| 2404 | if ($@) { | ||||||||||||||||||||||||||||
| 2405 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2406 | return; | ||||||||||||||||||||||||||||
| 2407 | } | ||||||||||||||||||||||||||||
| 2408 | |||||||||||||||||||||||||||||
| 2409 | $self->logger->debug("Attribute request is valid"); | ||||||||||||||||||||||||||||
| 2410 | |||||||||||||||||||||||||||||
| 2411 | return $query; | ||||||||||||||||||||||||||||
| 2412 | } | ||||||||||||||||||||||||||||
| 2413 | |||||||||||||||||||||||||||||
| 2414 | ## @method string buildAttributeResponse(Lasso::AssertionQuery query) | ||||||||||||||||||||||||||||
| 2415 | # Build attribute response | ||||||||||||||||||||||||||||
| 2416 | # @param query Lasso::AssertionQuery object | ||||||||||||||||||||||||||||
| 2417 | # @return attribute response | ||||||||||||||||||||||||||||
| 2418 | sub buildAttributeResponse { | ||||||||||||||||||||||||||||
| 2419 | my ( $self, $query ) = @_; | ||||||||||||||||||||||||||||
| 2420 | |||||||||||||||||||||||||||||
| 2421 | eval { Lasso::AssertionQuery::build_response_msg($query); }; | ||||||||||||||||||||||||||||
| 2422 | |||||||||||||||||||||||||||||
| 2423 | if ($@) { | ||||||||||||||||||||||||||||
| 2424 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2425 | return; | ||||||||||||||||||||||||||||
| 2426 | } | ||||||||||||||||||||||||||||
| 2427 | |||||||||||||||||||||||||||||
| 2428 | return $query->msg_body; | ||||||||||||||||||||||||||||
| 2429 | } | ||||||||||||||||||||||||||||
| 2430 | |||||||||||||||||||||||||||||
| 2431 | ## @method Lasso::AssertionQuery processAttributeResponse(Lasso::Server server, string response) | ||||||||||||||||||||||||||||
| 2432 | # Process an attribute response | ||||||||||||||||||||||||||||
| 2433 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 2434 | # @param response Response content | ||||||||||||||||||||||||||||
| 2435 | # @return assertion query | ||||||||||||||||||||||||||||
| 2436 | sub processAttributeResponse { | ||||||||||||||||||||||||||||
| 2437 | my ( $self, $server, $response ) = @_; | ||||||||||||||||||||||||||||
| 2438 | my $query; | ||||||||||||||||||||||||||||
| 2439 | |||||||||||||||||||||||||||||
| 2440 | # Create assertion query | ||||||||||||||||||||||||||||
| 2441 | return unless ( $query = $self->createAssertionQuery($server) ); | ||||||||||||||||||||||||||||
| 2442 | |||||||||||||||||||||||||||||
| 2443 | $self->logger->debug("Assertion query created"); | ||||||||||||||||||||||||||||
| 2444 | |||||||||||||||||||||||||||||
| 2445 | # Process response | ||||||||||||||||||||||||||||
| 2446 | eval { Lasso::AssertionQuery::process_response_msg( $query, $response ); }; | ||||||||||||||||||||||||||||
| 2447 | if ($@) { | ||||||||||||||||||||||||||||
| 2448 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2449 | return; | ||||||||||||||||||||||||||||
| 2450 | } | ||||||||||||||||||||||||||||
| 2451 | |||||||||||||||||||||||||||||
| 2452 | $self->logger->debug("Attribute response is valid"); | ||||||||||||||||||||||||||||
| 2453 | |||||||||||||||||||||||||||||
| 2454 | return $query; | ||||||||||||||||||||||||||||
| 2455 | } | ||||||||||||||||||||||||||||
| 2456 | |||||||||||||||||||||||||||||
| 2457 | ## @method string getNameIDFormat(string format) | ||||||||||||||||||||||||||||
| 2458 | # Convert configuration string into SAML2 NameIDFormat string | ||||||||||||||||||||||||||||
| 2459 | # @param format configuration string | ||||||||||||||||||||||||||||
| 2460 | # @return SAML2 NameIDFormat string | ||||||||||||||||||||||||||||
| 2461 | sub getNameIDFormat { | ||||||||||||||||||||||||||||
| 2462 | my ( $self, $format ) = @_; | ||||||||||||||||||||||||||||
| 2463 | |||||||||||||||||||||||||||||
| 2464 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_UNSPECIFIED | ||||||||||||||||||||||||||||
| 2465 | if ( $format =~ /unspecified/i ); | ||||||||||||||||||||||||||||
| 2466 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_EMAIL | ||||||||||||||||||||||||||||
| 2467 | if ( $format =~ /email/i ); | ||||||||||||||||||||||||||||
| 2468 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_X509 | ||||||||||||||||||||||||||||
| 2469 | if ( $format =~ /x509/i ); | ||||||||||||||||||||||||||||
| 2470 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_WINDOWS | ||||||||||||||||||||||||||||
| 2471 | if ( $format =~ /windows/i ); | ||||||||||||||||||||||||||||
| 2472 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_KERBEROS | ||||||||||||||||||||||||||||
| 2473 | if ( $format =~ /kerberos/i ); | ||||||||||||||||||||||||||||
| 2474 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_ENTITY | ||||||||||||||||||||||||||||
| 2475 | if ( $format =~ /entity/i ); | ||||||||||||||||||||||||||||
| 2476 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_PERSISTENT | ||||||||||||||||||||||||||||
| 2477 | if ( $format =~ /persistent/i ); | ||||||||||||||||||||||||||||
| 2478 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_TRANSIENT | ||||||||||||||||||||||||||||
| 2479 | if ( $format =~ /transient/i ); | ||||||||||||||||||||||||||||
| 2480 | return Lasso::Constants::SAML2_NAME_IDENTIFIER_FORMAT_ENCRYPTED | ||||||||||||||||||||||||||||
| 2481 | if ( $format =~ /encrypted/i ); | ||||||||||||||||||||||||||||
| 2482 | |||||||||||||||||||||||||||||
| 2483 | return; | ||||||||||||||||||||||||||||
| 2484 | } | ||||||||||||||||||||||||||||
| 2485 | |||||||||||||||||||||||||||||
| 2486 | ## @method int getHttpMethod(string method) | ||||||||||||||||||||||||||||
| 2487 | # Convert configuration string into Lasso HTTP Method integer | ||||||||||||||||||||||||||||
| 2488 | # @param method configuration string | ||||||||||||||||||||||||||||
| 2489 | # @return Lasso HTTP Method integer | ||||||||||||||||||||||||||||
| 2490 | sub getHttpMethod { | ||||||||||||||||||||||||||||
| 2491 | my ( $self, $method ) = @_; | ||||||||||||||||||||||||||||
| 2492 | |||||||||||||||||||||||||||||
| 2493 | $method ||= ''; | ||||||||||||||||||||||||||||
| 2494 | return Lasso::Constants::HTTP_METHOD_POST | ||||||||||||||||||||||||||||
| 2495 | if ( $method =~ /^(http)?[-_]?post$/i ); | ||||||||||||||||||||||||||||
| 2496 | return Lasso::Constants::HTTP_METHOD_REDIRECT | ||||||||||||||||||||||||||||
| 2497 | if ( $method =~ /^(http)?[-_]?redirect$/i ); | ||||||||||||||||||||||||||||
| 2498 | return Lasso::Constants::HTTP_METHOD_SOAP | ||||||||||||||||||||||||||||
| 2499 | if ( $method =~ /^(http)?[-_]?soap$/i ); | ||||||||||||||||||||||||||||
| 2500 | return Lasso::Constants::HTTP_METHOD_ARTIFACT_GET | ||||||||||||||||||||||||||||
| 2501 | if ( $method =~ /^(artifact)[-_]get$/i ); | ||||||||||||||||||||||||||||
| 2502 | return Lasso::Constants::HTTP_METHOD_ARTIFACT_POST | ||||||||||||||||||||||||||||
| 2503 | if ( $method =~ /^(artifact)[-_]post$/i ); | ||||||||||||||||||||||||||||
| 2504 | |||||||||||||||||||||||||||||
| 2505 | return; | ||||||||||||||||||||||||||||
| 2506 | } | ||||||||||||||||||||||||||||
| 2507 | |||||||||||||||||||||||||||||
| 2508 | ## @method int getHttpMethodString(int method) | ||||||||||||||||||||||||||||
| 2509 | # Convert configuration Lasso HTTP Method integer into string | ||||||||||||||||||||||||||||
| 2510 | # @param method Lasso HTTP Method | ||||||||||||||||||||||||||||
| 2511 | # @return method string | ||||||||||||||||||||||||||||
| 2512 | sub getHttpMethodString { | ||||||||||||||||||||||||||||
| 2513 | my ( $self, $method ) = @_; | ||||||||||||||||||||||||||||
| 2514 | |||||||||||||||||||||||||||||
| 2515 | return "POST" if ( $method == Lasso::Constants::HTTP_METHOD_POST ); | ||||||||||||||||||||||||||||
| 2516 | return "REDIRECT" | ||||||||||||||||||||||||||||
| 2517 | if ( $method == Lasso::Constants::HTTP_METHOD_REDIRECT ); | ||||||||||||||||||||||||||||
| 2518 | return "SOAP" if ( $method == Lasso::Constants::HTTP_METHOD_SOAP ); | ||||||||||||||||||||||||||||
| 2519 | return "ARTIFACT GET" | ||||||||||||||||||||||||||||
| 2520 | if ( $method == Lasso::Constants::HTTP_METHOD_ARTIFACT_GET ); | ||||||||||||||||||||||||||||
| 2521 | return "ARTIFACT POST" | ||||||||||||||||||||||||||||
| 2522 | if ( $method == Lasso::Constants::HTTP_METHOD_ARTIFACT_POST ); | ||||||||||||||||||||||||||||
| 2523 | |||||||||||||||||||||||||||||
| 2524 | return "UNDEFINED"; | ||||||||||||||||||||||||||||
| 2525 | } | ||||||||||||||||||||||||||||
| 2526 | ## @method int getFirstHttpMethod(Lasso::Server server, string entityID, int protocolType) | ||||||||||||||||||||||||||||
| 2527 | # Find a suitable HTTP method for an entity with a given protocol | ||||||||||||||||||||||||||||
| 2528 | # @param server Lasso::Server object | ||||||||||||||||||||||||||||
| 2529 | # @param entityID entity ID | ||||||||||||||||||||||||||||
| 2530 | # @param protocolType Lasso protocol type | ||||||||||||||||||||||||||||
| 2531 | # @return Lasso HTTP Method | ||||||||||||||||||||||||||||
| 2532 | sub getFirstHttpMethod { | ||||||||||||||||||||||||||||
| 2533 | my ( $self, $server, $entityID, $protocolType ) = @_; | ||||||||||||||||||||||||||||
| 2534 | my $entity_provider; | ||||||||||||||||||||||||||||
| 2535 | my $method; | ||||||||||||||||||||||||||||
| 2536 | |||||||||||||||||||||||||||||
| 2537 | # Get Lasso::Provider object | ||||||||||||||||||||||||||||
| 2538 | eval { | ||||||||||||||||||||||||||||
| 2539 | $entity_provider = Lasso::Server::get_provider( $server, $entityID ); | ||||||||||||||||||||||||||||
| 2540 | }; | ||||||||||||||||||||||||||||
| 2541 | if ($@) { | ||||||||||||||||||||||||||||
| 2542 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2543 | return; | ||||||||||||||||||||||||||||
| 2544 | } | ||||||||||||||||||||||||||||
| 2545 | |||||||||||||||||||||||||||||
| 2546 | # Find HTTP method | ||||||||||||||||||||||||||||
| 2547 | eval { | ||||||||||||||||||||||||||||
| 2548 | $method = | ||||||||||||||||||||||||||||
| 2549 | Lasso::Provider::get_first_http_method( $server, $entity_provider, | ||||||||||||||||||||||||||||
| 2550 | $protocolType ); | ||||||||||||||||||||||||||||
| 2551 | }; | ||||||||||||||||||||||||||||
| 2552 | if ($@) { | ||||||||||||||||||||||||||||
| 2553 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2554 | return; | ||||||||||||||||||||||||||||
| 2555 | } | ||||||||||||||||||||||||||||
| 2556 | |||||||||||||||||||||||||||||
| 2557 | return $method; | ||||||||||||||||||||||||||||
| 2558 | } | ||||||||||||||||||||||||||||
| 2559 | |||||||||||||||||||||||||||||
| 2560 | ## @method boolean disableSignature(Lasso::Profile profile) | ||||||||||||||||||||||||||||
| 2561 | # Modify Lasso signature hint to disable signature | ||||||||||||||||||||||||||||
| 2562 | # @param profile Lasso profile object | ||||||||||||||||||||||||||||
| 2563 | # @return result | ||||||||||||||||||||||||||||
| 2564 | sub disableSignature { | ||||||||||||||||||||||||||||
| 2565 | my ( $self, $profile ) = @_; | ||||||||||||||||||||||||||||
| 2566 | |||||||||||||||||||||||||||||
| 2567 | eval { | ||||||||||||||||||||||||||||
| 2568 | Lasso::Profile::set_signature_hint( $profile, | ||||||||||||||||||||||||||||
| 2569 | Lasso::Constants::PROFILE_SIGNATURE_HINT_FORBID ); | ||||||||||||||||||||||||||||
| 2570 | }; | ||||||||||||||||||||||||||||
| 2571 | |||||||||||||||||||||||||||||
| 2572 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2573 | } | ||||||||||||||||||||||||||||
| 2574 | |||||||||||||||||||||||||||||
| 2575 | ## @method boolean forceSignature(Lasso::Profile profile) | ||||||||||||||||||||||||||||
| 2576 | # Modify Lasso signature hint to force signature | ||||||||||||||||||||||||||||
| 2577 | # @param profile Lasso profile object | ||||||||||||||||||||||||||||
| 2578 | # @return result | ||||||||||||||||||||||||||||
| 2579 | sub forceSignature { | ||||||||||||||||||||||||||||
| 2580 | my ( $self, $profile ) = @_; | ||||||||||||||||||||||||||||
| 2581 | |||||||||||||||||||||||||||||
| 2582 | eval { | ||||||||||||||||||||||||||||
| 2583 | Lasso::Profile::set_signature_hint( $profile, | ||||||||||||||||||||||||||||
| 2584 | Lasso::Constants::PROFILE_SIGNATURE_HINT_FORCE ); | ||||||||||||||||||||||||||||
| 2585 | }; | ||||||||||||||||||||||||||||
| 2586 | |||||||||||||||||||||||||||||
| 2587 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2588 | } | ||||||||||||||||||||||||||||
| 2589 | |||||||||||||||||||||||||||||
| 2590 | ## @method boolean disableSignatureVerification(Lasso::Profile profile) | ||||||||||||||||||||||||||||
| 2591 | # Modify Lasso signature hint to disable signature verification | ||||||||||||||||||||||||||||
| 2592 | # @param profile Lasso profile object | ||||||||||||||||||||||||||||
| 2593 | # @return result | ||||||||||||||||||||||||||||
| 2594 | sub disableSignatureVerification { | ||||||||||||||||||||||||||||
| 2595 | my ( $self, $profile ) = @_; | ||||||||||||||||||||||||||||
| 2596 | |||||||||||||||||||||||||||||
| 2597 | eval { | ||||||||||||||||||||||||||||
| 2598 | Lasso::Profile::set_signature_verify_hint( $profile, | ||||||||||||||||||||||||||||
| 2599 | Lasso::Constants::PROFILE_SIGNATURE_VERIFY_HINT_IGNORE ); | ||||||||||||||||||||||||||||
| 2600 | }; | ||||||||||||||||||||||||||||
| 2601 | |||||||||||||||||||||||||||||
| 2602 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2603 | } | ||||||||||||||||||||||||||||
| 2604 | |||||||||||||||||||||||||||||
| 2605 | ## @method boolean forceSignatureVerification(Lasso::Profile profile) | ||||||||||||||||||||||||||||
| 2606 | # Modify Lasso signature hint to force signature verification | ||||||||||||||||||||||||||||
| 2607 | # @param profile Lasso profile object | ||||||||||||||||||||||||||||
| 2608 | # @return result | ||||||||||||||||||||||||||||
| 2609 | sub forceSignatureVerification { | ||||||||||||||||||||||||||||
| 2610 | my ( $self, $profile ) = @_; | ||||||||||||||||||||||||||||
| 2611 | |||||||||||||||||||||||||||||
| 2612 | eval { | ||||||||||||||||||||||||||||
| 2613 | Lasso::Profile::set_signature_verify_hint( $profile, | ||||||||||||||||||||||||||||
| 2614 | Lasso::Constants::PROFILE_SIGNATURE_VERIFY_HINT_MAYBE ); | ||||||||||||||||||||||||||||
| 2615 | }; | ||||||||||||||||||||||||||||
| 2616 | |||||||||||||||||||||||||||||
| 2617 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 2618 | } | ||||||||||||||||||||||||||||
| 2619 | |||||||||||||||||||||||||||||
| 2620 | ## @method string getAuthnContext(string context) | ||||||||||||||||||||||||||||
| 2621 | # Convert configuration string into SAML2 AuthnContextClassRef string | ||||||||||||||||||||||||||||
| 2622 | # @param context configuration string | ||||||||||||||||||||||||||||
| 2623 | # @return SAML2 AuthnContextClassRef string | ||||||||||||||||||||||||||||
| 2624 | sub getAuthnContext { | ||||||||||||||||||||||||||||
| 2625 | my ( $self, $context ) = @_; | ||||||||||||||||||||||||||||
| 2626 | |||||||||||||||||||||||||||||
| 2627 | return Lasso::Constants::SAML2_AUTHN_CONTEXT_KERBEROS | ||||||||||||||||||||||||||||
| 2628 | if ( $context =~ /^kerberos$/i ); | ||||||||||||||||||||||||||||
| 2629 | return Lasso::Constants::SAML2_AUTHN_CONTEXT_PASSWORD_PROTECTED_TRANSPORT | ||||||||||||||||||||||||||||
| 2630 | if ( $context =~ /^password[-_ ]protected[-_ ]transport$/i ); | ||||||||||||||||||||||||||||
| 2631 | return Lasso::Constants::SAML2_AUTHN_CONTEXT_PASSWORD | ||||||||||||||||||||||||||||
| 2632 | if ( $context =~ /^password$/i ); | ||||||||||||||||||||||||||||
| 2633 | return Lasso::Constants::SAML2_AUTHN_CONTEXT_X509 | ||||||||||||||||||||||||||||
| 2634 | if ( $context =~ /^x509$/i ); | ||||||||||||||||||||||||||||
| 2635 | return Lasso::Constants::SAML2_AUTHN_CONTEXT_TLS_CLIENT | ||||||||||||||||||||||||||||
| 2636 | if ( $context =~ /^tls[-_ ]client$/i ); | ||||||||||||||||||||||||||||
| 2637 | return Lasso::Constants::SAML2_AUTHN_CONTEXT_UNSPECIFIED | ||||||||||||||||||||||||||||
| 2638 | if ( $context =~ /^unspecified$/i ); | ||||||||||||||||||||||||||||
| 2639 | |||||||||||||||||||||||||||||
| 2640 | return; | ||||||||||||||||||||||||||||
| 2641 | } | ||||||||||||||||||||||||||||
| 2642 | |||||||||||||||||||||||||||||
| 2643 | ## @method string timestamp2samldate(string timestamp) | ||||||||||||||||||||||||||||
| 2644 | # Convert timestamp into SAML2 date format | ||||||||||||||||||||||||||||
| 2645 | # @param timestamp UNIX timestamp | ||||||||||||||||||||||||||||
| 2646 | # @return SAML2 date | ||||||||||||||||||||||||||||
| 2647 | sub timestamp2samldate { | ||||||||||||||||||||||||||||
| 2648 | my ( $self, $timestamp ) = @_; | ||||||||||||||||||||||||||||
| 2649 | |||||||||||||||||||||||||||||
| 2650 | my @t = gmtime($timestamp); | ||||||||||||||||||||||||||||
| 2651 | my $samldate = strftime( "%Y-%m-%dT%TZ", @t ); | ||||||||||||||||||||||||||||
| 2652 | |||||||||||||||||||||||||||||
| 2653 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2654 | "Convert timestamp $timestamp in SAML2 date: $samldate"); | ||||||||||||||||||||||||||||
| 2655 | |||||||||||||||||||||||||||||
| 2656 | return $samldate; | ||||||||||||||||||||||||||||
| 2657 | } | ||||||||||||||||||||||||||||
| 2658 | |||||||||||||||||||||||||||||
| 2659 | ## @method string samldate2timestamp(string samldate) | ||||||||||||||||||||||||||||
| 2660 | # Convert SAML2 date format into timestamp | ||||||||||||||||||||||||||||
| 2661 | # @param samldate SAML2 date format | ||||||||||||||||||||||||||||
| 2662 | # @return UNIX timestamp | ||||||||||||||||||||||||||||
| 2663 | sub samldate2timestamp { | ||||||||||||||||||||||||||||
| 2664 | my ( $self, $samldate ) = @_; | ||||||||||||||||||||||||||||
| 2665 | |||||||||||||||||||||||||||||
| 2666 | my ( $year, $mon, $mday, $hour, $min, $sec, $msec, $ztime ) = ( $samldate =~ | ||||||||||||||||||||||||||||
| 2667 | /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z)?/ ); | ||||||||||||||||||||||||||||
| 2668 | |||||||||||||||||||||||||||||
| 2669 | my $timestamp = | ||||||||||||||||||||||||||||
| 2670 | timegm( $sec, $min, $hour, $mday, $mon - 1, $year - 1900, 0 ); | ||||||||||||||||||||||||||||
| 2671 | |||||||||||||||||||||||||||||
| 2672 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2673 | "Convert SAML2 date $samldate in timestamp: $timestamp"); | ||||||||||||||||||||||||||||
| 2674 | |||||||||||||||||||||||||||||
| 2675 | return $timestamp; | ||||||||||||||||||||||||||||
| 2676 | } | ||||||||||||||||||||||||||||
| 2677 | |||||||||||||||||||||||||||||
| 2678 | ## @pmethod int sendLogoutResponseToServiceProvider(Lasso::Logout $logout, int $method) | ||||||||||||||||||||||||||||
| 2679 | # Send logout response issue from a logout request. | ||||||||||||||||||||||||||||
| 2680 | # @param $logout Lasso Logout object | ||||||||||||||||||||||||||||
| 2681 | # @param $method Method to use | ||||||||||||||||||||||||||||
| 2682 | # @return boolean False if failed. | ||||||||||||||||||||||||||||
| 2683 | sub sendLogoutResponseToServiceProvider { | ||||||||||||||||||||||||||||
| 2684 | my ( $self, $req, $logout, $method ) = @_; | ||||||||||||||||||||||||||||
| 2685 | |||||||||||||||||||||||||||||
| 2686 | # Logout response | ||||||||||||||||||||||||||||
| 2687 | unless ( $self->buildLogoutResponseMsg($logout) ) { | ||||||||||||||||||||||||||||
| 2688 | $self->logger->warn( "Could not build a logout response for provider " | ||||||||||||||||||||||||||||
| 2689 | . $logout->remote_providerID | ||||||||||||||||||||||||||||
| 2690 | . ", staying on portal" ); | ||||||||||||||||||||||||||||
| 2691 | return $self->p->doPE( $req, PE_LOGOUT_OK ); | ||||||||||||||||||||||||||||
| 2692 | } | ||||||||||||||||||||||||||||
| 2693 | |||||||||||||||||||||||||||||
| 2694 | # Send response depending on request method | ||||||||||||||||||||||||||||
| 2695 | # HTTP-REDIRECT | ||||||||||||||||||||||||||||
| 2696 | if ( $method == Lasso::Constants::HTTP_METHOD_REDIRECT ) { | ||||||||||||||||||||||||||||
| 2697 | |||||||||||||||||||||||||||||
| 2698 | # Redirect user to response URL | ||||||||||||||||||||||||||||
| 2699 | my $slo_url = $logout->msg_url; | ||||||||||||||||||||||||||||
| 2700 | return [ 302, [ Location => URI->new($slo_url)->as_string ], [] ]; | ||||||||||||||||||||||||||||
| 2701 | } | ||||||||||||||||||||||||||||
| 2702 | |||||||||||||||||||||||||||||
| 2703 | # HTTP-POST | ||||||||||||||||||||||||||||
| 2704 | elsif ( $method == Lasso::Constants::HTTP_METHOD_POST ) { | ||||||||||||||||||||||||||||
| 2705 | |||||||||||||||||||||||||||||
| 2706 | # Use autosubmit form | ||||||||||||||||||||||||||||
| 2707 | my $slo_url = $logout->msg_url; | ||||||||||||||||||||||||||||
| 2708 | my $slo_body = $logout->msg_body; | ||||||||||||||||||||||||||||
| 2709 | my $relaystate = $logout->msg_relayState; | ||||||||||||||||||||||||||||
| 2710 | |||||||||||||||||||||||||||||
| 2711 | # TODO: insert postUrl in $req | ||||||||||||||||||||||||||||
| 2712 | $req->postUrl($slo_url); | ||||||||||||||||||||||||||||
| 2713 | $req->{postFields} = { 'SAMLResponse' => $slo_body }; | ||||||||||||||||||||||||||||
| 2714 | |||||||||||||||||||||||||||||
| 2715 | # RelayState | ||||||||||||||||||||||||||||
| 2716 | if ($relaystate) { | ||||||||||||||||||||||||||||
| 2717 | $req->{postFields}->{'RelayState'} = encode_entities($relaystate); | ||||||||||||||||||||||||||||
| 2718 | $req->data->{safeHiddenFormValues}->{RelayState} = 1; | ||||||||||||||||||||||||||||
| 2719 | } | ||||||||||||||||||||||||||||
| 2720 | |||||||||||||||||||||||||||||
| 2721 | return $self->p->do( $req, ['autoPost'] ); | ||||||||||||||||||||||||||||
| 2722 | } | ||||||||||||||||||||||||||||
| 2723 | elsif ( $method == Lasso::Constants::HTTP_METHOD_SOAP ) { | ||||||||||||||||||||||||||||
| 2724 | return $self->sendSLOSoapErrorResponse( $req, $logout, $method ); | ||||||||||||||||||||||||||||
| 2725 | } | ||||||||||||||||||||||||||||
| 2726 | return $self->p->sendError( $req, | ||||||||||||||||||||||||||||
| 2727 | "Lasso method '$method' should not be handle here...", 400 ); | ||||||||||||||||||||||||||||
| 2728 | } | ||||||||||||||||||||||||||||
| 2729 | |||||||||||||||||||||||||||||
| 2730 | ## @pmethod int sendLogoutRequestToProvider(Lasso::Logout $logout, string $providerID, int $method, boolean $relay, string $relayState) | ||||||||||||||||||||||||||||
| 2731 | # Send a logout request to a provider | ||||||||||||||||||||||||||||
| 2732 | # If information have to be displayed to users, such as iframe to send | ||||||||||||||||||||||||||||
| 2733 | # HTTP-Redirect or HTTP-POST logout request, then $self->{_info} will be | ||||||||||||||||||||||||||||
| 2734 | # updated. | ||||||||||||||||||||||||||||
| 2735 | # @param $logout Lasso Logout object | ||||||||||||||||||||||||||||
| 2736 | # @param $providerID The concerned service provider | ||||||||||||||||||||||||||||
| 2737 | # @param $method The method used to send the logout request | ||||||||||||||||||||||||||||
| 2738 | # @param $relay If SOAP method, build a relay logout request | ||||||||||||||||||||||||||||
| 2739 | # @param $relayState Relay State for SLO status | ||||||||||||||||||||||||||||
| 2740 | # @return int Number of concerned providers. | ||||||||||||||||||||||||||||
| 2741 | sub sendLogoutRequestToProvider { | ||||||||||||||||||||||||||||
| 2742 | my ( $self, $req, $logout, $providerID, $method, $relay, $relayState ) = @_; | ||||||||||||||||||||||||||||
| 2743 | my $server = $self->lassoServer; | ||||||||||||||||||||||||||||
| 2744 | my $info; | ||||||||||||||||||||||||||||
| 2745 | |||||||||||||||||||||||||||||
| 2746 | # Test if provider is mentionned | ||||||||||||||||||||||||||||
| 2747 | if ( !$providerID ) { | ||||||||||||||||||||||||||||
| 2748 | return ( 0, undef, undef ); | ||||||||||||||||||||||||||||
| 2749 | } | ||||||||||||||||||||||||||||
| 2750 | |||||||||||||||||||||||||||||
| 2751 | # Lazy load provider | ||||||||||||||||||||||||||||
| 2752 | $self->lazy_load_entityid($providerID); | ||||||||||||||||||||||||||||
| 2753 | |||||||||||||||||||||||||||||
| 2754 | my $type = defined $self->spList->{$providerID} ? "SP" : "IDP"; | ||||||||||||||||||||||||||||
| 2755 | |||||||||||||||||||||||||||||
| 2756 | # Find EntityID in spList or idpList | ||||||||||||||||||||||||||||
| 2757 | unless ( defined $self->{ lc($type) . 'List' }->{$providerID} ) { | ||||||||||||||||||||||||||||
| 2758 | $self->logger->error("$providerID does not match any known $type"); | ||||||||||||||||||||||||||||
| 2759 | return ( 0, undef, undef ); | ||||||||||||||||||||||||||||
| 2760 | } | ||||||||||||||||||||||||||||
| 2761 | |||||||||||||||||||||||||||||
| 2762 | # Get Provider Name and Conf Key from EntityID | ||||||||||||||||||||||||||||
| 2763 | my $providerName = | ||||||||||||||||||||||||||||
| 2764 | $self->{ lc($type) . 'List' }->{$providerID}->{name}; | ||||||||||||||||||||||||||||
| 2765 | my $confKey = | ||||||||||||||||||||||||||||
| 2766 | $self->{ lc($type) . 'List' }->{$providerID}->{confKey}; | ||||||||||||||||||||||||||||
| 2767 | |||||||||||||||||||||||||||||
| 2768 | # Get first HTTP method | ||||||||||||||||||||||||||||
| 2769 | my $protocolType = Lasso::Constants::MD_PROTOCOL_TYPE_SINGLE_LOGOUT; | ||||||||||||||||||||||||||||
| 2770 | if ( !$method ) { | ||||||||||||||||||||||||||||
| 2771 | $method = | ||||||||||||||||||||||||||||
| 2772 | $self->getFirstHttpMethod( $server, $providerID, $protocolType ); | ||||||||||||||||||||||||||||
| 2773 | } | ||||||||||||||||||||||||||||
| 2774 | |||||||||||||||||||||||||||||
| 2775 | # Fix a default value for the relay parameter | ||||||||||||||||||||||||||||
| 2776 | $relay = 0 unless ( defined $relay ); | ||||||||||||||||||||||||||||
| 2777 | |||||||||||||||||||||||||||||
| 2778 | # Signature | ||||||||||||||||||||||||||||
| 2779 | my $signSLOMessage = | ||||||||||||||||||||||||||||
| 2780 | $self->{ lc($type) . 'Options' }->{$providerID} | ||||||||||||||||||||||||||||
| 2781 | ->{ 'saml' . $type . 'MetaDataOptionsSignSLOMessage' } // -1; | ||||||||||||||||||||||||||||
| 2782 | |||||||||||||||||||||||||||||
| 2783 | if ( $signSLOMessage == 0 ) { | ||||||||||||||||||||||||||||
| 2784 | $self->logger->debug("SLO request will not be signed"); | ||||||||||||||||||||||||||||
| 2785 | $self->disableSignature($logout); | ||||||||||||||||||||||||||||
| 2786 | } | ||||||||||||||||||||||||||||
| 2787 | elsif ( $signSLOMessage == 1 ) { | ||||||||||||||||||||||||||||
| 2788 | $self->logger->debug("SLO request will be signed"); | ||||||||||||||||||||||||||||
| 2789 | $self->forceSignature($logout); | ||||||||||||||||||||||||||||
| 2790 | } | ||||||||||||||||||||||||||||
| 2791 | else { | ||||||||||||||||||||||||||||
| 2792 | $self->logger->debug("SLO request signature according to metadata"); | ||||||||||||||||||||||||||||
| 2793 | } | ||||||||||||||||||||||||||||
| 2794 | |||||||||||||||||||||||||||||
| 2795 | # Relay State | ||||||||||||||||||||||||||||
| 2796 | if ($relayState) { | ||||||||||||||||||||||||||||
| 2797 | eval { $logout->msg_relayState($relayState); }; | ||||||||||||||||||||||||||||
| 2798 | if ($@) { | ||||||||||||||||||||||||||||
| 2799 | $self->logger->error( | ||||||||||||||||||||||||||||
| 2800 | "Unable to set Relay State $relayState in SLO request for $confKey" | ||||||||||||||||||||||||||||
| 2801 | ); | ||||||||||||||||||||||||||||
| 2802 | return ( 0, $method, undef ); | ||||||||||||||||||||||||||||
| 2803 | } | ||||||||||||||||||||||||||||
| 2804 | $self->logger->debug('Relay state set'); | ||||||||||||||||||||||||||||
| 2805 | } | ||||||||||||||||||||||||||||
| 2806 | |||||||||||||||||||||||||||||
| 2807 | # Skip SLO if no method found (#2746) | ||||||||||||||||||||||||||||
| 2808 | unless ( defined $method and $method != -1 ) { | ||||||||||||||||||||||||||||
| 2809 | $self->logger->debug("No HTTP SLO method found for $providerID"); | ||||||||||||||||||||||||||||
| 2810 | return ( 0, $method, undef ); | ||||||||||||||||||||||||||||
| 2811 | } | ||||||||||||||||||||||||||||
| 2812 | |||||||||||||||||||||||||||||
| 2813 | # Initiate the logout request | ||||||||||||||||||||||||||||
| 2814 | unless ( $self->initLogoutRequest( $logout, $providerID, $method ) ) { | ||||||||||||||||||||||||||||
| 2815 | $self->logger->error("Initiate logout request failed for $providerID"); | ||||||||||||||||||||||||||||
| 2816 | return ( 0, $method, undef ); | ||||||||||||||||||||||||||||
| 2817 | } | ||||||||||||||||||||||||||||
| 2818 | |||||||||||||||||||||||||||||
| 2819 | # Build request message | ||||||||||||||||||||||||||||
| 2820 | unless ( $self->buildLogoutRequestMsg($logout) ) { | ||||||||||||||||||||||||||||
| 2821 | $self->logger->error("Build logout request failed for $providerID"); | ||||||||||||||||||||||||||||
| 2822 | return ( 0, $method, undef ); | ||||||||||||||||||||||||||||
| 2823 | } | ||||||||||||||||||||||||||||
| 2824 | |||||||||||||||||||||||||||||
| 2825 | $self->logger->debug("Request built for $providerID"); | ||||||||||||||||||||||||||||
| 2826 | |||||||||||||||||||||||||||||
| 2827 | # Keep message ID in memory to prevent replay | ||||||||||||||||||||||||||||
| 2828 | my $samlID = $logout->request()->ID; | ||||||||||||||||||||||||||||
| 2829 | unless ( $self->storeReplayProtection($samlID) ) { | ||||||||||||||||||||||||||||
| 2830 | $self->logger->error("Unable to store message ID"); | ||||||||||||||||||||||||||||
| 2831 | return ( 0, $method, undef ); | ||||||||||||||||||||||||||||
| 2832 | } | ||||||||||||||||||||||||||||
| 2833 | |||||||||||||||||||||||||||||
| 2834 | # Get portal value | ||||||||||||||||||||||||||||
| 2835 | my $portal = $self->p->buildUrl; | ||||||||||||||||||||||||||||
| 2836 | $portal =~ s/\/$//; | ||||||||||||||||||||||||||||
| 2837 | |||||||||||||||||||||||||||||
| 2838 | # Send logout request to the provider depending of the request method | ||||||||||||||||||||||||||||
| 2839 | # HTTP-REDIRECT | ||||||||||||||||||||||||||||
| 2840 | if ( $method == Lasso::Constants::HTTP_METHOD_REDIRECT ) { | ||||||||||||||||||||||||||||
| 2841 | |||||||||||||||||||||||||||||
| 2842 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2843 | "Send HTTP-REDIRECT logout request to $providerID"); | ||||||||||||||||||||||||||||
| 2844 | |||||||||||||||||||||||||||||
| 2845 | # Redirect user to response URL | ||||||||||||||||||||||||||||
| 2846 | my $slo_url = $logout->msg_url; | ||||||||||||||||||||||||||||
| 2847 | |||||||||||||||||||||||||||||
| 2848 | # Create iFrame | ||||||||||||||||||||||||||||
| 2849 | $info .= $self->loadTemplate( | ||||||||||||||||||||||||||||
| 2850 | $req, | ||||||||||||||||||||||||||||
| 2851 | 'samlSpLogout', | ||||||||||||||||||||||||||||
| 2852 | params => { | ||||||||||||||||||||||||||||
| 2853 | url => $slo_url, | ||||||||||||||||||||||||||||
| 2854 | name => $providerName, | ||||||||||||||||||||||||||||
| 2855 | } | ||||||||||||||||||||||||||||
| 2856 | ); | ||||||||||||||||||||||||||||
| 2857 | } | ||||||||||||||||||||||||||||
| 2858 | |||||||||||||||||||||||||||||
| 2859 | # HTTP-POST | ||||||||||||||||||||||||||||
| 2860 | elsif ( $method == Lasso::Constants::HTTP_METHOD_POST ) { | ||||||||||||||||||||||||||||
| 2861 | |||||||||||||||||||||||||||||
| 2862 | $self->logger->debug("Build POST relay logout request to $providerID"); | ||||||||||||||||||||||||||||
| 2863 | |||||||||||||||||||||||||||||
| 2864 | my $infos; | ||||||||||||||||||||||||||||
| 2865 | |||||||||||||||||||||||||||||
| 2866 | # Store infos | ||||||||||||||||||||||||||||
| 2867 | $infos->{type} = 'relay'; | ||||||||||||||||||||||||||||
| 2868 | $infos->{_utime} = time; | ||||||||||||||||||||||||||||
| 2869 | $infos->{url} = $logout->msg_url; | ||||||||||||||||||||||||||||
| 2870 | $infos->{body} = $logout->msg_body; | ||||||||||||||||||||||||||||
| 2871 | $infos->{relayState} = $logout->msg_relayState; | ||||||||||||||||||||||||||||
| 2872 | |||||||||||||||||||||||||||||
| 2873 | # Create a new relay session | ||||||||||||||||||||||||||||
| 2874 | my $relayInfos = $self->getSamlSession( undef, $infos ); | ||||||||||||||||||||||||||||
| 2875 | |||||||||||||||||||||||||||||
| 2876 | my $relayID = $relayInfos->id; | ||||||||||||||||||||||||||||
| 2877 | |||||||||||||||||||||||||||||
| 2878 | # Build the URL that could be used to play this logout request | ||||||||||||||||||||||||||||
| 2879 | my $slo_url = | ||||||||||||||||||||||||||||
| 2880 | $portal | ||||||||||||||||||||||||||||
| 2881 | . '/saml/relaySingleLogoutPOST?' | ||||||||||||||||||||||||||||
| 2882 | . build_urlencoded( relay => $relayID ); | ||||||||||||||||||||||||||||
| 2883 | |||||||||||||||||||||||||||||
| 2884 | # Create iFrame | ||||||||||||||||||||||||||||
| 2885 | $info .= $self->loadTemplate( | ||||||||||||||||||||||||||||
| 2886 | $req, | ||||||||||||||||||||||||||||
| 2887 | 'samlSpLogout', | ||||||||||||||||||||||||||||
| 2888 | params => { | ||||||||||||||||||||||||||||
| 2889 | url => $slo_url, | ||||||||||||||||||||||||||||
| 2890 | name => $providerName, | ||||||||||||||||||||||||||||
| 2891 | } | ||||||||||||||||||||||||||||
| 2892 | ); | ||||||||||||||||||||||||||||
| 2893 | $req->data->{cspChildSrc}->{ $self->p->cspGetHost( $logout->msg_url ) } | ||||||||||||||||||||||||||||
| 2894 | = 1; | ||||||||||||||||||||||||||||
| 2895 | } | ||||||||||||||||||||||||||||
| 2896 | |||||||||||||||||||||||||||||
| 2897 | # HTTP-SOAP | ||||||||||||||||||||||||||||
| 2898 | elsif ( $method == Lasso::Constants::HTTP_METHOD_SOAP ) { | ||||||||||||||||||||||||||||
| 2899 | |||||||||||||||||||||||||||||
| 2900 | # Build a relay request, to be used after SLO process is done | ||||||||||||||||||||||||||||
| 2901 | if ($relay) { | ||||||||||||||||||||||||||||
| 2902 | |||||||||||||||||||||||||||||
| 2903 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2904 | "Build SOAP relay logout request for $providerID"); | ||||||||||||||||||||||||||||
| 2905 | |||||||||||||||||||||||||||||
| 2906 | my $infos; | ||||||||||||||||||||||||||||
| 2907 | $infos->{type} = 'relay'; | ||||||||||||||||||||||||||||
| 2908 | $infos->{_utime} = time; | ||||||||||||||||||||||||||||
| 2909 | $infos->{ $self->lsDump } = $req->sessionInfo->{ $self->lsDump }; | ||||||||||||||||||||||||||||
| 2910 | $infos->{ $self->liDump } = $req->sessionInfo->{ $self->liDump }; | ||||||||||||||||||||||||||||
| 2911 | $infos->{_providerID} = $providerID; | ||||||||||||||||||||||||||||
| 2912 | $infos->{_relayState} = $logout->msg_relayState; | ||||||||||||||||||||||||||||
| 2913 | |||||||||||||||||||||||||||||
| 2914 | # Create a new relay session | ||||||||||||||||||||||||||||
| 2915 | my $relayInfos = $self->getSamlSession( undef, $infos ); | ||||||||||||||||||||||||||||
| 2916 | |||||||||||||||||||||||||||||
| 2917 | my $relayID = $relayInfos->id; | ||||||||||||||||||||||||||||
| 2918 | |||||||||||||||||||||||||||||
| 2919 | # Build the URL that could be used to play this logout request | ||||||||||||||||||||||||||||
| 2920 | my $slo_url = | ||||||||||||||||||||||||||||
| 2921 | $portal | ||||||||||||||||||||||||||||
| 2922 | . '/saml/relaySingleLogoutSOAP?' | ||||||||||||||||||||||||||||
| 2923 | . build_urlencoded( relay => $relayID ); | ||||||||||||||||||||||||||||
| 2924 | |||||||||||||||||||||||||||||
| 2925 | # Display information to the user | ||||||||||||||||||||||||||||
| 2926 | $info .= $self->loadTemplate( | ||||||||||||||||||||||||||||
| 2927 | $req, | ||||||||||||||||||||||||||||
| 2928 | 'samlSpSoapLogout', | ||||||||||||||||||||||||||||
| 2929 | params => { | ||||||||||||||||||||||||||||
| 2930 | imgUrl => $slo_url, | ||||||||||||||||||||||||||||
| 2931 | name => $providerName, | ||||||||||||||||||||||||||||
| 2932 | } | ||||||||||||||||||||||||||||
| 2933 | ); | ||||||||||||||||||||||||||||
| 2934 | } | ||||||||||||||||||||||||||||
| 2935 | |||||||||||||||||||||||||||||
| 2936 | # Send the request directly | ||||||||||||||||||||||||||||
| 2937 | else { | ||||||||||||||||||||||||||||
| 2938 | |||||||||||||||||||||||||||||
| 2939 | $self->logger->debug("Send SOAP logout request to $providerID"); | ||||||||||||||||||||||||||||
| 2940 | |||||||||||||||||||||||||||||
| 2941 | my $slo_url = $logout->msg_url; | ||||||||||||||||||||||||||||
| 2942 | my $slo_body = $logout->msg_body; | ||||||||||||||||||||||||||||
| 2943 | |||||||||||||||||||||||||||||
| 2944 | # Send SOAP request and manage response | ||||||||||||||||||||||||||||
| 2945 | my $sp_response = $self->sendSOAPMessage( $slo_url, $slo_body ); | ||||||||||||||||||||||||||||
| 2946 | |||||||||||||||||||||||||||||
| 2947 | unless ($sp_response) { | ||||||||||||||||||||||||||||
| 2948 | $self->logger->error("No logout response to SOAP request"); | ||||||||||||||||||||||||||||
| 2949 | return ( 0, $method, undef ); | ||||||||||||||||||||||||||||
| 2950 | } | ||||||||||||||||||||||||||||
| 2951 | |||||||||||||||||||||||||||||
| 2952 | # Process logout response | ||||||||||||||||||||||||||||
| 2953 | my $sp_result = | ||||||||||||||||||||||||||||
| 2954 | $self->processLogoutResponseMsg( $logout, $sp_response ); | ||||||||||||||||||||||||||||
| 2955 | |||||||||||||||||||||||||||||
| 2956 | unless ($sp_result) { | ||||||||||||||||||||||||||||
| 2957 | $self->logger->error("Fail to process logout response"); | ||||||||||||||||||||||||||||
| 2958 | return ( 0, $method, undef ); | ||||||||||||||||||||||||||||
| 2959 | } | ||||||||||||||||||||||||||||
| 2960 | |||||||||||||||||||||||||||||
| 2961 | if ($relayState) { | ||||||||||||||||||||||||||||
| 2962 | |||||||||||||||||||||||||||||
| 2963 | # Store success status for this SLO request | ||||||||||||||||||||||||||||
| 2964 | my $sloStatusSessionInfos = $self->getSamlSession($relayState); | ||||||||||||||||||||||||||||
| 2965 | |||||||||||||||||||||||||||||
| 2966 | if ($sloStatusSessionInfos) { | ||||||||||||||||||||||||||||
| 2967 | $sloStatusSessionInfos->update( { $confKey => 1 } ); | ||||||||||||||||||||||||||||
| 2968 | $self->logger->debug( | ||||||||||||||||||||||||||||
| 2969 | "Store SLO status for $confKey in session $relayState"); | ||||||||||||||||||||||||||||
| 2970 | } | ||||||||||||||||||||||||||||
| 2971 | else { | ||||||||||||||||||||||||||||
| 2972 | $self->logger->warn( | ||||||||||||||||||||||||||||
| 2973 | "Unable to store SLO status for $confKey in session $relayState" | ||||||||||||||||||||||||||||
| 2974 | ); | ||||||||||||||||||||||||||||
| 2975 | } | ||||||||||||||||||||||||||||
| 2976 | } | ||||||||||||||||||||||||||||
| 2977 | |||||||||||||||||||||||||||||
| 2978 | $self->logger->debug("Logout response is valid"); | ||||||||||||||||||||||||||||
| 2979 | |||||||||||||||||||||||||||||
| 2980 | } | ||||||||||||||||||||||||||||
| 2981 | |||||||||||||||||||||||||||||
| 2982 | } | ||||||||||||||||||||||||||||
| 2983 | |||||||||||||||||||||||||||||
| 2984 | return ( 1, $method, $info ); | ||||||||||||||||||||||||||||
| 2985 | |||||||||||||||||||||||||||||
| 2986 | } | ||||||||||||||||||||||||||||
| 2987 | |||||||||||||||||||||||||||||
| 2988 | ## @pmethod int sendLogoutRequestToProviders(Lasso::Logout logout, string relayState ) | ||||||||||||||||||||||||||||
| 2989 | # Send logout response issue from a logout request to all other | ||||||||||||||||||||||||||||
| 2990 | # providers. If information have to be displayed to users, such as | ||||||||||||||||||||||||||||
| 2991 | # iframe to send HTTP-Redirect or HTTP-POST logout request, then | ||||||||||||||||||||||||||||
| 2992 | # $self->{_info} will be updated. | ||||||||||||||||||||||||||||
| 2993 | # @param logout Lasso Logout object | ||||||||||||||||||||||||||||
| 2994 | # @param relayState Relay State for SLO status | ||||||||||||||||||||||||||||
| 2995 | # @return int Number of concerned providers. | ||||||||||||||||||||||||||||
| 2996 | sub sendLogoutRequestToProviders { | ||||||||||||||||||||||||||||
| 2997 | my ( $self, $req, $logout, $relayState ) = @_; | ||||||||||||||||||||||||||||
| 2998 | my $server = $self->lassoServer; | ||||||||||||||||||||||||||||
| 2999 | my $providersCount = 0; | ||||||||||||||||||||||||||||
| 3000 | my $content = ''; | ||||||||||||||||||||||||||||
| 3001 | |||||||||||||||||||||||||||||
| 3002 | # Reset providerID into Lasso::Logout object | ||||||||||||||||||||||||||||
| 3003 | $self->resetProviderIdIndex($logout); | ||||||||||||||||||||||||||||
| 3004 | |||||||||||||||||||||||||||||
| 3005 | # Foreach SP found in session, get it from configuration, and send the | ||||||||||||||||||||||||||||
| 3006 | # appropriate logout request (HTTP,POST,SOAP). | ||||||||||||||||||||||||||||
| 3007 | while ( my $providerID = $self->getNextProviderId($logout) ) { | ||||||||||||||||||||||||||||
| 3008 | |||||||||||||||||||||||||||||
| 3009 | # Send logout request | ||||||||||||||||||||||||||||
| 3010 | my ( $rstatus, $rmethod, $rinfo ) = | ||||||||||||||||||||||||||||
| 3011 | $self->sendLogoutRequestToProvider( $req, $logout, $providerID, | ||||||||||||||||||||||||||||
| 3012 | undef, 1, $relayState ); | ||||||||||||||||||||||||||||
| 3013 | |||||||||||||||||||||||||||||
| 3014 | next unless ($rstatus); | ||||||||||||||||||||||||||||
| 3015 | |||||||||||||||||||||||||||||
| 3016 | # Count providers that have to be request by HTTP redirect | ||||||||||||||||||||||||||||
| 3017 | $providersCount++; | ||||||||||||||||||||||||||||
| 3018 | |||||||||||||||||||||||||||||
| 3019 | # Add information if necessary | ||||||||||||||||||||||||||||
| 3020 | if ($rinfo) { | ||||||||||||||||||||||||||||
| 3021 | $content .= $rinfo; | ||||||||||||||||||||||||||||
| 3022 | } | ||||||||||||||||||||||||||||
| 3023 | |||||||||||||||||||||||||||||
| 3024 | } | ||||||||||||||||||||||||||||
| 3025 | |||||||||||||||||||||||||||||
| 3026 | # Print some information to the user. | ||||||||||||||||||||||||||||
| 3027 | $req->info( | ||||||||||||||||||||||||||||
| 3028 | $self->loadTemplate( | ||||||||||||||||||||||||||||
| 3029 | $req, 'samlSpsLogout', params => { content => $content } | ||||||||||||||||||||||||||||
| 3030 | ) | ||||||||||||||||||||||||||||
| 3031 | ) if $providersCount; | ||||||||||||||||||||||||||||
| 3032 | |||||||||||||||||||||||||||||
| 3033 | return $providersCount; | ||||||||||||||||||||||||||||
| 3034 | } | ||||||||||||||||||||||||||||
| 3035 | |||||||||||||||||||||||||||||
| 3036 | ## @method boolean checkSignatureStatus(Lasso::Profile profile) | ||||||||||||||||||||||||||||
| 3037 | # Check signature status | ||||||||||||||||||||||||||||
| 3038 | # @param profile Lasso::Profile object | ||||||||||||||||||||||||||||
| 3039 | # @return result | ||||||||||||||||||||||||||||
| 3040 | sub checkSignatureStatus { | ||||||||||||||||||||||||||||
| 3041 | my ( $self, $profile ) = @_; | ||||||||||||||||||||||||||||
| 3042 | |||||||||||||||||||||||||||||
| 3043 | eval { Lasso::Profile::get_signature_status($profile); }; | ||||||||||||||||||||||||||||
| 3044 | |||||||||||||||||||||||||||||
| 3045 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 3046 | } | ||||||||||||||||||||||||||||
| 3047 | |||||||||||||||||||||||||||||
| 3048 | ## @method int authnContext2authnLevel(string authnContext) | ||||||||||||||||||||||||||||
| 3049 | # Return authentication level corresponding to authnContext | ||||||||||||||||||||||||||||
| 3050 | # @param authnContext SAML authentication context | ||||||||||||||||||||||||||||
| 3051 | # return authentication level | ||||||||||||||||||||||||||||
| 3052 | sub authnContext2authnLevel { | ||||||||||||||||||||||||||||
| 3053 | my ( $self, $authnContext ) = @_; | ||||||||||||||||||||||||||||
| 3054 | |||||||||||||||||||||||||||||
| 3055 | # Standard contexts | ||||||||||||||||||||||||||||
| 3056 | return $self->conf->{samlAuthnContextMapPassword} | ||||||||||||||||||||||||||||
| 3057 | if ( $authnContext eq $self->getAuthnContext("password") ); | ||||||||||||||||||||||||||||
| 3058 | return $self->conf->{samlAuthnContextMapPasswordProtectedTransport} | ||||||||||||||||||||||||||||
| 3059 | if ( | ||||||||||||||||||||||||||||
| 3060 | $authnContext eq $self->getAuthnContext("password-protected-transport") | ||||||||||||||||||||||||||||
| 3061 | ); | ||||||||||||||||||||||||||||
| 3062 | return $self->conf->{samlAuthnContextMapKerberos} | ||||||||||||||||||||||||||||
| 3063 | if ( $authnContext eq $self->getAuthnContext("kerberos") ); | ||||||||||||||||||||||||||||
| 3064 | return $self->conf->{samlAuthnContextMapTLSClient} | ||||||||||||||||||||||||||||
| 3065 | if ( $authnContext eq $self->getAuthnContext("tls-client") ); | ||||||||||||||||||||||||||||
| 3066 | |||||||||||||||||||||||||||||
| 3067 | # Extras contexts | ||||||||||||||||||||||||||||
| 3068 | if ( defined $self->conf->{samlAuthnContextMapExtra} | ||||||||||||||||||||||||||||
| 3069 | and defined $self->conf->{samlAuthnContextMapExtra}->{$authnContext} ) | ||||||||||||||||||||||||||||
| 3070 | { | ||||||||||||||||||||||||||||
| 3071 | return $self->conf->{samlAuthnContextMapExtra}->{$authnContext}; | ||||||||||||||||||||||||||||
| 3072 | } | ||||||||||||||||||||||||||||
| 3073 | |||||||||||||||||||||||||||||
| 3074 | return 0; | ||||||||||||||||||||||||||||
| 3075 | } | ||||||||||||||||||||||||||||
| 3076 | |||||||||||||||||||||||||||||
| 3077 | ## @method int authnLevel2authnContext(int authnLevel) | ||||||||||||||||||||||||||||
| 3078 | # Return SAML authentication context corresponding to authnLevel | ||||||||||||||||||||||||||||
| 3079 | # @param authnLevel internal authentication level | ||||||||||||||||||||||||||||
| 3080 | # return SAML authentication context | ||||||||||||||||||||||||||||
| 3081 | sub authnLevel2authnContext { | ||||||||||||||||||||||||||||
| 3082 | my ( $self, $authnLevel ) = @_; | ||||||||||||||||||||||||||||
| 3083 | |||||||||||||||||||||||||||||
| 3084 | # Standard contexts | ||||||||||||||||||||||||||||
| 3085 | return $self->getAuthnContext("password") | ||||||||||||||||||||||||||||
| 3086 | if ( $authnLevel == $self->conf->{samlAuthnContextMapPassword} ); | ||||||||||||||||||||||||||||
| 3087 | return $self->getAuthnContext("password-protected-transport") | ||||||||||||||||||||||||||||
| 3088 | if ( $authnLevel == | ||||||||||||||||||||||||||||
| 3089 | $self->conf->{samlAuthnContextMapPasswordProtectedTransport} ); | ||||||||||||||||||||||||||||
| 3090 | return $self->getAuthnContext("kerberos") | ||||||||||||||||||||||||||||
| 3091 | if ( $authnLevel == $self->conf->{samlAuthnContextMapKerberos} ); | ||||||||||||||||||||||||||||
| 3092 | return $self->getAuthnContext("tls-client") | ||||||||||||||||||||||||||||
| 3093 | if ( $authnLevel == $self->conf->{samlAuthnContextMapTLSClient} ); | ||||||||||||||||||||||||||||
| 3094 | |||||||||||||||||||||||||||||
| 3095 | # Extras contexts | ||||||||||||||||||||||||||||
| 3096 | if ( defined $self->conf->{samlAuthnContextMapExtra} ) { | ||||||||||||||||||||||||||||
| 3097 | foreach | ||||||||||||||||||||||||||||
| 3098 | my $authnContext ( keys %{ $self->conf->{samlAuthnContextMapExtra} } ) | ||||||||||||||||||||||||||||
| 3099 | { | ||||||||||||||||||||||||||||
| 3100 | return $authnContext | ||||||||||||||||||||||||||||
| 3101 | if ( $authnLevel == | ||||||||||||||||||||||||||||
| 3102 | $self->conf->{samlAuthnContextMapExtra}->{$authnContext} ); | ||||||||||||||||||||||||||||
| 3103 | } | ||||||||||||||||||||||||||||
| 3104 | } | ||||||||||||||||||||||||||||
| 3105 | |||||||||||||||||||||||||||||
| 3106 | return $self->getAuthnContext("unspecified"); | ||||||||||||||||||||||||||||
| 3107 | } | ||||||||||||||||||||||||||||
| 3108 | |||||||||||||||||||||||||||||
| 3109 | ## @method boolean checkDestination(Lasso::Node message, string url) | ||||||||||||||||||||||||||||
| 3110 | # If SAML Destination attribute is present, check it | ||||||||||||||||||||||||||||
| 3111 | # @param message SAML request or response | ||||||||||||||||||||||||||||
| 3112 | # @param url Requested URL | ||||||||||||||||||||||||||||
| 3113 | # @return Result | ||||||||||||||||||||||||||||
| 3114 | sub checkDestination { | ||||||||||||||||||||||||||||
| 3115 | my ( $self, $message, $url ) = @_; | ||||||||||||||||||||||||||||
| 3116 | my $destination; | ||||||||||||||||||||||||||||
| 3117 | |||||||||||||||||||||||||||||
| 3118 | # Read Destination | ||||||||||||||||||||||||||||
| 3119 | eval { $destination = $message->Destination(); }; | ||||||||||||||||||||||||||||
| 3120 | |||||||||||||||||||||||||||||
| 3121 | # Ok if no Destination | ||||||||||||||||||||||||||||
| 3122 | if ( $@ or !$destination ) { | ||||||||||||||||||||||||||||
| 3123 | $self->logger->debug("No Destination in SAML message"); | ||||||||||||||||||||||||||||
| 3124 | return 1; | ||||||||||||||||||||||||||||
| 3125 | } | ||||||||||||||||||||||||||||
| 3126 | |||||||||||||||||||||||||||||
| 3127 | $self->logger->debug("Destination $destination found in SAML message"); | ||||||||||||||||||||||||||||
| 3128 | |||||||||||||||||||||||||||||
| 3129 | # Retrieve full URL | ||||||||||||||||||||||||||||
| 3130 | my $portal = $self->p->buildUrl; | ||||||||||||||||||||||||||||
| 3131 | $portal =~ s#^(https?://[^/]+)/.*#$1#; # remove path of portal URL | ||||||||||||||||||||||||||||
| 3132 | $url = $portal . $url; | ||||||||||||||||||||||||||||
| 3133 | $url =~ s/\?.*//; | ||||||||||||||||||||||||||||
| 3134 | |||||||||||||||||||||||||||||
| 3135 | # Compare Destination and URL | ||||||||||||||||||||||||||||
| 3136 | if ( $destination eq $url ) { | ||||||||||||||||||||||||||||
| 3137 | $self->logger->debug("Destination match URL $url"); | ||||||||||||||||||||||||||||
| 3138 | return 1; | ||||||||||||||||||||||||||||
| 3139 | } | ||||||||||||||||||||||||||||
| 3140 | |||||||||||||||||||||||||||||
| 3141 | $self->logger->error("Destination does not match URL $url"); | ||||||||||||||||||||||||||||
| 3142 | return 0; | ||||||||||||||||||||||||||||
| 3143 | } | ||||||||||||||||||||||||||||
| 3144 | |||||||||||||||||||||||||||||
| 3145 | ## @method hashref getSamlSession(string id) | ||||||||||||||||||||||||||||
| 3146 | # Try to recover the SAML session corresponding to id and return session | ||||||||||||||||||||||||||||
| 3147 | # If id is set to undef, return a new session | ||||||||||||||||||||||||||||
| 3148 | # @param id session reference | ||||||||||||||||||||||||||||
| 3149 | # @return Lemonldap::NG::Common::Session object | ||||||||||||||||||||||||||||
| 3150 | sub getSamlSession { | ||||||||||||||||||||||||||||
| 3151 | my ( $self, $id, $info ) = @_; | ||||||||||||||||||||||||||||
| 3152 | |||||||||||||||||||||||||||||
| 3153 | my $samlSession = Lemonldap::NG::Common::Session->new( { | ||||||||||||||||||||||||||||
| 3154 | storageModule => $self->aModule, | ||||||||||||||||||||||||||||
| 3155 | storageModuleOptions => $self->amOpts, | ||||||||||||||||||||||||||||
| 3156 | cacheModule => $self->conf->{localSessionStorage}, | ||||||||||||||||||||||||||||
| 3157 | cacheModuleOptions => $self->conf->{localSessionStorageOptions}, | ||||||||||||||||||||||||||||
| 3158 | id => $id, | ||||||||||||||||||||||||||||
| 3159 | kind => $self->sessionKind, | ||||||||||||||||||||||||||||
| 3160 | ( $info ? ( info => $info ) : () ), | ||||||||||||||||||||||||||||
| 3161 | } | ||||||||||||||||||||||||||||
| 3162 | ); | ||||||||||||||||||||||||||||
| 3163 | |||||||||||||||||||||||||||||
| 3164 | if ( $samlSession->error ) { | ||||||||||||||||||||||||||||
| 3165 | if ($id) { | ||||||||||||||||||||||||||||
| 3166 | $self->userLogger->warn("SAML session $id isn't yet available"); | ||||||||||||||||||||||||||||
| 3167 | } | ||||||||||||||||||||||||||||
| 3168 | else { | ||||||||||||||||||||||||||||
| 3169 | $self->logger->error("Unable to create new SAML session"); | ||||||||||||||||||||||||||||
| 3170 | $self->logger->error( $samlSession->error ); | ||||||||||||||||||||||||||||
| 3171 | } | ||||||||||||||||||||||||||||
| 3172 | return undef; | ||||||||||||||||||||||||||||
| 3173 | } | ||||||||||||||||||||||||||||
| 3174 | |||||||||||||||||||||||||||||
| 3175 | return $samlSession; | ||||||||||||||||||||||||||||
| 3176 | } | ||||||||||||||||||||||||||||
| 3177 | |||||||||||||||||||||||||||||
| 3178 | ## @method Lasso::Saml2Attribute createAttribute(string name, string format, string friendly_name) | ||||||||||||||||||||||||||||
| 3179 | # Create a new SAML attribute | ||||||||||||||||||||||||||||
| 3180 | # @param name Attribute name | ||||||||||||||||||||||||||||
| 3181 | # @param format optional Attribute format | ||||||||||||||||||||||||||||
| 3182 | # @param friendly_name optional Attribute friendly name | ||||||||||||||||||||||||||||
| 3183 | # @return SAML attribute | ||||||||||||||||||||||||||||
| 3184 | sub createAttribute { | ||||||||||||||||||||||||||||
| 3185 | my ( $self, $name, $format, $friendly_name ) = @_; | ||||||||||||||||||||||||||||
| 3186 | my $attribute; | ||||||||||||||||||||||||||||
| 3187 | |||||||||||||||||||||||||||||
| 3188 | # Name is required | ||||||||||||||||||||||||||||
| 3189 | return unless defined $name; | ||||||||||||||||||||||||||||
| 3190 | |||||||||||||||||||||||||||||
| 3191 | # SAML2 attribute | ||||||||||||||||||||||||||||
| 3192 | eval { $attribute = Lasso::Saml2Attribute->new(); }; | ||||||||||||||||||||||||||||
| 3193 | if ($@) { | ||||||||||||||||||||||||||||
| 3194 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 3195 | return; | ||||||||||||||||||||||||||||
| 3196 | } | ||||||||||||||||||||||||||||
| 3197 | |||||||||||||||||||||||||||||
| 3198 | # Default values | ||||||||||||||||||||||||||||
| 3199 | $friendly_name ||= $name; | ||||||||||||||||||||||||||||
| 3200 | $format ||= Lasso::Constants::SAML2_ATTRIBUTE_NAME_FORMAT_BASIC; | ||||||||||||||||||||||||||||
| 3201 | |||||||||||||||||||||||||||||
| 3202 | # Set attribute properties | ||||||||||||||||||||||||||||
| 3203 | $attribute->Name($name); | ||||||||||||||||||||||||||||
| 3204 | $attribute->NameFormat($format); | ||||||||||||||||||||||||||||
| 3205 | $attribute->FriendlyName($friendly_name); | ||||||||||||||||||||||||||||
| 3206 | |||||||||||||||||||||||||||||
| 3207 | return $attribute; | ||||||||||||||||||||||||||||
| 3208 | } | ||||||||||||||||||||||||||||
| 3209 | |||||||||||||||||||||||||||||
| 3210 | ## @method Lasso::Saml2AttributeValue createAttributeValue(string value, boolean force_utf8) | ||||||||||||||||||||||||||||
| 3211 | # Create a new SAML attribute value | ||||||||||||||||||||||||||||
| 3212 | # @param value Value to store | ||||||||||||||||||||||||||||
| 3213 | # @param force_utf8 set to 1 to decode UTF8 value | ||||||||||||||||||||||||||||
| 3214 | # @return SAML attribute value | ||||||||||||||||||||||||||||
| 3215 | sub createAttributeValue { | ||||||||||||||||||||||||||||
| 3216 | my ( $self, $value, $force_utf8 ) = @_; | ||||||||||||||||||||||||||||
| 3217 | my $saml2value; | ||||||||||||||||||||||||||||
| 3218 | $force_utf8 = 1 unless defined($force_utf8); | ||||||||||||||||||||||||||||
| 3219 | |||||||||||||||||||||||||||||
| 3220 | # Value is required | ||||||||||||||||||||||||||||
| 3221 | return unless defined $value; | ||||||||||||||||||||||||||||
| 3222 | |||||||||||||||||||||||||||||
| 3223 | # Decode UTF-8 | ||||||||||||||||||||||||||||
| 3224 | $self->logger->debug("Decode UTF8 value $value") if $force_utf8; | ||||||||||||||||||||||||||||
| 3225 | $value = decode( "utf8", $value ) if $force_utf8; | ||||||||||||||||||||||||||||
| 3226 | $self->logger->debug("Create attribute value $value"); | ||||||||||||||||||||||||||||
| 3227 | |||||||||||||||||||||||||||||
| 3228 | # SAML2 attribute value | ||||||||||||||||||||||||||||
| 3229 | eval { $saml2value = Lasso::Saml2AttributeValue->new(); }; | ||||||||||||||||||||||||||||
| 3230 | if ($@) { | ||||||||||||||||||||||||||||
| 3231 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 3232 | return; | ||||||||||||||||||||||||||||
| 3233 | } | ||||||||||||||||||||||||||||
| 3234 | |||||||||||||||||||||||||||||
| 3235 | my @any; | ||||||||||||||||||||||||||||
| 3236 | |||||||||||||||||||||||||||||
| 3237 | # Text node | ||||||||||||||||||||||||||||
| 3238 | my $textNode; | ||||||||||||||||||||||||||||
| 3239 | eval { $textNode = Lasso::MiscTextNode->new(); }; | ||||||||||||||||||||||||||||
| 3240 | if ($@) { | ||||||||||||||||||||||||||||
| 3241 | $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 3242 | return; | ||||||||||||||||||||||||||||
| 3243 | } | ||||||||||||||||||||||||||||
| 3244 | |||||||||||||||||||||||||||||
| 3245 | $textNode->text_child(1); | ||||||||||||||||||||||||||||
| 3246 | $textNode->content($value); | ||||||||||||||||||||||||||||
| 3247 | |||||||||||||||||||||||||||||
| 3248 | push @any, $textNode; | ||||||||||||||||||||||||||||
| 3249 | |||||||||||||||||||||||||||||
| 3250 | $saml2value->any(@any); | ||||||||||||||||||||||||||||
| 3251 | |||||||||||||||||||||||||||||
| 3252 | return $saml2value; | ||||||||||||||||||||||||||||
| 3253 | } | ||||||||||||||||||||||||||||
| 3254 | |||||||||||||||||||||||||||||
| 3255 | ## @method int getEncryptionMode(string encryption_mode) | ||||||||||||||||||||||||||||
| 3256 | # Return Lasso encryption mode | ||||||||||||||||||||||||||||
| 3257 | # @param encryption_mode Encryption mode string | ||||||||||||||||||||||||||||
| 3258 | # @return Lasso encryption mode | ||||||||||||||||||||||||||||
| 3259 | sub getEncryptionMode { | ||||||||||||||||||||||||||||
| 3260 | my ( $self, $encryption_mode ) = @_; | ||||||||||||||||||||||||||||
| 3261 | |||||||||||||||||||||||||||||
| 3262 | return Lasso::Constants::ENCRYPTION_MODE_NAMEID | ||||||||||||||||||||||||||||
| 3263 | if ( $encryption_mode =~ /^nameid$/i ); | ||||||||||||||||||||||||||||
| 3264 | return Lasso::Constants::ENCRYPTION_MODE_ASSERTION | ||||||||||||||||||||||||||||
| 3265 | if ( $encryption_mode =~ /^assertion$/i ); | ||||||||||||||||||||||||||||
| 3266 | return Lasso::Constants::ENCRYPTION_MODE_NONE; | ||||||||||||||||||||||||||||
| 3267 | } | ||||||||||||||||||||||||||||
| 3268 | |||||||||||||||||||||||||||||
| 3269 | ## @method boolean setProviderEncryptionMode(Lasso::Provider provider, int encryption_mode) | ||||||||||||||||||||||||||||
| 3270 | # Set encryption mode on a provider | ||||||||||||||||||||||||||||
| 3271 | # @param provider Lasso::Provider object | ||||||||||||||||||||||||||||
| 3272 | # @param encryption_mode Lasso encryption mode | ||||||||||||||||||||||||||||
| 3273 | # @return result | ||||||||||||||||||||||||||||
| 3274 | sub setProviderEncryptionMode { | ||||||||||||||||||||||||||||
| 3275 | my ( $self, $provider, $encryption_mode ) = @_; | ||||||||||||||||||||||||||||
| 3276 | |||||||||||||||||||||||||||||
| 3277 | eval { | ||||||||||||||||||||||||||||
| 3278 | Lasso::Provider::set_encryption_mode( $provider, $encryption_mode ); | ||||||||||||||||||||||||||||
| 3279 | }; | ||||||||||||||||||||||||||||
| 3280 | |||||||||||||||||||||||||||||
| 3281 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 3282 | |||||||||||||||||||||||||||||
| 3283 | } | ||||||||||||||||||||||||||||
| 3284 | |||||||||||||||||||||||||||||
| 3285 | ## @method boolean updateSAMLSecondarySessions(string old_session_id, string new_session_id) | ||||||||||||||||||||||||||||
| 3286 | # Update _saml_id of secondary sessions when the session ID is changed (upgrade) | ||||||||||||||||||||||||||||
| 3287 | sub updateSAMLSecondarySessions { | ||||||||||||||||||||||||||||
| 3288 | my ( $self, $req, $old_session_id, $new_session_id ) = @_; | ||||||||||||||||||||||||||||
| 3289 | |||||||||||||||||||||||||||||
| 3290 | # Find SAML sessions | ||||||||||||||||||||||||||||
| 3291 | my $saml_sessions = | ||||||||||||||||||||||||||||
| 3292 | Lemonldap::NG::Common::Apache::Session->searchOn( $self->amOpts, | ||||||||||||||||||||||||||||
| 3293 | "_saml_id", $old_session_id ); | ||||||||||||||||||||||||||||
| 3294 | |||||||||||||||||||||||||||||
| 3295 | if ( | ||||||||||||||||||||||||||||
| 3296 | my @saml_sessions_keys = | ||||||||||||||||||||||||||||
| 3297 | grep { $saml_sessions->{$_}->{_session_kind} eq $self->sessionKind } | ||||||||||||||||||||||||||||
| 3298 | keys %$saml_sessions | ||||||||||||||||||||||||||||
| 3299 | ) | ||||||||||||||||||||||||||||
| 3300 | { | ||||||||||||||||||||||||||||
| 3301 | |||||||||||||||||||||||||||||
| 3302 | foreach my $saml_session (@saml_sessions_keys) { | ||||||||||||||||||||||||||||
| 3303 | |||||||||||||||||||||||||||||
| 3304 | # Get session | ||||||||||||||||||||||||||||
| 3305 | $self->logger->debug("Retrieve SAML session $saml_session"); | ||||||||||||||||||||||||||||
| 3306 | |||||||||||||||||||||||||||||
| 3307 | my $samlSessionInfo = $self->getSamlSession($saml_session); | ||||||||||||||||||||||||||||
| 3308 | |||||||||||||||||||||||||||||
| 3309 | # Update session | ||||||||||||||||||||||||||||
| 3310 | if ($samlSessionInfo) { | ||||||||||||||||||||||||||||
| 3311 | $samlSessionInfo->update( { '_saml_id' => $new_session_id } ); | ||||||||||||||||||||||||||||
| 3312 | } | ||||||||||||||||||||||||||||
| 3313 | } | ||||||||||||||||||||||||||||
| 3314 | } | ||||||||||||||||||||||||||||
| 3315 | return; | ||||||||||||||||||||||||||||
| 3316 | } | ||||||||||||||||||||||||||||
| 3317 | |||||||||||||||||||||||||||||
| 3318 | ## @method boolean deleteSAMLSecondarySessions(string session_id) | ||||||||||||||||||||||||||||
| 3319 | # Find and delete SAML sessions bounded to a primary session | ||||||||||||||||||||||||||||
| 3320 | # @param session_id Primary session ID | ||||||||||||||||||||||||||||
| 3321 | # @return result | ||||||||||||||||||||||||||||
| 3322 | sub deleteSAMLSecondarySessions { | ||||||||||||||||||||||||||||
| 3323 | my ( $self, $session_id ) = @_; | ||||||||||||||||||||||||||||
| 3324 | my $result = 1; | ||||||||||||||||||||||||||||
| 3325 | |||||||||||||||||||||||||||||
| 3326 | # Find SAML sessions | ||||||||||||||||||||||||||||
| 3327 | my $saml_sessions = | ||||||||||||||||||||||||||||
| 3328 | Lemonldap::NG::Common::Apache::Session->searchOn( $self->amOpts, | ||||||||||||||||||||||||||||
| 3329 | "_saml_id", $session_id ); | ||||||||||||||||||||||||||||
| 3330 | |||||||||||||||||||||||||||||
| 3331 | if ( | ||||||||||||||||||||||||||||
| 3332 | my @saml_sessions_keys = | ||||||||||||||||||||||||||||
| 3333 | grep { $saml_sessions->{$_}->{_session_kind} eq $self->sessionKind } | ||||||||||||||||||||||||||||
| 3334 | keys %$saml_sessions | ||||||||||||||||||||||||||||
| 3335 | ) | ||||||||||||||||||||||||||||
| 3336 | { | ||||||||||||||||||||||||||||
| 3337 | |||||||||||||||||||||||||||||
| 3338 | foreach my $saml_session (@saml_sessions_keys) { | ||||||||||||||||||||||||||||
| 3339 | |||||||||||||||||||||||||||||
| 3340 | # Get session | ||||||||||||||||||||||||||||
| 3341 | $self->logger->debug("Retrieve SAML session $saml_session"); | ||||||||||||||||||||||||||||
| 3342 | |||||||||||||||||||||||||||||
| 3343 | my $samlSessionInfo = $self->getSamlSession($saml_session); | ||||||||||||||||||||||||||||
| 3344 | |||||||||||||||||||||||||||||
| 3345 | # Delete session | ||||||||||||||||||||||||||||
| 3346 | if ( $samlSessionInfo->remove ) { | ||||||||||||||||||||||||||||
| 3347 | $self->logger->debug("SAML session $saml_session deleted"); | ||||||||||||||||||||||||||||
| 3348 | } | ||||||||||||||||||||||||||||
| 3349 | else { | ||||||||||||||||||||||||||||
| 3350 | $self->logger->error( | ||||||||||||||||||||||||||||
| 3351 | "Unable to delete SAML session $saml_session"); | ||||||||||||||||||||||||||||
| 3352 | $self->logger->error( $samlSessionInfo->error ); | ||||||||||||||||||||||||||||
| 3353 | $result = 0; | ||||||||||||||||||||||||||||
| 3354 | } | ||||||||||||||||||||||||||||
| 3355 | } | ||||||||||||||||||||||||||||
| 3356 | } | ||||||||||||||||||||||||||||
| 3357 | elsif ($session_id) { | ||||||||||||||||||||||||||||
| 3358 | $self->logger->debug("No SAML session found for session $session_id"); | ||||||||||||||||||||||||||||
| 3359 | } | ||||||||||||||||||||||||||||
| 3360 | |||||||||||||||||||||||||||||
| 3361 | return $result; | ||||||||||||||||||||||||||||
| 3362 | } | ||||||||||||||||||||||||||||
| 3363 | |||||||||||||||||||||||||||||
| 3364 | ## @method void sendSLOErrorResponse(Lasso::Logout logout, string method) | ||||||||||||||||||||||||||||
| 3365 | # Send an SLO error response | ||||||||||||||||||||||||||||
| 3366 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 3367 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 3368 | sub sendSLOErrorResponse { | ||||||||||||||||||||||||||||
| 3369 | my ( $self, $req, $logout, $method ) = @_; | ||||||||||||||||||||||||||||
| 3370 | |||||||||||||||||||||||||||||
| 3371 | # Load empty session | ||||||||||||||||||||||||||||
| 3372 | my $session = | ||||||||||||||||||||||||||||
| 3373 | '<Session xmlns="http://www.entrouvert.org/namespaces/lasso/0.0"/>'; | ||||||||||||||||||||||||||||
| 3374 | |||||||||||||||||||||||||||||
| 3375 | unless ( $self->setSessionFromDump( $logout, $session ) ) { | ||||||||||||||||||||||||||||
| 3376 | return $self->p->sendError( $req, | ||||||||||||||||||||||||||||
| 3377 | "Could not set empty session in logout object", 500 ); | ||||||||||||||||||||||||||||
| 3378 | } | ||||||||||||||||||||||||||||
| 3379 | |||||||||||||||||||||||||||||
| 3380 | # Send invalidated SLO response | ||||||||||||||||||||||||||||
| 3381 | return $self->sendLogoutResponseToServiceProvider( $req, $logout, $method ); | ||||||||||||||||||||||||||||
| 3382 | } | ||||||||||||||||||||||||||||
| 3383 | |||||||||||||||||||||||||||||
| 3384 | ## @method void sendSLOSoapErrorResponse(Lasso::Logout logout, string method) | ||||||||||||||||||||||||||||
| 3385 | # Send an SLO error response | ||||||||||||||||||||||||||||
| 3386 | # @param logout Lasso::Logout object | ||||||||||||||||||||||||||||
| 3387 | # @param method HTTP method | ||||||||||||||||||||||||||||
| 3388 | # @return PSGI response | ||||||||||||||||||||||||||||
| 3389 | sub sendSLOSoapErrorResponse { | ||||||||||||||||||||||||||||
| 3390 | my ( $self, $req, $logout, $method ) = @_; | ||||||||||||||||||||||||||||
| 3391 | |||||||||||||||||||||||||||||
| 3392 | # Load empty session | ||||||||||||||||||||||||||||
| 3393 | my $session = | ||||||||||||||||||||||||||||
| 3394 | '<Session xmlns="http://www.entrouvert.org/namespaces/lasso/0.0"/>'; | ||||||||||||||||||||||||||||
| 3395 | |||||||||||||||||||||||||||||
| 3396 | unless ( $self->setSessionFromDump( $logout, $session ) ) { | ||||||||||||||||||||||||||||
| 3397 | return $self->p->sendError( $req, | ||||||||||||||||||||||||||||
| 3398 | "Could not set empty session in logout object" ); | ||||||||||||||||||||||||||||
| 3399 | } | ||||||||||||||||||||||||||||
| 3400 | my $slo_body = $logout->msg_body; | ||||||||||||||||||||||||||||
| 3401 | $self->logger->debug("SOAP response $slo_body"); | ||||||||||||||||||||||||||||
| 3402 | return [ | ||||||||||||||||||||||||||||
| 3403 | 200, | ||||||||||||||||||||||||||||
| 3404 | [ | ||||||||||||||||||||||||||||
| 3405 | 'Content-Type' => 'text/xml', | ||||||||||||||||||||||||||||
| 3406 | 'Content-Length' => length($slo_body) | ||||||||||||||||||||||||||||
| 3407 | ], | ||||||||||||||||||||||||||||
| 3408 | [$slo_body] | ||||||||||||||||||||||||||||
| 3409 | ]; | ||||||||||||||||||||||||||||
| 3410 | } | ||||||||||||||||||||||||||||
| 3411 | |||||||||||||||||||||||||||||
| 3412 | ## @method string getQueryString() | ||||||||||||||||||||||||||||
| 3413 | # Return query string with or without CGI query_string() method | ||||||||||||||||||||||||||||
| 3414 | # @return query string | ||||||||||||||||||||||||||||
| 3415 | sub getQueryString { | ||||||||||||||||||||||||||||
| 3416 | my ( $self, $req ) = @_; | ||||||||||||||||||||||||||||
| 3417 | |||||||||||||||||||||||||||||
| 3418 | my $query_string; | ||||||||||||||||||||||||||||
| 3419 | |||||||||||||||||||||||||||||
| 3420 | if ( $self->conf->{samlUseQueryStringSpecific} ) { | ||||||||||||||||||||||||||||
| 3421 | my @pairs = | ||||||||||||||||||||||||||||
| 3422 | split( /&/, $req->param('issuerQuery') || $req->query_string ); | ||||||||||||||||||||||||||||
| 3423 | $query_string = join( ';', @pairs ); | ||||||||||||||||||||||||||||
| 3424 | |||||||||||||||||||||||||||||
| 3425 | } | ||||||||||||||||||||||||||||
| 3426 | else { | ||||||||||||||||||||||||||||
| 3427 | # TODO: verify this | ||||||||||||||||||||||||||||
| 3428 | $query_string = $req->param('issuerQuery') || $req->query_string; | ||||||||||||||||||||||||||||
| 3429 | } | ||||||||||||||||||||||||||||
| 3430 | |||||||||||||||||||||||||||||
| 3431 | return $query_string; | ||||||||||||||||||||||||||||
| 3432 | } | ||||||||||||||||||||||||||||
| 3433 | |||||||||||||||||||||||||||||
| 3434 | sub importRealSession { | ||||||||||||||||||||||||||||
| 3435 | my ( $self, $req, $ssoSession ) = @_; | ||||||||||||||||||||||||||||
| 3436 | $req->sessionInfo( $ssoSession->data ); | ||||||||||||||||||||||||||||
| 3437 | $req->id( $ssoSession->id ); | ||||||||||||||||||||||||||||
| 3438 | $req->user( $ssoSession->data->{ $self->conf->{whatToTrace} } ); | ||||||||||||||||||||||||||||
| 3439 | } | ||||||||||||||||||||||||||||
| 3440 | |||||||||||||||||||||||||||||
| 3441 | sub _get_metadata_xml { | ||||||||||||||||||||||||||||
| 3442 | my ( $self, $req_or_undef, $type, $sp, $idp ) = @_; | ||||||||||||||||||||||||||||
| 3443 | |||||||||||||||||||||||||||||
| 3444 | require Lemonldap::NG::Common::Conf::SAML::Metadata; | ||||||||||||||||||||||||||||
| 3445 | |||||||||||||||||||||||||||||
| 3446 | my @signing_keys; | ||||||||||||||||||||||||||||
| 3447 | if ($sp) { | ||||||||||||||||||||||||||||
| 3448 | $self->lazy_load_entityid($sp); | ||||||||||||||||||||||||||||
| 3449 | if ( my $key_list = | ||||||||||||||||||||||||||||
| 3450 | $self->spOptions->{$sp}->{samlSPMetaDataOptionsSignatureKey} ) | ||||||||||||||||||||||||||||
| 3451 | { | ||||||||||||||||||||||||||||
| 3452 | @signing_keys = $self->_get_keys_from_config($key_list); | ||||||||||||||||||||||||||||
| 3453 | } | ||||||||||||||||||||||||||||
| 3454 | |||||||||||||||||||||||||||||
| 3455 | } | ||||||||||||||||||||||||||||
| 3456 | elsif ($idp) { | ||||||||||||||||||||||||||||
| 3457 | $self->lazy_load_entityid($idp); | ||||||||||||||||||||||||||||
| 3458 | if ( my $key_list = | ||||||||||||||||||||||||||||
| 3459 | $self->idpOptions->{$idp}->{samlIDPMetaDataOptionsSignatureKey} ) | ||||||||||||||||||||||||||||
| 3460 | { | ||||||||||||||||||||||||||||
| 3461 | @signing_keys = $self->_get_keys_from_config($key_list); | ||||||||||||||||||||||||||||
| 3462 | } | ||||||||||||||||||||||||||||
| 3463 | } | ||||||||||||||||||||||||||||
| 3464 | if ( !@signing_keys ) { | ||||||||||||||||||||||||||||
| 3465 | @signing_keys = | ||||||||||||||||||||||||||||
| 3466 | $self->_get_keys_from_config( $self->conf->{samlServiceSignatureKey} | ||||||||||||||||||||||||||||
| 3467 | || "default-saml-sig" ); | ||||||||||||||||||||||||||||
| 3468 | } | ||||||||||||||||||||||||||||
| 3469 | |||||||||||||||||||||||||||||
| 3470 | my @encryption_keys = | ||||||||||||||||||||||||||||
| 3471 | $self->_get_keys_from_config( $self->conf->{samlServiceEncryptionKey} | ||||||||||||||||||||||||||||
| 3472 | || "default-saml-enc" ); | ||||||||||||||||||||||||||||
| 3473 | |||||||||||||||||||||||||||||
| 3474 | if ( my $metadata = Lemonldap::NG::Common::Conf::SAML::Metadata->new() ) { | ||||||||||||||||||||||||||||
| 3475 | my $portal = | ||||||||||||||||||||||||||||
| 3476 | $req_or_undef | ||||||||||||||||||||||||||||
| 3477 | ? $req_or_undef->portal | ||||||||||||||||||||||||||||
| 3478 | : $self->p->HANDLER->tsv->{portal}->(); | ||||||||||||||||||||||||||||
| 3479 | return $metadata->serviceToXML( | ||||||||||||||||||||||||||||
| 3480 | $self->conf, | ||||||||||||||||||||||||||||
| 3481 | $type, | ||||||||||||||||||||||||||||
| 3482 | portal => $portal, | ||||||||||||||||||||||||||||
| 3483 | signing_keys => \@signing_keys, | ||||||||||||||||||||||||||||
| 3484 | ( | ||||||||||||||||||||||||||||
| 3485 | @encryption_keys ? ( encryption_keys => \@encryption_keys ) : () | ||||||||||||||||||||||||||||
| 3486 | ), | ||||||||||||||||||||||||||||
| 3487 | ); | ||||||||||||||||||||||||||||
| 3488 | } | ||||||||||||||||||||||||||||
| 3489 | return; | ||||||||||||||||||||||||||||
| 3490 | } | ||||||||||||||||||||||||||||
| 3491 | |||||||||||||||||||||||||||||
| 3492 | sub _get_keys_from_config { | ||||||||||||||||||||||||||||
| 3493 | my ( $self, $list_of_keys ) = @_; | ||||||||||||||||||||||||||||
| 3494 | my @keys; | ||||||||||||||||||||||||||||
| 3495 | |||||||||||||||||||||||||||||
| 3496 | if ($list_of_keys) { | ||||||||||||||||||||||||||||
| 3497 | for my $key_id ( split( /\s*,\s*/, $list_of_keys ) ) { | ||||||||||||||||||||||||||||
| 3498 | my $key = $self->get_public_key($key_id); | ||||||||||||||||||||||||||||
| 3499 | if ($key) { | ||||||||||||||||||||||||||||
| 3500 | push @keys, $key; | ||||||||||||||||||||||||||||
| 3501 | } | ||||||||||||||||||||||||||||
| 3502 | else { | ||||||||||||||||||||||||||||
| 3503 | $self->logger->debug("Could not publish $key_id in metadata"); | ||||||||||||||||||||||||||||
| 3504 | } | ||||||||||||||||||||||||||||
| 3505 | } | ||||||||||||||||||||||||||||
| 3506 | } | ||||||||||||||||||||||||||||
| 3507 | return @keys; | ||||||||||||||||||||||||||||
| 3508 | } | ||||||||||||||||||||||||||||
| 3509 | |||||||||||||||||||||||||||||
| 3510 | sub metadata { | ||||||||||||||||||||||||||||
| 3511 | my ( $self, $req ) = @_; | ||||||||||||||||||||||||||||
| 3512 | my $type = $req->param('type') || 'all'; | ||||||||||||||||||||||||||||
| 3513 | my $idp = $req->param('idp'); | ||||||||||||||||||||||||||||
| 3514 | my $sp = $req->param('sp'); | ||||||||||||||||||||||||||||
| 3515 | if ( my $metadata = $self->_get_metadata_xml( $req, $type, $sp, $idp ) ) { | ||||||||||||||||||||||||||||
| 3516 | return [ | ||||||||||||||||||||||||||||
| 3517 | 200, | ||||||||||||||||||||||||||||
| 3518 | [ | ||||||||||||||||||||||||||||
| 3519 | 'Content-Type' => 'application/xml', | ||||||||||||||||||||||||||||
| 3520 | 'Content-Length' => length($metadata), | ||||||||||||||||||||||||||||
| 3521 | ], | ||||||||||||||||||||||||||||
| 3522 | [$metadata] | ||||||||||||||||||||||||||||
| 3523 | ]; | ||||||||||||||||||||||||||||
| 3524 | } | ||||||||||||||||||||||||||||
| 3525 | return $self->p->sendError( $req, 'Unable to build Metadata', 500 ); | ||||||||||||||||||||||||||||
| 3526 | } | ||||||||||||||||||||||||||||
| 3527 | |||||||||||||||||||||||||||||
| 3528 | ## @method int getSignatureMethod(string signature_method) | ||||||||||||||||||||||||||||
| 3529 | # Return Lasso signature method | ||||||||||||||||||||||||||||
| 3530 | # @param signature_method Signature method string | ||||||||||||||||||||||||||||
| 3531 | # @return Lasso signature method | ||||||||||||||||||||||||||||
| 3532 | sub getSignatureMethod { | ||||||||||||||||||||||||||||
| 3533 | my ( $self, $signature_method ) = @_; | ||||||||||||||||||||||||||||
| 3534 | |||||||||||||||||||||||||||||
| 3535 | $signature_method ||= $self->getDefaultSignatureMethod(); | ||||||||||||||||||||||||||||
| 3536 | |||||||||||||||||||||||||||||
| 3537 | if ( my $const = | ||||||||||||||||||||||||||||
| 3538 | Lasso::Constants->can( "SIGNATURE_METHOD_" . uc($signature_method) ) ) | ||||||||||||||||||||||||||||
| 3539 | { | ||||||||||||||||||||||||||||
| 3540 | return $const->(); | ||||||||||||||||||||||||||||
| 3541 | } | ||||||||||||||||||||||||||||
| 3542 | else { | ||||||||||||||||||||||||||||
| 3543 | return 0; | ||||||||||||||||||||||||||||
| 3544 | } | ||||||||||||||||||||||||||||
| 3545 | } | ||||||||||||||||||||||||||||
| 3546 | |||||||||||||||||||||||||||||
| 3547 | sub getDefaultSignatureMethod { | ||||||||||||||||||||||||||||
| 3548 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 3549 | |||||||||||||||||||||||||||||
| 3550 | my $signature_method = | ||||||||||||||||||||||||||||
| 3551 | $self->conf->{samlServiceSignatureMethod} || 'RSA_SHA1'; | ||||||||||||||||||||||||||||
| 3552 | return $signature_method; | ||||||||||||||||||||||||||||
| 3553 | } | ||||||||||||||||||||||||||||
| 3554 | |||||||||||||||||||||||||||||
| 3555 | ## @method boolean setProviderSignatureMethod(Lasso::Provider provider, int signature_method) | ||||||||||||||||||||||||||||
| 3556 | # Set signature method on a provider | ||||||||||||||||||||||||||||
| 3557 | # @param provider Lasso::Provider object | ||||||||||||||||||||||||||||
| 3558 | # @param signature_method Lasso signature method | ||||||||||||||||||||||||||||
| 3559 | # @return result | ||||||||||||||||||||||||||||
| 3560 | sub setProviderSignatureMethod { | ||||||||||||||||||||||||||||
| 3561 | my ( $self, $provider, $signature_method ) = @_; | ||||||||||||||||||||||||||||
| 3562 | |||||||||||||||||||||||||||||
| 3563 | my $key = $self->get_private_key( $self->_get_default_signing_key_name ); | ||||||||||||||||||||||||||||
| 3564 | return $self->setProviderSignatureOptions( $provider, $signature_method, | ||||||||||||||||||||||||||||
| 3565 | $key ); | ||||||||||||||||||||||||||||
| 3566 | } | ||||||||||||||||||||||||||||
| 3567 | |||||||||||||||||||||||||||||
| 3568 | sub setProviderSignatureOptions { | ||||||||||||||||||||||||||||
| 3569 | my ( $self, $provider, $signature_method, $key ) = @_; | ||||||||||||||||||||||||||||
| 3570 | |||||||||||||||||||||||||||||
| 3571 | # We have to use an intermediate variable to avoid interferences between | ||||||||||||||||||||||||||||
| 3572 | # Lasso binding and tied hashes (#3105) | ||||||||||||||||||||||||||||
| 3573 | my $priv = $key->{private}; | ||||||||||||||||||||||||||||
| 3574 | my $pass = $key->{password}; | ||||||||||||||||||||||||||||
| 3575 | my $cert = $key->{public}; | ||||||||||||||||||||||||||||
| 3576 | |||||||||||||||||||||||||||||
| 3577 | eval { | ||||||||||||||||||||||||||||
| 3578 | my $key = Lasso::Key::new_for_signature_from_file( $priv, $pass, | ||||||||||||||||||||||||||||
| 3579 | $signature_method, $cert, ); | ||||||||||||||||||||||||||||
| 3580 | $provider->set_server_signing_key($key); | ||||||||||||||||||||||||||||
| 3581 | }; | ||||||||||||||||||||||||||||
| 3582 | |||||||||||||||||||||||||||||
| 3583 | return $self->checkLassoError($@); | ||||||||||||||||||||||||||||
| 3584 | } | ||||||||||||||||||||||||||||
| 3585 | |||||||||||||||||||||||||||||
| 3586 | sub _override_signature_or_key { | ||||||||||||||||||||||||||||
| 3587 | my ( $self, $entityID, $log_description, $signature_method, | ||||||||||||||||||||||||||||
| 3588 | $signature_key_list ) | ||||||||||||||||||||||||||||
| 3589 | = @_; | ||||||||||||||||||||||||||||
| 3590 | if ( $signature_method or $signature_key_list ) { | ||||||||||||||||||||||||||||
| 3591 | $signature_key_list //= ""; | ||||||||||||||||||||||||||||
| 3592 | my $signature_key = ( split( /\s*,\s*/, $signature_key_list ) )[0]; | ||||||||||||||||||||||||||||
| 3593 | |||||||||||||||||||||||||||||
| 3594 | $signature_method ||= $self->getDefaultSignatureMethod; | ||||||||||||||||||||||||||||
| 3595 | my $lasso_signature_method = | ||||||||||||||||||||||||||||
| 3596 | $self->getSignatureMethod($signature_method); | ||||||||||||||||||||||||||||
| 3597 | |||||||||||||||||||||||||||||
| 3598 | $signature_key ||= $self->_get_default_signing_key_name; | ||||||||||||||||||||||||||||
| 3599 | my $key = $self->get_private_key($signature_key); | ||||||||||||||||||||||||||||
| 3600 | |||||||||||||||||||||||||||||
| 3601 | # Fallback to default key if custom key was not found | ||||||||||||||||||||||||||||
| 3602 | if ( !$key ) { | ||||||||||||||||||||||||||||
| 3603 | $signature_key = $self->_get_default_signing_key_name; | ||||||||||||||||||||||||||||
| 3604 | $key = $self->get_private_key($signature_key); | ||||||||||||||||||||||||||||
| 3605 | } | ||||||||||||||||||||||||||||
| 3606 | |||||||||||||||||||||||||||||
| 3607 | $self->logger->debug( "Setting signature key $signature_key" | ||||||||||||||||||||||||||||
| 3608 | . " and signature method $signature_method" | ||||||||||||||||||||||||||||
| 3609 | . " on $log_description" ); | ||||||||||||||||||||||||||||
| 3610 | |||||||||||||||||||||||||||||
| 3611 | unless ( | ||||||||||||||||||||||||||||
| 3612 | $self->setProviderSignatureOptions( | ||||||||||||||||||||||||||||
| 3613 | $self->lassoServer->get_provider($entityID), | ||||||||||||||||||||||||||||
| 3614 | $lasso_signature_method, $key | ||||||||||||||||||||||||||||
| 3615 | ) | ||||||||||||||||||||||||||||
| 3616 | ) | ||||||||||||||||||||||||||||
| 3617 | { | ||||||||||||||||||||||||||||
| 3618 | $self->logger->error( | ||||||||||||||||||||||||||||
| 3619 | "Unable to set signature options on $log_description"); | ||||||||||||||||||||||||||||
| 3620 | return; | ||||||||||||||||||||||||||||
| 3621 | } | ||||||||||||||||||||||||||||
| 3622 | } | ||||||||||||||||||||||||||||
| 3623 | } | ||||||||||||||||||||||||||||
| 3624 | |||||||||||||||||||||||||||||
| 3625 | # The default signing key is the first key listed in samlServiceSignatureKey, with | ||||||||||||||||||||||||||||
| 3626 | # fallback to default-saml-sig | ||||||||||||||||||||||||||||
| 3627 | sub _get_default_signing_key_name { | ||||||||||||||||||||||||||||
| 3628 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 3629 | my @key_list = | ||||||||||||||||||||||||||||
| 3630 | split( /\s*,\s*/, ( $self->conf->{samlServiceSignatureKey} || "" ) ); | ||||||||||||||||||||||||||||
| 3631 | |||||||||||||||||||||||||||||
| 3632 | return ( $key_list[0] || "default-saml-sig" ); | ||||||||||||||||||||||||||||
| 3633 | } | ||||||||||||||||||||||||||||
| 3634 | |||||||||||||||||||||||||||||
| 3635 | # The default encryption key is the first key listed in samlServiceEncryptionKey, with | ||||||||||||||||||||||||||||
| 3636 | # fallback to default-saml-enc | ||||||||||||||||||||||||||||
| 3637 | sub _get_default_encryption_key_name { | ||||||||||||||||||||||||||||
| 3638 | my ($self) = @_; | ||||||||||||||||||||||||||||
| 3639 | my @key_list = | ||||||||||||||||||||||||||||
| 3640 | split( /\s*,\s*/, ( $self->conf->{samlServiceEncryptionKey} || "" ) ); | ||||||||||||||||||||||||||||
| 3641 | |||||||||||||||||||||||||||||
| 3642 | return ( $key_list[0] || "default-saml-enc" ); | ||||||||||||||||||||||||||||
| 3643 | } | ||||||||||||||||||||||||||||
| 3644 | |||||||||||||||||||||||||||||
| 3645 | 1; | ||||||||||||||||||||||||||||
| 3646 | |||||||||||||||||||||||||||||
| 3647 | __END__ | ||||||||||||||||||||||||||||
| 3648 | |||||||||||||||||||||||||||||
| 3649 | =head1 NAME | ||||||||||||||||||||||||||||
| 3650 | |||||||||||||||||||||||||||||
| 3651 | =encoding utf8 | ||||||||||||||||||||||||||||
| 3652 | |||||||||||||||||||||||||||||
| 3653 | Lemonldap::NG::Portal::Lib::SAML - Common SAML functions | ||||||||||||||||||||||||||||
| 3654 | |||||||||||||||||||||||||||||
| 3655 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 3656 | |||||||||||||||||||||||||||||
| 3657 | use Lemonldap::NG::Portal::Lib::SAML; | ||||||||||||||||||||||||||||
| 3658 | |||||||||||||||||||||||||||||
| 3659 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 3660 | |||||||||||||||||||||||||||||
| 3661 | This module contains common methods for SAML authentication | ||||||||||||||||||||||||||||
| 3662 | and user information loading | ||||||||||||||||||||||||||||
| 3663 | |||||||||||||||||||||||||||||
| 3664 | =head1 METHODS | ||||||||||||||||||||||||||||
| 3665 | |||||||||||||||||||||||||||||
| 3666 | =head2 loadLasso | ||||||||||||||||||||||||||||
| 3667 | |||||||||||||||||||||||||||||
| 3668 | Load Lasso module | ||||||||||||||||||||||||||||
| 3669 | |||||||||||||||||||||||||||||
| 3670 | =head2 loadService | ||||||||||||||||||||||||||||
| 3671 | |||||||||||||||||||||||||||||
| 3672 | Load SAML service by creating a Lasso::Server | ||||||||||||||||||||||||||||
| 3673 | |||||||||||||||||||||||||||||
| 3674 | =head2 loadIDPs | ||||||||||||||||||||||||||||
| 3675 | |||||||||||||||||||||||||||||
| 3676 | Load SAML identity providers | ||||||||||||||||||||||||||||
| 3677 | |||||||||||||||||||||||||||||
| 3678 | =head2 loadSPs | ||||||||||||||||||||||||||||
| 3679 | |||||||||||||||||||||||||||||
| 3680 | Load SAML service providers | ||||||||||||||||||||||||||||
| 3681 | |||||||||||||||||||||||||||||
| 3682 | =head2 checkMessage | ||||||||||||||||||||||||||||
| 3683 | |||||||||||||||||||||||||||||
| 3684 | Check SAML requests and responses | ||||||||||||||||||||||||||||
| 3685 | |||||||||||||||||||||||||||||
| 3686 | =head2 checkLassoError | ||||||||||||||||||||||||||||
| 3687 | |||||||||||||||||||||||||||||
| 3688 | Log Lasso error code and message if this is actually a Lasso::Error with code > 0 | ||||||||||||||||||||||||||||
| 3689 | |||||||||||||||||||||||||||||
| 3690 | =head2 createServer | ||||||||||||||||||||||||||||
| 3691 | |||||||||||||||||||||||||||||
| 3692 | Load service metadata and create Lasso::Server object | ||||||||||||||||||||||||||||
| 3693 | |||||||||||||||||||||||||||||
| 3694 | =head2 addIDP | ||||||||||||||||||||||||||||
| 3695 | |||||||||||||||||||||||||||||
| 3696 | Add IDP to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 3697 | |||||||||||||||||||||||||||||
| 3698 | =head2 addSP | ||||||||||||||||||||||||||||
| 3699 | |||||||||||||||||||||||||||||
| 3700 | Add SP to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 3701 | |||||||||||||||||||||||||||||
| 3702 | =head2 addAA | ||||||||||||||||||||||||||||
| 3703 | |||||||||||||||||||||||||||||
| 3704 | Add Attribute Authority to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 3705 | |||||||||||||||||||||||||||||
| 3706 | =head2 addProvider | ||||||||||||||||||||||||||||
| 3707 | |||||||||||||||||||||||||||||
| 3708 | Add provider to an existing Lasso::Server | ||||||||||||||||||||||||||||
| 3709 | |||||||||||||||||||||||||||||
| 3710 | =head2 getOrganizationName | ||||||||||||||||||||||||||||
| 3711 | |||||||||||||||||||||||||||||
| 3712 | Return name of organization picked up from metadata | ||||||||||||||||||||||||||||
| 3713 | |||||||||||||||||||||||||||||
| 3714 | =head2 createAuthnRequest | ||||||||||||||||||||||||||||
| 3715 | |||||||||||||||||||||||||||||
| 3716 | Create authentication request for selected IDP | ||||||||||||||||||||||||||||
| 3717 | |||||||||||||||||||||||||||||
| 3718 | =head2 createLogin | ||||||||||||||||||||||||||||
| 3719 | |||||||||||||||||||||||||||||
| 3720 | Create Lasso::Login object | ||||||||||||||||||||||||||||
| 3721 | |||||||||||||||||||||||||||||
| 3722 | =head2 initAuthnRequest | ||||||||||||||||||||||||||||
| 3723 | |||||||||||||||||||||||||||||
| 3724 | Init authentication request | ||||||||||||||||||||||||||||
| 3725 | |||||||||||||||||||||||||||||
| 3726 | =head2 initIdpInitiatedAuthnRequest | ||||||||||||||||||||||||||||
| 3727 | |||||||||||||||||||||||||||||
| 3728 | Init authentication request for IDP initiated | ||||||||||||||||||||||||||||
| 3729 | |||||||||||||||||||||||||||||
| 3730 | =head2 buildAuthnRequestMsg | ||||||||||||||||||||||||||||
| 3731 | |||||||||||||||||||||||||||||
| 3732 | Build authentication request message | ||||||||||||||||||||||||||||
| 3733 | |||||||||||||||||||||||||||||
| 3734 | =head2 processAuthnRequestMsg | ||||||||||||||||||||||||||||
| 3735 | |||||||||||||||||||||||||||||
| 3736 | Process authentication request message | ||||||||||||||||||||||||||||
| 3737 | |||||||||||||||||||||||||||||
| 3738 | =head2 processAuthnRequestMsgWithError | ||||||||||||||||||||||||||||
| 3739 | |||||||||||||||||||||||||||||
| 3740 | Process authentication request message and return Lasso error | ||||||||||||||||||||||||||||
| 3741 | |||||||||||||||||||||||||||||
| 3742 | =head2 validateRequestMsg | ||||||||||||||||||||||||||||
| 3743 | |||||||||||||||||||||||||||||
| 3744 | Validate request message | ||||||||||||||||||||||||||||
| 3745 | |||||||||||||||||||||||||||||
| 3746 | =head2 buildAuthnResponseMsg | ||||||||||||||||||||||||||||
| 3747 | |||||||||||||||||||||||||||||
| 3748 | Build authentication response message | ||||||||||||||||||||||||||||
| 3749 | |||||||||||||||||||||||||||||
| 3750 | =head2 buildArtifactMsg | ||||||||||||||||||||||||||||
| 3751 | |||||||||||||||||||||||||||||
| 3752 | Build artifact message | ||||||||||||||||||||||||||||
| 3753 | |||||||||||||||||||||||||||||
| 3754 | =head2 buildAssertion | ||||||||||||||||||||||||||||
| 3755 | |||||||||||||||||||||||||||||
| 3756 | Build assertion | ||||||||||||||||||||||||||||
| 3757 | |||||||||||||||||||||||||||||
| 3758 | =head2 processAuthnResponseMsg | ||||||||||||||||||||||||||||
| 3759 | |||||||||||||||||||||||||||||
| 3760 | Process authentication response message | ||||||||||||||||||||||||||||
| 3761 | |||||||||||||||||||||||||||||
| 3762 | =head2 getNameIdentifier | ||||||||||||||||||||||||||||
| 3763 | |||||||||||||||||||||||||||||
| 3764 | Get NameID from Lasso Profile | ||||||||||||||||||||||||||||
| 3765 | |||||||||||||||||||||||||||||
| 3766 | =head2 createIdentity | ||||||||||||||||||||||||||||
| 3767 | |||||||||||||||||||||||||||||
| 3768 | Create Lasso::Identity object | ||||||||||||||||||||||||||||
| 3769 | |||||||||||||||||||||||||||||
| 3770 | =head2 createSession | ||||||||||||||||||||||||||||
| 3771 | |||||||||||||||||||||||||||||
| 3772 | Create Lasso::Session object | ||||||||||||||||||||||||||||
| 3773 | |||||||||||||||||||||||||||||
| 3774 | =head2 acceptSSO | ||||||||||||||||||||||||||||
| 3775 | |||||||||||||||||||||||||||||
| 3776 | Accept SSO from IDP | ||||||||||||||||||||||||||||
| 3777 | |||||||||||||||||||||||||||||
| 3778 | =head2 storeRelayState | ||||||||||||||||||||||||||||
| 3779 | |||||||||||||||||||||||||||||
| 3780 | Store information in relayState database and return | ||||||||||||||||||||||||||||
| 3781 | |||||||||||||||||||||||||||||
| 3782 | =head2 extractRelayState | ||||||||||||||||||||||||||||
| 3783 | |||||||||||||||||||||||||||||
| 3784 | Extract RelayState information into $self | ||||||||||||||||||||||||||||
| 3785 | |||||||||||||||||||||||||||||
| 3786 | =head2 getAssertion | ||||||||||||||||||||||||||||
| 3787 | |||||||||||||||||||||||||||||
| 3788 | Get assertion in Lasso::Login object | ||||||||||||||||||||||||||||
| 3789 | |||||||||||||||||||||||||||||
| 3790 | =head2 getAttributeValue | ||||||||||||||||||||||||||||
| 3791 | |||||||||||||||||||||||||||||
| 3792 | Get SAML attribute value corresponding to name, format and friendly_name | ||||||||||||||||||||||||||||
| 3793 | Multivaluated values are separated by ';' | ||||||||||||||||||||||||||||
| 3794 | |||||||||||||||||||||||||||||
| 3795 | =head2 validateConditions | ||||||||||||||||||||||||||||
| 3796 | |||||||||||||||||||||||||||||
| 3797 | Validate conditions | ||||||||||||||||||||||||||||
| 3798 | |||||||||||||||||||||||||||||
| 3799 | =head2 createLogoutRequest | ||||||||||||||||||||||||||||
| 3800 | |||||||||||||||||||||||||||||
| 3801 | Create logout request for selected entity | ||||||||||||||||||||||||||||
| 3802 | |||||||||||||||||||||||||||||
| 3803 | =head2 createLogout | ||||||||||||||||||||||||||||
| 3804 | |||||||||||||||||||||||||||||
| 3805 | Create Lasso::Logout object | ||||||||||||||||||||||||||||
| 3806 | |||||||||||||||||||||||||||||
| 3807 | =head2 initLogoutRequest | ||||||||||||||||||||||||||||
| 3808 | |||||||||||||||||||||||||||||
| 3809 | Init logout request | ||||||||||||||||||||||||||||
| 3810 | |||||||||||||||||||||||||||||
| 3811 | =head2 buildLogoutRequestMsg | ||||||||||||||||||||||||||||
| 3812 | |||||||||||||||||||||||||||||
| 3813 | Build logout request message | ||||||||||||||||||||||||||||
| 3814 | |||||||||||||||||||||||||||||
| 3815 | =head2 setSessionFromDump | ||||||||||||||||||||||||||||
| 3816 | |||||||||||||||||||||||||||||
| 3817 | Set session from dump in Lasso::Profile object | ||||||||||||||||||||||||||||
| 3818 | |||||||||||||||||||||||||||||
| 3819 | =head2 setIdentityFromDump | ||||||||||||||||||||||||||||
| 3820 | |||||||||||||||||||||||||||||
| 3821 | Set identity from dump in Lasso::Profile object | ||||||||||||||||||||||||||||
| 3822 | |||||||||||||||||||||||||||||
| 3823 | =head2 getMetaDataURL | ||||||||||||||||||||||||||||
| 3824 | |||||||||||||||||||||||||||||
| 3825 | Get URL stored in a service metadata configuration key | ||||||||||||||||||||||||||||
| 3826 | |||||||||||||||||||||||||||||
| 3827 | =head2 processLogoutResponseMsg | ||||||||||||||||||||||||||||
| 3828 | |||||||||||||||||||||||||||||
| 3829 | Process logout response message | ||||||||||||||||||||||||||||
| 3830 | |||||||||||||||||||||||||||||
| 3831 | =head2 processLogoutRequestMsg | ||||||||||||||||||||||||||||
| 3832 | |||||||||||||||||||||||||||||
| 3833 | Process logout request message | ||||||||||||||||||||||||||||
| 3834 | |||||||||||||||||||||||||||||
| 3835 | =head2 validateLogoutRequest | ||||||||||||||||||||||||||||
| 3836 | |||||||||||||||||||||||||||||
| 3837 | Validate logout request | ||||||||||||||||||||||||||||
| 3838 | |||||||||||||||||||||||||||||
| 3839 | =head2 buildLogoutResponseMsg | ||||||||||||||||||||||||||||
| 3840 | |||||||||||||||||||||||||||||
| 3841 | Build logout response msg | ||||||||||||||||||||||||||||
| 3842 | |||||||||||||||||||||||||||||
| 3843 | =head2 storeReplayProtection | ||||||||||||||||||||||||||||
| 3844 | |||||||||||||||||||||||||||||
| 3845 | Store ID of an SAML message in Replay Protection base | ||||||||||||||||||||||||||||
| 3846 | |||||||||||||||||||||||||||||
| 3847 | =head2 replayProtection | ||||||||||||||||||||||||||||
| 3848 | |||||||||||||||||||||||||||||
| 3849 | Check if SAML message do not correspond to a previously responded message | ||||||||||||||||||||||||||||
| 3850 | |||||||||||||||||||||||||||||
| 3851 | =head2 resolveArtifact | ||||||||||||||||||||||||||||
| 3852 | |||||||||||||||||||||||||||||
| 3853 | Resolve artifact to get the real SAML message | ||||||||||||||||||||||||||||
| 3854 | |||||||||||||||||||||||||||||
| 3855 | =head2 storeArtifact | ||||||||||||||||||||||||||||
| 3856 | |||||||||||||||||||||||||||||
| 3857 | Store artifact | ||||||||||||||||||||||||||||
| 3858 | |||||||||||||||||||||||||||||
| 3859 | =head2 loadArtifact | ||||||||||||||||||||||||||||
| 3860 | |||||||||||||||||||||||||||||
| 3861 | Load artifact | ||||||||||||||||||||||||||||
| 3862 | |||||||||||||||||||||||||||||
| 3863 | =head2 createArtifactResponse | ||||||||||||||||||||||||||||
| 3864 | |||||||||||||||||||||||||||||
| 3865 | Create artifact response | ||||||||||||||||||||||||||||
| 3866 | |||||||||||||||||||||||||||||
| 3867 | =head2 processArtRequestMsg | ||||||||||||||||||||||||||||
| 3868 | |||||||||||||||||||||||||||||
| 3869 | Process artifact response message | ||||||||||||||||||||||||||||
| 3870 | |||||||||||||||||||||||||||||
| 3871 | =head2 processArtResponseMsg | ||||||||||||||||||||||||||||
| 3872 | |||||||||||||||||||||||||||||
| 3873 | Process artifact response message | ||||||||||||||||||||||||||||
| 3874 | |||||||||||||||||||||||||||||
| 3875 | =head2 sendSOAPMessage | ||||||||||||||||||||||||||||
| 3876 | |||||||||||||||||||||||||||||
| 3877 | Send SOAP message and get response | ||||||||||||||||||||||||||||
| 3878 | |||||||||||||||||||||||||||||
| 3879 | =head2 createAssertionQuery | ||||||||||||||||||||||||||||
| 3880 | |||||||||||||||||||||||||||||
| 3881 | Create a new assertion query | ||||||||||||||||||||||||||||
| 3882 | |||||||||||||||||||||||||||||
| 3883 | =head2 createAttributeRequest | ||||||||||||||||||||||||||||
| 3884 | |||||||||||||||||||||||||||||
| 3885 | Create an attribute request | ||||||||||||||||||||||||||||
| 3886 | |||||||||||||||||||||||||||||
| 3887 | =head2 validateAttributeRequest | ||||||||||||||||||||||||||||
| 3888 | |||||||||||||||||||||||||||||
| 3889 | Validate an attribute request | ||||||||||||||||||||||||||||
| 3890 | |||||||||||||||||||||||||||||
| 3891 | =head2 processAttributeRequest | ||||||||||||||||||||||||||||
| 3892 | |||||||||||||||||||||||||||||
| 3893 | Process an attribute request | ||||||||||||||||||||||||||||
| 3894 | |||||||||||||||||||||||||||||
| 3895 | =head2 buildAttributeResponse | ||||||||||||||||||||||||||||
| 3896 | |||||||||||||||||||||||||||||
| 3897 | Build attribute response | ||||||||||||||||||||||||||||
| 3898 | |||||||||||||||||||||||||||||
| 3899 | =head2 processAttributeResponse | ||||||||||||||||||||||||||||
| 3900 | |||||||||||||||||||||||||||||
| 3901 | Process an attribute response | ||||||||||||||||||||||||||||
| 3902 | |||||||||||||||||||||||||||||
| 3903 | =head2 getNameIDFormat | ||||||||||||||||||||||||||||
| 3904 | |||||||||||||||||||||||||||||
| 3905 | Convert configuration string into SAML2 NameIDFormat string | ||||||||||||||||||||||||||||
| 3906 | |||||||||||||||||||||||||||||
| 3907 | =head2 getHttpMethod | ||||||||||||||||||||||||||||
| 3908 | |||||||||||||||||||||||||||||
| 3909 | Convert configuration string into Lasso HTTP Method integer | ||||||||||||||||||||||||||||
| 3910 | |||||||||||||||||||||||||||||
| 3911 | =head2 getHttpMethodString | ||||||||||||||||||||||||||||
| 3912 | |||||||||||||||||||||||||||||
| 3913 | Convert configuration Lasso HTTP Method integer into string | ||||||||||||||||||||||||||||
| 3914 | |||||||||||||||||||||||||||||
| 3915 | =head2 getFirstHttpMethod | ||||||||||||||||||||||||||||
| 3916 | |||||||||||||||||||||||||||||
| 3917 | Find a suitable HTTP method for an entity with a given protocol | ||||||||||||||||||||||||||||
| 3918 | |||||||||||||||||||||||||||||
| 3919 | =head2 disableSignature | ||||||||||||||||||||||||||||
| 3920 | |||||||||||||||||||||||||||||
| 3921 | Modify Lasso signature hint to disable signature | ||||||||||||||||||||||||||||
| 3922 | |||||||||||||||||||||||||||||
| 3923 | =head2 forceSignature | ||||||||||||||||||||||||||||
| 3924 | |||||||||||||||||||||||||||||
| 3925 | Modify Lasso signature hint to force signature | ||||||||||||||||||||||||||||
| 3926 | |||||||||||||||||||||||||||||
| 3927 | =head2 disableSignatureVerification | ||||||||||||||||||||||||||||
| 3928 | |||||||||||||||||||||||||||||
| 3929 | Modify Lasso signature hint to disable signature verification | ||||||||||||||||||||||||||||
| 3930 | |||||||||||||||||||||||||||||
| 3931 | =head2 forceSignatureVerification | ||||||||||||||||||||||||||||
| 3932 | |||||||||||||||||||||||||||||
| 3933 | Modify Lasso signature hint to force signature verification | ||||||||||||||||||||||||||||
| 3934 | |||||||||||||||||||||||||||||
| 3935 | =head2 getAuthnContext | ||||||||||||||||||||||||||||
| 3936 | |||||||||||||||||||||||||||||
| 3937 | Convert configuration string into SAML2 AuthnContextClassRef string | ||||||||||||||||||||||||||||
| 3938 | |||||||||||||||||||||||||||||
| 3939 | =head2 timestamp2samldate | ||||||||||||||||||||||||||||
| 3940 | |||||||||||||||||||||||||||||
| 3941 | Convert timestamp into SAML2 date format | ||||||||||||||||||||||||||||
| 3942 | |||||||||||||||||||||||||||||
| 3943 | =head2 samldate2timestamp | ||||||||||||||||||||||||||||
| 3944 | |||||||||||||||||||||||||||||
| 3945 | Convert SAML2 date format into timestamp | ||||||||||||||||||||||||||||
| 3946 | |||||||||||||||||||||||||||||
| 3947 | =head2 sendLogoutResponseToServiceProvider | ||||||||||||||||||||||||||||
| 3948 | |||||||||||||||||||||||||||||
| 3949 | Send logout response issue from a logout request | ||||||||||||||||||||||||||||
| 3950 | |||||||||||||||||||||||||||||
| 3951 | =head2 sendLogoutRequestToProvider | ||||||||||||||||||||||||||||
| 3952 | |||||||||||||||||||||||||||||
| 3953 | Send logout request to a provider | ||||||||||||||||||||||||||||
| 3954 | |||||||||||||||||||||||||||||
| 3955 | =head2 sendLogoutRequestToProviders | ||||||||||||||||||||||||||||
| 3956 | |||||||||||||||||||||||||||||
| 3957 | Send logout response issue from a logout request to all other | ||||||||||||||||||||||||||||
| 3958 | providers. If information have to be displayed to users, such as | ||||||||||||||||||||||||||||
| 3959 | iframe to send HTTP-Redirect or HTTP-POST logout request, then | ||||||||||||||||||||||||||||
| 3960 | $self->{_info} will be updated. | ||||||||||||||||||||||||||||
| 3961 | |||||||||||||||||||||||||||||
| 3962 | =head2 checkSignatureStatus | ||||||||||||||||||||||||||||
| 3963 | |||||||||||||||||||||||||||||
| 3964 | Check signature status | ||||||||||||||||||||||||||||
| 3965 | |||||||||||||||||||||||||||||
| 3966 | =head2 authnContext2authnLevel | ||||||||||||||||||||||||||||
| 3967 | |||||||||||||||||||||||||||||
| 3968 | Return authentication level corresponding to authnContext | ||||||||||||||||||||||||||||
| 3969 | |||||||||||||||||||||||||||||
| 3970 | =head2 authnLevel2authnContext | ||||||||||||||||||||||||||||
| 3971 | |||||||||||||||||||||||||||||
| 3972 | Return SAML authentication context corresponding to authnLevel | ||||||||||||||||||||||||||||
| 3973 | |||||||||||||||||||||||||||||
| 3974 | =head2 checkDestination | ||||||||||||||||||||||||||||
| 3975 | |||||||||||||||||||||||||||||
| 3976 | If SAML Destination attribute is present, check it | ||||||||||||||||||||||||||||
| 3977 | |||||||||||||||||||||||||||||
| 3978 | =head2 getSamlSession | ||||||||||||||||||||||||||||
| 3979 | |||||||||||||||||||||||||||||
| 3980 | Try to recover the SAML session corresponding to id and return session data | ||||||||||||||||||||||||||||
| 3981 | |||||||||||||||||||||||||||||
| 3982 | =head2 createAttribute | ||||||||||||||||||||||||||||
| 3983 | |||||||||||||||||||||||||||||
| 3984 | Create a new SAML attribute | ||||||||||||||||||||||||||||
| 3985 | |||||||||||||||||||||||||||||
| 3986 | =head2 createAttributeValue | ||||||||||||||||||||||||||||
| 3987 | |||||||||||||||||||||||||||||
| 3988 | Create a new SAML attribute value | ||||||||||||||||||||||||||||
| 3989 | |||||||||||||||||||||||||||||
| 3990 | =head2 getEncryptionMode | ||||||||||||||||||||||||||||
| 3991 | |||||||||||||||||||||||||||||
| 3992 | Return Lasso encryption mode | ||||||||||||||||||||||||||||
| 3993 | |||||||||||||||||||||||||||||
| 3994 | =head2 setProviderEncryptionMode | ||||||||||||||||||||||||||||
| 3995 | |||||||||||||||||||||||||||||
| 3996 | Set encryption mode on a provider | ||||||||||||||||||||||||||||
| 3997 | |||||||||||||||||||||||||||||
| 3998 | =head2 deleteSAMLSecondarySessions | ||||||||||||||||||||||||||||
| 3999 | |||||||||||||||||||||||||||||
| 4000 | Find and delete SAML sessions bounded to a primary session | ||||||||||||||||||||||||||||
| 4001 | |||||||||||||||||||||||||||||
| 4002 | =head2 sendSLOErrorResponse | ||||||||||||||||||||||||||||
| 4003 | |||||||||||||||||||||||||||||
| 4004 | Send an SLO error response | ||||||||||||||||||||||||||||
| 4005 | |||||||||||||||||||||||||||||
| 4006 | =head2 getQueryString | ||||||||||||||||||||||||||||
| 4007 | |||||||||||||||||||||||||||||
| 4008 | Get query string with or without CGI query_string() method | ||||||||||||||||||||||||||||
| 4009 | |||||||||||||||||||||||||||||
| 4010 | =head2 getSignatureMethod | ||||||||||||||||||||||||||||
| 4011 | |||||||||||||||||||||||||||||
| 4012 | Return Lasso signature method | ||||||||||||||||||||||||||||
| 4013 | |||||||||||||||||||||||||||||
| 4014 | =head2 setProviderSignatureMethod | ||||||||||||||||||||||||||||
| 4015 | |||||||||||||||||||||||||||||
| 4016 | Set signature method on a provider | ||||||||||||||||||||||||||||
| 4017 | |||||||||||||||||||||||||||||
| 4018 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 4019 | |||||||||||||||||||||||||||||
| 4020 | L<Lemonldap::NG::Portal::Auth::SAML>, L<Lemonldap::NG::Portal::UserDBSAML> | ||||||||||||||||||||||||||||
| 4021 | |||||||||||||||||||||||||||||
| 4022 | =head1 AUTHORS | ||||||||||||||||||||||||||||
| 4023 | |||||||||||||||||||||||||||||
| 4024 | =over | ||||||||||||||||||||||||||||
| 4025 | |||||||||||||||||||||||||||||
| 4026 | =item LemonLDAP::NG team L<http://lemonldap-ng.org/team> | ||||||||||||||||||||||||||||
| 4027 | |||||||||||||||||||||||||||||
| 4028 | =back | ||||||||||||||||||||||||||||
| 4029 | |||||||||||||||||||||||||||||
| 4030 | =head1 BUG REPORT | ||||||||||||||||||||||||||||
| 4031 | |||||||||||||||||||||||||||||
| 4032 | Use OW2 system to report bug or ask for features: | ||||||||||||||||||||||||||||
| 4033 | L<https://gitlab.ow2.org/lemonldap-ng/lemonldap-ng/issues> | ||||||||||||||||||||||||||||
| 4034 | |||||||||||||||||||||||||||||
| 4035 | =head1 DOWNLOAD | ||||||||||||||||||||||||||||
| 4036 | |||||||||||||||||||||||||||||
| 4037 | Lemonldap::NG is available at | ||||||||||||||||||||||||||||
| 4038 | L<https://lemonldap-ng.org/download> | ||||||||||||||||||||||||||||
| 4039 | |||||||||||||||||||||||||||||
| 4040 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 4041 | |||||||||||||||||||||||||||||
| 4042 | See COPYING file for details. | ||||||||||||||||||||||||||||
| 4043 | |||||||||||||||||||||||||||||
| 4044 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 4045 | it under the terms of the GNU General Public License as published by | ||||||||||||||||||||||||||||
| 4046 | the Free Software Foundation; either version 2, or (at your option) | ||||||||||||||||||||||||||||
| 4047 | any later version. | ||||||||||||||||||||||||||||
| 4048 | |||||||||||||||||||||||||||||
| 4049 | This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||
| 4050 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||
| 4051 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||||||||||
| 4052 | GNU General Public License for more details. | ||||||||||||||||||||||||||||
| 4053 | |||||||||||||||||||||||||||||
| 4054 | You should have received a copy of the GNU General Public License | ||||||||||||||||||||||||||||
| 4055 | along with this program. If not, see L<http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||
| 4056 | |||||||||||||||||||||||||||||
| 4057 | =cut | ||||||||||||||||||||||||||||