Skip to content

TLS should accept same key with different values (Cherrypick #11763) #12014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions flow/TLSConfig.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ TLSPolicy::Rule::Rule(std::string input) {

s = eq + 3;
} else {
std::map<int, Criteria>* criteria = &subject_criteria;
std::set<std::pair<NID, Criteria>>* criteria = &subject_criteria;

if (term.find('.') != term.npos) {
auto scoped = splitPair(term, '.');
Expand All @@ -626,7 +626,15 @@ TLSPolicy::Rule::Rule(std::string input) {

NID termNID = abbrevToNID(term);
const X509Location loc = locationForNID(termNID);
criteria->insert(std::make_pair(termNID, Criteria(unesc, mt, loc)));
auto criteriaToInsert = Criteria(unesc, mt, loc);
auto res = criteria->insert(std::make_pair(termNID, criteriaToInsert));
if (!res.second) {
TraceEvent(SevWarn, "TLSKeyValueDuplicated")
.suppressFor(60.0)
.detail("TermNID", termNID)
.detail("NewCriteria", criteriaToInsert.criteria)
.detail("ExistingCriteria", res.first->second.criteria);
}

if (remain != input.size() && input[remain] != ',')
throw std::runtime_error("parse_verify");
Expand Down
14 changes: 12 additions & 2 deletions flow/include/flow/TLSConfig.actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#include "flow/FastRef.h"
#include "flow/Knobs.h"
#include "flow/flow.h"

#include "flow/actorcompiler.h" // This must be the last #include.

typedef int NID;
Expand Down Expand Up @@ -75,6 +74,17 @@ struct Criteria {
}

bool operator!=(const Criteria& c) const noexcept { return !(*this == c); }

bool operator<(const Criteria& c) const {
if (criteria != c.criteria) {
return criteria < c.criteria;
} else if (match_type != c.match_type) {
return match_type < c.match_type;
} else if (location != c.location) {
return location < c.location;
}
return false;
}
};

enum class TLSEndpointType { UNSET = 0, CLIENT, SERVER };
Expand Down Expand Up @@ -247,7 +257,7 @@ class TLSPolicy : ReferenceCounted<TLSPolicy> {
std::string toString() const;

struct Rule {
using CriteriaMap = std::map<NID, Criteria>;
using CriteriaMap = std::set<std::pair<NID, Criteria>>;

explicit Rule(std::string input);

Expand Down