@@ -1314,17 +1314,19 @@ static int on_copy_ticket(ptls_encrypt_ticket_t *self, ptls_t *tls, int is_encry
1314
1314
return 0 ;
1315
1315
}
1316
1316
1317
- static ptls_iovec_t saved_ticket = {NULL };
1317
+ static ptls_iovec_t saved_tickets [ 8 ] = {{ NULL } };
1318
1318
1319
1319
static int on_save_ticket (ptls_save_ticket_t * self , ptls_t * tls , ptls_iovec_t src )
1320
1320
{
1321
- saved_ticket .base = malloc (src .len );
1322
- memcpy (saved_ticket .base , src .base , src .len );
1323
- saved_ticket .len = src .len ;
1321
+ memmove (saved_tickets + 1 , saved_tickets , sizeof (saved_tickets [0 ]) * (PTLS_ELEMENTSOF (saved_tickets ) - 1 ));
1322
+ saved_tickets [0 ].base = malloc (src .len );
1323
+ memcpy (saved_tickets [0 ].base , src .base , src .len );
1324
+ saved_tickets [0 ].len = src .len ;
1324
1325
return 0 ;
1325
1326
}
1326
1327
1327
- static void test_resumption_impl (int different_preferred_key_share , int require_client_authentication , int transfer_session )
1328
+ static void test_resumption_impl (int different_preferred_key_share , int require_client_authentication , int use_ticket_request ,
1329
+ int transfer_session )
1328
1330
{
1329
1331
assert (ctx -> key_exchanges [0 ]-> id == ctx_peer -> key_exchanges [0 ]-> id );
1330
1332
assert (ctx -> key_exchanges [1 ] == NULL );
@@ -1335,6 +1337,10 @@ static void test_resumption_impl(int different_preferred_key_share, int require_
1335
1337
1336
1338
if (different_preferred_key_share )
1337
1339
ctx -> key_exchanges = different_key_exchanges ;
1340
+ if (use_ticket_request ) {
1341
+ ctx -> ticket_requests .client .new_session_count = 3 ;
1342
+ ctx -> ticket_requests .client .resumption_count = 2 ;
1343
+ }
1338
1344
1339
1345
ptls_encrypt_ticket_t et = {on_copy_ticket };
1340
1346
ptls_save_ticket_t st = {on_save_ticket };
@@ -1343,66 +1349,66 @@ static void test_resumption_impl(int different_preferred_key_share, int require_
1343
1349
assert (ctx_peer -> max_early_data_size == 0 );
1344
1350
assert (ctx_peer -> encrypt_ticket == NULL );
1345
1351
assert (ctx_peer -> save_ticket == NULL );
1346
- saved_ticket = ptls_iovec_init ( NULL , 0 );
1352
+ memset ( saved_tickets , 0 , sizeof ( saved_tickets ) );
1347
1353
1348
1354
ctx_peer -> ticket_lifetime = 86400 ;
1349
1355
ctx_peer -> max_early_data_size = 8192 ;
1350
1356
ctx_peer -> encrypt_ticket = & et ;
1351
1357
ctx -> save_ticket = & st ;
1352
1358
1353
- test_handshake (saved_ticket , different_preferred_key_share ? TEST_HANDSHAKE_2RTT : TEST_HANDSHAKE_1RTT , 1 , 0 , 0 ,
1359
+ test_handshake (ptls_iovec_init ( NULL , 0 ) , different_preferred_key_share ? TEST_HANDSHAKE_2RTT : TEST_HANDSHAKE_1RTT , 1 , 0 , 0 ,
1354
1360
transfer_session );
1355
1361
ok (server_sc_callcnt == 1 );
1356
- ok (saved_ticket .base != NULL );
1362
+ if (use_ticket_request ) {
1363
+ /* should have received 3 tickets */
1364
+ ok (saved_tickets [2 ].base != NULL );
1365
+ ok (saved_tickets [3 ].base == NULL );
1366
+ } else {
1367
+ ok (saved_tickets [0 ].base != NULL );
1368
+ }
1357
1369
1358
1370
/* psk using saved ticket */
1359
- test_handshake (saved_ticket , TEST_HANDSHAKE_1RTT , 1 , 0 , require_client_authentication , transfer_session );
1371
+ test_handshake (saved_tickets [ 0 ] , TEST_HANDSHAKE_1RTT , 1 , 0 , require_client_authentication , transfer_session );
1360
1372
ok (server_sc_callcnt == require_client_authentication ); /* client authentication turns off resumption */
1361
1373
ok (client_sc_callcnt == require_client_authentication );
1374
+ if (use_ticket_request && !require_client_authentication ) {
1375
+ /* should have received 2 tickets */
1376
+ ok (saved_tickets [4 ].base != NULL );
1377
+ ok (saved_tickets [5 ].base == NULL );
1378
+ }
1362
1379
1363
1380
/* 0-rtt psk using saved ticket */
1364
- test_handshake (saved_ticket , TEST_HANDSHAKE_EARLY_DATA , 1 , 0 , require_client_authentication , transfer_session );
1381
+ test_handshake (saved_tickets [ 0 ] , TEST_HANDSHAKE_EARLY_DATA , 1 , 0 , require_client_authentication , transfer_session );
1365
1382
ok (server_sc_callcnt == require_client_authentication ); /* client authentication turns off resumption */
1366
1383
ok (client_sc_callcnt == require_client_authentication );
1367
1384
1368
1385
ctx -> require_dhe_on_psk = 1 ;
1369
1386
1370
1387
/* psk-dhe using saved ticket */
1371
- test_handshake (saved_ticket , TEST_HANDSHAKE_1RTT , 1 , 0 , require_client_authentication , transfer_session );
1388
+ test_handshake (saved_tickets [ 0 ] , TEST_HANDSHAKE_1RTT , 1 , 0 , require_client_authentication , transfer_session );
1372
1389
ok (server_sc_callcnt == require_client_authentication ); /* client authentication turns off resumption */
1373
1390
ok (client_sc_callcnt == require_client_authentication );
1374
1391
1375
1392
/* 0-rtt psk-dhe using saved ticket */
1376
- test_handshake (saved_ticket , TEST_HANDSHAKE_EARLY_DATA , 1 , 0 , require_client_authentication , transfer_session );
1393
+ test_handshake (saved_tickets [ 0 ] , TEST_HANDSHAKE_EARLY_DATA , 1 , 0 , require_client_authentication , transfer_session );
1377
1394
ok (server_sc_callcnt == require_client_authentication ); /* client authentication turns off resumption */
1378
1395
ok (client_sc_callcnt == require_client_authentication );
1379
1396
1380
1397
ctx -> require_dhe_on_psk = 0 ;
1398
+ ctx -> ticket_requests .client .new_session_count = 0 ;
1399
+ ctx -> ticket_requests .client .resumption_count = 0 ;
1381
1400
ctx_peer -> ticket_lifetime = 0 ;
1382
1401
ctx_peer -> max_early_data_size = 0 ;
1383
1402
ctx_peer -> encrypt_ticket = NULL ;
1384
1403
ctx -> save_ticket = NULL ;
1385
1404
ctx -> key_exchanges = key_exchanges_orig ;
1386
1405
}
1387
1406
1388
- static void test_resumption (void )
1389
- {
1390
- test_resumption_impl (0 , 0 , 0 );
1391
- test_resumption_impl (0 , 0 , 1 );
1392
- }
1393
-
1394
- static void test_resumption_different_preferred_key_share (void )
1395
- {
1396
- if (ctx == ctx_peer )
1397
- return ;
1398
- test_resumption_impl (1 , 0 , 0 );
1399
- test_resumption_impl (0 , 0 , 1 );
1400
- }
1401
-
1402
- static void test_resumption_with_client_authentication (void )
1407
+ static void test_resumption (int different_preferred_key_share , int require_client_authentication )
1403
1408
{
1404
- test_resumption_impl (0 , 0 , 0 );
1405
- test_resumption_impl (0 , 1 , 1 );
1409
+ subtest ("basic" , test_resumption_impl , different_preferred_key_share , require_client_authentication , 0 , 0 );
1410
+ subtest ("transfer-session" , test_resumption_impl , different_preferred_key_share , require_client_authentication , 0 , 1 );
1411
+ subtest ("ticket-request" , test_resumption_impl , different_preferred_key_share , require_client_authentication , 1 , 0 );
1406
1412
}
1407
1413
1408
1414
static void test_async_sign_certificate (void )
@@ -1844,7 +1850,7 @@ static void test_handshake_api(void)
1844
1850
ctx_peer -> ticket_lifetime = 86400 ;
1845
1851
ctx_peer -> max_early_data_size = 8192 ;
1846
1852
1847
- saved_ticket = ptls_iovec_init ( NULL , 0 );
1853
+ memset ( saved_tickets , 0 , sizeof ( saved_tickets ) );
1848
1854
1849
1855
ptls_buffer_init (& cbuf , "" , 0 );
1850
1856
ptls_buffer_init (& sbuf , "" , 0 );
@@ -1893,7 +1899,7 @@ static void test_handshake_api(void)
1893
1899
1894
1900
/* 0-RTT resumption */
1895
1901
size_t max_early_data_size = 0 ;
1896
- ptls_handshake_properties_t client_hs_prop = {{{{NULL }, saved_ticket , & max_early_data_size }}};
1902
+ ptls_handshake_properties_t client_hs_prop = {{{{NULL }, saved_tickets [ 0 ] , & max_early_data_size }}};
1897
1903
client = ptls_new (ctx , 0 );
1898
1904
* ptls_get_data_ptr (client ) = & client_secrets ;
1899
1905
server = ptls_new (ctx_peer , 1 );
@@ -1935,7 +1941,7 @@ static void test_handshake_api(void)
1935
1941
1936
1942
/* 0-RTT rejection */
1937
1943
ctx_peer -> max_early_data_size = 0 ;
1938
- client_hs_prop = (ptls_handshake_properties_t ){{{{NULL }, saved_ticket , & max_early_data_size }}};
1944
+ client_hs_prop = (ptls_handshake_properties_t ){{{{NULL }, saved_tickets [ 0 ] , & max_early_data_size }}};
1939
1945
client = ptls_new (ctx , 0 );
1940
1946
* ptls_get_data_ptr (client ) = & client_secrets ;
1941
1947
server = ptls_new (ctx_peer , 1 );
@@ -1973,7 +1979,7 @@ static void test_handshake_api(void)
1973
1979
ctx_peer -> max_early_data_size = 8192 ;
1974
1980
ptls_handshake_properties_t server_hs_prop = {{{{NULL }}}};
1975
1981
server_hs_prop .server .enforce_retry = 1 ;
1976
- client_hs_prop = (ptls_handshake_properties_t ){{{{NULL }, saved_ticket , & max_early_data_size }}};
1982
+ client_hs_prop = (ptls_handshake_properties_t ){{{{NULL }, saved_tickets [ 0 ] , & max_early_data_size }}};
1977
1983
client = ptls_new (ctx , 0 );
1978
1984
* ptls_get_data_ptr (client ) = & client_secrets ;
1979
1985
server = ptls_new (ctx_peer , 1 );
@@ -2015,7 +2021,7 @@ static void test_handshake_api(void)
2015
2021
ctx -> omit_end_of_early_data = 0 ;
2016
2022
ctx_peer -> update_traffic_key = NULL ;
2017
2023
ctx_peer -> omit_end_of_early_data = 0 ;
2018
- client_hs_prop = (ptls_handshake_properties_t ){{{{NULL }, saved_ticket , & max_early_data_size }}};
2024
+ client_hs_prop = (ptls_handshake_properties_t ){{{{NULL }, saved_tickets [ 0 ] , & max_early_data_size }}};
2019
2025
server_hs_prop = (ptls_handshake_properties_t ){{{{NULL }}}};
2020
2026
server_hs_prop .server .enforce_retry = 1 ;
2021
2027
client = ptls_new (ctx , 0 );
@@ -2083,9 +2089,10 @@ static void test_all_handshakes_core(void)
2083
2089
subtest ("hrr-handshake" , test_hrr_handshake );
2084
2090
/* resumption does not work when the client offers ECH but the server does not recognize that */
2085
2091
if (!(can_ech (ctx , 0 ) && !can_ech (ctx_peer , 1 ))) {
2086
- subtest ("resumption" , test_resumption );
2087
- subtest ("resumption-different-preferred-key-share" , test_resumption_different_preferred_key_share );
2088
- subtest ("resumption-with-client-authentication" , test_resumption_with_client_authentication );
2092
+ subtest ("resumption" , test_resumption , 0 , 0 );
2093
+ if (ctx != ctx_peer )
2094
+ subtest ("resumption-different-preferred-key-share" , test_resumption , 1 , 0 );
2095
+ subtest ("resumption-with-client-authentication" , test_resumption , 0 , 1 );
2089
2096
}
2090
2097
subtest ("async-sign-certificate" , test_async_sign_certificate );
2091
2098
subtest ("enforce-retry-stateful" , test_enforce_retry_stateful );
0 commit comments