You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2018/11/27 05:06:27 UTC
[trafficserver] branch quic_latest created (now 0ef9bce)
This is an automated email from the ASF dual-hosted git repository.
maskit pushed a change to branch quic_latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git.
at 0ef9bce Send original_connection_id TP
This branch includes the following new commits:
new c625b48 Refacotr retry token and stateless reset token
new 0ef9bce Send original_connection_id TP
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[trafficserver] 01/02: Refacotr retry token and stateless reset
token
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
maskit pushed a commit to branch quic_latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit c625b48a78ddb86cd3b5768e37f000295dbb8a31
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Mon Nov 26 16:13:46 2018 +0900
Refacotr retry token and stateless reset token
---
iocore/net/QUICNetVConnection.cc | 2 +-
iocore/net/QUICPacketHandler.cc | 22 +++-----
iocore/net/quic/Makefile.am | 1 -
iocore/net/quic/QUICAltConnectionManager.cc | 3 +-
iocore/net/quic/QUICConfig.cc | 3 --
iocore/net/quic/QUICPacket.cc | 10 ++--
iocore/net/quic/QUICPacket.h | 2 +-
iocore/net/quic/QUICStatelessRetry.cc | 69 --------------------------
iocore/net/quic/QUICStatelessRetry.h | 38 --------------
iocore/net/quic/QUICTypes.cc | 19 ++++++-
iocore/net/quic/QUICTypes.h | 47 +++++++++++++++---
iocore/net/quic/test/test_QUICPacketFactory.cc | 16 +++---
12 files changed, 83 insertions(+), 149 deletions(-)
diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index 5873292..3556dd9 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -207,7 +207,7 @@ QUICNetVConnection::start()
// Version 0x00000001 uses stream 0 for cryptographic handshake with TLS 1.3, but newer version may not
if (this->direction() == NET_VCONNECTION_IN) {
this->_ack_frame_creator.set_ack_delay_exponent(params->ack_delay_exponent_in());
- this->_reset_token.generate(this->_quic_connection_id, params->instance_id());
+ this->_reset_token = QUICStatelessResetToken(this->_quic_connection_id, params->instance_id());
this->_hs_protocol = this->_setup_handshake_protocol(params->server_ssl_ctx());
this->_handshake_handler = new QUICHandshake(this, this->_hs_protocol, this->_reset_token, params->stateless_retry());
} else {
diff --git a/iocore/net/QUICPacketHandler.cc b/iocore/net/QUICPacketHandler.cc
index a97a871..fb6b3a0 100644
--- a/iocore/net/QUICPacketHandler.cc
+++ b/iocore/net/QUICPacketHandler.cc
@@ -29,7 +29,6 @@
#include "QUICPacket.h"
#include "QUICDebugNames.h"
#include "QUICEvents.h"
-#include "QUICStatelessRetry.h"
static constexpr int LONG_HDR_OFFSET_CONNECTION_ID = 6;
static constexpr char tag[] = "quic_sec";
@@ -292,11 +291,8 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet)
// Servers MUST drop incoming packets under all other circumstances. They SHOULD send a Stateless Reset (Section 6.10.4) if a
// connection ID is present in the header.
if ((!vc && !QUICInvariants::is_long_header(buf)) || (vc && vc->in_closed_queue)) {
- QUICStatelessResetToken token;
- {
- QUICConfig::scoped_config params;
- token.generate(dcid, params->instance_id());
- }
+ QUICConfig::scoped_config params;
+ QUICStatelessResetToken token(dcid, params->instance_id());
auto packet = QUICPacketFactory::create_stateless_reset_packet(dcid, token);
this->_send_packet(this, *packet, udp_packet->getConnection(), udp_packet->from, 1200, nullptr, 0);
udp_packet->free();
@@ -378,14 +374,10 @@ QUICPacketHandlerIn::_stateless_retry(const uint8_t *buf, uint64_t buf_len, UDPC
}
if (token_length == 0) {
- ats_unique_buf retry_token = ats_unique_malloc(QUICStatelessRetry::MAX_TOKEN_LEN);
- size_t retry_token_len = 0;
- QUICStatelessRetry::generate_cookie(retry_token.get(), &retry_token_len, from);
-
+ QUICRetryToken token(from);
QUICConnectionId local_cid;
local_cid.randomize();
- QUICPacketUPtr retry_packet =
- QUICPacketFactory::create_retry_packet(scid, local_cid, dcid, std::move(retry_token), retry_token_len);
+ QUICPacketUPtr retry_packet = QUICPacketFactory::create_retry_packet(scid, local_cid, dcid, token);
this->_send_packet(this, *retry_packet, connection, from, 1200, nullptr, 0);
@@ -394,9 +386,11 @@ QUICPacketHandlerIn::_stateless_retry(const uint8_t *buf, uint64_t buf_len, UDPC
uint8_t dcil, scil;
QUICPacketLongHeader::dcil(dcil, buf, buf_len);
QUICPacketLongHeader::scil(scil, buf, buf_len);
-
const uint8_t *token = buf + LONG_HDR_OFFSET_CONNECTION_ID + dcil + scil + token_length_field_len;
- if (QUICStatelessRetry::verify_cookie(token, token_length, from)) {
+
+ QUICRetryToken token1(token, token_length);
+ QUICRetryToken token2(from);
+ if (token1 == token2) {
return 0;
} else {
return -3;
diff --git a/iocore/net/quic/Makefile.am b/iocore/net/quic/Makefile.am
index 519ae17..0b68e05 100644
--- a/iocore/net/quic/Makefile.am
+++ b/iocore/net/quic/Makefile.am
@@ -78,7 +78,6 @@ libquic_a_SOURCES = \
QUICPacketReceiveQueue.cc \
QUICPacketRetransmitter.cc \
QUICPathValidator.cc \
- QUICStatelessRetry.cc \
QUICFrameGenerator.cc
#
diff --git a/iocore/net/quic/QUICAltConnectionManager.cc b/iocore/net/quic/QUICAltConnectionManager.cc
index 8bd208e..d272bf6 100644
--- a/iocore/net/quic/QUICAltConnectionManager.cc
+++ b/iocore/net/quic/QUICAltConnectionManager.cc
@@ -99,9 +99,8 @@ QUICAltConnectionManager::AltConnectionInfo
QUICAltConnectionManager::_generate_next_alt_con_info()
{
QUICConnectionId conn_id;
- QUICStatelessResetToken token;
conn_id.randomize();
- token.generate(conn_id, this->_instance_id);
+ QUICStatelessResetToken token(conn_id, this->_instance_id);
AltConnectionInfo aci = {++this->_alt_quic_connection_id_seq_num, conn_id, token, {false}};
if (this->_qc->direction() == NET_VCONNECTION_IN) {
diff --git a/iocore/net/quic/QUICConfig.cc b/iocore/net/quic/QUICConfig.cc
index 905568b..3b0c879 100644
--- a/iocore/net/quic/QUICConfig.cc
+++ b/iocore/net/quic/QUICConfig.cc
@@ -31,7 +31,6 @@
#include "QUICGlobals.h"
#include "QUICTransportParameters.h"
-#include "QUICStatelessRetry.h"
// OpenSSL protocol-lists format (vector of 8-bit length-prefixed, byte strings)
// https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_alpn_protos.html
@@ -197,8 +196,6 @@ QUICConfigParams::initialize()
REC_EstablishStaticConfigInt32U(this->_cc_minimum_window_scale, "proxy.config.quic.congestion_control.minimum_window_scale");
REC_EstablishStaticConfigFloat(this->_cc_loss_reduction_factor, "proxy.config.quic.congestion_control.loss_reduction_factor");
- QUICStatelessRetry::init();
-
this->_server_ssl_ctx = quic_init_server_ssl_ctx(this);
this->_client_ssl_ctx = quic_init_client_ssl_ctx(this);
}
diff --git a/iocore/net/quic/QUICPacket.cc b/iocore/net/quic/QUICPacket.cc
index 6f218ee..670bcee 100644
--- a/iocore/net/quic/QUICPacket.cc
+++ b/iocore/net/quic/QUICPacket.cc
@@ -1257,10 +1257,14 @@ QUICPacketFactory::create_initial_packet(QUICConnectionId destination_cid, QUICC
QUICPacketUPtr
QUICPacketFactory::create_retry_packet(QUICConnectionId destination_cid, QUICConnectionId source_cid,
- QUICConnectionId original_dcid, ats_unique_buf payload, size_t len)
+ QUICConnectionId original_dcid, QUICRetryToken &token)
{
- QUICPacketHeaderUPtr header = QUICPacketHeader::build(QUICPacketType::RETRY, QUICKeyPhase::INITIAL, QUIC_SUPPORTED_VERSIONS[0],
- destination_cid, source_cid, original_dcid, std::move(payload), len);
+ ats_unique_buf payload = ats_unique_malloc(token.length());
+ memcpy(payload.get(), token.buf(), token.length());
+
+ QUICPacketHeaderUPtr header =
+ QUICPacketHeader::build(QUICPacketType::RETRY, QUICKeyPhase::INITIAL, QUIC_SUPPORTED_VERSIONS[0], destination_cid, source_cid,
+ original_dcid, std::move(payload), token.length());
return QUICPacketFactory::_create_unprotected_packet(std::move(header));
}
diff --git a/iocore/net/quic/QUICPacket.h b/iocore/net/quic/QUICPacket.h
index 3c35fcb..63ccbdf 100644
--- a/iocore/net/quic/QUICPacket.h
+++ b/iocore/net/quic/QUICPacket.h
@@ -436,7 +436,7 @@ public:
static QUICPacketUPtr create_stateless_reset_packet(QUICConnectionId connection_id,
QUICStatelessResetToken stateless_reset_token);
static QUICPacketUPtr create_retry_packet(QUICConnectionId destination_cid, QUICConnectionId source_cid,
- QUICConnectionId original_dcid, ats_unique_buf payload, size_t len);
+ QUICConnectionId original_dcid, QUICRetryToken &token);
QUICPacketUPtr create(IpEndpoint from, ats_unique_buf buf, size_t len, QUICPacketNumber base_packet_number,
QUICPacketCreationResult &result);
diff --git a/iocore/net/quic/QUICStatelessRetry.cc b/iocore/net/quic/QUICStatelessRetry.cc
deleted file mode 100644
index 86cf803..0000000
--- a/iocore/net/quic/QUICStatelessRetry.cc
+++ /dev/null
@@ -1,69 +0,0 @@
-/** @file
- *
- * Callbacks for Stateless Retry
- *
- * @section license License
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "QUICStatelessRetry.h"
-
-#include <openssl/hmac.h>
-#include <openssl/evp.h>
-#include <openssl/rand.h>
-
-#include "QUICGlobals.h"
-#include "QUICConnection.h"
-
-static constexpr size_t STATELESS_COOKIE_SECRET_LENGTH = 16;
-static uint8_t stateless_cookie_secret[STATELESS_COOKIE_SECRET_LENGTH] = {0};
-
-void
-QUICStatelessRetry::init()
-{
- // TODO: read cookie secret from file like SSLTicketKeyConfig
- RAND_bytes(stateless_cookie_secret, STATELESS_COOKIE_SECRET_LENGTH);
-}
-
-int
-QUICStatelessRetry::generate_cookie(unsigned char *cookie, size_t *cookie_len, IpEndpoint src)
-{
- uint8_t key[INET6_ADDRPORTSTRLEN] = {0};
- size_t key_len = INET6_ADDRPORTSTRLEN;
- ats_ip_nptop(src, reinterpret_cast<char *>(key), key_len);
-
- unsigned int dst_len = 0;
- HMAC(EVP_sha1(), stateless_cookie_secret, STATELESS_COOKIE_SECRET_LENGTH, key, key_len, cookie, &dst_len);
- *cookie_len = dst_len;
-
- return 1;
-}
-
-int
-QUICStatelessRetry::verify_cookie(const unsigned char *cookie, size_t cookie_len, IpEndpoint src)
-{
- uint8_t token[EVP_MAX_MD_SIZE];
- size_t token_len;
-
- if (QUICStatelessRetry::generate_cookie(token, &token_len, src) && cookie_len == token_len &&
- memcmp(token, cookie, cookie_len) == 0) {
- return 1;
- } else {
- return 0;
- }
-}
diff --git a/iocore/net/quic/QUICStatelessRetry.h b/iocore/net/quic/QUICStatelessRetry.h
deleted file mode 100644
index dc213f7..0000000
--- a/iocore/net/quic/QUICStatelessRetry.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/** @file
- *
- * Callbacks for Stateless Retry
- *
- * @section license License
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <openssl/evp.h>
-
-#include "tscore/ink_inet.h"
-
-class QUICStatelessRetry
-{
-public:
- static constexpr size_t MAX_TOKEN_LEN = EVP_MAX_MD_SIZE;
-
- static void init();
- static int generate_cookie(unsigned char *cookie, size_t *cookie_len, IpEndpoint src);
- static int verify_cookie(const unsigned char *cookie, size_t cookie_len, IpEndpoint src);
-};
diff --git a/iocore/net/quic/QUICTypes.cc b/iocore/net/quic/QUICTypes.cc
index 80973ea..5649619 100644
--- a/iocore/net/quic/QUICTypes.cc
+++ b/iocore/net/quic/QUICTypes.cc
@@ -24,6 +24,8 @@
#include <algorithm>
#include "QUICTypes.h"
#include "QUICIntUtil.h"
+#include "tscore/CryptoHash.h"
+#include <openssl/hmac.h>
uint8_t QUICConnectionId::SCID_LEN = 0;
@@ -260,9 +262,9 @@ QUICTypeUtil::write_QUICMaxData(uint64_t max_data, uint8_t *buf, size_t *len)
QUICIntUtil::write_QUICVariableInt(max_data, buf, len);
}
-void
-QUICStatelessResetToken::_gen_token(uint64_t data)
+QUICStatelessResetToken::QUICStatelessResetToken(QUICConnectionId conn_id, uint32_t instance_id)
{
+ uint64_t data = conn_id ^ instance_id;
CryptoHash _hash;
static constexpr char STATELESS_RESET_TOKEN_KEY[] = "stateless_token_reset_key";
CryptoContext ctx;
@@ -275,6 +277,19 @@ QUICStatelessResetToken::_gen_token(uint64_t data)
QUICIntUtil::write_uint_as_nbytes(_hash.u64[1], 8, _token + 8, &dummy);
}
+QUICRetryToken::QUICRetryToken(const IpEndpoint &src)
+{
+ // TODO: read cookie secret from file like SSLTicketKeyConfig
+ static constexpr char stateless_retry_token_secret[] = "stateless_cookie_secret";
+
+ uint8_t key[INET6_ADDRPORTSTRLEN] = {0};
+ size_t key_len = INET6_ADDRPORTSTRLEN;
+ ats_ip_nptop(src, reinterpret_cast<char *>(key), key_len);
+
+ HMAC(EVP_sha1(), stateless_retry_token_secret, sizeof(stateless_retry_token_secret), key, key_len, this->_token,
+ &this->_token_len);
+}
+
QUICFrameType
QUICConnectionError::frame_type() const
{
diff --git a/iocore/net/quic/QUICTypes.h b/iocore/net/quic/QUICTypes.h
index 419daa4..e3b1008 100644
--- a/iocore/net/quic/QUICTypes.h
+++ b/iocore/net/quic/QUICTypes.h
@@ -29,9 +29,9 @@
#include <memory>
#include <random>
#include <cstdint>
-#include "tscore/INK_MD5.h"
#include "tscore/ink_memory.h"
#include "tscore/ink_inet.h"
+#include "openssl/evp.h"
// These magical defines should be removed when we implement seriously
#define MAGIC_NUMBER_0 0
@@ -274,11 +274,13 @@ public:
constexpr static int8_t LEN = 16;
QUICStatelessResetToken() {}
+ QUICStatelessResetToken(QUICConnectionId conn_id, uint32_t instance_id);
QUICStatelessResetToken(const uint8_t *buf) { memcpy(this->_token, buf, QUICStatelessResetToken::LEN); }
- void
- generate(QUICConnectionId conn_id, uint32_t instance_id)
+
+ bool
+ operator==(const QUICStatelessResetToken &x) const
{
- this->_gen_token(conn_id ^ instance_id);
+ return memcmp(this->_token, x._token, QUICStatelessResetToken::LEN) == 0;
}
const uint8_t *
@@ -288,9 +290,42 @@ public:
}
private:
- uint8_t _token[16] = {0};
+ uint8_t _token[LEN] = {0};
+
+ void _generate(uint64_t data);
+};
+
+class QUICRetryToken
+{
+public:
+ QUICRetryToken() {}
+ QUICRetryToken(const uint8_t *buf, uint8_t len) : _token_len(len) { memcpy(this->_token, buf, len); }
+ QUICRetryToken(const IpEndpoint &src);
+
+ bool
+ operator==(const QUICRetryToken &x) const
+ {
+ if (this->_token_len != x._token_len) {
+ return false;
+ }
+ return memcmp(this->_token, x._token, this->_token_len) == 0;
+ }
- void _gen_token(uint64_t data);
+ const uint8_t *
+ buf() const
+ {
+ return this->_token;
+ }
+
+ uint8_t
+ length() const
+ {
+ return this->_token_len;
+ }
+
+private:
+ uint8_t _token[EVP_MAX_MD_SIZE] = {};
+ unsigned int _token_len = 0;
};
class QUICPreferredAddress
diff --git a/iocore/net/quic/test/test_QUICPacketFactory.cc b/iocore/net/quic/test/test_QUICPacketFactory.cc
index e6cd60f..65e0d5e 100644
--- a/iocore/net/quic/test/test_QUICPacketFactory.cc
+++ b/iocore/net/quic/test/test_QUICPacketFactory.cc
@@ -69,14 +69,13 @@ TEST_CASE("QUICPacketFactory_Create_Retry", "[quic]")
factory.set_hs_protocol(&hs_protocol);
factory.set_version(0x11223344);
- uint8_t raw[] = {0xaa, 0xbb, 0xcc, 0xdd};
- ats_unique_buf payload = ats_unique_malloc(sizeof(raw));
- memcpy(payload.get(), raw, sizeof(raw));
+ uint8_t raw[] = {0xaa, 0xbb, 0xcc, 0xdd};
+ QUICRetryToken token(raw, 4);
- QUICPacketUPtr packet = factory.create_retry_packet(QUICConnectionId(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04"), 4),
- QUICConnectionId(reinterpret_cast<const uint8_t *>("\x11\x12\x13\x14"), 4),
- QUICConnectionId(reinterpret_cast<const uint8_t *>("\x04\x03\x02\x01"), 4),
- std::move(payload), sizeof(raw));
+ QUICPacketUPtr packet =
+ factory.create_retry_packet(QUICConnectionId(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04"), 4),
+ QUICConnectionId(reinterpret_cast<const uint8_t *>("\x11\x12\x13\x14"), 4),
+ QUICConnectionId(reinterpret_cast<const uint8_t *>("\x04\x03\x02\x01"), 4), token);
CHECK(packet->type() == QUICPacketType::RETRY);
CHECK((packet->destination_cid() == QUICConnectionId(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04"), 4)));
CHECK(memcmp(packet->payload(), raw, sizeof(raw)) == 0);
@@ -112,8 +111,7 @@ TEST_CASE("QUICPacketFactory_Create_StatelessResetPacket", "[quic]")
QUICPacketFactory factory;
MockQUICHandshakeProtocol hs_protocol;
factory.set_hs_protocol(&hs_protocol);
- QUICStatelessResetToken token;
- token.generate({reinterpret_cast<const uint8_t *>("\x30\x39"), 2}, 67890);
+ QUICStatelessResetToken token({reinterpret_cast<const uint8_t *>("\x30\x39"), 2}, 67890);
QUICPacketUPtr packet =
factory.create_stateless_reset_packet(QUICConnectionId(reinterpret_cast<const uint8_t *>("\x01\x02\x03\x04"), 4), token);
[trafficserver] 02/02: Send original_connection_id TP
Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
maskit pushed a commit to branch quic_latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 0ef9bce3206ac4bc949003c3a7dc78aacc7780e6
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Tue Nov 27 13:59:23 2018 +0900
Send original_connection_id TP
---
iocore/net/P_QUICNetVConnection.h | 7 +++++--
iocore/net/P_QUICPacketHandler.h | 2 +-
iocore/net/QUICNetVConnection.cc | 35 +++++++++++++++++++++++++++++++++--
iocore/net/QUICPacketHandler.cc | 14 +++++++++-----
iocore/net/quic/Mock.h | 12 ++++++++++++
iocore/net/quic/QUICConnection.h | 1 +
iocore/net/quic/QUICHandshake.cc | 4 ++++
iocore/net/quic/QUICTypes.cc | 26 +++++++++++++++++++++-----
iocore/net/quic/QUICTypes.h | 9 ++++++---
9 files changed, 92 insertions(+), 18 deletions(-)
diff --git a/iocore/net/P_QUICNetVConnection.h b/iocore/net/P_QUICNetVConnection.h
index 27c6919..76e5fe9 100644
--- a/iocore/net/P_QUICNetVConnection.h
+++ b/iocore/net/P_QUICNetVConnection.h
@@ -152,8 +152,9 @@ class QUICNetVConnection : public UnixNetVConnection, public QUICConnection, pub
public:
QUICNetVConnection() {}
- void init(QUICConnectionId peer_cid, QUICConnectionId original_cid, UDPConnection *, QUICPacketHandler *,
- QUICConnectionTable *ctable = nullptr);
+ void init(QUICConnectionId peer_cid, QUICConnectionId original_cid, UDPConnection *, QUICPacketHandler *);
+ void init(QUICConnectionId peer_cid, QUICConnectionId original_cid, QUICConnectionId first_cid, UDPConnection *,
+ QUICPacketHandler *, QUICConnectionTable *ctable);
// accept new conn_id
int acceptEvent(int event, Event *e);
@@ -196,6 +197,7 @@ public:
// QUICConnection (QUICConnectionInfoProvider)
QUICConnectionId peer_connection_id() const override;
QUICConnectionId original_connection_id() const override;
+ QUICConnectionId first_connection_id() const override;
QUICConnectionId connection_id() const override;
std::string_view cids() const override;
const QUICFiveTuple five_tuple() const override;
@@ -233,6 +235,7 @@ private:
QUICConnectionId _peer_quic_connection_id; // dst cid in local
QUICConnectionId _peer_old_quic_connection_id; // dst previous cid in local
QUICConnectionId _original_quic_connection_id; // dst cid of initial packet from client
+ QUICConnectionId _first_quic_connection_id; // dst cid of initial packet from client that doesn't have retry token
QUICConnectionId _quic_connection_id; // src cid in local
QUICFiveTuple _five_tuple;
bool _connection_migration_initiated = false;
diff --git a/iocore/net/P_QUICPacketHandler.h b/iocore/net/P_QUICPacketHandler.h
index f96deaa..c475e9f 100644
--- a/iocore/net/P_QUICPacketHandler.h
+++ b/iocore/net/P_QUICPacketHandler.h
@@ -80,7 +80,7 @@ public:
private:
void _recv_packet(int event, UDPPacket *udp_packet) override;
int _stateless_retry(const uint8_t *buf, uint64_t buf_len, UDPConnection *connection, IpEndpoint from, QUICConnectionId dcid,
- QUICConnectionId scid);
+ QUICConnectionId scid, QUICConnectionId *original_cid);
QUICConnectionTable *_ctable = nullptr;
};
diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index 3556dd9..2a35eae 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -79,7 +79,7 @@ ClassAllocator<QUICNetVConnection> quicNetVCAllocator("quicNetVCAllocator");
// XXX This might be called on ET_UDP thread
void
QUICNetVConnection::init(QUICConnectionId peer_cid, QUICConnectionId original_cid, UDPConnection *udp_con,
- QUICPacketHandler *packet_handler, QUICConnectionTable *ctable)
+ QUICPacketHandler *packet_handler)
{
SET_HANDLER((NetVConnHandler)&QUICNetVConnection::acceptEvent);
this->_packet_transmitter_mutex = new_ProxyMutex();
@@ -89,7 +89,32 @@ QUICNetVConnection::init(QUICConnectionId peer_cid, QUICConnectionId original_ci
this->_peer_quic_connection_id = peer_cid;
this->_original_quic_connection_id = original_cid;
this->_quic_connection_id.randomize();
- // PacketHandler for out going connection doesn't have connection table
+
+ this->_update_cids();
+
+ if (is_debug_tag_set(QUIC_DEBUG_TAG.data())) {
+ char dcid_hex_str[QUICConnectionId::MAX_HEX_STR_LENGTH];
+ char scid_hex_str[QUICConnectionId::MAX_HEX_STR_LENGTH];
+ this->_peer_quic_connection_id.hex(dcid_hex_str, QUICConnectionId::MAX_HEX_STR_LENGTH);
+ this->_quic_connection_id.hex(scid_hex_str, QUICConnectionId::MAX_HEX_STR_LENGTH);
+
+ QUICConDebug("dcid=%s scid=%s", dcid_hex_str, scid_hex_str);
+ }
+}
+void
+QUICNetVConnection::init(QUICConnectionId peer_cid, QUICConnectionId original_cid, QUICConnectionId first_cid,
+ UDPConnection *udp_con, QUICPacketHandler *packet_handler, QUICConnectionTable *ctable)
+{
+ SET_HANDLER((NetVConnHandler)&QUICNetVConnection::acceptEvent);
+ this->_packet_transmitter_mutex = new_ProxyMutex();
+ this->_frame_transmitter_mutex = new_ProxyMutex();
+ this->_udp_con = udp_con;
+ this->_packet_handler = packet_handler;
+ this->_peer_quic_connection_id = peer_cid;
+ this->_original_quic_connection_id = original_cid;
+ this->_first_quic_connection_id = first_cid;
+ this->_quic_connection_id.randomize();
+
if (ctable) {
this->_ctable = ctable;
this->_ctable->insert(this->_quic_connection_id, this);
@@ -348,6 +373,12 @@ QUICNetVConnection::original_connection_id() const
}
QUICConnectionId
+QUICNetVConnection::first_connection_id() const
+{
+ return this->_first_quic_connection_id;
+}
+
+QUICConnectionId
QUICNetVConnection::connection_id() const
{
return this->_quic_connection_id;
diff --git a/iocore/net/QUICPacketHandler.cc b/iocore/net/QUICPacketHandler.cc
index fb6b3a0..5512297 100644
--- a/iocore/net/QUICPacketHandler.cc
+++ b/iocore/net/QUICPacketHandler.cc
@@ -279,8 +279,9 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet)
// Server Stateless Retry
QUICConfig::scoped_config params;
+ QUICConnectionId cid_in_retry_token;
if (!vc && params->stateless_retry()) {
- int ret = this->_stateless_retry(buf, buf_len, udp_packet->getConnection(), udp_packet->from, dcid, scid);
+ int ret = this->_stateless_retry(buf, buf_len, udp_packet->getConnection(), udp_packet->from, dcid, scid, &cid_in_retry_token);
if (ret < 0) {
udp_packet->free();
return;
@@ -316,7 +317,7 @@ QUICPacketHandlerIn::_recv_packet(int event, UDPPacket *udp_packet)
}
vc = static_cast<QUICNetVConnection *>(getNetProcessor()->allocate_vc(nullptr));
- vc->init(peer_cid, original_cid, udp_packet->getConnection(), this, this->_ctable);
+ vc->init(peer_cid, original_cid, cid_in_retry_token, udp_packet->getConnection(), this, this->_ctable);
vc->id = net_next_connection_number();
vc->con.move(con);
vc->submit_time = Thread::get_hrtime();
@@ -357,7 +358,7 @@ QUICPacketHandlerIn::send_packet(QUICNetVConnection *vc, Ptr<IOBufferBlock> udp_
int
QUICPacketHandlerIn::_stateless_retry(const uint8_t *buf, uint64_t buf_len, UDPConnection *connection, IpEndpoint from,
- QUICConnectionId dcid, QUICConnectionId scid)
+ QUICConnectionId dcid, QUICConnectionId scid, QUICConnectionId *original_cid)
{
QUICPacketType type = QUICPacketType::UNINITIALIZED;
QUICPacketLongHeader::type(type, buf, buf_len);
@@ -374,7 +375,7 @@ QUICPacketHandlerIn::_stateless_retry(const uint8_t *buf, uint64_t buf_len, UDPC
}
if (token_length == 0) {
- QUICRetryToken token(from);
+ QUICRetryToken token(from, dcid);
QUICConnectionId local_cid;
local_cid.randomize();
QUICPacketUPtr retry_packet = QUICPacketFactory::create_retry_packet(scid, local_cid, dcid, token);
@@ -388,9 +389,12 @@ QUICPacketHandlerIn::_stateless_retry(const uint8_t *buf, uint64_t buf_len, UDPC
QUICPacketLongHeader::scil(scil, buf, buf_len);
const uint8_t *token = buf + LONG_HDR_OFFSET_CONNECTION_ID + dcil + scil + token_length_field_len;
+ QUICConnectionId attached_cid = QUICTypeUtil::read_QUICConnectionId(token + 20, token_length - 20);
QUICRetryToken token1(token, token_length);
- QUICRetryToken token2(from);
+ QUICRetryToken token2(from, attached_cid);
if (token1 == token2) {
+ // Tokein is valid
+ *original_cid = attached_cid;
return 0;
} else {
return -3;
diff --git a/iocore/net/quic/Mock.h b/iocore/net/quic/Mock.h
index b660b97..008b312 100644
--- a/iocore/net/quic/Mock.h
+++ b/iocore/net/quic/Mock.h
@@ -166,6 +166,12 @@ public:
return {reinterpret_cast<const uint8_t *>("\x00"), 1};
}
+ QUICConnectionId
+ first_connection_id() const override
+ {
+ return {reinterpret_cast<const uint8_t *>("\x00"), 1};
+ }
+
const QUICFiveTuple
five_tuple() const override
{
@@ -301,6 +307,12 @@ class MockQUICConnectionInfoProvider : public QUICConnectionInfoProvider
return {reinterpret_cast<const uint8_t *>("\x00"), 1};
}
+ QUICConnectionId
+ first_connection_id() const override
+ {
+ return {reinterpret_cast<const uint8_t *>("\x00"), 1};
+ }
+
const QUICFiveTuple
five_tuple() const override
{
diff --git a/iocore/net/quic/QUICConnection.h b/iocore/net/quic/QUICConnection.h
index 7e4ae8b..aa67aec 100644
--- a/iocore/net/quic/QUICConnection.h
+++ b/iocore/net/quic/QUICConnection.h
@@ -38,6 +38,7 @@ class QUICConnectionInfoProvider
public:
virtual QUICConnectionId peer_connection_id() const = 0;
virtual QUICConnectionId original_connection_id() const = 0;
+ virtual QUICConnectionId first_connection_id() const = 0;
virtual QUICConnectionId connection_id() const = 0;
virtual std::string_view cids() const = 0;
virtual const QUICFiveTuple five_tuple() const = 0;
diff --git a/iocore/net/quic/QUICHandshake.cc b/iocore/net/quic/QUICHandshake.cc
index 6b2f829..5912a7a 100644
--- a/iocore/net/quic/QUICHandshake.cc
+++ b/iocore/net/quic/QUICHandshake.cc
@@ -367,6 +367,10 @@ QUICHandshake::_load_local_server_transport_parameters(QUICVersion negotiated_ve
// MUSTs
tp->set(QUICTransportParameterId::IDLE_TIMEOUT, static_cast<uint16_t>(params->no_activity_timeout_in()));
+ if (this->_stateless_retry) {
+ tp->set(QUICTransportParameterId::ORIGINAL_CONNECTION_ID, this->_qc->first_connection_id(),
+ this->_qc->first_connection_id().length());
+ }
// MAYs
if (params->initial_max_data_in() != 0) {
diff --git a/iocore/net/quic/QUICTypes.cc b/iocore/net/quic/QUICTypes.cc
index 5649619..74c9b95 100644
--- a/iocore/net/quic/QUICTypes.cc
+++ b/iocore/net/quic/QUICTypes.cc
@@ -277,17 +277,33 @@ QUICStatelessResetToken::QUICStatelessResetToken(QUICConnectionId conn_id, uint3
QUICIntUtil::write_uint_as_nbytes(_hash.u64[1], 8, _token + 8, &dummy);
}
-QUICRetryToken::QUICRetryToken(const IpEndpoint &src)
+QUICRetryToken::QUICRetryToken(const IpEndpoint &src, QUICConnectionId original_dcid)
{
// TODO: read cookie secret from file like SSLTicketKeyConfig
static constexpr char stateless_retry_token_secret[] = "stateless_cookie_secret";
- uint8_t key[INET6_ADDRPORTSTRLEN] = {0};
- size_t key_len = INET6_ADDRPORTSTRLEN;
- ats_ip_nptop(src, reinterpret_cast<char *>(key), key_len);
+ uint8_t data[INET6_ADDRPORTSTRLEN + QUICConnectionId::MAX_LENGTH] = {0};
+ size_t data_len = 0;
+ ats_ip_nptop(src, reinterpret_cast<char *>(data), sizeof(data));
+ data_len = strlen(reinterpret_cast<char *>(data));
- HMAC(EVP_sha1(), stateless_retry_token_secret, sizeof(stateless_retry_token_secret), key, key_len, this->_token,
+ size_t cid_len;
+ QUICTypeUtil::write_QUICConnectionId(original_dcid, data + data_len, &cid_len);
+ data_len += cid_len;
+
+ HMAC(EVP_sha1(), stateless_retry_token_secret, sizeof(stateless_retry_token_secret), data, data_len, this->_token,
&this->_token_len);
+ ink_assert(this->_token_len == 20);
+
+ QUICTypeUtil::write_QUICConnectionId(original_dcid, this->_token + this->_token_len, &cid_len);
+ this->_token_len += cid_len;
+}
+
+const QUICConnectionId
+QUICRetryToken::original_dcid() const
+{
+ // Output of EVP_sha1() should be 160 bits
+ return QUICTypeUtil::read_QUICConnectionId(this->_token + 20, this->_token_len - 20);
}
QUICFrameType
diff --git a/iocore/net/quic/QUICTypes.h b/iocore/net/quic/QUICTypes.h
index e3b1008..43acd9e 100644
--- a/iocore/net/quic/QUICTypes.h
+++ b/iocore/net/quic/QUICTypes.h
@@ -300,7 +300,7 @@ class QUICRetryToken
public:
QUICRetryToken() {}
QUICRetryToken(const uint8_t *buf, uint8_t len) : _token_len(len) { memcpy(this->_token, buf, len); }
- QUICRetryToken(const IpEndpoint &src);
+ QUICRetryToken(const IpEndpoint &src, QUICConnectionId original_dcid);
bool
operator==(const QUICRetryToken &x) const
@@ -311,6 +311,8 @@ public:
return memcmp(this->_token, x._token, this->_token_len) == 0;
}
+ const QUICConnectionId original_dcid() const;
+
const uint8_t *
buf() const
{
@@ -324,8 +326,9 @@ public:
}
private:
- uint8_t _token[EVP_MAX_MD_SIZE] = {};
- unsigned int _token_len = 0;
+ uint8_t _token[EVP_MAX_MD_SIZE + QUICConnectionId::MAX_LENGTH] = {};
+ unsigned int _token_len = 0;
+ QUICConnectionId _original_dcid;
};
class QUICPreferredAddress