<commit_before><?php
/**
 * Implementation of the SAML 2.0 SOAP binding.
 *
 * @author <NAME>
 * @package simpleSAMLphp
 * @version $Id$
 */
class SAML2_SOAPClient {

	const START_SOAP_ENVELOPE = '<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Header/><soap-env:Body>';
	const END_SOAP_ENVELOPE = '</soap-env:Body></soap-env:Envelope>';

	/**
	 * This function sends the SOAP message to the service location and returns SOAP response
	 *
	 * @param SAML2_Message $m  The request that should be sent.
	 * @param SimpleSAML_Configuration $srcMetadata  The metadata of the issuer of the message.
	 * @param SimpleSAML_Configuration $dstMetadata  The metadata of the destination of the message.
	 * @return SAML2_Message  The response we received.
	 */
	public function send(SAML2_Message $msg, SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata = NULL) {

		$issuer = $msg->getIssuer();

		$options = array(
			'uri' => $issuer,
			'location' => $msg->getDestination(),
		);

		// Determine if we are going to do a MutualSSL connection between the IdP and SP  - Shoaib
		if ($srcMetadata->hasValue('saml.SOAPClient.certificate')) {
			$options['local_cert'] = SimpleSAML_Utilities::resolveCert($srcMetadata->getString('saml.SOAPClient.certificate'));
			if ($srcMetadata->hasValue('saml.SOAPClient.privatekey_pass')) {
				$options['passphrase'] = $srcMetadata->getString('saml.SOAPClient.privatekey_pass');
			}
		} else {
			/* Use the SP certificate and privatekey if it is configured. */
			$privateKey = SimpleSAML_Utilities::loadPrivateKey($srcMetadata);
			$publicKey = SimpleSAML_Utilities::loadPublicKey($srcMetadata);
			if ($privateKey !== NULL && $publicKey !== NULL && isset($publicKey['PEM'])) {
				$keyCertData = $privateKey['PEM'] . $publicKey['PEM'];
				$file = SimpleSAML_Utilities::getTempDir() . '/' . sha1($keyCertData) . '.pem';
				if (!file_exists($file)) {
					SimpleSAML_Utilities::writeFile($file, $keyCertData);
				}
				$options['local_cert'] = $file;
				if (isset($privateKey['password'])) {
					$options['passphrase'] = $privateKey['password'];
				}
			}
		}

		// do peer certificate verification
		if ($dstMetadata !== NULL) {
			$peerPublicKey = SimpleSAML_Utilities::loadPublicKey($dstMetadata, TRUE);
			$certData = $peerPublicKey['PEM'];
			$peerCertFile = SimpleSAML_Utilities::getTempDir() . '/' . sha1($certData) . '.pem';
			if (!file_exists($peerCertFile)) {
				SimpleSAML_Utilities::writeFile($peerCertFile, $certData);
			}
			// create ssl context
			$ctxOpts = array(
				'ssl' => array(
					'verify_peer' => TRUE,
					'verify_depth' => 1,
					'cafile' => $peerCertFile
					));
			if (isset($options['local_cert'])) {
				$ctxOpts['ssl']['local_cert'] = $options['local_cert'];
				unset($options['local_cert']);
			}
			if (isset($options['passhprase'])) {
				$ctxOpts['ssl']['passphrase'] = $options['passphrase'];
				unset($options['passphrase']);
			}
			$context = stream_context_create($ctxOpts);<commit_msg>SOAPClient: Support for multiple signing certificates.<commit_after><?php
/**
 * Implementation of the SAML 2.0 SOAP binding.
 *
 * @author <NAME>
 * @package simpleSAMLphp
 * @version $Id$
 */
class SAML2_SOAPClient {

	const START_SOAP_ENVELOPE = '<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"><soap-env:Header/><soap-env:Body>';
	const END_SOAP_ENVELOPE = '</soap-env:Body></soap-env:Envelope>';

	/**
	 * This function sends the SOAP message to the service location and returns SOAP response
	 *
	 * @param SAML2_Message $m  The request that should be sent.
	 * @param SimpleSAML_Configuration $srcMetadata  The metadata of the issuer of the message.
	 * @param SimpleSAML_Configuration $dstMetadata  The metadata of the destination of the message.
	 * @return SAML2_Message  The response we received.
	 */
	public function send(SAML2_Message $msg, SimpleSAML_Configuration $srcMetadata, SimpleSAML_Configuration $dstMetadata = NULL) {

		$issuer = $msg->getIssuer();

		$options = array(
			'uri' => $issuer,
			'location' => $msg->getDestination(),
		);

		// Determine if we are going to do a MutualSSL connection between the IdP and SP  - Shoaib
		if ($srcMetadata->hasValue('saml.SOAPClient.certificate')) {
			$options['local_cert'] = SimpleSAML_Utilities::resolveCert($srcMetadata->getString('saml.SOAPClient.certificate'));
			if ($srcMetadata->hasValue('saml.SOAPClient.privatekey_pass')) {
				$options['passphrase'] = $srcMetadata->getString('saml.SOAPClient.privatekey_pass');
			}
		} else {
			/* Use the SP certificate and privatekey if it is configured. */
			$privateKey = SimpleSAML_Utilities::loadPrivateKey($srcMetadata);
			$publicKey = SimpleSAML_Utilities::loadPublicKey($srcMetadata);
			if ($privateKey !== NULL && $publicKey !== NULL && isset($publicKey['PEM'])) {
				$keyCertData = $privateKey['PEM'] . $publicKey['PEM'];
				$file = SimpleSAML_Utilities::getTempDir() . '/' . sha1($keyCertData) . '.pem';
				if (!file_exists($file)) {
					SimpleSAML_Utilities::writeFile($file, $keyCertData);
				}
				$options['local_cert'] = $file;
				if (isset($privateKey['password'])) {
					$options['passphrase'] = $privateKey['password'];
				}
			}
		}

		// do peer certificate verification
		if ($dstMetadata !== NULL) {
			$peerPublicKeys = $dstMetadata->getPublicKeys('signing', TRUE);
			$certData = '';
			foreach ($peerPublicKeys as $key) {
				if ($key['type'] !== 'X509Certificate') {
					continue;
				}
				$certData .= "-----BEGIN CERTIFICATE-----\n" .
					chunk_split($key['X509Certificate'], 64) .
					"-----END CERTIFICATE-----\n";
			}
			$peerCertFile = SimpleSAML_Utilities::getTempDir() . '/' . sha1($certData) . '.pem';
			if (!file_exists($peerCertFile)) {
				SimpleSAML_Utilities::writeFile($peerCertFile, $certData);
			}
			// create ssl context
			$ctxOpts = array(
				'ssl' => array(
					'verify_peer' => TRUE,
					'verify_depth' => 1,
					'cafile' => $peerCertFile
					));
			if (isset($options['local_cert'])) {
				$ctxOpts['ssl']['local_cert'] = $options['local_cert'];
				unset($options['local_cert']);
			}
			if (isset($options['passhprase'])) {
				$ctxOpts['ssl']['passphrase'] = $options['passphrase'];
				unset($options['passphrase']);
			}
			$context = stream_context_create($ctxOpts);
{'fraction_non_alphanumeric': 0.16293021787180298, 'fraction_numerical': 0.004104831070413641, 'mean_word_length': 4.355029585798817, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5076021', 'n_tokens_mistral': 2353, 'n_tokens_neox': 2031, 'n_words': 414}