本文整理汇总了PHP中stream_context_get_params函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_context_get_params函数的具体用法?PHP stream_context_get_params怎么用?PHP stream_context_get_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_context_get_params函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_raw_chain
function get_raw_chain($host, $port = 443)
{
global $timeout;
$data = [];
$stream = stream_context_create(array("ssl" => array("capture_peer_cert" => true, "capture_peer_cert_chain" => true, "verify_peer" => false, "peer_name" => $host, "verify_peer_name" => false, "allow_self_signed" => true, "capture_session_meta" => true, "sni_enabled" => true)));
$read_stream = stream_socket_client("ssl://{$host}:{$port}", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $stream);
if ($read_stream === false) {
return false;
} else {
$context = stream_context_get_params($read_stream);
$context_meta = stream_context_get_options($read_stream)['ssl']['session_meta'];
$cert_data = openssl_x509_parse($context["options"]["ssl"]["peer_certificate"]);
$chain_data = $context["options"]["ssl"]["peer_certificate_chain"];
$chain_length = count($chain_data);
if (isset($chain_data) && $chain_length < 10) {
foreach ($chain_data as $key => $value) {
$data["chain"][$key] = $value;
}
} else {
$data["error"] = ["Chain too long."];
return $data;
}
}
return $data;
}
示例2: make_request
public function make_request()
{
$g = stream_context_create(array("ssl" => array("capture_peer_cert" => true)));
set_error_handler(function () {
return true;
});
$r = stream_socket_client("ssl://{$this->target}:{$this->target_port}", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $g);
restore_error_handler();
if (!$r) {
return true;
} else {
$cont = stream_context_get_params($r);
$cert = openssl_x509_read($cont["options"]["ssl"]["peer_certificate"]);
$cert_data = openssl_x509_parse($cert);
openssl_x509_export($cert, $out, FALSE);
$signature_algorithm = null;
if (preg_match('/^\\s+Signature Algorithm:\\s*(.*)\\s*$/m', $out, $match)) {
$signature_algorithm = $match[1];
}
$this->sha_type = $signature_algorithm;
$this->common_name = $cert_data['subject']['CN'];
$this->alternative_names = $cert_data['extensions']['subjectAltName'];
$this->issuer = $cert_data['issuer']['O'];
$this->valid_from = date('m-d-Y H:i:s', strval($cert_data['validFrom_time_t']));
$this->valid_to = date('m-d-Y H:i:s', strval($cert_data['validTo_time_t']));
$this->parse_alternative_names();
}
}
示例3: getParameters
function getParameters()
{
if (empty($this->Parameters)) {
$this->Parameters->merge(stream_context_get_params($this->_resource));
}
return $this->Parameters;
}
示例4: testCreateContextDoesNotSetNotificationCallbackIfNotificationIsNull
/**
* Tests that create_context() does not set notification callback method if notification is empty.
*
* @covers Lunr\Network\StreamSocket::create_context
*/
public function testCreateContextDoesNotSetNotificationCallbackIfNotificationIsNull()
{
$method = $this->get_accessible_reflection_method('create_context');
$method->invoke($this->class);
$params = stream_context_get_params($this->get_reflection_property_value('context'));
$this->assertArrayNotHasKey('notification', $params);
}
示例5: getCertifacateInformation
private function getCertifacateInformation($host)
{
$sslOptions = stream_context_create(array('ssl' => array('capture_peer_cert' => true)));
$request = stream_socket_client('ssl://' . $host . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $sslOptions);
$content = stream_context_get_params($request);
$certinfo = openssl_x509_parse($content['options']['ssl']['peer_certificate']);
return $certinfo;
}
示例6: testGetContext
/**
* @dataProvider dataGetContext
*/
public function testGetContext($expectedOptions, $defaultOptions, $expectedParams, $defaultParams)
{
$context = StreamContextFactory::getContext($defaultOptions, $defaultParams);
$options = stream_context_get_options($context);
$params = stream_context_get_params($context);
$this->assertEquals($expectedOptions, $options);
$this->assertEquals($expectedParams, $params);
}
示例7: check_json
function check_json($host, $ip, $port)
{
global $timeout;
$data = [];
$stream = stream_context_create(array("ssl" => array("capture_peer_cert" => true, "capture_peer_cert_chain" => true, "verify_peer" => false, "peer_name" => $host, "verify_peer_name" => false, "allow_self_signed" => true, "capture_session_meta" => true, "sni_enabled" => true)));
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$connect_ip = "[" . $ip . "]";
} else {
$connect_ip = $ip;
}
$read_stream = stream_socket_client("ssl://{$connect_ip}:{$port}", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $stream);
if ($read_stream === false) {
$data["error"] = ["Failed to connect: " . htmlspecialchars($errstr)];
return $data;
} else {
$context = stream_context_get_params($read_stream);
$context_meta = stream_context_get_options($read_stream)['ssl']['session_meta'];
$cert_data = openssl_x509_parse($context["options"]["ssl"]["peer_certificate"]);
$chain_data = $context["options"]["ssl"]["peer_certificate_chain"];
$chain_length = count($chain_data);
if (isset($chain_data) && $chain_length < 10) {
$chain_length = count($chain_data);
$chain_arr_keys = $chain_data;
foreach (array_keys($chain_arr_keys) as $key) {
$curr = $chain_data[$key];
$next = $chain_data[$key + 1];
$prev = $chain_data[$key - 1];
$chain_key = (string) $key + 1;
if ($key == 0) {
$data["connection"] = ssl_conn_metadata_json($host, $ip, $port, $read_stream, $chain_data);
$data["chain"][$chain_key] = cert_parse_json($curr, $next, $host, $ip, true);
} else {
$data["chain"][$chain_key] = cert_parse_json($curr, $next, null, false);
}
// certificate transparency
$ct_urls = ["https://ct.ws.symantec.com", "https://ct.googleapis.com/pilot", "https://ct.googleapis.com/aviator", "https://ct.googleapis.com/rocketeer", "https://ct1.digicert-ct.com/log", "https://ct.izenpe.com", "https://ctlog.api.venafi.com", "https://log.certly.io"];
$data["certificate_transparency"] = [];
foreach ($ct_urls as $ct_url) {
$submitToCT = submitCertToCT($data["chain"], $ct_url);
$ct_result = json_decode($submitToCT, TRUE);
if ($ct_result === null && json_last_error() !== JSON_ERROR_NONE) {
$result_ct = array('result' => $submitToCT);
$data["certificate_transparency"][$ct_url] = $result_ct;
} else {
$data["certificate_transparency"][$ct_url] = $ct_result;
}
}
}
} else {
$data["error"] = ["Chain too long."];
return $data;
}
}
return $data;
}
示例8: initialize
/**
* Initializes observr collections by aliasing
* stream_context_set_option and stream_context_set_params
*/
private function initialize()
{
$this->options->merge(\stream_context_get_options($this->context));
$this->options->attach('set', function ($sender, $e) {
\stream_context_set_option($this->context, $this->wrapper, $e->offset, $e->value);
});
$this->data->merge(\stream_context_get_params($this->context));
$this->data->attach('set', function ($sender, $e) {
\stream_context_set_params($this->context, $this->data->toArray());
});
}
示例9: verifySslUrl
/**
* verifies if URL has SSL valid
* @param string $url
* @see http://stackoverflow.com/a/27706327/2324004
* @return bool
*/
public function verifySslUrl($url)
{
$stream = stream_context_create(['ssl' => ['capture_peer_cert' => true], 'http' => ['timeout' => self::HTTP_READ_TIMEOUT]]);
$read = @fopen($url, 'rb', false, $stream);
if (!$read) {
return false;
}
$cont = stream_context_get_params($read);
$var = !empty($cont['options']['ssl']['peer_certificate']);
return $var;
}
示例10: access
public function access($code, $options = array())
{
$type = isset($options['grant_type']) ? $options['grant_type'] : 'authorization_code';
$params = array('client_id' => $this->client_id, 'client_secret' => $this->client_secret, 'redirect_uri' => isset($options['redirect_uri']) ? $options['redirect_uri'] : $this->redirect_uri);
switch ($type) {
case 'authorization_code':
$params['code'] = $code;
$params['grant_type'] = $type;
break;
case 'refresh_token':
$params['refresh_token'] = $code;
$params['response_type'] = 'refresh_token';
$params['UserID'] = $options['uid'];
break;
}
$response = null;
$url = $this->url_access_token();
switch ($this->method) {
case 'GET':
// Need to switch to Request library, but need to test it on one that works
$url .= '?' . http_build_query($params);
$response = file_get_contents($url);
$return = json_decode($response, true);
break;
case 'POST':
$postdata = http_build_query($params);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$_default_opts = stream_context_get_params(stream_context_get_default());
$context = stream_context_create(array_merge_recursive($_default_opts['options'], $opts));
$response = file_get_contents($url, false, $context);
$return = json_decode($response, true);
break;
default:
throw new Exception('Method \'' . $this->method . '\' must be either GET or POST');
}
if (isset($return['Error'])) {
throw new Exception($return['Error'], $return['ErrorCode']);
}
// Converts keys to the equivalent
$return['access_token'] = $return['AccessToken'];
$return['expires'] = $return['Expires'];
$return['refresh_token'] = $return['RefreshToken'];
$return['uid'] = $return['UserID'];
// Unsets no longer used indexes
unset($return['AccessToken'], $return['Expires'], $return['RefreshToken'], $return['UserID']);
switch ($type) {
case 'authorization_code':
return Token::factory('access', $return);
break;
case 'refresh_token':
return Token::factory('refresh', $return);
break;
}
}
示例11: getCertificateExpirationDate
protected function getCertificateExpirationDate($socket)
{
$timeout = min(10, $this->getPingFrequency());
$context = stream_context_create(['ssl' => ['capture_peer_cert' => TRUE]]);
if (false === ($read = @stream_socket_client($socket, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $context))) {
throw new \RuntimeException($errstr);
}
$certificate = stream_context_get_params($read);
$infos = openssl_x509_parse($certificate['options']['ssl']['peer_certificate']);
return new \DateTime('@' . $infos['validTo_time_t']);
}
示例12: init
/**
* @param $url String
*/
public function init($url)
{
$parse = parse_url($url, PHP_URL_HOST);
$get = stream_context_create(["ssl" => ["capture_peer_cert" => true]]);
$read = stream_socket_client("ssl://" . $parse . ":443", $errno, $err, 30, STREAM_CLIENT_CONNECT, $get);
$cert = stream_context_get_params($read);
$this->certInfo = openssl_x509_parse($cert['options']['ssl']['peer_certificate']);
if (!is_array($this->certInfo)) {
throw new \InvalidArgumentException('cannot get ssl certificate information');
}
}
示例13: get_user_info
public function get_user_info(Access $token)
{
$opts = array('http' => array('method' => 'GET', 'header' => 'Authorization: OAuth ' . $token->access_token));
$_default_opts = stream_context_get_params(stream_context_get_default());
$opts = array_merge_recursive($_default_opts['options'], $opts);
$context = stream_context_create($opts);
$url = 'http://api-yaru.yandex.ru/me/?format=json';
$user = json_decode(file_get_contents($url, false, $context));
preg_match("/\\d+\$/", $user->id, $uid);
return array('uid' => $uid[0], 'nickname' => isset($user->name) ? $user->name : null, 'name' => isset($user->name) ? $user->name : null, 'first_name' => isset($user->first_name) ? $user->first_name : null, 'last_name' => isset($user->last_name) ? $user->last_name : null, 'email' => isset($user->email) ? $user->email : null, 'location' => isset($user->hometown->name) ? $user->hometown->name : null, 'description' => isset($user->bio) ? $user->bio : null, 'image' => $user->links->userpic);
}
示例14: checkCert
/**
* Preflight the SSL certificate presented by the backend. This isn't 100%
* bulletproof, in that we're not actually validating the transport used to
* communicate with Stripe, merely that the first attempt to does not use a
* revoked certificate.
*
* Unfortunately the interface to OpenSSL doesn't make it easy to check the
* certificate before sending potentially sensitive data on the wire. This
* approach raises the bar for an attacker significantly.
*
* @param string $url
*
* @return bool
*/
public function checkCert($url)
{
if (!$this->hasStreamExtensions()) {
return $this->showStreamExtensionWarning();
}
$this->setUrl($url);
list($result, $errorNo, $errorStr) = $this->streamSocketClient();
$this->checkResult($result, $errorNo, $errorStr);
openssl_x509_export(stream_context_get_params($result)['options']['ssl']['peer_certificate'], $pemCert);
$this->checkBlackList($pemCert);
return true;
}
示例15: connectScan
function connectScan()
{
$m = new MongoClient();
$time = time();
$out = "/var/log/httphunter.log";
$file = fopen($out, 'a+') or die("Could not open log file for reading / writing\n");
while (true) {
$ip = long2ip(rand(0, "4294967295"));
require_once "./sys/GeoIP/GeoIP.php";
$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_USERAGENT => md5(base64_encode(rand())), CURLOPT_HEADER => 1, CURLOPT_NOBODY => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 1.5, CURLOPT_URL => "http://{$ip}"));
if (curl_exec($curl)) {
$db = $m->httphunter;
$collection = $db->results;
$req_info = curl_getinfo($curl);
$foundtime = time();
$sslcheck = fsockopen("{$ip}", 443, $errno, $errstr, 3);
if (!$sslcheck) {
$results = array("ip" => $ip, "status" => $req_info['http_code'], "header" => curl_exec($curl), "request" => $req_info, "SSL" => "false", "SSL_DATA" => "false", "found" => $foundtime, "GeoIP" => array("country" => $geoip_country, "state" => $geoip_state, "Latitude" => $geoip_lat, "Longitude" => $geoip_lon));
} else {
$get_cert = stream_context_create(array("ssl" => array("capture_peer_cert" => true)));
$connect_host = stream_socket_client("ssl://{$ip}:443", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $get_cert);
$ssl = stream_context_get_params($connect_host);
$cert_info = json_encode(openssl_x509_parse($ssl["options"]["ssl"]["peer_certificate"]), true);
$ssl_data = $cert_info;
$results = array("ip" => $ip, "status" => $req_info['http_code'], "header" => curl_exec($curl), "request" => $req_info, "SSL" => true, "SSL_DATA" => $ssl_data, "found" => $foundtime, "GeoIP" => array("country" => $geoip_country, "state" => $geoip_state, "Latitude" => $geoip_lat, "Longitude" => $geoip_lon));
}
if ($req_info['http_code'] == 401) {
$collection->insert($results);
$output = "[" . date(DATE_RFC2822) . "] - {$ip} - 401 AUTH\n";
flock($file, LOCK_SH);
fwrite($file, $output);
flock($file, LOCK_UN);
} elseif ($req_info['http_code'] == 301) {
$collection->insert($results);
$output = "[" . date(DATE_RFC2822) . "] - {$ip} - 301 REDIRECT\n";
flock($file, LOCK_SH);
fwrite($file, $output);
flock($file, LOCK_UN);
} else {
$collection->insert($results);
$output = "[" . date(DATE_RFC2822) . "] - {$ip} - HTTP OK\n";
flock($file, LOCK_SH);
fwrite($file, $output);
flock($file, LOCK_UN);
}
fclose($sslcheck);
}
}
}