66 assert(is_string(
$xml));
71 throw new \Exception(
'Unable to parse AuthnResponse XML.');
89 if ($this->messageValidated) {
95 $this->validator =
new Validator($this->dom, array(
'ResponseID',
'AssertionID'));
104 $publicKeys = $md->getPublicKeys(
'signing');
105 if (!empty($publicKeys)) {
106 $certFingerprints = array();
107 foreach ($publicKeys as
$key) {
108 if ($key[
'type'] !==
'X509Certificate') {
111 $certFingerprints[] = sha1(base64_decode($key[
'X509Certificate']));
113 $this->validator->validateFingerprint($certFingerprints);
114 } elseif ($md->hasValue(
'certFingerprint')) {
115 $certFingerprints = $md->getArrayizeString(
'certFingerprint');
118 $this->validator->validateFingerprint($certFingerprints);
119 } elseif ($md->hasValue(
'caFile')) {
123 throw new \SimpleSAML_Error_Exception(
'Missing certificate in Shibboleth 1.3 IdP Remote metadata for identity provider [' .
$issuer .
'].');
138 if ($this->messageValidated) {
143 if ($this->validator === null) {
149 $node = dom_import_simplexml($node);
152 assert($node instanceof
DOMNode);
154 return $this->validator->isNodeValidated($node);
168 assert(is_string(
$query));
171 if ($node === null) {
172 $node = $this->dom->documentElement;
175 assert($node instanceof
DOMNode);
177 $xPath = new \DOMXpath($this->dom);
178 $xPath->registerNamespace(
'shibp', self::SHIB_PROTOCOL_NS);
179 $xPath->registerNamespace(
'shib', self::SHIB_ASSERT_NS);
181 return $xPath->query(
$query, $node);
193 $query =
'/shibp:Response/shib:Assertion/shib:AuthnStatement';
195 if ($node = $nodelist->item(0)) {
196 return $node->getAttribute(
'SessionIndex');
203 public function getAttributes()
207 $base64 = isset($md[
'base64attributes']) ? $md[
'base64attributes'] :
false;
215 $assertions = $this->
doXPathQuery(
'/shibp:Response/shib:Assertion');
217 foreach ($assertions as $assertion) {
219 throw new \Exception(
'Shib13 AuthnResponse contained an unsigned assertion.');
222 $conditions = $this->
doXPathQuery(
'shib:Conditions', $assertion);
223 if ($conditions && $conditions->length > 0) {
224 $condition = $conditions->item(0);
226 $start = $condition->getAttribute(
'NotBefore');
227 $end = $condition->getAttribute(
'NotOnOrAfter');
230 if (!self::checkDateConditions(
$start,
$end)) {
237 $attribute_nodes = $this->
doXPathQuery(
'shib:AttributeStatement/shib:Attribute/shib:AttributeValue', $assertion);
239 foreach ($attribute_nodes as $attribute) {
240 $value = $attribute->textContent;
241 $name = $attribute->parentNode->getAttribute(
'AttributeName');
243 if ($attribute->hasAttribute(
'Scope')) {
244 $scopePart =
'@' . $attribute->getAttribute(
'Scope');
249 if (!is_string(
$name)) {
250 throw new \Exception(
'Shib13 Attribute node without an AttributeName.');
258 $encodedvalues = explode(
'_', $value);
259 foreach ($encodedvalues as $v) {
274 $query =
'/shibp:Response/shib:Assertion/@Issuer';
277 if ($attr = $nodelist->item(0)) {
280 throw new \Exception(
'Could not find Issuer field in Authentication response');
288 $query =
'/shibp:Response/shib:Assertion/shib:AuthenticationStatement/shib:Subject/shib:NameIdentifier';
291 if ($node = $nodelist->item(0)) {
292 $nameID[
"Value"] = $node->nodeValue;
293 $nameID[
"Format"] = $node->getAttribute(
'Format');
311 assert(is_string($shire));
314 if ($sp->
hasValue(
'scopedattributes')) {
315 $scopedAttributes = $sp->
getArray(
'scopedattributes');
316 } elseif ($idp->
hasValue(
'scopedattributes')) {
317 $scopedAttributes = $idp->
getArray(
'scopedattributes');
319 $scopedAttributes = array();
336 $base64 = $sp->
getBoolean(
'base64attributes',
false);
343 ' Format="urn:mace:shibboleth:1.0:nameIdentifier"' .
344 ' NameQualifier="' . htmlspecialchars($namequalifier) .
'"' .
347 '</NameIdentifier>' .
348 '<SubjectConfirmation>' .
349 '<ConfirmationMethod>' .
350 'urn:oasis:names:tc:SAML:1.0:cm:bearer' .
351 '</ConfirmationMethod>' .
352 '</SubjectConfirmation>' .
355 $encodedattributes =
'';
358 $encodedattributes .=
'<AttributeStatement>';
359 $encodedattributes .= $subjectNode;
362 $encodedattributes .= $this->
enc_attribute(
$name, $value, $base64, $scopedAttributes);
365 $encodedattributes .=
'</AttributeStatement>';
371 $response =
'<Response xmlns="urn:oasis:names:tc:SAML:1.0:protocol" 372 xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion" 373 xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 374 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" IssueInstant="' . $issueInstant.
'" 375 MajorVersion="1" MinorVersion="1" 376 Recipient="' . htmlspecialchars($shire) .
'" ResponseID="' .
$id .
'"> 378 <StatusCode Value="samlp:Success" /> 380 <Assertion xmlns="urn:oasis:names:tc:SAML:1.0:assertion" 381 AssertionID="' . $assertionid .
'" IssueInstant="' . $issueInstant.
'" 382 Issuer="' . htmlspecialchars($idp->
getString(
'entityid')) .
'" MajorVersion="1" MinorVersion="1"> 383 <Conditions NotBefore="' . $notBefore.
'" NotOnOrAfter="'. $assertionExpire .
'"> 384 <AudienceRestrictionCondition> 385 <Audience>' . htmlspecialchars($audience) .
'</Audience> 386 </AudienceRestrictionCondition> 388 <AuthenticationStatement AuthenticationInstant="' . $issueInstant.
'" 389 AuthenticationMethod="urn:oasis:names:tc:SAML:1.0:am:unspecified">' .
391 </AuthenticationStatement> 392 ' . $encodedattributes .
' 411 assert(is_string(
$name));
413 assert(is_bool($base64));
414 assert(is_array($scopedAttributes));
416 if (in_array(
$name, $scopedAttributes,
true)) {
422 $attr =
'<Attribute AttributeName="' . htmlspecialchars(
$name) .
'" AttributeNamespace="urn:mace:shibboleth:1.0:attributeNamespace:uri">';
426 $tmp = explode(
'@', $value, 2);
427 if (count($tmp) === 2) {
429 $scopePart =
' Scope="' . htmlspecialchars($tmp[1]) .
'"';
434 $value = base64_encode($value);
437 $attr .=
'<AttributeValue' . $scopePart .
'>' . htmlspecialchars($value) .
'</AttributeValue>';
439 $attr .=
'</Attribute>';
463 $currentTime = time();
468 if (($startTime < 0) || (($startTime - 600) > $currentTime)) {
474 if (($endTime < 0) || ($endTime <= $currentTime)) {
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
generate(\SimpleSAML_Configuration $idp, \SimpleSAML_Configuration $sp, $shire, $attributes)
Build a authentication response.
getArray($name, $default=self::REQUIRED_OPTION)
This function retrieves an array configuration option.
isNodeValidated($node)
Checks if the given node is validated by the signature on this response.
hasValue($name)
Check whether a key in the configuration exists or not.
if(!array_key_exists('StateId', $_REQUEST)) $id
enc_attribute($name, $values, $base64, $scopedAttributes)
Format a shib13 attribute.
setMessageValidated($messageValidated)
Set whether this message was validated externally.
$metadata['__DYNAMIC:1__']
static generateTimestamp($instant=null)
This function generates a timestamp on the form used by the SAML protocols.
getBoolean($name, $default=self::REQUIRED_OPTION)
This function retrieves a boolean configuration option.
if(array_key_exists('yes', $_REQUEST)) $attributes
catch(Exception $e) if(!($request instanceof \SAML2\ArtifactResolve)) $issuer
static xsDateTimeToTimestamp($time)
This function converts a SAML2 timestamp on the form yyyy-mm-ddThh:mm:ss(.s+)?Z to a UNIX timestamp...
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
static checkDateConditions($start=null, $end=null)
Check if we are currently between the given date & time conditions.
static getCertPath($path)
Resolves a path that may be relative to the cert-directory.
setRelayState($relayState)
getSessionIndex()
Retrieve the session index of this response.
doXPathQuery($query, $node=null)
This function runs an xPath query on this authentication response.