Skip to content

Commit 014cfe0

Browse files
authored
Cherry-Pick: New Session Ticket Encryption Key API (#1213) (#1285)
1 parent 0f2752a commit 014cfe0

20 files changed

+526
-192
lines changed

.azure/azure-pipelines.qns.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
${{ if eq(variables['Build.Reason'], 'BatchedCI') }}:
5959
tags: |
6060
latest
61-
v1.1.1.$(Build.BuildId)
61+
v1.1.2.$(Build.BuildId)
6262
${{ if ne(variables['Build.Reason'], 'BatchedCI') }}:
6363
tags: custom-$(Build.BuildId)
6464
- template: .\templates\run-qns.yml

.azure/templates/create-package.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ jobs:
4343
4444
majorVer: 1
4545
minorVer: 1
46-
patchVer: 1
46+
patchVer: 2
4747
prereleaseVer: $(Build.BuildId)

CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,22 @@ if(WIN32)
253253
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_RESUMPTION)
254254
endif()
255255

256+
if(QUIC_TLS STREQUAL "schannel")
257+
# User mode schannel doesn't support this yet.
258+
message(STATUS "Disabling resumption rejection")
259+
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_RESUMPTION_REJECTION_TESTS)
260+
endif()
261+
256262
if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "schannel")
257263
# OpenSSL and SChannel don't support 0-RTT yet.
258264
message(STATUS "Disabling 0-RTT support")
259265
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_0RTT_TESTS)
266+
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_RESUMPTION_REJECTION_TESTS)
260267
endif()
261268

262269
if(QUIC_TLS STREQUAL "stub")
263270
list(APPEND QUIC_COMMON_DEFINES QUIC_TLS_STUB)
271+
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_RESUMPTION_REJECTION_TESTS)
264272
endif()
265273

266274
if(QUIC_ENABLE_SANITIZERS)
@@ -348,6 +356,7 @@ else()
348356
# OpenSSL doesn't support 0-RTT yet.
349357
message(STATUS "Disabling 0-RTT support")
350358
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_0RTT_TESTS)
359+
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_RESUMPTION_REJECTION_TESTS)
351360
endif()
352361

353362
if(QUIC_ENABLE_SANITIZERS)
@@ -360,6 +369,7 @@ else()
360369

361370
if(QUIC_TLS STREQUAL "stub")
362371
list(APPEND QUIC_COMMON_DEFINES QUIC_TLS_STUB)
372+
list(APPEND QUIC_COMMON_DEFINES QUIC_DISABLE_RESUMPTION_REJECTION_TESTS)
363373
endif()
364374

365375
set(QUIC_C_FLAGS ${QUIC_COMMON_FLAGS})

src/core/configuration.c

+24-2
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,11 @@ QuicConfigurationParamSet(
442442
const void* Buffer
443443
)
444444
{
445-
if (Param == QUIC_PARAM_CONFIGURATION_SETTINGS) {
445+
switch (Param) {
446+
case QUIC_PARAM_CONFIGURATION_SETTINGS:
446447

447-
if (BufferLength != sizeof(QUIC_SETTINGS)) {
448+
if (Buffer == NULL ||
449+
BufferLength != sizeof(QUIC_SETTINGS)) {
448450
return QUIC_STATUS_INVALID_PARAMETER; // TODO - Support partial
449451
}
450452

@@ -465,6 +467,26 @@ QuicConfigurationParamSet(
465467
QuicSettingsDumpNew(BufferLength, (QUIC_SETTINGS*)Buffer);
466468

467469
return QUIC_STATUS_SUCCESS;
470+
471+
case QUIC_PARAM_CONFIGURATION_TICKET_KEYS:
472+
473+
if (Buffer == NULL ||
474+
BufferLength < sizeof(QUIC_TICKET_KEY_CONFIG)) {
475+
return QUIC_STATUS_INVALID_PARAMETER;
476+
}
477+
478+
if (Configuration->SecurityConfig == NULL) {
479+
return QUIC_STATUS_INVALID_STATE;
480+
}
481+
482+
return
483+
CxPlatTlsSecConfigSetTicketKeys(
484+
Configuration->SecurityConfig,
485+
(QUIC_TICKET_KEY_CONFIG*)Buffer,
486+
(uint8_t)(BufferLength / sizeof(QUIC_TICKET_KEY_CONFIG)));
487+
488+
default:
489+
break;
468490
}
469491

470492
return QUIC_STATUS_INVALID_PARAMETER;

src/inc/msquic.h

+16-1
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,24 @@ typedef struct QUIC_CREDENTIAL_CONFIG {
243243
QUIC_CERTIFICATE_FILE* CertificateFile;
244244
};
245245
const char* Principal;
246-
void* TicketKey; // Optional, 44 byte array
246+
void* Reserved; // Currently unused
247247
QUIC_CREDENTIAL_LOAD_COMPLETE_HANDLER AsyncHandler; // Optional
248248
} QUIC_CREDENTIAL_CONFIG;
249249

250+
//
251+
// The maximum number of QUIC_TICKET_KEY_CONFIG that can be used at one time.
252+
//
253+
#define QUIC_MAX_TICKET_KEY_COUNT 16
254+
255+
//
256+
// TLS New Session Ticket encryption key configuration.
257+
//
258+
typedef struct QUIC_TICKET_KEY_CONFIG {
259+
uint8_t Id[16];
260+
uint8_t Material[64];
261+
uint8_t MaterialLength;
262+
} QUIC_TICKET_KEY_CONFIG;
263+
250264
//
251265
// A single contiguous buffer.
252266
//
@@ -502,6 +516,7 @@ typedef enum QUIC_PARAM_LEVEL {
502516
// Parameters for QUIC_PARAM_LEVEL_CONFIGURATION.
503517
//
504518
#define QUIC_PARAM_CONFIGURATION_SETTINGS 0 // QUIC_SETTINGS
519+
#define QUIC_PARAM_CONFIGURATION_TICKET_KEYS 1 // QUIC_TICKET_KEY_CONFIG[]
505520

506521
//
507522
// Parameters for QUIC_PARAM_LEVEL_LISTENER.

src/inc/msquic.hpp

+22
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,28 @@ class MsQuicConfiguration {
398398
LoadCredential(_In_ const QUIC_CREDENTIAL_CONFIG* CredConfig) noexcept {
399399
return MsQuic->ConfigurationLoadCredential(Handle, CredConfig);
400400
}
401+
QUIC_STATUS
402+
SetTicketKey(_In_ const QUIC_TICKET_KEY_CONFIG* KeyConfig) noexcept {
403+
return
404+
MsQuic->SetParam(
405+
Handle,
406+
QUIC_PARAM_LEVEL_CONFIGURATION,
407+
QUIC_PARAM_CONFIGURATION_TICKET_KEYS,
408+
sizeof(QUIC_TICKET_KEY_CONFIG),
409+
KeyConfig);
410+
}
411+
QUIC_STATUS
412+
SetTicketKeys(
413+
_In_reads_(KeyCount) const QUIC_TICKET_KEY_CONFIG* KeyConfig,
414+
uint8_t KeyCount) noexcept {
415+
return
416+
MsQuic->SetParam(
417+
Handle,
418+
QUIC_PARAM_LEVEL_CONFIGURATION,
419+
QUIC_PARAM_CONFIGURATION_TICKET_KEYS,
420+
KeyCount * sizeof(QUIC_TICKET_KEY_CONFIG),
421+
KeyConfig);
422+
}
401423
};
402424

403425
struct MsQuicListener {

src/inc/msquic.ver

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#define VER_LEGALCOPYRIGHT_STR "\251 Microsoft Corporation."
2121
#define VER_PRODUCTNAME_STR "Microsoft\256 QUIC"
2222

23-
#define VER_FILEVERSION 1,1.1.0
24-
#define VER_FILEVERSION_STR "1.1.1.0\0"
23+
#define VER_FILEVERSION 1,1.2.0
24+
#define VER_FILEVERSION_STR "1.1.2.0\0"
2525

26-
#define VER_PRODUCTVERSION_STR "1.1.1." STR(VER_BUILD_ID) STR(VER_SUFFIX) "\0"
26+
#define VER_PRODUCTVERSION_STR "1.1.2." STR(VER_BUILD_ID) STR(VER_SUFFIX) "\0"
2727

2828
VS_VERSION_INFO VERSIONINFO
2929
FILEVERSION VER_FILEVERSION

src/inc/quic_tls.h

+11
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,17 @@ CxPlatTlsSecConfigDelete(
344344
CXPLAT_SEC_CONFIG* SecurityConfig
345345
);
346346

347+
//
348+
// Sets a NST ticket key for a security configuration.
349+
//
350+
_IRQL_requires_max_(PASSIVE_LEVEL)
351+
QUIC_STATUS
352+
CxPlatTlsSecConfigSetTicketKeys(
353+
_In_ CXPLAT_SEC_CONFIG* SecurityConfig,
354+
_In_reads_(KeyCount) QUIC_TICKET_KEY_CONFIG* KeyConfig,
355+
_In_ uint8_t KeyCount
356+
);
357+
347358
//
348359
// Initializes a TLS context.
349360
//

src/platform/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ if(QUIC_TLS STREQUAL "openssl")
7979
target_link_libraries(platform PUBLIC OpenSSL)
8080
elseif(QUIC_TLS STREQUAL "mitls")
8181
target_link_libraries(platform PUBLIC kremlib evercrypt mitls quiccrypto)
82+
elseif(QUIC_TLS STREQUAL "schannel")
83+
target_link_libraries(platform PUBLIC secur32)
8284
endif()

src/platform/tls_mitls.c

+40-23
Original file line numberDiff line numberDiff line change
@@ -430,29 +430,7 @@ CxPlatTlsSecConfigCreate(
430430

431431
QUIC_STATUS Status = QUIC_STATUS_SUCCESS;
432432

433-
if (CredConfig->Flags & QUIC_CREDENTIAL_FLAG_CLIENT) {
434-
435-
if (CredConfig->TicketKey != NULL &&
436-
!FFI_mitls_set_sealing_key("AES256-GCM", (uint8_t*)CredConfig->TicketKey, 44)) {
437-
QuicTraceEvent(
438-
LibraryError,
439-
"[ lib] ERROR, %s.",
440-
"FFI_mitls_set_sealing_key failed");
441-
Status = QUIC_STATUS_INVALID_STATE;
442-
goto Error;
443-
}
444-
445-
} else {
446-
447-
if (CredConfig->TicketKey != NULL &&
448-
!FFI_mitls_set_ticket_key("AES256-GCM", (uint8_t*)CredConfig->TicketKey, 44)) {
449-
QuicTraceEvent(
450-
LibraryError,
451-
"[ lib] ERROR, %s.",
452-
"FFI_mitls_set_ticket_key failed");
453-
Status = QUIC_STATUS_INVALID_STATE;
454-
goto Error;
455-
}
433+
if (!(CredConfig->Flags & QUIC_CREDENTIAL_FLAG_CLIENT)) {
456434

457435
Status = CxPlatCertCreate(CredConfig, &SecurityConfig->Certificate);
458436
if (QUIC_FAILED(Status)) {
@@ -512,6 +490,45 @@ CxPlatTlsSecConfigDelete(
512490
CXPLAT_FREE(SecurityConfig, QUIC_POOL_TLS_SECCONF);
513491
}
514492

493+
const uint8_t miTlsTicketKeyLength = 44;
494+
495+
_IRQL_requires_max_(PASSIVE_LEVEL)
496+
QUIC_STATUS
497+
CxPlatTlsSecConfigSetTicketKeys(
498+
_In_ CXPLAT_SEC_CONFIG* SecurityConfig,
499+
_In_reads_(KeyCount) QUIC_TICKET_KEY_CONFIG* KeyConfig,
500+
_In_ uint8_t KeyCount
501+
)
502+
{
503+
CXPLAT_DBG_ASSERT(KeyCount >= 1);
504+
UNREFERENCED_PARAMETER(KeyCount);
505+
506+
if (KeyConfig->MaterialLength < miTlsTicketKeyLength) {
507+
return QUIC_STATUS_INVALID_PARAMETER;
508+
}
509+
510+
if (SecurityConfig->Flags & QUIC_CREDENTIAL_FLAG_CLIENT) {
511+
if (!FFI_mitls_set_sealing_key("AES256-GCM", KeyConfig->Material, miTlsTicketKeyLength)) {
512+
QuicTraceEvent(
513+
LibraryError,
514+
"[ lib] ERROR, %s.",
515+
"FFI_mitls_set_sealing_key failed");
516+
return QUIC_STATUS_INVALID_STATE;
517+
}
518+
519+
} else {
520+
if (!FFI_mitls_set_ticket_key("AES256-GCM", KeyConfig->Material, miTlsTicketKeyLength)) {
521+
QuicTraceEvent(
522+
LibraryError,
523+
"[ lib] ERROR, %s.",
524+
"FFI_mitls_set_ticket_key failed");
525+
return QUIC_STATUS_INVALID_STATE;
526+
}
527+
}
528+
529+
return QUIC_STATUS_SUCCESS;
530+
}
531+
515532
_IRQL_requires_max_(PASSIVE_LEVEL)
516533
QUIC_STATUS
517534
CxPlatTlsInitialize(

src/platform/tls_openssl.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ CxPlatTlsSecConfigCreate(
566566
return QUIC_STATUS_NOT_SUPPORTED; // Not supported by this TLS implementation
567567
}
568568

569-
if (CredConfig->TicketKey != NULL) {
570-
return QUIC_STATUS_NOT_SUPPORTED; // Not currently supported
569+
if (CredConfig->Reserved != NULL) {
570+
return QUIC_STATUS_INVALID_PARAMETER; // Not currently used and should be NULL.
571571
}
572572

573573
if (CredConfig->Flags & QUIC_CREDENTIAL_FLAG_CLIENT) {
@@ -863,6 +863,20 @@ CxPlatTlsSecConfigDelete(
863863
CXPLAT_FREE(SecurityConfig, QUIC_POOL_TLS_SECCONF);
864864
}
865865

866+
_IRQL_requires_max_(PASSIVE_LEVEL)
867+
QUIC_STATUS
868+
CxPlatTlsSecConfigSetTicketKeys(
869+
_In_ CXPLAT_SEC_CONFIG* SecurityConfig,
870+
_In_reads_(KeyCount) QUIC_TICKET_KEY_CONFIG* KeyConfig,
871+
_In_ uint8_t KeyCount
872+
)
873+
{
874+
UNREFERENCED_PARAMETER(SecurityConfig);
875+
UNREFERENCED_PARAMETER(KeyConfig);
876+
UNREFERENCED_PARAMETER(KeyCount);
877+
return QUIC_STATUS_NOT_SUPPORTED;
878+
}
879+
866880
QUIC_STATUS
867881
CxPlatTlsInitialize(
868882
_In_ const CXPLAT_TLS_CONFIG* Config,

0 commit comments

Comments
 (0)