rippled
WorkSSL.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2020 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/app/misc/detail/WorkSSL.h>
21 
22 namespace ripple {
23 namespace detail {
24 
26  std::string const& host,
27  std::string const& path,
28  std::string const& port,
29  boost::asio::io_service& ios,
31  Config const& config,
32  endpoint_type const& lastEndpoint,
33  bool lastStatus,
34  callback_type cb)
35  : WorkBase(host, path, port, ios, lastEndpoint, lastStatus, cb)
36  , context_(config, j, boost::asio::ssl::context::tlsv12_client)
37  , stream_(socket_, context_.context())
38 {
40  if (ec)
41  Throw<std::runtime_error>(
42  boost::str(boost::format("preConnectVerify: %s") % ec.message()));
43 }
44 
45 void
47 {
48  auto err = ec ? ec : context_.postConnectVerify(stream_, host_);
49  if (err)
50  return fail(err);
51 
52  stream_.async_handshake(
53  boost::asio::ssl::stream_base::client,
54  strand_.wrap(std::bind(
55  &WorkSSL::onHandshake, shared_from_this(), std::placeholders::_1)));
56 }
57 
58 void
60 {
61  if (ec)
62  return fail(ec);
63 
64  onStart();
65 }
66 
67 } // namespace detail
68 
69 } // namespace ripple
ripple::detail::WorkBase< WorkSSL >::endpoint_type
boost::asio::ip::tcp::endpoint endpoint_type
Definition: WorkBase.h:44
std::bind
T bind(T... args)
std::string
STL class.
ripple::detail::WorkBase< WorkSSL >::fail
void fail(error_code const &ec)
Definition: WorkBase.h:183
ripple::HTTPClientSSLContext::preConnectVerify
boost::system::error_code preConnectVerify(T &strm, std::string const &host)
invoked before connect/async_connect on an ssl stream to setup name verification.
Definition: HTTPClientSSLContext.h:107
ripple::detail::WorkBase< WorkSSL >::host_
std::string host_
Definition: WorkBase.h:57
ripple::detail::WorkSSL::onHandshake
void onHandshake(error_code const &ec)
Definition: WorkSSL.cpp:59
boost
Definition: IPAddress.h:103
std::function< void(error_code const &, endpoint_type const &, response_type &&)>
std::enable_shared_from_this< WorkSSL >::shared_from_this
T shared_from_this(T... args)
ripple::detail::WorkSSL::stream_
stream_type stream_
Definition: WorkSSL.h:46
ripple::detail::WorkSSL::context_
HTTPClientSSLContext context_
Definition: WorkSSL.h:45
ripple::Config
Definition: Config.h:89
ripple::detail::WorkBase< WorkSSL >::onStart
void onStart()
Definition: WorkBase.h:243
ripple::HTTPClientSSLContext::postConnectVerify
boost::system::error_code postConnectVerify(T &strm, std::string const &host)
invoked after connect/async_connect but before sending data on an ssl stream - to setup name verifica...
Definition: HTTPClientSSLContext.h:142
beast::Journal
A generic endpoint for log messages.
Definition: Journal.h:58
ripple::detail::WorkSSL::onConnect
void onConnect(error_code const &ec)
Definition: WorkSSL.cpp:46
ripple::detail::WorkBase
Definition: WorkBase.h:40
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::detail::WorkSSL::WorkSSL
WorkSSL(std::string const &host, std::string const &path, std::string const &port, boost::asio::io_service &ios, beast::Journal j, Config const &config, endpoint_type const &lastEndpoint, bool lastStatus, callback_type cb)
Definition: WorkSSL.cpp:25
ripple::detail::WorkBase< WorkSSL >::error_code
boost::system::error_code error_code
Definition: WorkBase.h:43
ripple::detail::WorkBase< WorkSSL >::strand_
boost::asio::io_service::strand strand_
Definition: WorkBase.h:62