• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP stream_socket_enable_crypto函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中stream_socket_enable_crypto函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_socket_enable_crypto函数的具体用法?PHP stream_socket_enable_crypto怎么用?PHP stream_socket_enable_crypto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了stream_socket_enable_crypto函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: connect

 public function connect()
 {
     // try open socket
     if ($this->getOption('tls')) {
         $this->handler = @stream_socket_client('tcp://' . $this->server . ':' . $this->port, $errno, $errstr, $this->getOption('timeout', 10));
         if ($this->handler) {
             stream_socket_enable_crypto($this->handler, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
         }
     } else {
         $this->handler = @fsockopen($this->server, $this->port, $errno, $errstr, $this->getOption('timeout', 10));
     }
     if ($this->handler) {
         // read welcome
         $this->read();
         // auth
         $this->auth();
     } else {
         if (!preg_match('//u', $errstr)) {
             $tmp = @iconv('windows-1251', 'utf-8//ignore', $errstr);
             if ($tmp) {
                 $errstr = $tmp;
             }
         }
         throw new waException($errstr . ' (' . $errno . ')', $errno);
     }
 }
开发者ID:cjmaximal,项目名称:webasyst-framework,代码行数:26,代码来源:waMailPOP3.class.php


示例2: StartTLS

 public function StartTLS()
 {
     $this->error = null;
     # to avoid confusion
     if (!$this->connected()) {
         $this->error = array("error" => "Called StartTLS() without being connected");
         return false;
     }
     fputs($this->smtp_conn, "STARTTLS" . $extra . $this->CRLF);
     $rply = $this->get_lines();
     $code = substr($rply, 0, 3);
     if ($this->do_debug >= 2) {
         echo "SMTP -> FROM SERVER:" . $this->CRLF . $rply;
     }
     if ($code != 220) {
         $this->error = array("error" => "STARTTLS not accepted from server", "smtp_code" => $code, "smtp_msg" => substr($rply, 4));
         if ($this->do_debug >= 1) {
             echo "SMTP -> ERROR: " . $this->error["error"] . ": " . $rply . $this->CRLF;
         }
         return false;
     }
     //Begin encrypted connection
     if (!stream_socket_enable_crypto($this->smtp_conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
         return false;
     }
     return true;
 }
开发者ID:hackingman,项目名称:TubeX,代码行数:27,代码来源:SMTP.php


示例3: enableSocketEncryption

 protected function enableSocketEncryption($socket, int $modes, float $timeout = 0) : \Generator
 {
     if ($modes === 0) {
         throw new SocketEncryptionException('No socket client encryption modes available');
     }
     $timed = $timeout;
     try {
         while (true) {
             (yield new AwaitWrite($socket, $timeout));
             $enabled = @\stream_socket_enable_crypto($socket, true, $modes);
             if ($enabled === false) {
                 throw new SocketEncryptionException(\sprintf('Failed to enable socket encryption: %s', \error_get_last()['message'] ?? ''));
             }
             if ($enabled !== 0) {
                 break;
             }
             $timeout = max(0, $timeout - (yield new Pause(0.005, 0.005)));
             if ($timed > 0 && $timeout == 0) {
                 throw new TimeoutException(\sprintf('Socket encryption activation timed out after %.3f seconds', $timed));
             }
         }
     } catch (SocketEncryptionException $e) {
         throw $e;
     } catch (\Throwable $e) {
         throw new SocketEncryptionException('Failed to enable socket encryption', 0, $e);
     }
 }
开发者ID:koolkode,项目名称:async,代码行数:27,代码来源:SocketEncryptionTrait.php


示例4: handleConnectedSocket

 public function handleConnectedSocket($callback, $socket)
 {
     $loop = $this->loop;
     $enableCrypto = function () use($callback, $socket, $loop) {
         $result = stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
         if (true === $result) {
             // crypto was successfully enabled
             $loop->removeWriteStream($socket);
             $loop->removeReadStream($socket);
             call_user_func($callback, new Stream($socket, $loop));
         } else {
             if (false === $result) {
                 // an error occured
                 $loop->removeWriteStream($socket);
                 $loop->removeReadStream($socket);
                 call_user_func($callback, null);
             } else {
                 // need more data, will retry
             }
         }
     };
     $this->loop->addWriteStream($socket, $enableCrypto);
     $this->loop->addReadStream($socket, $enableCrypto);
     $enableCrypto();
 }
开发者ID:romainneutron,项目名称:react,代码行数:25,代码来源:SecureConnectionManager.php


示例5: enableCrypto

 /**
  * {@inheritdoc}
  */
 public function enableCrypto($enable, $cryptoType = STREAM_CRYPTO_METHOD_TLS_CLIENT)
 {
     if (!stream_socket_enable_crypto($this->stream, $enable, $cryptoType)) {
         throw new SocketException();
     }
     return $this;
 }
开发者ID:thebandit,项目名称:php-nntp,代码行数:10,代码来源:Socket.php


示例6: connect

 /**
  * Open connection to IMAP server
  *
  * @param  string      $host  hostname or IP address of IMAP server
  * @param  int|null    $port  of IMAP server, default is 143 (993 for ssl)
  * @param  string|bool $ssl   use 'SSL', 'TLS' or false
  * @throws Exception\RuntimeException
  * @return string welcome message
  */
 public function connect($host, $port = null, $ssl = false)
 {
     if ($ssl == 'SSL') {
         $host = 'ssl://' . $host;
     }
     if ($port === null) {
         $port = $ssl === 'SSL' ? 993 : 143;
     }
     $errno = 0;
     $errstr = '';
     $this->_socket = @fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
     if (!$this->_socket) {
         throw new Exception\RuntimeException('cannot connect to host; error = ' . $errstr . ' (errno = ' . $errno . ' )');
     }
     if (!$this->_assumedNextLine('* OK')) {
         throw new Exception\RuntimeException('host doesn\'t allow connection');
     }
     if ($ssl === 'TLS') {
         $result = $this->requestAndResponse('STARTTLS');
         $result = $result && stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
         if (!$result) {
             throw new Exception\RuntimeException('cannot enable TLS');
         }
     }
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:34,代码来源:Imap.php


示例7: connect

 /**
  * Open connection to IMAP server
  *
  * @param  string      $host  hostname or IP address of IMAP server
  * @param  int|null    $port  of IMAP server, default is 143 (993 for ssl)
  * @param  string|bool $ssl   use 'SSL', 'TLS' or false
  * @throws Exception\RuntimeException
  * @return string welcome message
  */
 public function connect($host, $port = null, $ssl = false)
 {
     if ($ssl == 'SSL') {
         $host = 'ssl://' . $host;
     }
     if ($port === null) {
         $port = $ssl === 'SSL' ? 993 : 143;
     }
     ErrorHandler::start();
     $this->socket = fsockopen($host, $port, $errno, $errstr, self::TIMEOUT_CONNECTION);
     $error = ErrorHandler::stop();
     if (!$this->socket) {
         throw new Exception\RuntimeException(sprintf('cannot connect to host%s', $error ? sprintf('; error = %s (errno = %d )', $error->getMessage(), $error->getCode()) : ''), 0, $error);
     }
     if (!$this->_assumedNextLine('* OK')) {
         throw new Exception\RuntimeException('host doesn\'t allow connection');
     }
     if ($ssl === 'TLS') {
         $result = $this->requestAndResponse('STARTTLS');
         $result = $result && stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
         if (!$result) {
             throw new Exception\RuntimeException('cannot enable TLS');
         }
     }
 }
开发者ID:royaltyclubvp,项目名称:BuzzyGals,代码行数:34,代码来源:Imap.php


示例8: enableCrypto

 /**
  * {@inheritdoc}
  */
 public function enableCrypto(int $method, float $timeout = 0) : \Generator
 {
     $resource = $this->getResource();
     if ($method & 1 || 0 === $method) {
         yield from $this->await($timeout);
     } else {
         yield from $this->poll($timeout);
         $raw = stream_socket_recvfrom($resource, 11, STREAM_PEEK);
         if (11 > strlen($raw)) {
             throw new FailureException('Failed to read crypto handshake.');
         }
         $data = unpack('ctype/nversion/nlength/Nembed/nmax-version', $raw);
         if (0x16 !== $data['type']) {
             throw new FailureException('Invalid crypto handshake.');
         }
         $version = $this->selectCryptoVersion($data['max-version']);
         if ($method & $version) {
             // Check if version was available in $method.
             $method = $version;
         }
     }
     do {
         // Error reporting suppressed since stream_socket_enable_crypto() emits E_WARNING on failure.
         $result = @stream_socket_enable_crypto($resource, (bool) $method, $method);
     } while (0 === $result && !(yield from $this->poll($timeout)));
     if ($result) {
         $this->crypto = $method;
         return;
     }
     $message = 'Failed to enable crypto.';
     if ($error = error_get_last()) {
         $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
     }
     throw new FailureException($message);
 }
开发者ID:icicleio,项目名称:socket,代码行数:38,代码来源:NetworkSocket.php


示例9: _auth

 /**
  * Аутентификация пользователя
  *
  * @param   String    $login
  * @param   String    $password
  * @param   Bool      $admin
  * @return  Bool
  */
 protected function _auth($login, $password, $admin)
 {
     $packet = $this->packet();
     while (!feof($this->_socket)) {
         $packet->clean();
         $this->read($packet);
         switch ($this->_code) {
             case 192:
                 $digest = $packet->_attr[6]['data'];
                 $ctx = hash_init('md5');
                 hash_update($ctx, $digest);
                 hash_update($ctx, $password);
                 $hash = hash_final($ctx, true);
                 $packet->clean();
                 $this->_code = 193;
                 $packet->set_attr_string($login, 2);
                 $packet->set_attr_string($digest, 8);
                 $packet->set_attr_string($hash, 9);
                 $packet->set_attr_int($admin ? 4 : 2, 10);
                 $packet->set_attr_int(2, 1);
                 $this->write($packet);
                 break;
             case 194:
                 if ($packet->get_attr_int(10)) {
                     stream_socket_enable_crypto($this->_socket, TRUE, STREAM_CRYPTO_METHOD_SSLv3_CLIENT);
                 }
                 return TRUE;
             case 195:
                 return FALSE;
         }
     }
 }
开发者ID:TTpartizan,项目名称:URFAClient,代码行数:40,代码来源:Connection.php


示例10: _smtp_connect

 /**
  * SMTP Connect
  *
  * @access  protected
  * @return  string
  */
 protected function _smtp_connect()
 {
     $ssl = NULL;
     if ($this->smtp_crypto == 'ssl') {
         $ssl = 'ssl://';
     }
     $CI =& get_instance();
     if (!empty($this->proxy)) {
         $context = stream_context_create(['http' => ['proxy' => 'tcp://' . $this->proxy]]);
         $this->_smtp_connect = stream_socket_client($ssl . $this->smtp_host . ':' . $this->smtp_port, $errno, $errstr, $this->smtp_timeout, STREAM_CLIENT_CONNECT, $context);
     } else {
         $this->_smtp_connect = fsockopen($ssl . $this->smtp_host, $this->smtp_port, $errno, $errstr, $this->smtp_timeout);
     }
     if (!is_resource($this->_smtp_connect)) {
         $this->_set_error_message('lang:email_smtp_error', $errno . " " . $errstr);
         return FALSE;
     }
     $this->_set_error_message($this->_get_smtp_data());
     if ($this->smtp_crypto == 'tls') {
         $this->_send_command('hello');
         $this->_send_command('starttls');
         stream_socket_enable_crypto($this->_smtp_connect, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT);
     }
     return $this->_send_command('hello');
 }
开发者ID:wilsyle,项目名称:ci_proxy_email,代码行数:31,代码来源:My_Email.php


示例11: auth

 protected function auth()
 {
     fputs($this->conn, 'HELO ' . $this->localhost . $this->newline);
     $this->getServerResponse();
     if ($this->secure == 'tls') {
         fputs($this->conn, 'STARTTLS' . $this->newline);
         if (substr($this->getServerResponse(), 0, 3) != '220') {
             return false;
         }
         stream_socket_enable_crypto($this->conn, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
         fputs($this->conn, 'HELO ' . $this->localhost . $this->newline);
         if (substr($this->getServerResponse(), 0, 3) != '250') {
             return false;
         }
     }
     if ($this->server != 'localhost') {
         fputs($this->conn, 'AUTH LOGIN' . $this->newline);
         if (substr($this->getServerResponse(), 0, 3) != '334') {
             return false;
         }
         fputs($this->conn, base64_encode($this->username) . $this->newline);
         if (substr($this->getServerResponse(), 0, 3) != '334') {
             return false;
         }
         fputs($this->conn, base64_encode($this->password) . $this->newline);
         if (substr($this->getServerResponse(), 0, 3) != '235') {
             return false;
         }
     }
     return true;
 }
开发者ID:splitice,项目名称:radical-mail,代码行数:31,代码来源:SMTP.php


示例12: handleData

 public function handleData($stream)
 {
     if (!$this->isSecure) {
         $enabled = @stream_socket_enable_crypto($stream, true, $this->protocolNumber);
         if ($enabled === false) {
             $this->err('Failed to complete a secure handshake with the client.')->end();
             return;
         } elseif ($enabled === 0) {
             return;
         }
         $this->isSecure = true;
         $this->emit('connection', array($this));
         $scope = $this;
         $this->on('close', function () use($scope, $stream) {
             if (false === stream_socket_enable_crypto($stream, false)) {
                 $scope->err('Failed to gracefully shutdown a secure connection.');
             }
         });
     }
     $data = fread($stream, $this->bufferSize);
     if ('' !== $data && false !== $data) {
         $this->emit('data', array($data, $this));
     }
     if (false === $data || !is_resource($stream) || feof($stream)) {
         $this->end();
     }
 }
开发者ID:mpyw,项目名称:php-hyper-builtin-server,代码行数:27,代码来源:SecureConnection.php


示例13: connect

 /**
  * Connect, then enable crypto
  * 
  * @param   float $timeout
  * @return  bool
  * @throws  peer.SSLUnverifiedPeerException if peer verification fails
  * @throws  peer.SSLHandshakeException if handshake fails for any other reasons
  * @throws  peer.ConnectException for all other reasons
  */
 public function connect($timeout = 2.0)
 {
     if ($this->isConnected()) {
         return true;
     }
     parent::connect($timeout);
     if (stream_socket_enable_crypto($this->_sock, true, $this->cryptoImpl)) {
         return true;
     }
     // Parse OpenSSL errors:
     if (preg_match('/error:(\\d+):(.+)/', key(end(\xp::$errors[__FILE__])), $matches)) {
         switch ($matches[1]) {
             case '14090086':
                 $e = new SSLUnverifiedPeerException($matches[2]);
                 break;
             default:
                 $e = new SSLHandshakeException($matches[2]);
                 break;
         }
     } else {
         $e = new SSLHandshakeException('Unable to enable crypto.');
     }
     $this->close();
     throw $e;
 }
开发者ID:xp-framework,项目名称:networking,代码行数:34,代码来源:CryptoSocket.class.php


示例14: startTLS

 /**
  * Start TLS encryption on the buffer.
  */
 public function startTLS()
 {
     if (isset($this->_stream)) {
         return stream_socket_enable_crypto($this->_stream, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
     } else {
         return false;
     }
 }
开发者ID:bardascat,项目名称:blogify,代码行数:11,代码来源:StreamBuffer.php


示例15: do_enable_crypto_test

function do_enable_crypto_test($url, $context)
{
    $fh = stream_socket_client($url, $errno, $errstr, ini_get("default_socket_timeout"), STREAM_CLIENT_CONNECT, $context);
    assert($fh);
    $r = stream_socket_enable_crypto($fh, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
    assert($r);
    var_dump(get_CN($context));
}
开发者ID:gleamingthecube,项目名称:php,代码行数:8,代码来源:ext_openssl_tests_sni_001.php


示例16: prepareSocket

 /**
  * {@inheritdoc}
  */
 protected function prepareSocket(StreamSocket $socket)
 {
     $socket->block(true);
     if (false === stream_socket_enable_crypto($socket->getRaw(), true, STREAM_CRYPTO_METHOD_SSLv23_SERVER)) {
         throw new Exception('SSL negotiation failed');
     }
     $socket->block(false);
 }
开发者ID:kzykhys,项目名称:coupe,代码行数:11,代码来源:SslHttpHandler.php


示例17: execute

 /**
  * {@inheritdocs}
  */
 public function execute()
 {
     if ($this->perform('STARTTLS', 220)) {
         if (@stream_socket_enable_crypto($this->smtp->getStream(), true, STREAM_CRYPTO_METHOD_TLS_CLIENT) === false) {
             throw new RuntimeException('Cannot encrypt the connection.');
         }
     }
 }
开发者ID:fuelphp,项目名称:email,代码行数:11,代码来源:Starttls.php


示例18: enable

 /**
  * Enable cryptography on a given socket
  *
  * @param  peer.Socket $s
  * @param  [:int] $methods
  * @return void
  * @throws io.IOException
  */
 protected function enable($s, $methods)
 {
     foreach ($methods as $name => $method) {
         if (stream_socket_enable_crypto($s->getHandle(), true, $method)) {
             $this->cat && $this->cat->debug('@@@ Enabling', $name, 'cryptography');
             return;
         }
     }
     throw new \io\IOException('Cannot establish secure connection, tried ' . \xp::stringOf($methods));
 }
开发者ID:xp-framework,项目名称:http,代码行数:18,代码来源:SSLSocketHttpTransport.class.php


示例19: __construct

 public function __construct($host, $port, $security, $timeout = 30)
 {
     stream_set_timeout($this->socket = fsockopen($security === 'ssl' ? "ssl://{$host}" : $host, $port, $errno, $errstr, $timeout), $timeout);
     $this->get();
     $this->hello();
     if ($security === 'tls') {
         if ($this->set('STARTTLS') == 220 && stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
             $this->hello();
         } else {
             $this->set('RSET', 250);
         }
     }
 }
开发者ID:dapepe,项目名称:tymio,代码行数:13,代码来源:mail.php


示例20: handleOperation

 /** {@inheritdoc} */
 protected function handleOperation(RequestDescriptor $descriptor, RequestExecutorInterface $executor, EventHandlerInterface $eventHandler)
 {
     $operation = $descriptor->getOperation();
     $socket = $descriptor->getSocket();
     /** @var SslHandshakeOperation $operation */
     $resource = $descriptor->getSocket()->getStreamResource();
     $result = stream_socket_enable_crypto($resource, true, $operation->getCipher());
     if ($result === true) {
         return $operation->getNextOperation();
     } elseif ($result === false) {
         throw new SslHandshakeException($socket, 'SSL handshake failed.');
     }
     return $operation;
 }
开发者ID:edefimov,项目名称:async-sockets,代码行数:15,代码来源:SslHandshakeIoHandler.php



注:本文中的stream_socket_enable_crypto函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP stream_socket_get_name函数代码示例发布时间:2022-05-23
下一篇:
PHP stream_socket_client函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap