@@ -1554,19 +1554,153 @@ SEASTAR_THREAD_TEST_CASE(test_skip_wait_for_eof) {
1554
1554
}
1555
1555
}
1556
1556
1557
+ static void do_test_tls13_session_tickets (bool reset_server) {
1558
+ tls::credentials_builder b;
1559
+
1560
+ b.set_x509_key_file (certfile (" test.crt" ), certfile (" test.key" ), tls::x509_crt_format::PEM).get ();
1561
+ b.set_x509_trust_file (certfile (" catest.pem" ), tls::x509_crt_format::PEM).get ();
1562
+ b.set_session_resume_mode (tls::session_resume_mode::TLS13_SESSION_TICKET);
1563
+ b.set_priority_string (" SECURE128:+SECURE192:-VERS-TLS-ALL:+VERS-TLS1.3" );
1564
+
1565
+ auto creds = b.build_certificate_credentials ();
1566
+ auto serv = b.build_server_credentials ();
1567
+
1568
+ ::listen_options opts;
1569
+ opts.reuse_address = true ;
1570
+ opts.set_fixed_cpu (this_shard_id ());
1571
+
1572
+ auto addr = ::make_ipv4_address ( {0x7f000001 , 4712 });
1573
+ auto server = tls::listen (serv, addr, opts);
1574
+
1575
+ tls::session_data sess_data;
1576
+
1577
+ {
1578
+ auto sa = server.accept ();
1579
+ auto c = tls::connect (creds, addr).get ();
1580
+ auto s = sa.get ();
1581
+
1582
+ auto in = s.connection .input ();
1583
+ auto cin = c.input ();
1584
+ output_stream<char > out (c.output ().detach (), 1024 );
1585
+ output_stream<char > sout (s.connection .output ().detach (), 1024 );
1586
+
1587
+ // write data in both directions. Required for session data to
1588
+ // become available.
1589
+ out.write (" nils" ).get ();
1590
+ auto fin = in.read ();
1591
+ auto fout = out.flush ();
1592
+
1593
+ fout.get ();
1594
+ fin.get ();
1595
+
1596
+ sout.write (" banan" ).get ();
1597
+ fin = cin.read ();
1598
+ fout = sout.flush ();
1599
+
1600
+ fout.get ();
1601
+ fin.get ();
1602
+
1603
+ BOOST_REQUIRE (!tls::check_session_is_resumed (c).get ()); // no resume data
1604
+
1605
+ // get ticket data
1606
+ sess_data = tls::get_session_resume_data (c).get ();
1607
+ BOOST_REQUIRE (!sess_data.empty ());
1608
+
1609
+ in.close ().get ();
1610
+ out.close ().get ();
1611
+
1612
+ s.connection .shutdown_input ();
1613
+ s.connection .shutdown_output ();
1614
+
1615
+ c.shutdown_input ();
1616
+ c.shutdown_output ();
1617
+ }
1618
+
1619
+ if (reset_server) {
1620
+ server = {};
1621
+ // rebuild creds
1622
+ serv = b.build_server_credentials ();
1623
+ server = tls::listen (serv, addr, opts);
1624
+ }
1625
+
1626
+ {
1627
+ auto sa = server.accept ();
1628
+
1629
+ // tell client to try resuming.
1630
+ tls::tls_options tls_opts;
1631
+ tls_opts.session_resume_data = sess_data;
1632
+
1633
+ auto c = tls::connect (creds, addr, tls_opts).get ();
1634
+ auto s = sa.get ();
1635
+
1636
+ // This is ok. Will force a handshake.
1637
+ auto f = tls::check_session_is_resumed (c);
1638
+
1639
+ // But we need to force some IO to make the
1640
+ // handshake actually happen.
1641
+ auto in = s.connection .input ();
1642
+ output_stream<char > out (c.output ().detach (), 1024 );
1643
+
1644
+ auto fin = in.read ();
1645
+
1646
+ out.write (" nils" ).get ();
1647
+ auto fout = out.flush ();
1648
+
1649
+ fout.get ();
1650
+ fin.get ();
1651
+
1652
+ BOOST_REQUIRE (f.get ()); // Should work
1653
+
1654
+ in.close ().get ();
1655
+ out.close ().get ();
1656
+
1657
+ s.connection .shutdown_input ();
1658
+ s.connection .shutdown_output ();
1659
+
1660
+ c.shutdown_input ();
1661
+ c.shutdown_output ();
1662
+ }
1663
+
1664
+ }
1665
+
1557
1666
/* *
1558
1667
* Test TLS13 session ticket support.
1559
1668
*/
1560
1669
SEASTAR_THREAD_TEST_CASE (test_tls13_session_tickets) {
1670
+ do_test_tls13_session_tickets (false );
1671
+ }
1672
+
1673
+ SEASTAR_THREAD_TEST_CASE (test_tls13_session_tickets_retain_session_key) {
1674
+ do_test_tls13_session_tickets (true );
1675
+ }
1676
+
1677
+ SEASTAR_THREAD_TEST_CASE (test_tls13_session_tickets_invalidated_by_reload) {
1561
1678
tls::credentials_builder b;
1679
+ tmpdir tmp;
1562
1680
1563
- b.set_x509_key_file (certfile (" test.crt" ), certfile (" test.key" ), tls::x509_crt_format::PEM).get ();
1681
+ namespace fs = std::filesystem;
1682
+
1683
+ // copy the wrong certs. We don't trust these
1684
+ // blocking calls, but this is a test and seastar does not have a copy
1685
+ // util and I am lazy...
1686
+ fs::copy_file (certfile (" test.crt" ), tmp.path () / " test.crt" );
1687
+ fs::copy_file (certfile (" test.key" ), tmp.path () / " test.key" );
1688
+
1689
+ auto cert = (tmp.path () / " test.crt" ).native ();
1690
+ auto key = (tmp.path () / " test.key" ).native ();
1691
+ promise<> p;
1692
+
1693
+ b.set_x509_key_file (cert, key, tls::x509_crt_format::PEM).get ();
1564
1694
b.set_x509_trust_file (certfile (" catest.pem" ), tls::x509_crt_format::PEM).get ();
1565
1695
b.set_session_resume_mode (tls::session_resume_mode::TLS13_SESSION_TICKET);
1566
1696
b.set_priority_string (" SECURE128:+SECURE192:-VERS-TLS-ALL:+VERS-TLS1.3" );
1567
1697
1568
1698
auto creds = b.build_certificate_credentials ();
1569
- auto serv = b.build_server_credentials ();
1699
+ auto serv = b.build_reloadable_server_credentials ([&p](const std::unordered_set<sstring>&, std::exception_ptr) {
1700
+ p.set_value ();
1701
+ }).get ();
1702
+
1703
+ auto reloaded = p.get_future ();
1570
1704
1571
1705
::listen_options opts;
1572
1706
opts.reuse_address = true ;
@@ -1619,6 +1753,10 @@ SEASTAR_THREAD_TEST_CASE(test_tls13_session_tickets) {
1619
1753
c.shutdown_output ();
1620
1754
}
1621
1755
1756
+ BOOST_REQUIRE (!reloaded.available ());
1757
+
1758
+ fs::copy_file (certfile (" test.crt" ), tmp.path () / " test.crt" , fs::copy_options::overwrite_existing);
1759
+ reloaded.get ();
1622
1760
1623
1761
{
1624
1762
auto sa = server.accept ();
@@ -1646,7 +1784,7 @@ SEASTAR_THREAD_TEST_CASE(test_tls13_session_tickets) {
1646
1784
fout.get ();
1647
1785
fin.get ();
1648
1786
1649
- BOOST_REQUIRE (f.get ()); // Should work
1787
+ BOOST_REQUIRE (! f.get ()); // Should NOT work. Keys should have been replaced
1650
1788
1651
1789
in.close ().get ();
1652
1790
out.close ().get ();
0 commit comments