Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
session_ticket_store.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
7#include "transport_params.h"
8
9#include <chrono>
10#include <mutex>
11#include <optional>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
17{
18
28{
30 std::vector<uint8_t> ticket_data;
31
33 std::chrono::system_clock::time_point expiry;
34
36 std::string server_name;
37
39 unsigned short port{0};
40
43
46
48 uint32_t ticket_age_add{0};
49
51 std::chrono::system_clock::time_point received_time;
52
57 [[nodiscard]] auto is_valid() const noexcept -> bool;
58
63 [[nodiscard]] auto get_obfuscated_age() const noexcept -> uint32_t;
64};
65
97{
98public:
103
108
109 // Non-copyable, non-movable (contains mutex)
114
123 auto store(const std::string& server,
124 unsigned short port,
125 const session_ticket_info& ticket) -> void;
126
137 [[nodiscard]] auto retrieve(const std::string& server,
138 unsigned short port) const
139 -> std::optional<session_ticket_info>;
140
147 auto remove(const std::string& server, unsigned short port) -> bool;
148
153 auto cleanup_expired() -> size_t;
154
158 auto clear() -> void;
159
164 [[nodiscard]] auto size() const -> size_t;
165
172 [[nodiscard]] auto has_ticket(const std::string& server,
173 unsigned short port) const -> bool;
174
175private:
182 [[nodiscard]] static auto make_key(const std::string& server,
183 unsigned short port) -> std::string;
184
186 mutable std::mutex mutex_;
187
189 std::unordered_map<std::string, session_ticket_info> tickets_;
190};
191
210{
211public:
215 struct config
216 {
218 std::chrono::seconds window_size{10};
219
221 size_t max_entries{100000};
222 };
223
228
233 explicit replay_filter(const config& cfg);
234
243 [[nodiscard]] auto check_and_record(
244 std::span<const uint8_t> nonce,
245 std::chrono::system_clock::time_point timestamp
246 = std::chrono::system_clock::now()) -> bool;
247
253 auto cleanup(std::chrono::system_clock::time_point now
254 = std::chrono::system_clock::now()) -> size_t;
255
259 auto clear() -> void;
260
265 [[nodiscard]] auto size() const -> size_t;
266
267private:
269 {
270 std::vector<uint8_t> nonce;
271 std::chrono::system_clock::time_point timestamp;
272 };
273
275 mutable std::mutex mutex_;
276 std::vector<nonce_entry> entries_;
277};
278
279} // namespace kcenon::network::protocols::quic
Anti-replay protection for 0-RTT data.
Thread-safe storage for QUIC session tickets.
session_ticket_store & operator=(const session_ticket_store &)=delete
session_ticket_store(session_ticket_store &&)=delete
session_ticket_store & operator=(session_ticket_store &&)=delete
session_ticket_store(const session_ticket_store &)=delete
std::mutex mutex
std::vector< uint8_t > nonce
std::chrono::system_clock::time_point timestamp
Contains session ticket data for 0-RTT resumption.
std::chrono::system_clock::time_point received_time
Time when the ticket was received.
std::chrono::system_clock::time_point expiry
Ticket expiration time.
auto is_valid() const noexcept -> bool
Check if the ticket is still valid (not expired)
std::string server_name
Server name (for SNI matching)
auto get_obfuscated_age() const noexcept -> uint32_t
Get obfuscated ticket age (RFC 8446 Section 4.2.11.1)
transport_parameters saved_params
Saved transport parameters from the original connection.
uint32_t ticket_age_add
Ticket age add value for obfuscation (RFC 8446)
unsigned short port
Server port (for endpoint matching)
std::vector< uint8_t > ticket_data
Raw session ticket data from TLS 1.3 NewSessionTicket.
uint32_t max_early_data_size
Maximum early data size allowed (from max_early_data_size extension)
QUIC transport parameters (RFC 9000 Section 18)