當前位置: 首頁>>代碼示例>>PHP>>正文


PHP stream_socket_enable_crypto函數代碼示例

本文整理匯總了PHP中stream_socket_enable_crypto函數的典型用法代碼示例。如果您正苦於以下問題:PHP stream_socket_enable_crypto函數的具體用法?PHP stream_socket_enable_crypto怎麽用?PHP stream_socket_enable_crypto使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了stream_socket_enable_crypto函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的stream_socket_enable_crypto函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。