Skip to content

Add versioning support for Connection resumption ticket #5114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/core/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,31 @@
PacketSpace->CurrentKeyPhaseBytesSent = 0;
}

uint8_t
QuicGetOutgoingResumptionTicketVersion(_In_opt_ QUIC_CONNECTION* Connection)
{

CXPLAT_FRE_ASSERT(QuicVarIntSize(CXPLAT_TLS_RESUMPTION_TICKET_VERSION) == sizeof(Connection->Settings.ResumptionTicketMaxVersion));
CXPLAT_FRE_ASSERT(sizeof(uint8_t) == sizeof(Connection->Settings.ResumptionTicketMaxVersion));

if (Connection == NULL) {
return (uint8_t)CXPLAT_TLS_RESUMPTION_TICKET_VERSION;

Check warning on line 2155 in src/core/crypto.c

View check run for this annotation

Codecov / codecov/patch

src/core/crypto.c#L2155

Added line #L2155 was not covered by tests
}

return Connection->Settings.ResumptionTicketMaxVersion;
}

BOOLEAN
IsQuicIncomingResumptionTicketSupported(_In_ QUIC_CONNECTION* Connection, QUIC_VAR_INT TicketVersion)
{
if (TicketVersion >= Connection->Settings.ResumptionTicketMinVersion &&
TicketVersion <= Connection->Settings.ResumptionTicketMaxVersion) {
return TRUE;
}

return FALSE;

Check warning on line 2169 in src/core/crypto.c

View check run for this annotation

Codecov / codecov/patch

src/core/crypto.c#L2169

Added line #L2169 was not covered by tests
}

QUIC_STATUS
QuicCryptoEncodeServerTicket(
_In_opt_ QUIC_CONNECTION* Connection,
Expand Down Expand Up @@ -2233,7 +2258,7 @@
//

_Analysis_assume_(sizeof(*TicketBuffer) >= 8);
uint8_t* TicketCursor = QuicVarIntEncode(CXPLAT_TLS_RESUMPTION_TICKET_VERSION, TicketBuffer);
uint8_t* TicketCursor = QuicVarIntEncode(QuicGetOutgoingResumptionTicketVersion(Connection), TicketBuffer);
CxPlatCopyMemory(TicketCursor, &QuicVersion, sizeof(QuicVersion));
TicketCursor += sizeof(QuicVersion);
TicketCursor = QuicVarIntEncode(AlpnLength, TicketCursor);
Expand Down Expand Up @@ -2292,7 +2317,8 @@
"Resumption Ticket version failed to decode");
goto Error;
}
if (TicketVersion != CXPLAT_TLS_RESUMPTION_TICKET_VERSION) {

if (!IsQuicIncomingResumptionTicketSupported(Connection, TicketVersion)) {
QuicTraceEvent(
ConnError,
"[conn][%p] ERROR, %s.",
Expand All @@ -2301,6 +2327,10 @@
goto Error;
}

if (TicketVersion == CXPLAT_TLS_RESUMPTION_TICKET_VERSION_V2) {
// Handle V2 ticket specific extensions
}

if (TicketLength < Offset + sizeof(uint32_t)) {
QuicTraceEvent(
ConnError,
Expand Down
19 changes: 16 additions & 3 deletions src/core/quicdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,22 @@ CXPLAT_STATIC_ASSERT(
//
#define QUIC_DEFAULT_SERVER_RESUMPTION_LEVEL QUIC_SERVER_NO_RESUME


//
// Version of the wire-format for resumption tickets.
// This needs to be incremented for each change in order or count of fields.
// Valid Resumption Ticket Versions - these must be contiguous
//
#define CXPLAT_TLS_RESUMPTION_TICKET_VERSION_V1 1
#define CXPLAT_TLS_RESUMPTION_TICKET_VERSION_V2 2

//
// Min version of the wire-format for resumption tickets.
//
#define CXPLAT_TLS_RESUMPTION_TICKET_VERSION CXPLAT_TLS_RESUMPTION_TICKET_VERSION_V1

//
// Max version of the wire-format for resumption tickets.
//
#define CXPLAT_TLS_RESUMPTION_TICKET_VERSION 1
#define CXPLAT_TLS_RESUMPTION_TICKET_MAX_VERSION CXPLAT_TLS_RESUMPTION_TICKET_VERSION_V2

//
// Version of the blob for client resumption tickets.
Expand Down Expand Up @@ -700,3 +711,5 @@ CXPLAT_STATIC_ASSERT(
#define QUIC_SETTING_MTU_MISSING_PROBE_COUNT "MtuDiscoveryMissingProbeCount"

#define QUIC_SETTING_CONGESTION_CONTROL_ALGORITHM "CongestionControlAlgorithm"
#define QUIC_SETTING_RESUMPTION_TICKET_MIN_VERSION "ResumptionTicketMinVersion"
#define QUIC_SETTING_RESUMPTION_TICKET_MAX_VERSION "ResumptionTicketMaxVersion"
96 changes: 94 additions & 2 deletions src/core/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@
if (!Settings->IsSet.StreamMultiReceiveEnabled) {
Settings->StreamMultiReceiveEnabled = QUIC_DEFAULT_STREAM_MULTI_RECEIVE_ENABLED;
}
if (!Settings->IsSet.ResumptionTicketMinVersion) {
Settings->ResumptionTicketMinVersion = CXPLAT_TLS_RESUMPTION_TICKET_VERSION;
}
if (!Settings->IsSet.ResumptionTicketMaxVersion) {
// Default to the min version if not explicitly set
Settings->ResumptionTicketMaxVersion = CXPLAT_TLS_RESUMPTION_TICKET_VERSION;
}
}

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down Expand Up @@ -354,6 +361,12 @@
if (!Destination->IsSet.StreamMultiReceiveEnabled) {
Destination->StreamMultiReceiveEnabled = Source->StreamMultiReceiveEnabled;
}
if (!Destination->IsSet.ResumptionTicketMinVersion) {
Destination->ResumptionTicketMinVersion = Source->ResumptionTicketMinVersion;
}
if (!Destination->IsSet.ResumptionTicketMaxVersion) {
Destination->ResumptionTicketMaxVersion = Source->ResumptionTicketMaxVersion;
}
}

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down Expand Up @@ -747,6 +760,17 @@
Destination->StreamMultiReceiveEnabled = Source->StreamMultiReceiveEnabled;
Destination->IsSet.StreamMultiReceiveEnabled = TRUE;
}

if (Source->IsSet.ResumptionTicketMinVersion && (!Destination->IsSet.ResumptionTicketMinVersion || OverWrite)) {
Destination->ResumptionTicketMinVersion = Source->ResumptionTicketMinVersion;
Destination->IsSet.ResumptionTicketMinVersion = TRUE;

Check warning on line 766 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L765-L766

Added lines #L765 - L766 were not covered by tests
}

if (Source->IsSet.ResumptionTicketMaxVersion && (!Destination->IsSet.ResumptionTicketMaxVersion || OverWrite)) {
Destination->ResumptionTicketMaxVersion = Source->ResumptionTicketMaxVersion;
Destination->IsSet.ResumptionTicketMaxVersion = TRUE;

Check warning on line 771 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L770-L771

Added lines #L770 - L771 were not covered by tests
}

return TRUE;
}

Expand Down Expand Up @@ -1445,6 +1469,38 @@
&ValueLen);
Settings->StreamMultiReceiveEnabled = !!Value;
}
if (!Settings->IsSet.ResumptionTicketMinVersion) {
Value = CXPLAT_TLS_RESUMPTION_TICKET_VERSION;
ValueLen = sizeof(Value);
CxPlatStorageReadValue(
Storage,
QUIC_SETTING_RESUMPTION_TICKET_MIN_VERSION,
(uint8_t*)&Value,
&ValueLen);
Settings->ResumptionTicketMinVersion = (uint8_t)Value;

if (Settings->ResumptionTicketMinVersion > CXPLAT_TLS_RESUMPTION_TICKET_MAX_VERSION) {
Settings->ResumptionTicketMinVersion = CXPLAT_TLS_RESUMPTION_TICKET_MAX_VERSION;

Check warning on line 1483 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L1483

Added line #L1483 was not covered by tests
} else if (Settings->ResumptionTicketMinVersion < CXPLAT_TLS_RESUMPTION_TICKET_VERSION) {
Settings->ResumptionTicketMinVersion = CXPLAT_TLS_RESUMPTION_TICKET_VERSION;

Check warning on line 1485 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L1485

Added line #L1485 was not covered by tests
}
}
if (!Settings->IsSet.ResumptionTicketMaxVersion) {
Value = CXPLAT_TLS_RESUMPTION_TICKET_VERSION;
ValueLen = sizeof(Value);
CxPlatStorageReadValue(
Storage,
QUIC_SETTING_RESUMPTION_TICKET_MAX_VERSION,
(uint8_t*)&Value,
&ValueLen);
Settings->ResumptionTicketMaxVersion = (uint8_t)Value;
if (Settings->ResumptionTicketMaxVersion > CXPLAT_TLS_RESUMPTION_TICKET_MAX_VERSION) {
Settings->ResumptionTicketMaxVersion = CXPLAT_TLS_RESUMPTION_TICKET_MAX_VERSION;
}

Check warning on line 1499 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L1498-L1499

Added lines #L1498 - L1499 were not covered by tests
else if (Settings->ResumptionTicketMaxVersion < Settings->ResumptionTicketMinVersion) {
Settings->ResumptionTicketMaxVersion = Settings->ResumptionTicketMinVersion;

Check warning on line 1501 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L1501

Added line #L1501 was not covered by tests
}
}
}

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down Expand Up @@ -1517,6 +1573,8 @@
QuicTraceLogVerbose(SettingOneWayDelayEnabled, "[sett] OneWayDelayEnabled = %hhu", Settings->OneWayDelayEnabled);
QuicTraceLogVerbose(SettingNetStatsEventEnabled, "[sett] NetStatsEventEnabled = %hhu", Settings->NetStatsEventEnabled);
QuicTraceLogVerbose(SettingsStreamMultiReceiveEnabled, "[sett] StreamMultiReceiveEnabled= %hhu", Settings->StreamMultiReceiveEnabled);
QuicTraceLogVerbose(SettingsDumpResumptionTicketMinVersion, "[sett] ResumptionTicketMinVersion= %hhu", Settings->ResumptionTicketMinVersion);
QuicTraceLogVerbose(SettingsDumpResumptionTicketMaxVersion, "[sett] ResumptionTicketMaxVersion= %hhu", Settings->ResumptionTicketMaxVersion);
}

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down Expand Up @@ -1690,6 +1748,12 @@
if (Settings->IsSet.StreamMultiReceiveEnabled) {
QuicTraceLogVerbose(SettingStreamMultiReceiveEnabled, "[sett] StreamMultiReceiveEnabled = %hhu", Settings->StreamMultiReceiveEnabled);
}
if (Settings->IsSet.ResumptionTicketMinVersion) {
QuicTraceLogVerbose(SettingResumptionTicketMinVersion, "[sett] ResumptionTicketMinVersion= %hhu", Settings->ResumptionTicketMinVersion);

Check warning on line 1752 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L1752

Added line #L1752 was not covered by tests
}
if (Settings->IsSet.ResumptionTicketMaxVersion) {
QuicTraceLogVerbose(SettingResumptionTicketMaxVersion, "[sett] ResumptionTicketMaxVersion= %hhu", Settings->ResumptionTicketMaxVersion);

Check warning on line 1755 in src/core/settings.c

View check run for this annotation

Codecov / codecov/patch

src/core/settings.c#L1755

Added line #L1755 was not covered by tests
}
}

#define SETTING_COPY_TO_INTERNAL(Field, Settings, InternalSettings) \
Expand Down Expand Up @@ -1819,7 +1883,7 @@
_Out_ QUIC_SETTINGS_INTERNAL* InternalSettings
)
{
if (!CXPLAT_STRUCT_HAS_FIELD(QUIC_SETTINGS, SettingsSize, MtuDiscoveryMissingProbeCount)) {
if (!CXPLAT_STRUCT_HAS_FIELD(QUIC_SETTINGS, SettingsSize, ResumptionTicketMaxVersion)) {
return QUIC_STATUS_INVALID_PARAMETER;
}

Expand Down Expand Up @@ -1972,6 +2036,20 @@
SettingsSize,
InternalSettings);

SETTING_COPY_TO_INTERNAL_SIZED(
ResumptionTicketMinVersion,
QUIC_SETTINGS,
Settings,
SettingsSize,
InternalSettings);

SETTING_COPY_TO_INTERNAL_SIZED(
ResumptionTicketMaxVersion,
QUIC_SETTINGS,
Settings,
SettingsSize,
InternalSettings);

return QUIC_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -2000,7 +2078,7 @@
QUIC_SETTINGS* Settings
)
{
uint32_t MinimumSettingsSize = (uint32_t)CXPLAT_STRUCT_SIZE_THRU_FIELD(QUIC_SETTINGS, MtuDiscoveryMissingProbeCount);
uint32_t MinimumSettingsSize = (uint32_t)CXPLAT_STRUCT_SIZE_THRU_FIELD(QUIC_SETTINGS, ResumptionTicketMaxVersion);

if (*SettingsLength == 0) {
*SettingsLength = sizeof(QUIC_SETTINGS);
Expand Down Expand Up @@ -2165,6 +2243,20 @@
*SettingsLength,
InternalSettings);

SETTING_COPY_FROM_INTERNAL_SIZED(
ResumptionTicketMinVersion,
QUIC_SETTINGS,
Settings,
*SettingsLength,
InternalSettings);

SETTING_COPY_FROM_INTERNAL_SIZED(
ResumptionTicketMaxVersion,
QUIC_SETTINGS,
Settings,
*SettingsLength,
InternalSettings);

*SettingsLength = CXPLAT_MIN(*SettingsLength, sizeof(QUIC_SETTINGS));

return QUIC_STATUS_SUCCESS;
Expand Down
6 changes: 5 additions & 1 deletion src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ typedef struct QUIC_SETTINGS_INTERNAL {
uint64_t XdpEnabled : 1;
uint64_t QTIPEnabled : 1;
uint64_t RioEnabled : 1;
uint64_t RESERVED : 13;
uint64_t ResumptionTicketMinVersion : 1;
uint64_t ResumptionTicketMaxVersion : 1;
uint64_t RESERVED : 11;
} IsSet;
};

Expand Down Expand Up @@ -120,6 +122,8 @@ typedef struct QUIC_SETTINGS_INTERNAL {
uint8_t QTIPEnabled : 1;
uint8_t RioEnabled : 1;
uint8_t MtuDiscoveryMissingProbeCount;
uint8_t ResumptionTicketMinVersion;
uint8_t ResumptionTicketMaxVersion;
} QUIC_SETTINGS_INTERNAL;

//
Expand Down
Loading
Loading