32 assert(array_key_exists(
'QUERY_STRING',
$_SERVER));
38 $elements = explode(
'&',
$_SERVER[
'QUERY_STRING']);
39 foreach ($elements as $element) {
40 list(
$name, $value) = explode(
'=', $element, 2);
42 $value = urldecode($value);
44 if (
$name ===
'SAMLart') {
45 $artifacts[] = $value;
61 $msg =
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">' .
63 '<samlp:Request xmlns:samlp="urn:oasis:names:tc:SAML:1.0:protocol"' .
65 ' MajorVersion="1" MinorVersion="1"' .
69 foreach ($artifacts as $a) {
70 $msg .=
'<samlp:AssertionArtifact>' . htmlspecialchars($a) .
'</samlp:AssertionArtifact>';
73 $msg .=
'</samlp:Request>' .
75 '</SOAP-ENV:Envelope>';
90 assert(is_string($soapResponse));
95 throw new \SimpleSAML_Error_Exception(
'Error parsing SAML 1 artifact response.');
98 $soapEnvelope = $doc->firstChild;
99 if (!
XML::isDOMNodeOfType($soapEnvelope,
'Envelope',
'http://schemas.xmlsoap.org/soap/envelope/')) {
100 throw new \SimpleSAML_Error_Exception(
'Expected artifact response to contain a <soap:Envelope> element.');
103 $soapBody = XML::getDOMChildren($soapEnvelope,
'Body',
'http://schemas.xmlsoap.org/soap/envelope/');
104 if (count($soapBody) === 0) {
105 throw new \SimpleSAML_Error_Exception(
'Couldn\'t find <soap:Body> in <soap:Envelope>.');
107 $soapBody = $soapBody[0];
110 $responseElement = XML::getDOMChildren($soapBody,
'Response',
'urn:oasis:names:tc:SAML:1.0:protocol');
111 if (count($responseElement) === 0) {
112 throw new \SimpleSAML_Error_Exception(
'Couldn\'t find <saml1p:Response> in <soap:Body>.');
114 $responseElement = $responseElement[0];
121 $newDoc->appendChild($newDoc->importNode($responseElement,
true));
122 $responseXML = $newDoc->saveXML();
138 $artifacts = self::getArtifacts();
139 $request = self::buildRequest($artifacts);
143 $url = $idpMetadata->
getDefaultEndpoint(
'ArtifactResolutionService', array(
'urn:oasis:names:tc:SAML:1.0:bindings:SOAP-binding'));
146 $peerPublicKeys = $idpMetadata->
getPublicKeys(
'signing',
true);
148 foreach ($peerPublicKeys as
$key) {
149 if ($key[
'type'] !==
'X509Certificate') {
152 $certData .=
"-----BEGIN CERTIFICATE-----\n" .
153 chunk_split($key[
'X509Certificate'], 64) .
154 "-----END CERTIFICATE-----\n";
158 if (!file_exists($file)) {
166 'verify_peer' =>
true,
168 'local_cert' => $spKeyCertFile,
169 'capture_peer_cert' =>
true,
170 'capture_peer_chain' =>
true,
175 'header' =>
'SOAPAction: http://www.oasis-open.org/committees/security' .
"\r\n" .
176 'Content-Type: text/xml',
static generateID()
Generate a random identifier, ID_LENGTH bytes long.
static writeFile($filename, $data, $mode=0600)
Atomically write a file.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
foreach($paths as $path) $request
static getTempDir()
This function retrieves the path to a directory where temporary files can be saved.
static isDOMNodeOfType(\DOMNode $element, $name, $nsURI)
This function checks if the DOMElement has the correct localName and namespaceURI.
static getArtifacts()
Parse the query string, and extract the SAMLart parameters.
static extractResponse($soapResponse)
Extract the response element from the SOAP response.
static buildRequest(array $artifacts)
Build the request we will send to the IdP.
static generateTimestamp($instant=null)
This function generates a timestamp on the form used by the SAML protocols.
static debugSAMLMessage($message, $type)
Helper function to log SAML messages that we send or receive.
getDefaultEndpoint($endpointType, array $bindings=null, $default=self::REQUIRED_OPTION)
Find the default endpoint of the given type.
static fetch($url, $context=array(), $getHeaders=false)
Helper function to retrieve a file or URL with proxy support, also supporting proxy basic authorizati...
getPublicKeys($use=null, $required=false, $prefix='')
Get public key from metadata.
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
static getCertPath($path)
Resolves a path that may be relative to the cert-directory.