| Conditions | 19 |
| Paths | 768 |
| Total Lines | 134 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 53 | public function send( |
||
| 54 | AbstractMessage $msg, |
||
| 55 | Configuration $srcMetadata, |
||
| 56 | Configuration $dstMetadata = null, |
||
| 57 | ): AbstractMessage { |
||
| 58 | $issuer = $msg->getIssuer(); |
||
| 59 | |||
| 60 | $ctxOpts = [ |
||
| 61 | 'ssl' => [ |
||
| 62 | 'capture_peer_cert' => true, |
||
| 63 | 'allow_self_signed' => true, |
||
| 64 | ], |
||
| 65 | ]; |
||
| 66 | |||
| 67 | $container = ContainerSingleton::getInstance(); |
||
| 68 | |||
| 69 | // Determine if we are going to do a MutualSSL connection between the IdP and SP - Shoaib |
||
| 70 | if ($srcMetadata->hasValue('saml.SOAPClient.certificate')) { |
||
| 71 | $cert = $srcMetadata->getValue('saml.SOAPClient.certificate'); |
||
| 72 | if ($cert !== false) { |
||
| 73 | $configUtils = new Config(); |
||
| 74 | $ctxOpts['ssl']['local_cert'] = $configUtils->getCertPath( |
||
| 75 | $srcMetadata->getString('saml.SOAPClient.certificate') |
||
| 76 | ); |
||
| 77 | if ($srcMetadata->hasValue('saml.SOAPClient.privatekey_pass')) { |
||
| 78 | $ctxOpts['ssl']['passphrase'] = $srcMetadata->getString('saml.SOAPClient.privatekey_pass'); |
||
| 79 | } |
||
| 80 | } |
||
| 81 | } else { |
||
| 82 | /* Use the SP certificate and privatekey if it is configured. */ |
||
| 83 | $cryptoUtils = new Crypto(); |
||
| 84 | $privateKey = $cryptoUtils->loadPrivateKey($srcMetadata); |
||
| 85 | $publicKey = $cryptoUtils->loadPublicKey($srcMetadata); |
||
| 86 | if ($privateKey !== null && $publicKey !== null && isset($publicKey['PEM'])) { |
||
| 87 | $keyCertData = $privateKey['PEM'] . $publicKey['PEM']; |
||
| 88 | $file = $container->getTempDir() . '/' . sha1($keyCertData) . '.pem'; |
||
| 89 | if (!file_exists($file)) { |
||
| 90 | $container->writeFile($file, $keyCertData); |
||
| 91 | } |
||
| 92 | $ctxOpts['ssl']['local_cert'] = $file; |
||
| 93 | if (isset($privateKey['password'])) { |
||
| 94 | $ctxOpts['ssl']['passphrase'] = $privateKey['password']; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // do peer certificate verification |
||
| 100 | if ($dstMetadata !== null) { |
||
| 101 | $peerPublicKeys = $dstMetadata->getPublicKeys('signing', true); |
||
| 102 | $certData = ''; |
||
| 103 | foreach ($peerPublicKeys as $key) { |
||
| 104 | if ($key['type'] !== 'X509Certificate') { |
||
| 105 | continue; |
||
| 106 | } |
||
| 107 | $certData .= "-----BEGIN CERTIFICATE-----\n" . |
||
| 108 | chunk_split($key['X509Certificate'], 64) . |
||
| 109 | "-----END CERTIFICATE-----\n"; |
||
| 110 | } |
||
| 111 | $peerCertFile = $container->getTempDir() . '/' . sha1($certData) . '.pem'; |
||
| 112 | if (!file_exists($peerCertFile)) { |
||
| 113 | $container->writeFile($peerCertFile, $certData); |
||
| 114 | } |
||
| 115 | // create ssl context |
||
| 116 | $ctxOpts['ssl']['verify_peer'] = true; |
||
| 117 | $ctxOpts['ssl']['verify_depth'] = 1; |
||
| 118 | $ctxOpts['ssl']['cafile'] = $peerCertFile; |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($srcMetadata->hasValue('saml.SOAPClient.stream_context.ssl.peer_name')) { |
||
| 122 | $ctxOpts['ssl']['peer_name'] = $srcMetadata->getString('saml.SOAPClient.stream_context.ssl.peer_name'); |
||
| 123 | } |
||
| 124 | |||
| 125 | $context = stream_context_create($ctxOpts); |
||
| 126 | |||
| 127 | $options = [ |
||
| 128 | 'uri' => $issuer?->getContent(), |
||
| 129 | 'location' => $msg->getDestination(), |
||
| 130 | 'stream_context' => $context, |
||
| 131 | ]; |
||
| 132 | |||
| 133 | if ($srcMetadata->hasValue('saml.SOAPClient.proxyhost')) { |
||
| 134 | $options['proxy_host'] = $srcMetadata->getValue('saml.SOAPClient.proxyhost'); |
||
| 135 | } |
||
| 136 | |||
| 137 | if ($srcMetadata->hasValue('saml.SOAPClient.proxyport')) { |
||
| 138 | $options['proxy_port'] = $srcMetadata->getValue('saml.SOAPClient.proxyport'); |
||
| 139 | } |
||
| 140 | |||
| 141 | $destination = $msg->getDestination(); |
||
| 142 | if ($destination === null) { |
||
| 143 | throw new Exception('Cannot send SOAP message, no destination set.'); |
||
| 144 | } |
||
| 145 | |||
| 146 | // Add soap-envelopes |
||
| 147 | $env = (new Envelope(new Body([new Chunk($msg->toXML())])))->toXML(); |
||
| 148 | $request = $env->ownerDocument?->saveXML(); |
||
| 149 | |||
| 150 | $container->debugMessage($request, 'out'); |
||
| 151 | |||
| 152 | $action = 'http://www.oasis-open.org/committees/security'; |
||
| 153 | /* Perform SOAP Request over HTTP */ |
||
| 154 | $x = new BuiltinSoapClient(null, $options); |
||
| 155 | $soapresponsexml = $x->__doRequest($request, $destination, $action, SOAP_1_1, false); |
||
| 156 | if (empty($soapresponsexml)) { |
||
| 157 | throw new Exception('Empty SOAP response, check peer certificate.'); |
||
| 158 | } |
||
| 159 | |||
| 160 | Utils::getContainer()->debugMessage($soapresponsexml, 'in'); |
||
| 161 | |||
| 162 | $dom = DOMDocumentFactory::fromString($soapresponsexml); |
||
| 163 | $env = Envelope::fromXML($dom->documentElement); |
||
| 164 | $container->debugMessage($env->toXML()->ownerDocument?->saveXML(), 'in'); |
||
| 165 | |||
| 166 | $soapfault = $this->getSOAPFault($dom); |
||
| 167 | if ($soapfault !== null) { |
||
| 168 | throw new Exception( |
||
| 169 | sprintf( |
||
| 170 | "Actor: '%s'; Message: '%s'; Code: '%s'", |
||
| 171 | $soapfault->getFaultActor()?->getContent(), |
||
| 172 | $soapfault->getFaultString()->getContent(), |
||
| 173 | $soapfault->getFaultCode()->getContent(), |
||
| 174 | ), |
||
| 175 | ); |
||
| 176 | } |
||
| 177 | |||
| 178 | // Extract the message from the response |
||
| 179 | $samlresponse = MessageFactory::fromXML($env->getBody()->getElements()[0]->toXML()); |
||
| 180 | |||
| 181 | /* Add validator to message which uses the SSL context. */ |
||
| 182 | self::addSSLValidator($samlresponse, $context); |
||
| 183 | |||
| 184 | $container->getLogger()->debug("Valid ArtifactResponse received from IdP"); |
||
| 185 | |||
| 186 | return $samlresponse; |
||
| 187 | } |
||
| 278 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths