Skip to content

Commit bbbb36e

Browse files
author
Damir Zainullin
committed
++
1 parent 135b00a commit bbbb36e

File tree

10 files changed

+175
-597
lines changed

10 files changed

+175
-597
lines changed

process-plugin-api/process/quic/src/opensslContextWrapper.hpp

Whitespace-only changes.

process-plugin-api/process/quic/src/quic.cpp

Lines changed: 126 additions & 292 deletions
Large diffs are not rendered by default.

process-plugin-api/process/quic/src/quicDirection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
namespace ipxp
88
{
99
enum class QUICDirection : uint8_t {
10-
CLIENT_TO_SERVER = static_cast<uint8_t>(Direction::Forward),
11-
SERVER_TO_CLIENT = static_cast<uint8_t>(Direction::Reverse),
10+
CLIENT_TO_SERVER,
11+
SERVER_TO_CLIENT,
1212
};
1313

1414
} // namespace ipxp

process-plugin-api/process/quic/src/quicExport.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,44 @@
55
#include <span>
66
#include <boost/static_string.hpp>
77
#include <boost/container/static_vector.hpp>
8-
8+
#include <vector>
99

1010
#include "burst.hpp"
1111

1212
namespace ipxp
1313
{
1414

15+
constexpr static std::size_t MAX_CONNECTION_ID_LENGTH = 20;
16+
using ConnectionId = container::static_vector<uint8_t, MAX_CONNECTION_ID_LENGTH>;
17+
1518
struct QUICExport {
1619
constexpr static std::size_t BUFFER_SIZE = 255;
17-
constexpr static std::size_t MAX_CONNECTION_ID_LENGTH = 20;
20+
boost::static_string<BUFFER_SIZE> sni;
21+
boost::static_string<BUFFER_SIZE> userAgent;
22+
1823
constexpr static std::size_t MAX_PACKETS = 30;
24+
boost::container::static_vector<uint8_t, MAX_PACKETS> packetTypes;
25+
1926
constexpr static std::size_t MAX_TLS_EXTENSIONS = 30;
20-
constexpr static std::size_t MAX_BUFFER_SIZE = 1500;
27+
boost::container::static_vector<uint16_t, MAX_TLS_EXTENSIONS> tlsExtensionTypes;
28+
boost::container::static_vector<uint16_t, MAX_TLS_EXTENSIONS> tlsExtensionLengths;
29+
30+
constexpr static std::size_t MAX_TLS_PAYLOAD_TO_SAVE = 1500;
31+
std::vector<std::byte> extensionsPayload;
2132

22-
boost::static_string<BUFFER_SIZE> sni;
23-
boost::static_string<BUFFER_SIZE> userAgent;
2433
uint32_t quicVersion;
2534
uint32_t quicClientVersion;
2635
uint64_t quicTokenLength;
27-
boost::static_string<MAX_CONNECTION_ID_LENGTH> originalClientId;
28-
boost::static_string<MAX_CONNECTION_ID_LENGTH> originalServerId;
29-
boost::static_string<MAX_CONNECTION_ID_LENGTH> serverId;
30-
boost::static_string<MAX_CONNECTION_ID_LENGTH> retryScid;
3136
uint8_t multiplexedCount;
3237
uint8_t quicZeroRTTCount;
3338
uint8_t clientHelloParsed;
3439
uint16_t serverPort;
35-
boost::container::static_vector<uint8_t, MAX_PACKETS> packetTypes;
36-
boost::container::static_vector<uint16_t, MAX_TLS_EXTENSIONS> tlsExtensionTypes;
37-
boost::container::static_vector<uint16_t, MAX_TLS_EXTENSIONS> tlsExtensionLengths;
38-
boost::container::static_vector<std::byte, MAX_BUFFER_SIZE> extensionsPayload;
40+
41+
ConnectionId originalClientId;
42+
ConnectionId originalServerId;
43+
ConnectionId sourceId;
44+
ConnectionId retrySCID;
45+
3946

4047

4148

process-plugin-api/process/quic/src/quicHeader.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
namespace ipxp
99
{
1010

11-
struct FirstQUICHeader {
11+
struct PrimaryQUICHeader {
1212
uint8_t headerForm;
1313
uint32_t version;
1414
uint8_t destConnectionIdLength;
1515

1616
constexpr static
17-
std::optional<FirstQUICHeader>
17+
std::optional<PrimaryQUICHeader>
1818
createFromPayload(std::span<const std::byte> payload) noexcept
1919
{
20-
if (payload.size() < sizeof(FirstQUICHeader)) {
20+
if (payload.size() < sizeof(PrimaryQUICHeader)) {
2121
return std::nullopt;
2222
}
23-
return FirstQUICHeader{
23+
return PrimaryQUICHeader{
2424
.headerForm = static_cast<uint8_t>(payload[0]),
2525
.version = ntohl(*reinterpret_cast<const uint32_t*>(&payload[1])),
2626
.destConnectionIdLength = static_cast<uint8_t>(payload[5])

process-plugin-api/process/quic/src/quicInitialHeaderView.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,7 @@ createInitialSecrets(std::span<const std::byte> destConnectionId,
167167

168168
// HKDF-Extract
169169
//std::unique_ptr<EVP_PKEY_CTX> publicKeyContext
170-
auto publicKeyContext
171-
= std::unique_ptr<EVP_PKEY_CTX, std::function<void(EVP_PKEY_CTX*)>>{
172-
EVP_PKEY_CTX_new_id(EVP_PKEY_HKDF, nullptr), EVP_PKEY_CTX_free
173-
};
170+
auto publicKeyContext = createKeyContext();
174171

175172
const ExpandedLabel expandedLabel
176173
= expandLabel<QUICInitialHeaderView::SHA2_256_LENGTH>(
@@ -356,7 +353,7 @@ bool decryptInitialHeader(const QUICInitialSecrets& initialSecrets,
356353
return true;
357354
}
358355

359-
constexpr static std::optional<std::array<std::byte, QUICInitialHeaderView::MAX_BUFFER_SIZE>>
356+
constexpr static std::optional<std::array<std::byte, ReassembledFrame::capacity()>>
360357
decryptPayload(std::span<const std::byte> encryptedPayload) noexcept
361358
{
362359
const std::array<std::byte, 16> authTag;
@@ -365,15 +362,14 @@ decryptPayload(std::span<const std::byte> encryptedPayload) noexcept
365362
return std::nullopt;
366363
}
367364
/* Input is --> "header || ciphertext (buffer) || auth tag (16 bytes)" */
368-
if (encryptedPayload.size() > QUICInitialHeaderView::MAX_BUFFER_SIZE) {
365+
if (encryptedPayload.size() > ReassembledFrame::capacity()) {
369366
return std::nullopt;
370367
}
371368

372369
std::size_t decryptedLength;
373370

374-
auto decryptedPayload
375-
= std::make_optional<std::array<std::byte,
376-
QUICInitialHeaderView::MAX_BUFFER_SIZE>>();
371+
auto decryptedPayload = std::make_optional<std::array<std::byte,
372+
ReassembledFrame::capacity()>>();
377373

378374
// https://datatracker.ietf.org/doc/html/draft-ietf-quic-tls-34#section-5.3
379375
// "These cipher suites have a 16-byte authentication tag and produce an output 16 bytes larger
@@ -384,7 +380,6 @@ decryptPayload(std::span<const std::byte> encryptedPayload) noexcept
384380
std::copy(encryptedPayload.data() + encryptedPayload.size() - 16,
385381
encryptedPayload.data() + encryptedPayload.size(), authTag.begin());
386382

387-
// creating context
388383
auto cipherContext = createCipherContext();
389384

390385
if (!cipherContext ||
@@ -620,6 +615,7 @@ reassembleCryptoFrames(std::span<const std::byte> decryptedPayload) noexcept
620615
cryptoData->size(), reassembledFrame->capacity() - reassembledFrame->size());
621616
reassembledFrame->insert(
622617
cryptoData->begin(), cryptoData->begin() + sizeToCopy);
618+
623619
frameLength = cryptoData->data() -
624620
decryptedPayload.data() + cryptoData->size();
625621
case FrameType::ACK1:
@@ -651,6 +647,7 @@ reassembleCryptoFrames(std::span<const std::byte> decryptedPayload) noexcept
651647
return reassembledFrame;
652648
}
653649

650+
constexpr
654651
bool QUICParser::parseTLSExtensions(TLSParser& parser)
655652
{
656653
const bool extensionsParsed = parser.parseExtensions(
@@ -671,8 +668,8 @@ bool QUICParser::parseTLSExtensions(TLSParser& parser)
671668
|| extension_type == TLSExtensionType::QUIC_TRANSPORT_PARAMETERS
672669
|| extension_type == TLSExtensionType::QUIC_TRANSPORT_PARAMETERS_V2) {
673670
std::ranges::copy(extension.payload |
674-
std::views::take(m_tlsExtensionBuffer.capacity()),
675-
std::back_inserter(m_tlsExtensionBuffer));
671+
std::views::take(QUICExport::MAX_TLS_PAYLOAD_TO_SAVE),
672+
std::back_inserter(extensionsPayload));
676673
}
677674

678675
if (!m_exportData.extensionTypes.full()) {
@@ -684,18 +681,20 @@ bool QUICParser::parseTLSExtensions(TLSParser& parser)
684681
return extensionsParsed;
685682
}
686683

687-
constexpr static
684+
constexpr
688685
bool QUICInitialHeaderView::parseTLS(const ReassembledFrame& reassembledFrame)
689686
{
690687
TLSParser parser;
691688
if (!parser.parseHelloFromQUIC(toSpan(reassembledFrame))) {
692689
return false;
693690
}
691+
694692
tlsHandshake = parser.handshake;
693+
695694
return parseTLSExtensions(parser);
696695
}
697696

698-
constexpr static
697+
constexpr
699698
bool QUICInitialHeaderView::parse(std::span<const std::byte> destConnectionId,
700699
std::span<const std::byte> salt,
701700
const PacketType packetType,
@@ -728,7 +727,7 @@ bool QUICInitialHeaderView::parse(std::span<const std::byte> destConnectionId,
728727
// SNI and User Agent Extraction failed
729728
return false;
730729
}
731-
730+
732731
clientHelloParsed = tlsHandshake.type == TLSHandshake::Type::CLIENT_HELLO;
733732

734733
return true;

process-plugin-api/process/quic/src/quicInitialHeaderView.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <optional>
66

77
#include "quicInitialSecrets.hpp"
8+
#include "quicExport.hpp"
89

910
namespace ipxp
1011
{
@@ -21,7 +22,7 @@ struct QUICInitialHeaderView {
2122
= boost::container::static_vector<std::byte, MAX_BUFFER_SIZE>;
2223

2324
using TLSExtensionBuffer
24-
= boost::container::static_vector<std::byte, MAX_BUFFER_SIZE>;
25+
= boost::container::static_vector<std::byte, QUICExport::MAX_TLS_PAYLOAD_TO_SAVE>;
2526

2627
enum class FrameType : uint8_t{
2728
CRYPTO = 0x06,
@@ -55,7 +56,7 @@ struct QUICInitialHeaderView {
5556
std::optional<...> userAgent;
5657
boost::container::static_vector<uint16_t, MAX_TLS_EXTENSIONS> extensionTypes;
5758
boost::container::static_vector<uint16_t, MAX_TLS_EXTENSIONS> extensionLengths;
58-
std::vector<const std::byte> extensionsPayload;
59+
std::vector<std::byte> extensionsPayload;
5960
};
6061

6162
} // namespace ipxp

0 commit comments

Comments
 (0)