@@ -678,20 +678,37 @@ void JSQuicSessionListener::OnQLog(const uint8_t* data, size_t len) {
678
678
&str);
679
679
}
680
680
681
- // Generates and associates a new connection ID for this QuicSession.
681
+ // Generates a new connection ID for this QuicSession.
682
682
// ngtcp2 will call this multiple times at the start of a new connection
683
683
// in order to build a pool of available CIDs.
684
684
void RandomConnectionIDStrategy::GetNewConnectionID (
685
685
QuicSession* session,
686
686
ngtcp2_cid* cid,
687
- uint8_t * token,
688
687
size_t cidlen) {
689
688
cid->datalen = cidlen;
690
689
// cidlen shouldn't ever be zero here but just in case that
691
690
// behavior changes in ngtcp2 in the future...
692
691
if (cidlen > 0 )
693
692
EntropySource (cid->data , cidlen);
694
- EntropySource (token, NGTCP2_STATELESS_RESET_TOKENLEN);
693
+ }
694
+
695
+ // Generates a new stateless reset token randomly
696
+ void RandomStatelessResetTokenStrategy::GetNewStatelessToken (
697
+ QuicSession* session,
698
+ ngtcp2_cid* cid,
699
+ uint8_t * token,
700
+ size_t tokenlen) {
701
+ EntropySource (token, tokenlen);
702
+ }
703
+
704
+ void CryptoStatelessResetTokenStrategy::GetNewStatelessToken (
705
+ QuicSession* session,
706
+ ngtcp2_cid* cid,
707
+ uint8_t * token,
708
+ size_t tokenlen) {
709
+ std::array<uint8_t , NGTCP2_STATELESS_RESET_TOKENLEN>* secret =
710
+ session->Socket ()->GetSessionResetSecret ();
711
+ CHECK (GenerateResetToken (token, secret->data (), secret->size (), cid));
695
712
}
696
713
697
714
// Check required capabilities were not excluded from the OpenSSL build:
@@ -1260,6 +1277,7 @@ QuicSession::QuicSession(
1260
1277
reinterpret_cast<double*>(&recovery_stats_)) {
1261
1278
PushListener (&default_listener_);
1262
1279
SetConnectionIDStrategory (&default_connection_id_strategy_);
1280
+ SetStatelessResetTokenStrategy (&default_stateless_reset_strategy_);
1263
1281
crypto_context_.reset (new QuicCryptoContext (this , ctx, side, options));
1264
1282
application_.reset (SelectApplication (this ));
1265
1283
if (rcid != nullptr )
@@ -1634,6 +1652,12 @@ void QuicSession::SetConnectionIDStrategory(ConnectionIDStrategy* strategy) {
1634
1652
connection_id_strategy_ = strategy;
1635
1653
}
1636
1654
1655
+ void QuicSession::SetStatelessResetTokenStrategy (
1656
+ StatelessResetTokenStrategy* strategy) {
1657
+ CHECK_NOT_NULL (strategy);
1658
+ stateless_reset_strategy_ = strategy;
1659
+ }
1660
+
1637
1661
// Generates and associates a new connection ID for this QuicSession.
1638
1662
// ngtcp2 will call this multiple times at the start of a new connection
1639
1663
// in order to build a pool of available CIDs.
@@ -1643,7 +1667,16 @@ int QuicSession::GetNewConnectionID(
1643
1667
size_t cidlen) {
1644
1668
DCHECK (!IsFlagSet (QUICSESSION_FLAG_DESTROYED));
1645
1669
CHECK_NOT_NULL (connection_id_strategy_);
1646
- connection_id_strategy_->GetNewConnectionID (this , cid, token, cidlen);
1670
+ connection_id_strategy_->GetNewConnectionID (
1671
+ this ,
1672
+ cid,
1673
+ cidlen);
1674
+ stateless_reset_strategy_->GetNewStatelessToken (
1675
+ this ,
1676
+ cid,
1677
+ token,
1678
+ NGTCP2_STATELESS_RESET_TOKENLEN);
1679
+
1647
1680
AssociateCID (cid);
1648
1681
return 0 ;
1649
1682
}
0 commit comments