Gets a stream context set up for SSL
using our PEM file and passphrase

@return resource
970192
protected function getStreamContext()
    {
        $ctx = stream_context_create();

        stream_context_set_option($ctx, "ssl", "local_cert", $this->pem);
        if (strlen($this->passphrase)) {
            stream_context_set_option($ctx, "ssl", "passphrase", $this->passphrase);
        }

        return $ctx;
    }
47266
protected function proxy() {
        if (!$this->context) {
            $this->context = new PublicKeyContext($this->version, $this->solution['sid']);
        }

        return $this->context;
    }
649942
public function getFileStream() {
		$stream = new \FAL\FileStream();
		$pt = $stream->getProtocolName();
		file_put_contents($path = $pt.'://'.$this->file,$this->getContent());
		return $path;
	}
175073
private function getMasterKey()
    {
        if (!$this->masterKey) {
            $certificatePath = 'file://'.$this->masterKeyData['cert_file'];
            $passPhrase = $this->masterKeyData['passphrase'];

            $this->masterKey = openssl_pkey_get_private($certificatePath, $passPhrase);
            if (!$this->masterKey) {
                throw new EncryptionException('Could not open master encryption key');
            }
        }
        return $this->masterKey;
    }
476373
public static function loadPrivate($pem, $passphrase = '')
    {
        if (!is_string($pem)) {
            throw new \InvalidArgumentException();
        }

        if (!is_string($passphrase)) {
            throw new \InvalidArgumentException();
        }

        /// @FIXME support passphrase-protected EdDSA private keys.
        if ($passphrase !== '') {
            throw new \RuntimeException();
        }

        if (strncmp($pem, 'file://', 7) === 0) {
            $key = file_get_contents(substr($pem, 7));
        } else {
            $key = $pem;
        }

        $header = '-----BEGIN OPENSSH PRIVATE KEY-----';
        $footer = '-----END OPENSSH PRIVATE KEY-----';
        if (strncmp($key, $header, strlen($header)) !== 0) {
            throw new \InvalidArgumentException();
        } elseif (substr($key, -strlen($footer)) !== $footer) {
            throw new \InvalidArgumentException();
        }
        $key = base64_decode(substr($key, strlen($header), -strlen($footer)));

        if (strncmp($key, static::AUTH_MAGIC, strlen(static::AUTH_MAGIC))) {
            throw new \InvalidArgumentException();
        }

        $decoder = new \fpoirotte\Pssht\Wire\Decoder();
        $decoder->getBuffer()->push(substr($key, strlen(static::AUTH_MAGIC)));

        $ciphername = $decoder->decodeString();

        /// @FIXME support encrypted private keys
        if ($ciphername !== 'none') {
            throw new \InvalidArgumentException();
        }

        $kdfname    = $decoder->decodeString();
        $kdfoptions = $decoder->decodeString();
        $numKeys    = $decoder->decodeUint32();
        $publicKey  = array();

        // Block malicious inputs
        if ($numKeys <= 0 || $numKeys >= 0x80000000) {
            throw new \InvalidArgumentException();
        }

        for ($i = 0; $i < $numKeys; $i++) {
            $tmp = new \fpoirotte\Pssht\Wire\Decoder();
            $tmp->getBuffer()->push($decoder->decodeString());

            // Reject unknown key identifiers
            if ($tmp->decodeString() !== static::getName()) {
                continue;
            }

            $publicKey[$i] = $tmp->decodeString();
        }

        $tmp = new \fpoirotte\Pssht\Wire\Decoder();
        $tmp->getBuffer()->push($decoder->decodeString());

        // Both "checkint" fields must have the same value.
        if ($tmp->decodeUint32() !== $tmp->decodeUint32()) {
            throw new \InvalidArgumentException();
        }

        // Reject unknown identifiers.
        if ($tmp->decodeString() !== static::getName()) {
            throw new \InvalidArgumentException();
        }

        // Discard public key blob (duplicate).
        $tmp->decodeString();

        $secretKey = array();
        for ($i = 0; $i < $numKeys; $i++) {
            $secretKey[$i] = $tmp->decodeString();
            // Discard comment field.
            $tmp->decodeString();
        }

        // Should we also ensure that a correct padding
        // has been applied?

        $pk = reset($publicKey);
        if (!isset($secretKey[key($publicKey)])) {
            throw new \InvalidArgumentException();
        }
        $sk = $secretKey[key($publicKey)];

        return new static($pk, $sk);
    }
1146215
public function getWebfilesAsStream()
	{
		$client = $this->getClientWithToken();
		$service = new Google_Service_Calendar($client);

		// Print the next 10 events on the user's calendar.
		$optParams = array(
			'maxResults' => 5,
			'orderBy' => 'startTime',
			'singleEvents' => TRUE,
			'timeMin' => date('c'),
		);
		$results = $service->events->listEvents($this->m_sCalendarId, $optParams);


		$webfiles = array();

		foreach ($results->getItems() as $event) {

			$webfile = $this->toWebfileEvent($event);
			array_push($webfiles, $webfile);
		}

		return new MWebfileStream($webfiles);
	}
168253
protected function proxy() {
        if (!$this->context) {
            $this->context = new SyncMapContext(
                $this->version,
                $this->solution['serviceSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
105175
protected function buildStreamContext()
    {
        $opts = [];

        // If we have a logger defined, merge the context options from our logger with the context array
        if ($this->logQueries() && $logger = $this->logger()) {
            $opts['mongodb'] = $logger->getContext();
        }

        $context = stream_context_create($opts);
        return ['context' => $context];
    }
280101
function getContents()
    {
        if (!$this->isReadable())
            throw new \RuntimeException('Stream is not readable.');

        $content = '';
        while (!$this->eof()) {
            $buf = $this->read(1048576);
            // match on '' and false by loose equal
            if ($buf == null)
                break;

            $content .= $buf;
        }

        return $content;
    }
860587
public function applyContextToStream()
	{
		$retval = false;

		if ($this->fh)
		{
			// Capture PHP errors
			$php_errormsg = 'Unknown error setting context option';
			$track_errors = ini_get('track_errors');
			ini_set('track_errors', true);
			$retval = @stream_context_set_option($this->fh, $this->contextOptions);

			if (!$retval)
			{
				throw new \RuntimeException($php_errormsg);
			}

			// Restore error tracking to what it was before
			ini_set('track_errors', $track_errors);
		}

		return $retval;
	}
796037
protected StreamContext getStreamContext() {
    StreamContext context = new StreamContext();
    solrClientCache = new SparkSolrClientCache(cloudSolrClient, httpSolrClient);
    context.setSolrClientCache(solrClientCache);
    return context;
  }
214202
public function getIsSecureConnection()
    {
        return isset($this->swooleRequest->server['HTTPS']) && (strcasecmp($this->swooleRequest->server['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1)
            || isset($this->swooleRequest->server['HTTP_X_FORWARDED_PROTO']) && strcasecmp($this->swooleRequest->server['HTTP_X_FORWARDED_PROTO'], 'https') === 0;
    }
541108
def get_ssl_context(private_key, certificate):
    
    if (
        certificate
        and os.path.isfile(certificate)
        and private_key
        and os.path.isfile(private_key)
    ):
        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
        context.load_cert_chain(certificate, private_key)
        return context
    return None
308731
def get_kafka_ssl_context():
    
    # NOTE: We assume that Kafka environment variables are present. If using
    # Apache Kafka on Heroku, they will be available in your app configuration.
    #
    # 1. Write the PEM certificates necessary for connecting to the Kafka brokers to physical
    # files.  The broker connection SSL certs are passed in environment/config variables and
    # the python and ssl libraries require them in physical files.  The public keys are written
    # to short lived NamedTemporaryFile files; the client key is encrypted before writing to
    # the short lived NamedTemporaryFile
    #
    # 2. Create and return an SSLContext for connecting to the Kafka brokers referencing the
    # PEM certificates written above
    #

    # stash the kafka certs in named temporary files for loading into SSLContext.  Initialize the
    # SSLContext inside the with so when it goes out of scope the files are removed which has them
    # existing for the shortest amount of time.  As extra caution password
    # protect/encrypt the client key
    with NamedTemporaryFile(suffix='.crt') as cert_file, \
         NamedTemporaryFile(suffix='.key') as key_file, \
         NamedTemporaryFile(suffix='.crt') as trust_file:
        cert_file.write(os.environ['KAFKA_CLIENT_CERT'].encode('utf-8'))
        cert_file.flush()

        # setup cryptography to password encrypt/protect the client key so it's not in the clear on
        # the filesystem.  Use the generated password in the call to load_cert_chain
        passwd = standard_b64encode(os.urandom(33))
        private_key = serialization.load_pem_private_key(
            os.environ['KAFKA_CLIENT_CERT_KEY'].encode('utf-8'),
            password=None,
            backend=default_backend()
        )
        pem = private_key.private_bytes(
            encoding=serialization.Encoding.PEM,
            format=serialization.PrivateFormat.PKCS8,
            encryption_algorithm=serialization.BestAvailableEncryption(passwd)
        )
        key_file.write(pem)
        key_file.flush()

        trust_file.write(os.environ['KAFKA_TRUSTED_CERT'].encode('utf-8'))
        trust_file.flush()

        # create an SSLContext for passing into the kafka provider using the create_default_context
        # function which creates an SSLContext with protocol set to PROTOCOL_SSLv23, OP_NO_SSLv2,
        # and OP_NO_SSLv3 when purpose=SERVER_AUTH.
        ssl_context = ssl.create_default_context(
            purpose=ssl.Purpose.SERVER_AUTH, cafile=trust_file.name)
        ssl_context.load_cert_chain(cert_file.name, keyfile=key_file.name, password=passwd)

        # Intentionally disabling hostname checking.  The Kafka cluster runs in the cloud and Apache
        # Kafka on Heroku doesn't currently provide stable hostnames.  We're pinned to a specific certificate
        # for this connection even though the certificate doesn't include host information.  We rely
        # on the ca trust_cert for this purpose.
        ssl_context.check_hostname = False

    return ssl_context
733987
protected function proxy() {
        if (!$this->context) {
            $this->context = new MediaContext(
                $this->version,
                $this->solution['accountSid'],
                $this->solution['messageSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
311348
private SslContext buildSslContext() throws Exception {
        keyAndCertificateFactory().buildAndSaveCertificates();

        return SslContextBuilder.forServer(
            keyAndCertificateFactory().mockServerPrivateKey(),
            // do we need this password??
            ConfigurationProperties.javaKeyStorePassword(),
            new X509Certificate[]{
                keyAndCertificateFactory().mockServerX509Certificate(),
                keyAndCertificateFactory().mockServerCertificateAuthorityX509Certificate()
            }
        ).build();
    }
124792
private function getTokenStream(): TokenStream
    {
        if (null === $this->tokens) {
            $this->tokens = new TokenStream(file_get_contents($this->filename));
        }

        return $this->tokens;
    }