Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 3 | #pragma once |
Ed Tanous | 7531298 | 2021-02-11 14:26:02 -0800 | [diff] [blame] | 4 | #include "bmcweb_config.h" |
Adriana Kobylak | 0e1cf26 | 2019-12-05 13:57:57 -0600 | [diff] [blame] | 5 | |
Ed Tanous | d093c99 | 2023-01-19 19:01:49 -0800 | [diff] [blame] | 6 | #include "async_resp.hpp" |
Nan Zhou | d055a34 | 2022-05-25 01:15:34 +0000 | [diff] [blame] | 7 | #include "authentication.hpp" |
Ed Tanous | ed5f895 | 2023-06-22 14:06:22 -0700 | [diff] [blame] | 8 | #include "complete_response_fields.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include "forward_unauthorized.hpp" |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 10 | #include "http2_connection.hpp" |
Ed Tanous | b289614 | 2024-01-31 15:25:47 -0800 | [diff] [blame] | 11 | #include "http_body.hpp" |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 12 | #include "http_connect_types.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 13 | #include "http_request.hpp" |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 14 | #include "http_response.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 15 | #include "http_utility.hpp" |
Ed Tanous | 04e438c | 2020-10-03 08:06:26 -0700 | [diff] [blame] | 16 | #include "logging.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 17 | #include "mutual_tls.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 18 | #include "sessions.hpp" |
Ed Tanous | 18f8f60 | 2023-07-18 10:07:23 -0700 | [diff] [blame] | 19 | #include "str_utility.hpp" |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 20 | #include "utility.hpp" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 21 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 22 | #include <boost/asio/error.hpp> |
Ed Tanous | 3112a14 | 2018-11-29 15:45:10 -0800 | [diff] [blame] | 23 | #include <boost/asio/ip/tcp.hpp> |
Chandramohan Harkude | 352ee0e | 2025-06-04 11:16:34 +0530 | [diff] [blame^] | 24 | #include <boost/asio/ssl/error.hpp> |
Ed Tanous | d43cd0c | 2020-09-30 20:46:53 -0700 | [diff] [blame] | 25 | #include <boost/asio/ssl/stream.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 26 | #include <boost/asio/ssl/stream_base.hpp> |
| 27 | #include <boost/asio/ssl/verify_context.hpp> |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 28 | #include <boost/asio/steady_timer.hpp> |
Ed Tanous | 4fa45df | 2023-09-01 14:20:50 -0700 | [diff] [blame] | 29 | #include <boost/beast/_experimental/test/stream.hpp> |
Ed Tanous | 4d69861 | 2024-02-06 14:57:24 -0800 | [diff] [blame] | 30 | #include <boost/beast/core/buffers_generator.hpp> |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 31 | #include <boost/beast/core/detect_ssl.hpp> |
| 32 | #include <boost/beast/core/error.hpp> |
Ed Tanous | 3112a14 | 2018-11-29 15:45:10 -0800 | [diff] [blame] | 33 | #include <boost/beast/core/flat_static_buffer.hpp> |
Myung Bae | a4326fe | 2023-01-10 14:29:24 -0600 | [diff] [blame] | 34 | #include <boost/beast/http/error.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 35 | #include <boost/beast/http/field.hpp> |
Ed Tanous | 4d69861 | 2024-02-06 14:57:24 -0800 | [diff] [blame] | 36 | #include <boost/beast/http/message_generator.hpp> |
Ed Tanous | 918ef25 | 2022-05-25 10:40:41 -0700 | [diff] [blame] | 37 | #include <boost/beast/http/parser.hpp> |
| 38 | #include <boost/beast/http/read.hpp> |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 39 | #include <boost/beast/http/rfc7230.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 40 | #include <boost/beast/http/status.hpp> |
| 41 | #include <boost/beast/http/verb.hpp> |
| 42 | #include <boost/none.hpp> |
| 43 | #include <boost/optional/optional.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 44 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 45 | #include <bit> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 46 | #include <chrono> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 47 | #include <cstddef> |
| 48 | #include <cstdint> |
| 49 | #include <functional> |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 50 | #include <memory> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 51 | #include <optional> |
| 52 | #include <string> |
| 53 | #include <string_view> |
| 54 | #include <system_error> |
| 55 | #include <type_traits> |
| 56 | #include <utility> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 57 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | namespace crow |
| 59 | { |
Ed Tanous | 257f579 | 2018-03-17 14:40:09 -0700 | [diff] [blame] | 60 | |
Ed Tanous | cf9e417 | 2022-12-21 09:30:16 -0800 | [diff] [blame] | 61 | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) |
Ed Tanous | 6fbdbca | 2021-12-06 14:36:06 -0800 | [diff] [blame] | 62 | static int connectionCount = 0; |
Jennifer Lee | acb7cfb | 2018-06-07 16:08:15 -0700 | [diff] [blame] | 63 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 64 | // request body limit size set by the BMCWEB_HTTP_BODY_LIMIT option |
| 65 | constexpr uint64_t httpReqBodyLimit = 1024UL * 1024UL * BMCWEB_HTTP_BODY_LIMIT; |
Jennifer Lee | acb7cfb | 2018-06-07 16:08:15 -0700 | [diff] [blame] | 66 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 67 | constexpr uint64_t loggedOutPostBodyLimit = 4096U; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 68 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 69 | constexpr uint32_t httpHeaderLimit = 8192U; |
James Feist | 3909dc8 | 2020-04-03 10:58:55 -0700 | [diff] [blame] | 70 | |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 71 | template <typename Adaptor, typename Handler> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 72 | class Connection : |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 73 | public std::enable_shared_from_this<Connection<Adaptor, Handler>> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 74 | { |
Ed Tanous | 7c8e064 | 2022-02-21 12:11:14 -0800 | [diff] [blame] | 75 | using self_type = Connection<Adaptor, Handler>; |
| 76 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 77 | public: |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 78 | Connection(Handler* handlerIn, HttpType httpTypeIn, |
| 79 | boost::asio::steady_timer&& timerIn, |
Ed Tanous | 81ce609 | 2020-12-17 16:54:55 +0000 | [diff] [blame] | 80 | std::function<std::string()>& getCachedDateStrF, |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 81 | boost::asio::ssl::stream<Adaptor>&& adaptorIn) : |
| 82 | httpType(httpTypeIn), adaptor(std::move(adaptorIn)), handler(handlerIn), |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 83 | timer(std::move(timerIn)), getCachedDateStr(getCachedDateStrF) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 84 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 85 | initParser(); |
Kowalski, Kamil | 55e43f6 | 2019-07-10 13:12:57 +0200 | [diff] [blame] | 86 | |
Ed Tanous | 40aa058 | 2021-07-14 13:24:40 -0700 | [diff] [blame] | 87 | connectionCount++; |
Ed Tanous | 6fbdbca | 2021-12-06 14:36:06 -0800 | [diff] [blame] | 88 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 89 | BMCWEB_LOG_DEBUG("{} Connection created, total {}", logPtr(this), |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 90 | connectionCount); |
Ed Tanous | 40aa058 | 2021-07-14 13:24:40 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | ~Connection() |
| 94 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 95 | res.releaseCompleteRequestHandler(); |
Ed Tanous | 40aa058 | 2021-07-14 13:24:40 -0700 | [diff] [blame] | 96 | cancelDeadlineTimer(); |
Ed Tanous | 6fbdbca | 2021-12-06 14:36:06 -0800 | [diff] [blame] | 97 | |
Ed Tanous | 40aa058 | 2021-07-14 13:24:40 -0700 | [diff] [blame] | 98 | connectionCount--; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 99 | BMCWEB_LOG_DEBUG("{} Connection closed, total {}", logPtr(this), |
| 100 | connectionCount); |
Ed Tanous | 40aa058 | 2021-07-14 13:24:40 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Ed Tanous | ecd6a3a | 2022-01-07 09:18:40 -0800 | [diff] [blame] | 103 | Connection(const Connection&) = delete; |
| 104 | Connection(Connection&&) = delete; |
| 105 | Connection& operator=(const Connection&) = delete; |
| 106 | Connection& operator=(Connection&&) = delete; |
| 107 | |
Ed Tanous | 7c8e064 | 2022-02-21 12:11:14 -0800 | [diff] [blame] | 108 | bool tlsVerifyCallback(bool preverified, |
| 109 | boost::asio::ssl::verify_context& ctx) |
| 110 | { |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 111 | BMCWEB_LOG_DEBUG("{} tlsVerifyCallback called with preverified {}", |
| 112 | logPtr(this), preverified); |
Ed Tanous | 7c8e064 | 2022-02-21 12:11:14 -0800 | [diff] [blame] | 113 | if (preverified) |
| 114 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 115 | mtlsSession = verifyMtlsUser(ip, ctx); |
Boleslaw Ogonczyk Makowski | b496307 | 2023-02-06 09:59:58 +0100 | [diff] [blame] | 116 | if (mtlsSession) |
Ed Tanous | 7c8e064 | 2022-02-21 12:11:14 -0800 | [diff] [blame] | 117 | { |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 118 | BMCWEB_LOG_DEBUG("{} Generated TLS session: {}", logPtr(this), |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 119 | mtlsSession->uniqueId); |
Ed Tanous | 7c8e064 | 2022-02-21 12:11:14 -0800 | [diff] [blame] | 120 | } |
| 121 | } |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 122 | const persistent_data::AuthConfigMethods& c = |
| 123 | persistent_data::SessionStore::getInstance().getAuthMethodsConfig(); |
| 124 | if (c.tlsStrict) |
| 125 | { |
Ed Tanous | 463a0e3 | 2024-10-14 11:21:48 -0700 | [diff] [blame] | 126 | BMCWEB_LOG_DEBUG( |
| 127 | "{} TLS is in strict mode, returning preverified as is.", |
| 128 | logPtr(this)); |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 129 | return preverified; |
| 130 | } |
| 131 | // If tls strict mode is disabled |
| 132 | // We always return true to allow full auth flow for resources that |
| 133 | // don't require auth |
Ed Tanous | 7c8e064 | 2022-02-21 12:11:14 -0800 | [diff] [blame] | 134 | return true; |
| 135 | } |
| 136 | |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 137 | bool prepareMutualTls() |
Ed Tanous | 40aa058 | 2021-07-14 13:24:40 -0700 | [diff] [blame] | 138 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 139 | BMCWEB_LOG_DEBUG("prepareMutualTls"); |
| 140 | |
| 141 | constexpr std::string_view id = "bmcweb"; |
| 142 | |
| 143 | const char* idPtr = id.data(); |
| 144 | const auto* idCPtr = std::bit_cast<const unsigned char*>(idPtr); |
| 145 | auto idLen = static_cast<unsigned int>(id.length()); |
| 146 | int ret = |
| 147 | SSL_set_session_id_context(adaptor.native_handle(), idCPtr, idLen); |
| 148 | if (ret == 0) |
Zbigniew Kurzynski | 009c2a4 | 2019-11-14 13:37:15 +0100 | [diff] [blame] | 149 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 150 | BMCWEB_LOG_ERROR("{} failed to set SSL id", logPtr(this)); |
| 151 | return false; |
| 152 | } |
Zbigniew Kurzynski | 009c2a4 | 2019-11-14 13:37:15 +0100 | [diff] [blame] | 153 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 154 | BMCWEB_LOG_DEBUG("set_verify_callback"); |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 155 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 156 | boost::system::error_code ec; |
| 157 | adaptor.set_verify_callback( |
| 158 | std::bind_front(&self_type::tlsVerifyCallback, this), ec); |
| 159 | if (ec) |
| 160 | { |
| 161 | BMCWEB_LOG_ERROR("Failed to set verify callback {}", ec); |
| 162 | return false; |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | return true; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 168 | void afterDetectSsl(const std::shared_ptr<self_type>& /*self*/, |
| 169 | boost::beast::error_code ec, bool isTls) |
| 170 | { |
| 171 | if (ec) |
| 172 | { |
| 173 | BMCWEB_LOG_ERROR("Couldn't detect ssl ", ec); |
| 174 | return; |
| 175 | } |
| 176 | BMCWEB_LOG_DEBUG("{} TLS was detected as {}", logPtr(this), isTls); |
| 177 | if (isTls) |
| 178 | { |
| 179 | if (httpType != HttpType::HTTPS && httpType != HttpType::BOTH) |
| 180 | { |
| 181 | BMCWEB_LOG_WARNING( |
| 182 | "{} Connection closed due to incompatible type", |
| 183 | logPtr(this)); |
| 184 | return; |
| 185 | } |
| 186 | httpType = HttpType::HTTPS; |
| 187 | adaptor.async_handshake( |
| 188 | boost::asio::ssl::stream_base::server, buffer.data(), |
| 189 | std::bind_front(&self_type::afterSslHandshake, this, |
| 190 | shared_from_this())); |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | if (httpType != HttpType::HTTP && httpType != HttpType::BOTH) |
| 195 | { |
| 196 | BMCWEB_LOG_WARNING( |
| 197 | "{} Connection closed due to incompatible type", |
| 198 | logPtr(this)); |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | httpType = HttpType::HTTP; |
| 203 | BMCWEB_LOG_INFO("Starting non-SSL session"); |
| 204 | doReadHeaders(); |
| 205 | } |
| 206 | } |
| 207 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 208 | void start() |
| 209 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 210 | BMCWEB_LOG_DEBUG("{} Connection started, total {}", logPtr(this), |
| 211 | connectionCount); |
Gunnar Mills | 4f63be0 | 2023-10-25 09:14:07 -0500 | [diff] [blame] | 212 | if (connectionCount >= 200) |
Ed Tanous | 6fbdbca | 2021-12-06 14:36:06 -0800 | [diff] [blame] | 213 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 214 | BMCWEB_LOG_CRITICAL("{} Max connection count exceeded.", |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 215 | logPtr(this)); |
Ed Tanous | 6fbdbca | 2021-12-06 14:36:06 -0800 | [diff] [blame] | 216 | return; |
| 217 | } |
| 218 | |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 219 | if constexpr (BMCWEB_MUTUAL_TLS_AUTH) |
| 220 | { |
| 221 | if (!prepareMutualTls()) |
| 222 | { |
| 223 | BMCWEB_LOG_ERROR("{} Failed to prepare mTLS", logPtr(this)); |
| 224 | return; |
| 225 | } |
| 226 | } |
| 227 | |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 228 | startDeadline(); |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 229 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 230 | readClientIp(); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 231 | boost::beast::async_detect_ssl( |
| 232 | adaptor.next_layer(), buffer, |
| 233 | std::bind_front(&self_type::afterDetectSsl, this, |
| 234 | shared_from_this())); |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 235 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 236 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 237 | void afterSslHandshake(const std::shared_ptr<self_type>& /*self*/, |
| 238 | const boost::system::error_code& ec, |
| 239 | size_t bytesParsed) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 240 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 241 | buffer.consume(bytesParsed); |
| 242 | if (ec) |
| 243 | { |
| 244 | BMCWEB_LOG_ERROR("{} SSL handshake failed", logPtr(this)); |
| 245 | return; |
| 246 | } |
| 247 | BMCWEB_LOG_DEBUG("{} SSL handshake succeeded", logPtr(this)); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 248 | // If http2 is enabled, negotiate the protocol |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 249 | if constexpr (BMCWEB_EXPERIMENTAL_HTTP2) |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 250 | { |
| 251 | const unsigned char* alpn = nullptr; |
| 252 | unsigned int alpnlen = 0; |
| 253 | SSL_get0_alpn_selected(adaptor.native_handle(), &alpn, &alpnlen); |
| 254 | if (alpn != nullptr) |
| 255 | { |
| 256 | std::string_view selectedProtocol( |
| 257 | std::bit_cast<const char*>(alpn), alpnlen); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 258 | BMCWEB_LOG_DEBUG("ALPN selected protocol \"{}\" len: {}", |
| 259 | selectedProtocol, alpnlen); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 260 | if (selectedProtocol == "h2") |
| 261 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 262 | upgradeToHttp2(); |
Ed Tanous | fca2cbe | 2021-01-28 14:49:59 -0800 | [diff] [blame] | 263 | return; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | doReadHeaders(); |
| 269 | } |
| 270 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 271 | void initParser() |
| 272 | { |
| 273 | boost::beast::http::request_parser<bmcweb::HttpBody>& instance = |
Ed Tanous | 38afdb9 | 2024-12-11 23:57:53 -0800 | [diff] [blame] | 274 | parser.emplace(); |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 275 | |
| 276 | // reset header limit for newly created parser |
| 277 | instance.header_limit(httpHeaderLimit); |
| 278 | |
| 279 | // Initially set no body limit. We don't yet know if the user is |
| 280 | // authenticated. |
| 281 | instance.body_limit(boost::none); |
| 282 | } |
| 283 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 284 | void upgradeToHttp2() |
| 285 | { |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 286 | auto http2 = std::make_shared<HTTP2Connection<Adaptor, Handler>>( |
| 287 | std::move(adaptor), handler, getCachedDateStr, httpType); |
| 288 | if (http2settings.empty()) |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 289 | { |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 290 | http2->start(); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 291 | } |
| 292 | else |
| 293 | { |
Ed Tanous | ebe4c57 | 2025-02-08 14:29:53 -0800 | [diff] [blame] | 294 | http2->startFromSettings(http2settings); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 298 | // returns whether connection was upgraded |
| 299 | bool doUpgrade(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 300 | { |
| 301 | using boost::beast::http::field; |
| 302 | using boost::beast::http::token_list; |
| 303 | |
| 304 | bool isSse = |
| 305 | isContentTypeAllowed(req->getHeaderValue("Accept"), |
| 306 | http_helpers::ContentType::EventStream, false); |
| 307 | |
| 308 | bool isWebsocket = false; |
| 309 | bool isH2c = false; |
| 310 | // Check connection header is upgrade |
| 311 | if (token_list{req->req[field::connection]}.exists("upgrade")) |
| 312 | { |
| 313 | BMCWEB_LOG_DEBUG("{} Connection: Upgrade header was present", |
| 314 | logPtr(this)); |
| 315 | // Parse if upgrade is h2c or websocket |
| 316 | token_list upgrade{req->req[field::upgrade]}; |
| 317 | isWebsocket = upgrade.exists("websocket"); |
| 318 | isH2c = upgrade.exists("h2c"); |
| 319 | BMCWEB_LOG_DEBUG("{} Upgrade isWebsocket: {} isH2c: {}", |
| 320 | logPtr(this), isWebsocket, isH2c); |
| 321 | } |
| 322 | |
| 323 | if (BMCWEB_EXPERIMENTAL_HTTP2 && isH2c) |
| 324 | { |
| 325 | std::string_view base64settings = req->req[field::http2_settings]; |
| 326 | if (utility::base64Decode<true>(base64settings, http2settings)) |
| 327 | { |
| 328 | res.result(boost::beast::http::status::switching_protocols); |
| 329 | res.addHeader(boost::beast::http::field::connection, "Upgrade"); |
| 330 | res.addHeader(boost::beast::http::field::upgrade, "h2c"); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // websocket and SSE are only allowed on GET |
| 335 | if (req->req.method() == boost::beast::http::verb::get) |
| 336 | { |
| 337 | if (isWebsocket || isSse) |
| 338 | { |
| 339 | asyncResp->res.setCompleteRequestHandler( |
| 340 | [self(shared_from_this())](crow::Response& thisRes) { |
| 341 | if (thisRes.result() != boost::beast::http::status::ok) |
| 342 | { |
| 343 | // When any error occurs before handle upgradation, |
| 344 | // the result in response will be set to respective |
| 345 | // error. By default the Result will be OK (200), |
| 346 | // which implies successful handle upgrade. Response |
| 347 | // needs to be sent over this connection only on |
| 348 | // failure. |
| 349 | self->completeRequest(thisRes); |
| 350 | return; |
| 351 | } |
| 352 | }); |
| 353 | BMCWEB_LOG_INFO("{} Upgrading socket", logPtr(this)); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 354 | if (httpType == HttpType::HTTP) |
| 355 | { |
| 356 | handler->handleUpgrade(req, asyncResp, |
| 357 | std::move(adaptor.next_layer())); |
| 358 | } |
| 359 | else |
| 360 | { |
| 361 | handler->handleUpgrade(req, asyncResp, std::move(adaptor)); |
| 362 | } |
| 363 | |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 364 | return true; |
| 365 | } |
| 366 | } |
| 367 | return false; |
| 368 | } |
| 369 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 370 | void handle() |
| 371 | { |
Ed Tanous | f79b7a5 | 2021-09-22 19:04:29 -0700 | [diff] [blame] | 372 | std::error_code reqEc; |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 373 | if (!parser) |
| 374 | { |
| 375 | return; |
| 376 | } |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 377 | req = std::make_shared<crow::Request>(parser->release(), reqEc); |
Ed Tanous | f79b7a5 | 2021-09-22 19:04:29 -0700 | [diff] [blame] | 378 | if (reqEc) |
| 379 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 380 | BMCWEB_LOG_DEBUG("Request failed to construct{}", reqEc.message()); |
Gunnar Mills | 262f115 | 2022-12-20 15:18:47 -0600 | [diff] [blame] | 381 | res.result(boost::beast::http::status::bad_request); |
| 382 | completeRequest(res); |
Ed Tanous | f79b7a5 | 2021-09-22 19:04:29 -0700 | [diff] [blame] | 383 | return; |
| 384 | } |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 385 | req->session = userSession; |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 386 | accept = req->getHeaderValue("Accept"); |
Ivan Mikhaylov | f65b0be | 2021-04-19 10:05:30 +0000 | [diff] [blame] | 387 | // Fetch the client IP address |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 388 | req->ipAddress = ip; |
Ivan Mikhaylov | f65b0be | 2021-04-19 10:05:30 +0000 | [diff] [blame] | 389 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 390 | // Check for HTTP version 1.1. |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 391 | if (req->version() == 11) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 392 | { |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 393 | if (req->getHeaderValue(boost::beast::http::field::host).empty()) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 394 | { |
Ed Tanous | de5c9f3 | 2019-03-26 09:17:55 -0700 | [diff] [blame] | 395 | res.result(boost::beast::http::status::bad_request); |
Nan Zhou | 72374eb | 2022-01-27 17:06:51 -0800 | [diff] [blame] | 396 | completeRequest(res); |
Ed Tanous | 6c7f01d | 2021-08-25 13:42:35 -0700 | [diff] [blame] | 397 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 398 | } |
| 399 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 400 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 401 | BMCWEB_LOG_INFO("Request: {} HTTP/{}.{} {} {} {}", logPtr(this), |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 402 | req->version() / 10, req->version() % 10, |
| 403 | req->methodString(), req->target(), |
| 404 | req->ipAddress.to_string()); |
Ed Tanous | d32c4fa | 2021-09-14 13:16:51 -0700 | [diff] [blame] | 405 | |
Ed Tanous | 6c7f01d | 2021-08-25 13:42:35 -0700 | [diff] [blame] | 406 | if (res.completed) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 407 | { |
Nan Zhou | 72374eb | 2022-01-27 17:06:51 -0800 | [diff] [blame] | 408 | completeRequest(res); |
Ed Tanous | 6c7f01d | 2021-08-25 13:42:35 -0700 | [diff] [blame] | 409 | return; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 410 | } |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 411 | keepAlive = req->keepAlive(); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 412 | |
| 413 | if (authenticationEnabled) |
Ed Tanous | 1d3c14a | 2021-09-22 18:54:40 -0700 | [diff] [blame] | 414 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 415 | if (!crow::authentication::isOnAllowlist(req->url().path(), |
| 416 | req->method()) && |
| 417 | req->session == nullptr) |
Ed Tanous | 4fa45df | 2023-09-01 14:20:50 -0700 | [diff] [blame] | 418 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 419 | BMCWEB_LOG_WARNING("Authentication failed"); |
| 420 | forward_unauthorized::sendUnauthorized( |
| 421 | req->url().encoded_path(), |
| 422 | req->getHeaderValue("X-Requested-With"), |
| 423 | req->getHeaderValue("Accept"), res); |
| 424 | completeRequest(res); |
| 425 | return; |
Ed Tanous | 4fa45df | 2023-09-01 14:20:50 -0700 | [diff] [blame] | 426 | } |
Ed Tanous | 4fa45df | 2023-09-01 14:20:50 -0700 | [diff] [blame] | 427 | } |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 428 | |
Nan Zhou | 72374eb | 2022-01-27 17:06:51 -0800 | [diff] [blame] | 429 | auto asyncResp = std::make_shared<bmcweb::AsyncResp>(); |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 430 | BMCWEB_LOG_DEBUG("Setting completion handler"); |
Nan Zhou | 72374eb | 2022-01-27 17:06:51 -0800 | [diff] [blame] | 431 | asyncResp->res.setCompleteRequestHandler( |
| 432 | [self(shared_from_this())](crow::Response& thisRes) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 433 | self->completeRequest(thisRes); |
| 434 | }); |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 435 | if (doUpgrade(asyncResp)) |
Ed Tanous | 6c7f01d | 2021-08-25 13:42:35 -0700 | [diff] [blame] | 436 | { |
Ed Tanous | 6c7f01d | 2021-08-25 13:42:35 -0700 | [diff] [blame] | 437 | return; |
| 438 | } |
Ed Tanous | 291d709 | 2022-04-13 12:34:57 -0700 | [diff] [blame] | 439 | std::string_view expected = |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 440 | req->getHeaderValue(boost::beast::http::field::if_none_match); |
Ed Tanous | 291d709 | 2022-04-13 12:34:57 -0700 | [diff] [blame] | 441 | if (!expected.empty()) |
| 442 | { |
Ed Tanous | 37b912f | 2025-03-20 18:24:30 -0700 | [diff] [blame] | 443 | asyncResp->res.setExpectedHash(expected); |
Ed Tanous | 291d709 | 2022-04-13 12:34:57 -0700 | [diff] [blame] | 444 | } |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 445 | handler->handle(req, asyncResp); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 446 | } |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 447 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 448 | void hardClose() |
Ed Tanous | e278c18 | 2019-03-13 16:23:37 -0700 | [diff] [blame] | 449 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 450 | BMCWEB_LOG_DEBUG("{} Closing socket", logPtr(this)); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 451 | adaptor.next_layer().close(); |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | void tlsShutdownComplete(const std::shared_ptr<self_type>& self, |
| 455 | const boost::system::error_code& ec) |
| 456 | { |
| 457 | if (ec) |
| 458 | { |
| 459 | BMCWEB_LOG_WARNING("{} Failed to shut down TLS cleanly {}", |
| 460 | logPtr(self.get()), ec); |
| 461 | } |
| 462 | self->hardClose(); |
| 463 | } |
| 464 | |
| 465 | void gracefulClose() |
| 466 | { |
| 467 | BMCWEB_LOG_DEBUG("{} Socket close requested", logPtr(this)); |
Ed Tanous | 3281bcf | 2024-06-25 16:02:05 -0700 | [diff] [blame] | 468 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 469 | if (httpType == HttpType::HTTPS) |
Ed Tanous | e278c18 | 2019-03-13 16:23:37 -0700 | [diff] [blame] | 470 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 471 | if (mtlsSession != nullptr) |
| 472 | { |
| 473 | BMCWEB_LOG_DEBUG("{} Removing TLS session: {}", logPtr(this), |
| 474 | mtlsSession->uniqueId); |
| 475 | persistent_data::SessionStore::getInstance().removeSession( |
| 476 | mtlsSession); |
| 477 | } |
| 478 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 479 | adaptor.async_shutdown(std::bind_front( |
| 480 | &self_type::tlsShutdownComplete, this, shared_from_this())); |
Ed Tanous | e278c18 | 2019-03-13 16:23:37 -0700 | [diff] [blame] | 481 | } |
| 482 | else |
| 483 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 484 | hardClose(); |
Ed Tanous | e278c18 | 2019-03-13 16:23:37 -0700 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | |
Nan Zhou | 72374eb | 2022-01-27 17:06:51 -0800 | [diff] [blame] | 488 | void completeRequest(crow::Response& thisRes) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 489 | { |
Nan Zhou | 72374eb | 2022-01-27 17:06:51 -0800 | [diff] [blame] | 490 | res = std::move(thisRes); |
Ed Tanous | 4cdc2e8 | 2023-01-13 10:03:22 -0800 | [diff] [blame] | 491 | res.keepAlive(keepAlive); |
Ed Tanous | 5ae6f92 | 2023-01-09 10:45:53 -0800 | [diff] [blame] | 492 | |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 493 | completeResponseFields(accept, res); |
Ed Tanous | 998e0cb | 2023-09-06 13:57:30 -0700 | [diff] [blame] | 494 | res.addHeader(boost::beast::http::field::date, getCachedDateStr()); |
Ed Tanous | 291d709 | 2022-04-13 12:34:57 -0700 | [diff] [blame] | 495 | |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 496 | doWrite(); |
Jan Sowinski | ee52ae1 | 2020-01-09 16:28:32 +0000 | [diff] [blame] | 497 | |
| 498 | // delete lambda with self shared_ptr |
| 499 | // to enable connection destruction |
John Edward Broadbent | 4147b8a | 2021-07-19 16:52:24 -0700 | [diff] [blame] | 500 | res.setCompleteRequestHandler(nullptr); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 503 | void readClientIp() |
| 504 | { |
| 505 | boost::system::error_code ec; |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 506 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 507 | boost::asio::ip::tcp::endpoint endpoint = |
| 508 | boost::beast::get_lowest_layer(adaptor).remote_endpoint(ec); |
Ed Tanous | 4fa45df | 2023-09-01 14:20:50 -0700 | [diff] [blame] | 509 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 510 | if (ec) |
| 511 | { |
| 512 | // If remote endpoint fails keep going. "ClientOriginIPAddress" |
| 513 | // will be empty. |
| 514 | BMCWEB_LOG_ERROR("Failed to get the client's IP Address. ec : {}", |
| 515 | ec); |
| 516 | return; |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 517 | } |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 518 | ip = endpoint.address(); |
| 519 | } |
| 520 | |
| 521 | void disableAuth() |
| 522 | { |
| 523 | authenticationEnabled = false; |
Sunitha Harish | c0ea7ae | 2020-10-30 02:37:30 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 526 | private: |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 527 | uint64_t getContentLengthLimit() |
| 528 | { |
Ed Tanous | 8332831 | 2024-05-09 15:48:09 -0700 | [diff] [blame] | 529 | if constexpr (!BMCWEB_INSECURE_DISABLE_AUTH) |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 530 | { |
Ed Tanous | 8332831 | 2024-05-09 15:48:09 -0700 | [diff] [blame] | 531 | if (userSession == nullptr) |
| 532 | { |
| 533 | return loggedOutPostBodyLimit; |
| 534 | } |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 535 | } |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 536 | |
| 537 | return httpReqBodyLimit; |
| 538 | } |
| 539 | |
| 540 | // Returns true if content length was within limits |
| 541 | // Returns false if content length error has been returned |
| 542 | bool handleContentLengthError() |
| 543 | { |
| 544 | if (!parser) |
| 545 | { |
Manojkiran Eda | efff2b5 | 2024-06-18 18:01:46 +0530 | [diff] [blame] | 546 | BMCWEB_LOG_CRITICAL("Parser was null"); |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 547 | return false; |
| 548 | } |
| 549 | const boost::optional<uint64_t> contentLength = |
| 550 | parser->content_length(); |
| 551 | if (!contentLength) |
| 552 | { |
| 553 | BMCWEB_LOG_DEBUG("{} No content length available", logPtr(this)); |
| 554 | return true; |
| 555 | } |
| 556 | |
| 557 | uint64_t maxAllowedContentLength = getContentLengthLimit(); |
| 558 | |
| 559 | if (*contentLength > maxAllowedContentLength) |
| 560 | { |
| 561 | // If the users content limit is between the logged in |
| 562 | // and logged out limits They probably just didn't log |
| 563 | // in |
| 564 | if (*contentLength > loggedOutPostBodyLimit && |
| 565 | *contentLength < httpReqBodyLimit) |
| 566 | { |
| 567 | BMCWEB_LOG_DEBUG( |
| 568 | "{} Content length {} valid, but greater than logged out" |
| 569 | " limit of {}. Setting unauthorized", |
| 570 | logPtr(this), *contentLength, loggedOutPostBodyLimit); |
| 571 | res.result(boost::beast::http::status::unauthorized); |
| 572 | } |
| 573 | else |
| 574 | { |
| 575 | // Otherwise they're over both limits, so inform |
| 576 | // them |
| 577 | BMCWEB_LOG_DEBUG( |
| 578 | "{} Content length {} was greater than global limit {}." |
| 579 | " Setting payload too large", |
| 580 | logPtr(this), *contentLength, httpReqBodyLimit); |
| 581 | res.result(boost::beast::http::status::payload_too_large); |
| 582 | } |
| 583 | |
| 584 | keepAlive = false; |
| 585 | doWrite(); |
| 586 | return false; |
| 587 | } |
| 588 | |
| 589 | return true; |
| 590 | } |
| 591 | |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 592 | void afterReadHeaders(const std::shared_ptr<self_type>& /*self*/, |
| 593 | const boost::system::error_code& ec, |
| 594 | std::size_t bytesTransferred) |
| 595 | { |
| 596 | BMCWEB_LOG_DEBUG("{} async_read_header {} Bytes", logPtr(this), |
| 597 | bytesTransferred); |
| 598 | |
| 599 | if (ec) |
| 600 | { |
| 601 | cancelDeadlineTimer(); |
| 602 | |
| 603 | if (ec == boost::beast::http::error::header_limit) |
| 604 | { |
| 605 | BMCWEB_LOG_ERROR("{} Header field too large, closing", |
| 606 | logPtr(this), ec.message()); |
| 607 | |
| 608 | res.result(boost::beast::http::status:: |
| 609 | request_header_fields_too_large); |
| 610 | keepAlive = false; |
| 611 | doWrite(); |
| 612 | return; |
| 613 | } |
Chandramohan Harkude | 352ee0e | 2025-06-04 11:16:34 +0530 | [diff] [blame^] | 614 | if (ec == boost::beast::http::error::end_of_stream || |
| 615 | ec == boost::asio::ssl::error::stream_truncated) |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 616 | { |
| 617 | BMCWEB_LOG_WARNING("{} End of stream, closing {}", logPtr(this), |
| 618 | ec); |
| 619 | hardClose(); |
| 620 | return; |
| 621 | } |
| 622 | |
| 623 | BMCWEB_LOG_DEBUG("{} Closing socket due to read error {}", |
| 624 | logPtr(this), ec.message()); |
| 625 | gracefulClose(); |
| 626 | |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | if (!parser) |
| 631 | { |
| 632 | BMCWEB_LOG_ERROR("Parser was unexpectedly null"); |
| 633 | return; |
| 634 | } |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 635 | auto& parse = *parser; |
| 636 | const auto& value = parser->get(); |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 637 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 638 | if (authenticationEnabled) |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 639 | { |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 640 | boost::beast::http::verb method = value.method(); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 641 | userSession = authentication::authenticate( |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 642 | ip, res, method, value.base(), mtlsSession); |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 643 | } |
| 644 | |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 645 | std::string_view expect = value[boost::beast::http::field::expect]; |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 646 | if (bmcweb::asciiIEquals(expect, "100-continue")) |
| 647 | { |
| 648 | res.result(boost::beast::http::status::continue_); |
| 649 | doWrite(); |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | if (!handleContentLengthError()) |
| 654 | { |
| 655 | return; |
| 656 | } |
| 657 | |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 658 | parse.body_limit(getContentLengthLimit()); |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 659 | |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 660 | if (parse.is_done()) |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 661 | { |
| 662 | handle(); |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | doRead(); |
| 667 | } |
| 668 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 669 | void doReadHeaders() |
| 670 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 671 | BMCWEB_LOG_DEBUG("{} doReadHeaders", logPtr(this)); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 672 | if (!parser) |
| 673 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 674 | BMCWEB_LOG_CRITICAL("Parser was not initialized."); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 675 | return; |
| 676 | } |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 677 | |
| 678 | if (httpType == HttpType::HTTP) |
| 679 | { |
| 680 | boost::beast::http::async_read_header( |
| 681 | adaptor.next_layer(), buffer, *parser, |
| 682 | std::bind_front(&self_type::afterReadHeaders, this, |
| 683 | shared_from_this())); |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | boost::beast::http::async_read_header( |
| 688 | adaptor, buffer, *parser, |
| 689 | std::bind_front(&self_type::afterReadHeaders, this, |
| 690 | shared_from_this())); |
| 691 | } |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 692 | } |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 693 | |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 694 | void afterRead(const std::shared_ptr<self_type>& /*self*/, |
| 695 | const boost::system::error_code& ec, |
| 696 | std::size_t bytesTransferred) |
| 697 | { |
| 698 | BMCWEB_LOG_DEBUG("{} async_read_some {} Bytes", logPtr(this), |
| 699 | bytesTransferred); |
| 700 | |
| 701 | if (ec) |
| 702 | { |
| 703 | BMCWEB_LOG_ERROR("{} Error while reading: {}", logPtr(this), |
| 704 | ec.message()); |
| 705 | if (ec == boost::beast::http::error::body_limit) |
| 706 | { |
| 707 | if (handleContentLengthError()) |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 708 | { |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 709 | BMCWEB_LOG_CRITICAL("Body length limit reached, " |
| 710 | "but no content-length " |
| 711 | "available? Should never happen"); |
| 712 | res.result( |
| 713 | boost::beast::http::status::internal_server_error); |
| 714 | keepAlive = false; |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 715 | doWrite(); |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 716 | } |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 717 | return; |
| 718 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 719 | |
Chandramohan Harkude | 352ee0e | 2025-06-04 11:16:34 +0530 | [diff] [blame^] | 720 | if (ec == boost::beast::http::error::end_of_stream || |
| 721 | ec == boost::asio::ssl::error::stream_truncated) |
| 722 | { |
| 723 | BMCWEB_LOG_WARNING("{} End of stream, closing {}", logPtr(this), |
| 724 | ec); |
| 725 | hardClose(); |
| 726 | return; |
| 727 | } |
| 728 | |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 729 | gracefulClose(); |
| 730 | return; |
| 731 | } |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 732 | |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 733 | // If the user is logged in, allow them to send files |
| 734 | // incrementally one piece at a time. If authentication is |
| 735 | // disabled then there is no user session hence always allow to |
| 736 | // send one piece at a time. |
| 737 | if (userSession != nullptr) |
| 738 | { |
| 739 | cancelDeadlineTimer(); |
| 740 | } |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 741 | |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 742 | if (!parser) |
| 743 | { |
| 744 | BMCWEB_LOG_ERROR("Parser was unexpectedly null"); |
| 745 | return; |
| 746 | } |
| 747 | if (!parser->is_done()) |
| 748 | { |
| 749 | doRead(); |
| 750 | return; |
| 751 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 752 | |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 753 | cancelDeadlineTimer(); |
| 754 | handle(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | void doRead() |
| 758 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 759 | BMCWEB_LOG_DEBUG("{} doRead", logPtr(this)); |
Ed Tanous | e01d0c3 | 2023-06-30 13:21:32 -0700 | [diff] [blame] | 760 | if (!parser) |
| 761 | { |
| 762 | return; |
| 763 | } |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 764 | auto& parse = *parser; |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 765 | startDeadline(); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 766 | if (httpType == HttpType::HTTP) |
| 767 | { |
| 768 | boost::beast::http::async_read_some( |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 769 | adaptor.next_layer(), buffer, parse, |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 770 | std::bind_front(&self_type::afterRead, this, |
| 771 | shared_from_this())); |
| 772 | } |
| 773 | else |
| 774 | { |
| 775 | boost::beast::http::async_read_some( |
Ed Tanous | 3d15864 | 2025-05-12 14:20:49 -0700 | [diff] [blame] | 776 | adaptor, buffer, parse, |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 777 | std::bind_front(&self_type::afterRead, this, |
| 778 | shared_from_this())); |
| 779 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 782 | void afterDoWrite(const std::shared_ptr<self_type>& /*self*/, |
| 783 | const boost::system::error_code& ec, |
| 784 | std::size_t bytesTransferred) |
| 785 | { |
Ed Tanous | 0242baf | 2024-05-16 19:52:47 -0700 | [diff] [blame] | 786 | BMCWEB_LOG_DEBUG("{} async_write wrote {} bytes, ec={}", logPtr(this), |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 787 | bytesTransferred, ec); |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 788 | |
| 789 | cancelDeadlineTimer(); |
| 790 | |
Ed Tanous | 0242baf | 2024-05-16 19:52:47 -0700 | [diff] [blame] | 791 | if (ec == boost::system::errc::operation_would_block || |
| 792 | ec == boost::system::errc::resource_unavailable_try_again) |
| 793 | { |
| 794 | doWrite(); |
| 795 | return; |
| 796 | } |
Chandramohan Harkude | 352ee0e | 2025-06-04 11:16:34 +0530 | [diff] [blame^] | 797 | |
| 798 | if (ec == boost::beast::http::error::end_of_stream || |
| 799 | ec == boost::asio::ssl::error::stream_truncated) |
| 800 | { |
| 801 | BMCWEB_LOG_WARNING("{} End of stream, closing {}", logPtr(this), |
| 802 | ec); |
| 803 | hardClose(); |
| 804 | return; |
| 805 | } |
| 806 | |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 807 | if (ec) |
| 808 | { |
| 809 | BMCWEB_LOG_DEBUG("{} from write(2)", logPtr(this)); |
| 810 | return; |
| 811 | } |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 812 | |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 813 | if (res.result() == boost::beast::http::status::switching_protocols) |
| 814 | { |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 815 | upgradeToHttp2(); |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 816 | return; |
| 817 | } |
| 818 | |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 819 | if (res.result() == boost::beast::http::status::continue_) |
| 820 | { |
| 821 | // Reset the result to ok |
| 822 | res.result(boost::beast::http::status::ok); |
| 823 | doRead(); |
| 824 | return; |
| 825 | } |
| 826 | |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 827 | if (!keepAlive) |
| 828 | { |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 829 | BMCWEB_LOG_DEBUG("{} keepalive not set. Closing socket", |
| 830 | logPtr(this)); |
| 831 | |
| 832 | gracefulClose(); |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 833 | return; |
| 834 | } |
| 835 | |
| 836 | BMCWEB_LOG_DEBUG("{} Clearing response", logPtr(this)); |
| 837 | res.clear(); |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 838 | initParser(); |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 839 | |
| 840 | userSession = nullptr; |
| 841 | |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 842 | req->clear(); |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 843 | doReadHeaders(); |
| 844 | } |
| 845 | |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 846 | void doWrite() |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 847 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 848 | BMCWEB_LOG_DEBUG("{} doWrite", logPtr(this)); |
Ed Tanous | 52e3162 | 2024-01-23 16:31:11 -0800 | [diff] [blame] | 849 | res.preparePayload(); |
Ed Tanous | 27b0cf9 | 2023-08-07 12:02:40 -0700 | [diff] [blame] | 850 | |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 851 | startDeadline(); |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 852 | if (httpType == HttpType::HTTP) |
| 853 | { |
| 854 | boost::beast::async_write( |
| 855 | adaptor.next_layer(), |
| 856 | boost::beast::http::message_generator(std::move(res.response)), |
| 857 | std::bind_front(&self_type::afterDoWrite, this, |
| 858 | shared_from_this())); |
| 859 | } |
| 860 | else |
| 861 | { |
| 862 | boost::beast::async_write( |
| 863 | adaptor, |
| 864 | boost::beast::http::message_generator(std::move(res.response)), |
| 865 | std::bind_front(&self_type::afterDoWrite, this, |
| 866 | shared_from_this())); |
| 867 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 870 | void cancelDeadlineTimer() |
| 871 | { |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 872 | timer.cancel(); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 873 | } |
| 874 | |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 875 | void afterTimerWait(const std::weak_ptr<self_type>& weakSelf, |
| 876 | const boost::system::error_code& ec) |
| 877 | { |
| 878 | // Note, we are ignoring other types of errors here; If the timer |
| 879 | // failed for any reason, we should still close the connection |
| 880 | std::shared_ptr<Connection<Adaptor, Handler>> self = weakSelf.lock(); |
| 881 | if (!self) |
| 882 | { |
| 883 | if (ec == boost::asio::error::operation_aborted) |
| 884 | { |
| 885 | BMCWEB_LOG_DEBUG( |
| 886 | "{} Timer canceled on connection being destroyed", |
| 887 | logPtr(self.get())); |
| 888 | } |
| 889 | else |
| 890 | { |
| 891 | BMCWEB_LOG_CRITICAL("{} Failed to capture connection", |
| 892 | logPtr(self.get())); |
| 893 | } |
| 894 | return; |
| 895 | } |
| 896 | |
| 897 | self->timerStarted = false; |
| 898 | |
| 899 | if (ec) |
| 900 | { |
| 901 | if (ec == boost::asio::error::operation_aborted) |
| 902 | { |
| 903 | BMCWEB_LOG_DEBUG("{} Timer canceled", logPtr(self.get())); |
| 904 | return; |
| 905 | } |
| 906 | BMCWEB_LOG_CRITICAL("{} Timer failed {}", logPtr(self.get()), ec); |
| 907 | } |
| 908 | |
| 909 | BMCWEB_LOG_WARNING("{} Connection timed out, hard closing", |
| 910 | logPtr(self.get())); |
| 911 | |
| 912 | self->hardClose(); |
| 913 | } |
| 914 | |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 915 | void startDeadline() |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 916 | { |
Ed Tanous | 7d243eb | 2023-01-23 15:57:41 -0800 | [diff] [blame] | 917 | // Timer is already started so no further action is required. |
| 918 | if (timerStarted) |
| 919 | { |
| 920 | return; |
| 921 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 922 | |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 923 | std::chrono::seconds timeout(15); |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 924 | |
| 925 | std::weak_ptr<Connection<Adaptor, Handler>> weakSelf = weak_from_this(); |
| 926 | timer.expires_after(timeout); |
Ed Tanous | 116370d | 2024-10-08 10:37:28 -0700 | [diff] [blame] | 927 | timer.async_wait(std::bind_front(&self_type::afterTimerWait, this, |
| 928 | weak_from_this())); |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 929 | |
Ed Tanous | 7d243eb | 2023-01-23 15:57:41 -0800 | [diff] [blame] | 930 | timerStarted = true; |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 931 | BMCWEB_LOG_DEBUG("{} timer started", logPtr(this)); |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Ed Tanous | 796ba93 | 2020-08-02 04:29:21 +0000 | [diff] [blame] | 934 | bool authenticationEnabled = !BMCWEB_INSECURE_DISABLE_AUTH; |
| 935 | HttpType httpType = HttpType::BOTH; |
| 936 | |
| 937 | boost::asio::ssl::stream<Adaptor> adaptor; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 938 | Handler* handler; |
Ed Tanous | 1d1d778 | 2024-04-09 12:54:08 -0700 | [diff] [blame] | 939 | |
| 940 | boost::asio::ip::address ip; |
| 941 | |
Ed Tanous | a24526d | 2018-12-10 15:17:59 -0800 | [diff] [blame] | 942 | // Making this a std::optional allows it to be efficiently destroyed and |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 943 | // re-created on Connection reset |
Ed Tanous | b289614 | 2024-01-31 15:25:47 -0800 | [diff] [blame] | 944 | std::optional<boost::beast::http::request_parser<bmcweb::HttpBody>> parser; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 945 | |
Ed Tanous | 3112a14 | 2018-11-29 15:45:10 -0800 | [diff] [blame] | 946 | boost::beast::flat_static_buffer<8192> buffer; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 947 | |
Jonathan Doman | 102a4cd | 2024-04-15 16:56:23 -0700 | [diff] [blame] | 948 | std::shared_ptr<crow::Request> req; |
Ed Tanous | 89cda63 | 2024-04-16 08:45:54 -0700 | [diff] [blame] | 949 | std::string accept; |
Ed Tanous | cd7dbb3 | 2025-02-01 12:37:56 -0800 | [diff] [blame] | 950 | std::string http2settings; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 951 | crow::Response res; |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 952 | |
John Edward Broadbent | 59b98b2 | 2021-07-13 15:36:32 -0700 | [diff] [blame] | 953 | std::shared_ptr<persistent_data::UserSession> userSession; |
Boleslaw Ogonczyk Makowski | b496307 | 2023-02-06 09:59:58 +0100 | [diff] [blame] | 954 | std::shared_ptr<persistent_data::UserSession> mtlsSession; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 955 | |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 956 | boost::asio::steady_timer timer; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 957 | |
Ed Tanous | 4cdc2e8 | 2023-01-13 10:03:22 -0800 | [diff] [blame] | 958 | bool keepAlive = true; |
| 959 | |
Ed Tanous | 7d243eb | 2023-01-23 15:57:41 -0800 | [diff] [blame] | 960 | bool timerStarted = false; |
| 961 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 962 | std::function<std::string()>& getCachedDateStr; |
Jan Sowinski | ee52ae1 | 2020-01-09 16:28:32 +0000 | [diff] [blame] | 963 | |
| 964 | using std::enable_shared_from_this< |
Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 965 | Connection<Adaptor, Handler>>::shared_from_this; |
Ed Tanous | 5dfb5b2 | 2021-12-03 11:24:53 -0800 | [diff] [blame] | 966 | |
| 967 | using std::enable_shared_from_this< |
| 968 | Connection<Adaptor, Handler>>::weak_from_this; |
Ed Tanous | 3112a14 | 2018-11-29 15:45:10 -0800 | [diff] [blame] | 969 | }; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 970 | } // namespace crow |