Skip to content

Commit b983f75

Browse files
committed
[Release-7.3] TLS should accept same key with different values (#11763)
* fix tls * address comment
1 parent 6ee6e0b commit b983f75

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

flow/TLSConfig.actor.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ TLSPolicy::Rule::Rule(std::string input) {
601601

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

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

627627
NID termNID = abbrevToNID(term);
628628
const X509Location loc = locationForNID(termNID);
629-
criteria->insert(std::make_pair(termNID, Criteria(unesc, mt, loc)));
629+
auto criteriaToInsert = Criteria(unesc, mt, loc);
630+
auto res = criteria->insert(std::make_pair(termNID, criteriaToInsert));
631+
if (!res.second) {
632+
TraceEvent(SevWarn, "TLSKeyValueDuplicated")
633+
.suppressFor(60.0)
634+
.detail("TermNID", termNID)
635+
.detail("NewCriteria", criteriaToInsert.criteria)
636+
.detail("ExistingCriteria", res.first->second.criteria);
637+
}
630638

631639
if (remain != input.size() && input[remain] != ',')
632640
throw std::runtime_error("parse_verify");

flow/include/flow/TLSConfig.actor.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
#include "flow/FastRef.h"
4343
#include "flow/Knobs.h"
4444
#include "flow/flow.h"
45-
4645
#include "flow/actorcompiler.h" // This must be the last #include.
4746

4847
typedef int NID;
@@ -75,6 +74,17 @@ struct Criteria {
7574
}
7675

7776
bool operator!=(const Criteria& c) const noexcept { return !(*this == c); }
77+
78+
bool operator<(const Criteria& c) const {
79+
if (criteria != c.criteria) {
80+
return criteria < c.criteria;
81+
} else if (match_type != c.match_type) {
82+
return match_type < c.match_type;
83+
} else if (location != c.location) {
84+
return location < c.location;
85+
}
86+
return false;
87+
}
7888
};
7989

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

249259
struct Rule {
250-
using CriteriaMap = std::map<NID, Criteria>;
260+
using CriteriaMap = std::set<std::pair<NID, Criteria>>;
251261

252262
explicit Rule(std::string input);
253263

0 commit comments

Comments
 (0)