| Conditions | 20 |
| Paths | 408 |
| Total Lines | 122 |
| Code Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 23 | * |
||
| 24 | * @param \SAML2\Message $msg The request that should be sent. |
||
| 25 | * @param \SimpleSAML_Configuration $srcMetadata The metadata of the issuer of the message. |
||
| 26 | * @param \SimpleSAML_Configuration $dstMetadata The metadata of the destination of the message. |
||
| 27 | * @return \SAML2\Message The response we received. |
||
| 28 | * @throws \Exception |
||
| 29 | */ |
||
| 30 | public function send(Message $msg, SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata = null) |
||
| 31 | { |
||
| 32 | $issuer = $msg->getIssuer(); |
||
| 33 | |||
| 34 | $ctxOpts = array( |
||
| 35 | 'ssl' => array( |
||
| 36 | 'capture_peer_cert' => true, |
||
| 37 | ), |
||
| 38 | ); |
||
| 39 | |||
| 40 | // Determine if we are going to do a MutualSSL connection between the IdP and SP - Shoaib |
||
| 41 | if ($srcMetadata->hasValue('saml.SOAPClient.certificate')) { |
||
| 42 | $cert = $srcMetadata->getValue('saml.SOAPClient.certificate'); |
||
| 43 | if ($cert !== false) { |
||
| 44 | $ctxOpts['ssl']['local_cert'] = SimpleSAML_Utilities::resolveCert( |
||
| 45 | $srcMetadata->getString('saml.SOAPClient.certificate') |
||
| 46 | ); |
||
| 47 | if ($srcMetadata->hasValue('saml.SOAPClient.privatekey_pass')) { |
||
| 48 | $ctxOpts['ssl']['passphrase'] = $srcMetadata->getString('saml.SOAPClient.privatekey_pass'); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | } else { |
||
| 52 | /* Use the SP certificate and privatekey if it is configured. */ |
||
| 53 | $privateKey = SimpleSAML_Utilities::loadPrivateKey($srcMetadata); |
||
| 54 | $publicKey = SimpleSAML_Utilities::loadPublicKey($srcMetadata); |
||
| 55 | if ($privateKey !== null && $publicKey !== null && isset($publicKey['PEM'])) { |
||
| 56 | $keyCertData = $privateKey['PEM'] . $publicKey['PEM']; |
||
| 57 | $file = SimpleSAML_Utilities::getTempDir() . '/' . sha1($keyCertData) . '.pem'; |
||
| 58 | if (!file_exists($file)) { |
||
| 59 | SimpleSAML_Utilities::writeFile($file, $keyCertData); |
||
| 60 | } |
||
| 61 | $ctxOpts['ssl']['local_cert'] = $file; |
||
| 62 | if (isset($privateKey['password'])) { |
||
| 63 | $ctxOpts['ssl']['passphrase'] = $privateKey['password']; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | // do peer certificate verification |
||
| 69 | if ($dstMetadata !== null) { |
||
| 70 | $peerPublicKeys = $dstMetadata->getPublicKeys('signing', true); |
||
| 71 | $certData = ''; |
||
| 72 | foreach ($peerPublicKeys as $key) { |
||
| 73 | if ($key['type'] !== 'X509Certificate') { |
||
| 74 | continue; |
||
| 75 | } |
||
| 76 | $certData .= "-----BEGIN CERTIFICATE-----\n" . |
||
| 77 | chunk_split($key['X509Certificate'], 64) . |
||
| 78 | "-----END CERTIFICATE-----\n"; |
||
| 79 | } |
||
| 80 | $peerCertFile = SimpleSAML_Utilities::getTempDir() . '/' . sha1($certData) . '.pem'; |
||
| 81 | if (!file_exists($peerCertFile)) { |
||
| 82 | SimpleSAML_Utilities::writeFile($peerCertFile, $certData); |
||
| 83 | } |
||
| 84 | // create ssl context |
||
| 85 | $ctxOpts['ssl']['verify_peer'] = true; |
||
| 86 | $ctxOpts['ssl']['verify_depth'] = 1; |
||
| 87 | $ctxOpts['ssl']['cafile'] = $peerCertFile; |
||
| 88 | } |
||
| 89 | |||
| 90 | $context = stream_context_create($ctxOpts); |
||
| 91 | if ($context === null) { |
||
| 92 | throw new \Exception('Unable to create SSL stream context'); |
||
| 93 | } |
||
| 94 | |||
| 95 | $options = array( |
||
| 96 | 'uri' => $issuer, |
||
| 97 | 'location' => $msg->getDestination(), |
||
| 98 | 'stream_context' => $context, |
||
| 99 | ); |
||
| 100 | |||
| 101 | if ($srcMetadata->hasValue('saml.SOAPClient.proxyhost')) { |
||
| 102 | $options['proxy_host'] = $srcMetadata->getValue('saml.SOAPClient.proxyhost'); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($srcMetadata->hasValue('saml.SOAPClient.proxyport')) { |
||
| 106 | $options['proxy_port'] = $srcMetadata->getValue('saml.SOAPClient.proxyport'); |
||
| 107 | } |
||
| 108 | |||
| 109 | $x = new SoapClient(null, $options); |
||
|
|
|||
| 110 | |||
| 111 | // Add soap-envelopes |
||
| 112 | $request = $msg->toSignedXML(); |
||
| 113 | $request = self::START_SOAP_ENVELOPE . $request->ownerDocument->saveXML($request) . self::END_SOAP_ENVELOPE; |
||
| 114 | |||
| 115 | Utils::getContainer()->debugMessage($request, 'out'); |
||
| 116 | |||
| 117 | $action = 'http://www.oasis-open.org/committees/security'; |
||
| 118 | $version = '1.1'; |
||
| 119 | $destination = $msg->getDestination(); |
||
| 120 | |||
| 121 | /* Perform SOAP Request over HTTP */ |
||
| 122 | $soapresponsexml = $x->__doRequest($request, $destination, $action, $version); |
||
| 123 | if ($soapresponsexml === null || $soapresponsexml === "") { |
||
| 124 | throw new \Exception('Empty SOAP response, check peer certificate.'); |
||
| 125 | } |
||
| 126 | |||
| 127 | Utils::getContainer()->debugMessage($soapresponsexml, 'in'); |
||
| 128 | |||
| 129 | // Convert to SAML2\Message (\DOMElement) |
||
| 130 | try { |
||
| 131 | $dom = DOMDocumentFactory::fromString($soapresponsexml); |
||
| 132 | } catch (RuntimeException $e) { |
||
| 133 | throw new \Exception('Not a SOAP response.', 0, $e); |
||
| 134 | } |
||
| 135 | |||
| 136 | $soapfault = $this->getSOAPFault($dom); |
||
| 137 | if (isset($soapfault)) { |
||
| 138 | throw new \Exception($soapfault); |
||
| 139 | } |
||
| 140 | //Extract the message from the response |
||
| 141 | $samlresponse = Utils::xpQuery($dom->firstChild, '/soap-env:Envelope/soap-env:Body/*[1]'); |
||
| 142 | $samlresponse = Message::fromXML($samlresponse[0]); |
||
| 143 | |||
| 144 | /* Add validator to message which uses the SSL context. */ |
||
| 145 | self::addSSLValidator($samlresponse, $context); |
||
| 246 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.