/usr/include/libtorrent/ssl_stream.hpp is in libtorrent-rasterbar-dev 1.1.1-1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | /*
Copyright (c) 2008-2016, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_SSL_STREAM_HPP_INCLUDED
#define TORRENT_SSL_STREAM_HPP_INCLUDED
#ifdef TORRENT_USE_OPENSSL
#include "libtorrent/socket.hpp"
#include "libtorrent/error_code.hpp"
#include "libtorrent/io_service.hpp"
#include "libtorrent/aux_/openssl.hpp"
#include "libtorrent/aux_/disable_warnings_push.hpp"
#include <boost/function/function1.hpp>
#include <boost/bind.hpp>
#include <boost/asio/ssl.hpp>
// openssl seems to believe it owns
// this name in every single scope
#undef set_key
#if defined TORRENT_BUILD_SIMULATOR
#include "simulator/simulator.hpp"
#endif
#include "libtorrent/aux_/disable_warnings_pop.hpp"
namespace libtorrent {
namespace ssl {
#if defined TORRENT_BUILD_SIMULATOR
using sim::asio::ssl::context;
using sim::asio::ssl::stream_base;
using sim::asio::ssl::stream;
#else
using boost::asio::ssl::context;
using boost::asio::ssl::stream_base;
using boost::asio::ssl::stream;
#endif
}
template <class Stream>
class ssl_stream
{
public:
explicit ssl_stream(io_service& io_service, ssl::context& ctx)
: m_sock(io_service, ctx)
{
}
typedef typename boost::asio::ssl::stream<Stream> sock_type;
typedef typename sock_type::next_layer_type next_layer_type;
typedef typename Stream::lowest_layer_type lowest_layer_type;
typedef typename Stream::endpoint_type endpoint_type;
typedef typename Stream::protocol_type protocol_type;
void set_host_name(std::string name)
{
aux::openssl_set_tlsext_hostname(m_sock.native_handle(), name.c_str());
}
template <class T>
void set_verify_callback(T const& fun, error_code& ec)
{ m_sock.set_verify_callback(fun, ec); }
#if BOOST_VERSION >= 104700
SSL* native_handle() { return m_sock.native_handle(); }
#endif
typedef boost::function<void(error_code const&)> handler_type;
template <class Handler>
void async_connect(endpoint_type const& endpoint, Handler const& handler)
{
// the connect is split up in the following steps:
// 1. connect to peer
// 2. perform SSL client handshake
// to avoid unnecessary copying of the handler,
// store it in a shared_ptr
boost::shared_ptr<handler_type> h(new handler_type(handler));
m_sock.next_layer().async_connect(endpoint
, boost::bind(&ssl_stream::connected, this, _1, h));
}
template <class Handler>
void async_accept_handshake(Handler const& handler)
{
// this is used for accepting SSL connections
boost::shared_ptr<handler_type> h(new handler_type(handler));
m_sock.async_handshake(ssl::stream_base::server
, boost::bind(&ssl_stream::handshake, this, _1, h));
}
void accept_handshake(error_code& ec)
{
// this is used for accepting SSL connections
m_sock.handshake(ssl::stream_base::server, ec);
}
template <class Handler>
void async_shutdown(Handler const& handler)
{
error_code ec;
m_sock.next_layer().cancel(ec);
m_sock.async_shutdown(handler);
}
void shutdown(error_code& ec)
{
m_sock.shutdown(ec);
}
template <class Mutable_Buffers, class Handler>
void async_read_some(Mutable_Buffers const& buffers, Handler const& handler)
{
m_sock.async_read_some(buffers, handler);
}
template <class Mutable_Buffers>
std::size_t read_some(Mutable_Buffers const& buffers, error_code& ec)
{
return m_sock.read_some(buffers, ec);
}
#ifndef BOOST_NO_EXCEPTIONS
template <class SettableSocketOption>
void set_option(SettableSocketOption const& opt)
{
m_sock.next_layer().set_option(opt);
}
#endif
template <class SettableSocketOption>
error_code set_option(SettableSocketOption const& opt, error_code& ec)
{
return m_sock.next_layer().set_option(opt, ec);
}
#ifndef BOOST_NO_EXCEPTIONS
template <class GettableSocketOption>
void get_option(GettableSocketOption& opt)
{
m_sock.next_layer().get_option(opt);
}
#endif
template <class GettableSocketOption>
error_code get_option(GettableSocketOption& opt, error_code& ec)
{
return m_sock.next_layer().get_option(opt, ec);
}
#ifndef BOOST_NO_EXCEPTIONS
template <class Mutable_Buffers>
std::size_t read_some(Mutable_Buffers const& buffers)
{
return m_sock.read_some(buffers);
}
template <class IO_Control_Command>
void io_control(IO_Control_Command& ioc)
{
m_sock.next_layer().io_control(ioc);
}
#endif
template <class IO_Control_Command>
void io_control(IO_Control_Command& ioc, error_code& ec)
{
m_sock.next_layer().io_control(ioc, ec);
}
template <class Const_Buffers, class Handler>
void async_write_some(Const_Buffers const& buffers, Handler const& handler)
{
m_sock.async_write_some(buffers, handler);
}
template <class Const_Buffers>
std::size_t write_some(Const_Buffers const& buffers, error_code& ec)
{
return m_sock.write_some(buffers, ec);
}
// the SSL stream may cache 17 kiB internally, and there's no way of
// asking how large its buffer is. 17 kiB isn't very much though, so it
// seems fine to potentially over-estimate the number of bytes available.
#ifndef BOOST_NO_EXCEPTIONS
std::size_t available() const
{ return 17 * 1024 + const_cast<sock_type&>(m_sock).next_layer().available(); }
#endif
std::size_t available(error_code& ec) const
{ return 17 * 1024 + const_cast<sock_type&>(m_sock).next_layer().available(ec); }
#ifndef BOOST_NO_EXCEPTIONS
void bind(endpoint_type const& endpoint)
{
m_sock.next_layer().bind(endpoint);
}
#endif
void bind(endpoint_type const& endpoint, error_code& ec)
{
m_sock.next_layer().bind(endpoint, ec);
}
#ifndef BOOST_NO_EXCEPTIONS
void open(protocol_type const& p)
{
m_sock.next_layer().open(p);
}
#endif
void open(protocol_type const& p, error_code& ec)
{
m_sock.next_layer().open(p, ec);
}
bool is_open() const
{
return const_cast<sock_type&>(m_sock).next_layer().is_open();
}
#ifndef BOOST_NO_EXCEPTIONS
void close()
{
m_sock.next_layer().close();
}
#endif
void close(error_code& ec)
{
m_sock.next_layer().close(ec);
}
#ifndef BOOST_NO_EXCEPTIONS
endpoint_type remote_endpoint() const
{
return const_cast<sock_type&>(m_sock).next_layer().remote_endpoint();
}
#endif
endpoint_type remote_endpoint(error_code& ec) const
{
return const_cast<sock_type&>(m_sock).next_layer().remote_endpoint(ec);
}
#ifndef BOOST_NO_EXCEPTIONS
endpoint_type local_endpoint() const
{
return const_cast<sock_type&>(m_sock).next_layer().local_endpoint();
}
#endif
endpoint_type local_endpoint(error_code& ec) const
{
return const_cast<sock_type&>(m_sock).next_layer().local_endpoint(ec);
}
io_service& get_io_service()
{
return m_sock.get_io_service();
}
lowest_layer_type& lowest_layer()
{
return m_sock.lowest_layer();
}
next_layer_type& next_layer()
{
return m_sock.next_layer();
}
private:
void connected(error_code const& e, boost::shared_ptr<handler_type> h)
{
if (e)
{
(*h)(e);
return;
}
m_sock.async_handshake(ssl::stream_base::client
, boost::bind(&ssl_stream::handshake, this, _1, h));
}
void handshake(error_code const& e, boost::shared_ptr<handler_type> h)
{
(*h)(e);
}
ssl::stream<Stream> m_sock;
};
}
#endif // TORRENT_USE_OPENSSL
#endif
|