31 {
33
34 $ctxOpts = array(
35 'ssl' => array(
36 'capture_peer_cert' => true,
37 'allow_self_signed' => true
38 ),
39 );
40
41
42 if ($srcMetadata->
hasValue(
'saml.SOAPClient.certificate')) {
43 $cert = $srcMetadata->
getValue(
'saml.SOAPClient.certificate');
44 if ($cert !== false) {
46 $srcMetadata->
getString(
'saml.SOAPClient.certificate')
47 );
48 if ($srcMetadata->
hasValue(
'saml.SOAPClient.privatekey_pass')) {
49 $ctxOpts[
'ssl'][
'passphrase'] = $srcMetadata->
getString(
'saml.SOAPClient.privatekey_pass');
50 }
51 }
52 } else {
53
56 if ($privateKey !== null && $publicKey !== null && isset($publicKey['PEM'])) {
57 $keyCertData = $privateKey['PEM'] . $publicKey['PEM'];
59 if (!file_exists($file)) {
61 }
62 $ctxOpts['ssl']['local_cert'] = $file;
63 if (isset($privateKey['password'])) {
64 $ctxOpts['ssl']['passphrase'] = $privateKey['password'];
65 }
66 }
67 }
68
69
70 if ($dstMetadata !== null) {
71 $peerPublicKeys = $dstMetadata->
getPublicKeys(
'signing',
true);
72 $certData = '';
73 foreach ($peerPublicKeys as
$key) {
74 if (
$key[
'type'] !==
'X509Certificate') {
75 continue;
76 }
77 $certData .= "-----BEGIN CERTIFICATE-----\n" .
78 chunk_split(
$key[
'X509Certificate'], 64) .
79 "-----END CERTIFICATE-----\n";
80 }
82 if (!file_exists($peerCertFile)) {
84 }
85
86 $ctxOpts['ssl']['verify_peer'] = true;
87 $ctxOpts['ssl']['verify_depth'] = 1;
88 $ctxOpts['ssl']['cafile'] = $peerCertFile;
89 }
90
91 if ($srcMetadata->
hasValue(
'saml.SOAPClient.stream_context.ssl.peer_name')) {
92 $ctxOpts[
'ssl'][
'peer_name'] = $srcMetadata->
getString(
'saml.SOAPClient.stream_context.ssl.peer_name');
93 }
94
95 $context = stream_context_create($ctxOpts);
97 throw new \Exception('Unable to create SSL stream context');
98 }
99
102 'location' => $msg->getDestination(),
104 );
105
106 if ($srcMetadata->
hasValue(
'saml.SOAPClient.proxyhost')) {
107 $options[
'proxy_host'] = $srcMetadata->
getValue(
'saml.SOAPClient.proxyhost');
108 }
109
110 if ($srcMetadata->
hasValue(
'saml.SOAPClient.proxyport')) {
111 $options[
'proxy_port'] = $srcMetadata->
getValue(
'saml.SOAPClient.proxyport');
112 }
113
115
116
119
121
122 $action =
'http://www.oasis-open.org/committees/security';
125
126
128 if ($soapresponsexml === null || $soapresponsexml === "") {
129 throw new \Exception('Empty SOAP response, check peer certificate.');
130 }
131
133
134
135 try {
137 } catch (RuntimeException $e) {
138 throw new \Exception('Not a SOAP response.', 0, $e);
139 }
140
142 if (isset($soapfault)) {
143 throw new \Exception($soapfault);
144 }
145
146 $samlresponse =
Utils::xpQuery($dom->firstChild,
'/soap-env:Envelope/soap-env:Body/*[1]');
148
149
151
153
154 return $samlresponse;
155 }
catch(Exception $e) if(!($request instanceof \SAML2\ArtifactResolve)) $issuer
foreach($paths as $path) $request
static fromXML(\DOMElement $xml)
Convert an XML element into a message.
getSOAPFault($soapMessage)
static addSSLValidator(Message $msg, $context)
Add a signature validator based on a SSL context.
getString($name, $default=self::REQUIRED_OPTION)
This function retrieves a string configuration option.
getValue($name, $default=null)
Retrieve a configuration option set in config.php.
getPublicKeys($use=null, $required=false, $prefix='')
Get public key from metadata.
hasValue($name)
Check whether a key in the configuration exists or not.
static loadPrivateKey(SimpleSAML_Configuration $metadata, $required=false, $prefix='')
static loadPublicKey(SimpleSAML_Configuration $metadata, $required=false, $prefix='')
static resolveCert($path)
static writeFile($filename, $data, $mode=0600)