Coverage Report

Created: 2026-01-21 08:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/node/src/quic/sessionticket.h
Line
Count
Source
1
#pragma once
2
3
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
4
5
#include <crypto/crypto_common.h>
6
#include <env.h>
7
#include <memory_tracker.h>
8
#include <uv.h>
9
#include <v8.h>
10
#include "data.h"
11
#include "defs.h"
12
13
namespace node::quic {
14
15
// A TLS 1.3 Session resumption ticket. Encapsulates both the TLS
16
// ticket and the encoded QUIC transport parameters. The encoded
17
// structure should be considered to be opaque for end users.
18
// In JavaScript, the ticket will be represented as a Buffer
19
// instance with opaque data. To resume a session, the user code
20
// would pass that Buffer back into to client connection API.
21
class SessionTicket final : public MemoryRetainer {
22
 public:
23
  static v8::Maybe<SessionTicket> FromV8Value(Environment* env,
24
                                              v8::Local<v8::Value> value);
25
26
0
  SessionTicket() = default;
27
  SessionTicket(Store&& ticket, Store&& transport_params);
28
29
  const uv_buf_t ticket() const;
30
31
  const ngtcp2_vec transport_params() const;
32
33
  v8::MaybeLocal<v8::Object> encode(Environment* env) const;
34
35
  void MemoryInfo(MemoryTracker* tracker) const override;
36
  SET_MEMORY_INFO_NAME(SessionTicket)
37
  SET_SELF_SIZE(SessionTicket)
38
39
  class AppData;
40
41
  // The callback that OpenSSL will call when generating the session ticket
42
  // and it needs to collect additional application specific data.
43
  static int GenerateCallback(SSL* ssl, void* arg);
44
45
  // The callback that OpenSSL will call when consuming the session ticket
46
  // and it needs to pass embedded application data back into the app.
47
  static SSL_TICKET_RETURN DecryptedCallback(SSL* ssl,
48
                                             SSL_SESSION* session,
49
                                             const unsigned char* keyname,
50
                                             size_t keyname_len,
51
                                             SSL_TICKET_STATUS status,
52
                                             void* arg);
53
54
 private:
55
  Store ticket_;
56
  Store transport_params_;
57
};
58
59
// SessionTicket::AppData is a utility class that is used only during the
60
// generation or access of TLS stateless session tickets. It exists solely to
61
// provide a easier way for Session::Application instances to set relevant
62
// metadata in the session ticket when it is created, and the extract and
63
// subsequently verify that data when a ticket is received and is being
64
// validated. The app data is completely opaque to anything other than the
65
// server-side of the Session::Application that sets it.
66
class SessionTicket::AppData final {
67
 public:
68
  enum class Status : uint8_t {
69
    TICKET_IGNORE = SSL_TICKET_RETURN_IGNORE,
70
    TICKET_IGNORE_RENEW = SSL_TICKET_RETURN_IGNORE_RENEW,
71
    TICKET_USE = SSL_TICKET_RETURN_USE,
72
    TICKET_USE_RENEW = SSL_TICKET_RETURN_USE_RENEW,
73
  };
74
75
  explicit AppData(SSL* session);
76
  DISALLOW_COPY_AND_MOVE(AppData)
77
78
  bool Set(const uv_buf_t& data);
79
  std::optional<const uv_buf_t> Get() const;
80
81
  // A source of application data collected during the creation of the
82
  // session ticket. This interface will be implemented by the QUIC
83
  // Session.
84
  class Source {
85
   public:
86
    enum class Flag : uint8_t { STATUS_NONE, STATUS_RENEW };
87
88
    // Collect application data into the given AppData instance.
89
    virtual void CollectSessionTicketAppData(AppData* app_data) const = 0;
90
91
    // Extract application data from the given AppData instance.
92
    virtual Status ExtractSessionTicketAppData(
93
        const AppData& app_data, Flag flag = Flag::STATUS_NONE) = 0;
94
  };
95
96
  static void Collect(SSL* ssl);
97
  static Status Extract(SSL* ssl);
98
99
 private:
100
  bool set_ = false;
101
  SSL* ssl_;
102
};
103
104
}  // namespace node::quic
105
106
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS