ssl.qbk

来自「Boost provides free peer-reviewed portab」· QBK 代码 · 共 69 行

QBK
69
字号
[/ / Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com) / / Distributed under the Boost Software License, Version 1.0. (See accompanying / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) /][section:ssl SSL]Boost.Asio contains classes and class templates for basic SSL support. These classesallow encrypted communication to be layered on top of an existing stream, suchas a TCP socket.Before creating an encrypted stream, an application must construct an SSLcontext object. This object is used to set SSL options such as verificationmode, certificate files, and so on. As an illustration, client-sideinitialisation may look something like:  ssl::context ctx(io_service, ssl::context::sslv23);  ctx.set_verify_mode(ssl::context::verify_peer);  ctx.load_verify_file("ca.pem");To use SSL with a TCP socket, one may write:  ssl::stream<ip::tcp::socket> ssl_sock(my_io_service, ctx);To perform socket-specific operations, such as establishing an outboundconnection or accepting an incoming one, the underlying socket must first beobtained using the `ssl::stream` template's [linkboost_asio.reference.ssl__stream.lowest_layer `lowest_layer()`] member function:  ip::tcp::socket& sock = ssl_sock.lowest_layer();  sock.connect(my_endpoint);In some use cases the underlying stream object will need to have a longerlifetime than the SSL stream, in which case the template parameter should be areference to the stream type:  ip::tcp::socket sock(my_io_service);  ssl::stream<ip::tcp::socket&> ssl_sock(sock, ctx);Once connected, SSL stream objects are used as synchronous or asynchronous readand write streams. This means the objects can be used with any of the [linkboost_asio.reference.read read()], [link boost_asio.reference.async_read async_read()],[link boost_asio.reference.write write()], [link boost_asio.reference.async_writeasync_write()], [link boost_asio.reference.read_until read_until()] or [linkboost_asio.reference.async_read_until async_read_until()] free functions.[heading See Also][link boost_asio.reference.ssl__basic_context ssl::basic_context],[link boost_asio.reference.ssl__context ssl::context],[link boost_asio.reference.ssl__context_base ssl::context_base],[link boost_asio.reference.ssl__context_service ssl::context_service],[link boost_asio.reference.ssl__stream ssl::stream],[link boost_asio.reference.ssl__stream_base ssl::stream_base],[link boost_asio.reference.ssl__stream_service ssl::stream_service],[link boost_asio.examples.ssl SSL example].[heading Notes][@http://www.openssl.org OpenSSL] is required to make use of Boost.Asio's SSLsupport. When an application needs to use OpenSSL functionality that is notwrapped by Boost.Asio, the underlying OpenSSL types may be obtained by calling [linkboost_asio.reference.ssl__basic_context.impl `ssl::context::impl()`] or [linkboost_asio.reference.ssl__stream.impl `ssl::stream::impl()`].[endsect]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?