Skip to content

Commit

Permalink
Modify function selectECHConfig to take in a const vector of ech configs
Browse files Browse the repository at this point in the history
Summary: Modify function `selectECHConfig` to take in a const vector of ech configs.

Reviewed By: reanimus

Differential Revision: D24865309

fbshipit-source-id: be079d3e8b50d8dd037000d103ff641770c9ab0d
  • Loading branch information
xubonnie authored and facebook-github-bot committed Nov 14, 2020
1 parent 3f07673 commit 47ee698
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions fizz/protocol/ech/Encryption.cpp
Expand Up @@ -18,12 +18,12 @@ namespace fizz {
namespace ech {

folly::Optional<SupportedECHConfig> selectECHConfig(
std::vector<ECHConfig> configs,
const std::vector<ECHConfig>& configs,
std::vector<hpke::KEMId> supportedKEMs,
std::vector<hpke::AeadId> supportedAeads) {
// Received set of configs is in order of server preference so
// we should be selecting the first one that we can support.
for (auto& config : configs) {
for (const auto& config : configs) {
folly::io::Cursor cursor(config.ech_config_content.get());
if (config.version == ECHVersion::V7) {
auto echConfig = decode<ECHConfigContentDraft7>(cursor);
Expand All @@ -45,7 +45,7 @@ folly::Optional<SupportedECHConfig> selectECHConfig(
auto associatedCipherKdf =
hpke::getKDFId(getHashFunction(getCipherSuite(suite.aeadId)));
if (suite.kdfId == associatedCipherKdf) {
return SupportedECHConfig{std::move(config), suite};
return SupportedECHConfig{config.clone(), suite};
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fizz/protocol/ech/Encryption.h
Expand Up @@ -23,7 +23,7 @@ struct SupportedECHConfig {
};

folly::Optional<SupportedECHConfig> selectECHConfig(
std::vector<ECHConfig> configs,
const std::vector<ECHConfig>& configs,
std::vector<hpke::KEMId> supportedKEMs,
std::vector<hpke::AeadId> supportedAeads);

Expand Down
14 changes: 10 additions & 4 deletions fizz/protocol/ech/Types.h
Expand Up @@ -41,11 +41,17 @@ struct ECHConfigContentDraft7 {
std::vector<Extension> extensions;
};


struct ECHConfig {
ECHVersion version;
uint16_t length;
Buf ech_config_content;
ECHVersion version;
uint16_t length;
Buf ech_config_content;
ECHConfig clone() const {
ECHConfig copy;
copy.version = this->version;
copy.length = this->length;
copy.ech_config_content = this->ech_config_content->clone();
return copy;
}
};

} // namespace ech
Expand Down
4 changes: 2 additions & 2 deletions fizz/protocol/ech/test/EncryptionTest.cpp
Expand Up @@ -127,7 +127,7 @@ TEST(EncryptionTest, TestValidECHConfigContent) {
hpke::AeadId::TLS_AES_128_GCM_SHA256};

folly::Optional<SupportedECHConfig> result =
selectECHConfig(std::move(configs), supportedKEMs, supportedAeads);
selectECHConfig(configs, supportedKEMs, supportedAeads);
EXPECT_TRUE(result.hasValue());

ECHConfig gotConfig = std::move(result.value().config);
Expand Down Expand Up @@ -157,7 +157,7 @@ TEST(EncryptionTest, TestInvalidECHConfigContent) {
hpke::AeadId::TLS_AES_128_GCM_SHA256};

folly::Optional<SupportedECHConfig> result =
selectECHConfig(std::move(configs), supportedKEMs, supportedAeads);
selectECHConfig(configs, supportedKEMs, supportedAeads);

EXPECT_FALSE(result.hasValue());
}
Expand Down

0 comments on commit 47ee698

Please sign in to comment.