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

@return resource
771195
protected function getStreamContext()
    {
        $pem = $this->pemPath;
        $passphrase = $this->passphrase;

        // Create cache pem file if needed
        if (!empty($this->pemContent)) {
            $filename = $this->cachedir . self::APNS_CERTIFICATE_FILE;

            $fs = new Filesystem();
            $fs->mkdir(dirname($filename));
            file_put_contents($filename, $this->pemContent);

            // Now we use this file as pem
            $pem = $filename;
            $passphrase = $this->pemContentPassphrase;
        }

        $ctx = stream_context_create();
        stream_context_set_option($ctx, "ssl", "local_cert", $pem);
        if (strlen($passphrase)) {
            stream_context_set_option($ctx, "ssl", "passphrase", $passphrase);
        }

        return $ctx;
    }
322170
def getContextFactory(path):
    
    with path.child("client.pem").open() as pemFile:
        cert = PrivateCertificate.loadPEM(pemFile.read())

    certOptions = cert.options() # TODO: verify server cert (see #1)
    certOptions.method = SSL.SSLv23_METHOD
    ctxFactory = SecureCiphersContextFactory(certOptions)
    return ctxFactory
611580
public function connect()
    {
        $sslContext = stream_context_create([
            'ssl' => [
                'allow_self_signed' => true,
                'verify_peer'       => true,
                'verify_peer_name'  => false,
                'cafile'            => $this->serverCertificate,
                'local_cert'        => $this->localCertificate,
                'local_pk'          => $this->privateKey,
                'passphrase'        => $this->privateKeyPass,
                'crypto_method'     => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
            ]
        ]);

        set_error_handler(function ($err_severity, $err_msg) {
            throw new RuntimeException($err_msg);
        });

        $this->_connection = stream_socket_client("tls://{$this->host}:{$this->port}",
            $errno,
            $errstr,
            30,
            STREAM_CLIENT_CONNECT,
            $sslContext
        );
        restore_error_handler();

        if ( ! $this->_connection) {
            throw new RuntimeException('Could not connect to host: '
                . $this->host
                . ', port:' . $this->port
                . "(Error $errno: $errstr)");
        }

        stream_set_blocking($this->_connection, true);
    }
822469
protected function streamContextArray()
    {
        return [
            'http' => [
                // direct connection properties
                'method'           => $this->method,
                'header'           => $this->header,
                'content'          => $this->content,
                'protocol_version' => $this->protocolVersion,

                // options
                'ignore_errors'    => $this->getOption('ignore_errors'),
                'follow_location'  => $this->getOption('max_redirects') > 0,
                'max_redirects'    => $this->getOption('max_redirects') + 1,
                'timeout'          => $this->timeout === -1 ? 30 : $this->timeout
            ],
            'ssl' => [
                'verify_peer' => $this->getOption('verify_peer'),
                'verify_host' => $this->getOption('verify_host'),
            ]
        ];

    }
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];
    }
1238525
public static function GetCurrentProtocol () {
		$https_flag = (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') || (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off');
		return $https_flag ? 'https' : 'http';
	}
608782
function getStream()
    {
        if ($err = $this->getError() !== UPLOAD_ERR_OK)
            // TODO Handle Upload With Exception Error
            throw new \RuntimeException(sprintf(
                'Cannot retrieve stream due to upload error. error: (%s).'
                , getUploadErrorMessageFromCode($err)
            ));

        if ($this->isFileMoved)
            throw new \RuntimeException('Cannot retrieve stream after it has already been moved');

        if ($this->stream)
            return $this->stream;

        $givenFileResource = $this->_c_givenResource;
        if (!$givenFileResource instanceof StreamInterface)
            $givenFileResource = new Stream($givenFileResource, 'r');
        
        return $this->stream = $givenFileResource;
    }
234221
public function chanContext()
    {
        try
        {
            return $this->getSNMP()->walk1d( self::OID_ASTERISK_CHANNEL_CONTEXT );
        }
        catch( \Cityware\Snmp\Exception $e )
        {
            return null;
        }
    }
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;
    }
1089010
public function clientSideCert($cert, $key, $passphrase = null, $encoding = 'PEM')
    {
        $this->client_cert          = $cert;
        $this->client_key           = $key;
        $this->client_passphrase    = $passphrase;
        $this->client_encoding      = $encoding;

        return $this;
    }
517902
private function getStreamSocketClient()
    {
        $stream_socket_client = stream_socket_client(
            $this->params['endpoint'],
            $errno,
            $errstr,
            30,
            STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT,
            $this->getStreamContext()
        );

        if ($stream_socket_client === false) {
            throw new PushException('An error occurred while trying to contact APNS server.');
        }

        return $stream_socket_client;
    }
707523
public function getStream($context = null)
	{
		if (is_null($context)) {
			return fopen($this->path, 'rb', false);
		} else {
			return fopen($this->path, 'rb', false, $context);
		}
	}
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;
    }
105058
def _docker_machine_ssl_context():
        
        context = ssl.SSLContext(ssl.PROTOCOL_TLS)
        context.set_ciphers(ssl._RESTRICTED_SERVER_CIPHERS)
        certs_path = os.environ.get("DOCKER_CERT_PATH", None)
        if certs_path is None:
            raise ValueError(
                "Cannot create ssl context, " "DOCKER_CERT_PATH is not set!"
            )
        certs_path = Path(certs_path)
        context.load_verify_locations(cafile=certs_path / "ca.pem")
        context.load_cert_chain(
            certfile=certs_path / "cert.pem", keyfile=certs_path / "key.pem"
        )
        return context
162073
public function serialize()
	{
		return serialize(array(	$this->pemFile,
								$this->passphrase,
								$this->endpointEnv,

								$this->isValidated,
								$this->description,
								$this->validFrom,
								$this->validTo));
	}
190398
public static function getStream()
    {
        $tweetStore = Store::get('Tweet');

        $consumerKey = Setting::getSetting('twitter', 'consumer_key');
        $consumerSecret = Setting::getSetting('twitter', 'consumer_secret');
        $accessToken = Setting::getSetting('twitter', 'access_token');
        $accessTokenSecret = Setting::getSetting('twitter', 'access_token_secret');
        $streamSearch = Setting::getSetting('twitter', 'stream_search');

        $twitter = new Twitter($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);

        if (self::canCallAPI()) {
            self::updateLastAPICall();

            $stream = $twitter->search($streamSearch);

            foreach ($stream as $s) {
                if (!$tweetStore->getByTwitterIdForScope($s->id, 'stream')) {
                    $t = new Tweet;
                    $t->setTwitterId($s->id);
                    $t->setText($s->text);
                    $t->setHtmlText(Twitter::clickable($s));
                    $t->setScreenname($s->user->screen_name);
                    $t->setPosted($s->created_at);
                    $t->setCreatedDate(new \DateTime());
                    $t->setScope('stream');
                    $tweetStore->insert($t);
                }
            }
        }
    }
327842
public function getIsSecureConnection()
    {
        $https = $this->getServerParam('HTTPS');
        if ($https !== null && (strcasecmp($https, 'on') === 0 || $https == 1)) {
            return true;
        }
        foreach ($this->secureProtocolHeaders as $header => $values) {
            if ($this->hasHeader($header)) {
                foreach ($values as $value) {
                    if (strcasecmp($this->getHeaderLine($header), $value) === 0) {
                        return true;
                    }
                }
            }
        }

        return false;
    }