13 using namespace folly;
23 const std::vector<SignatureScheme>& supportedSigSchemes,
24 const std::vector<SignatureScheme>& peerSigSchemes,
26 auto it = certs_.find(key);
27 if (it == certs_.end()) {
30 for (
auto scheme : supportedSigSchemes) {
31 auto cert = it->second.find(scheme);
32 if (cert == it->second.end()) {
35 if (std::find(peerSigSchemes.begin(), peerSigSchemes.end(), scheme) !=
36 peerSigSchemes.end()) {
37 return std::make_pair(cert->second, scheme);
38 }
else if (!lastResort) {
39 lastResort = std::make_pair(cert->second, scheme);
47 const std::vector<SignatureScheme>& supportedSigSchemes,
48 const std::vector<SignatureScheme>& peerSigSchemes)
const {
54 auto ret = findCert(key, supportedSigSchemes, peerSigSchemes, lastResort);
56 VLOG(8) <<
"Found exact SNI match for: " << key;
60 auto dot = key.find_first_of(
'.');
61 if (
dot != std::string::npos) {
64 wildcardKey, supportedSigSchemes, peerSigSchemes, lastResort);
66 VLOG(8) <<
"Found wildcard SNI match for: " << key;
71 VLOG(8) <<
"Did not find match for SNI: " << key;
75 findCert(default_, supportedSigSchemes, peerSigSchemes, lastResort);
80 VLOG(8) <<
"No matching cert for client sig schemes found";
86 auto it = identMap_.find(identity);
87 if (it == identMap_.end()) {
95 throw std::runtime_error(
"empty identity");
99 if (ident.front() ==
'*') {
109 void CertManager::addCertIdentity(
110 std::shared_ptr<SelfCert> cert,
114 if (key.empty() || key ==
"." || key.find(
'*') != std::string::npos) {
115 throw std::runtime_error(to<std::string>(
"invalid identity: ", ident));
118 auto sigSchemes = cert->getSigSchemes();
119 auto& schemeMap = certs_[key];
120 for (
auto sigScheme : sigSchemes) {
121 if (schemeMap.find(sigScheme) != schemeMap.end()) {
122 LOG(
INFO) <<
"Skipping duplicate certificate for " << key;
124 schemeMap[sigScheme] = cert;
129 void CertManager::addCert(std::shared_ptr<SelfCert> cert,
bool defaultCert) {
130 auto primaryIdent = cert->getIdentity();
131 addCertIdentity(cert, primaryIdent);
133 auto altIdents = cert->getAltIdentities();
134 for (
const auto& ident : altIdents) {
135 if (ident != primaryIdent) {
136 addCertIdentity(cert, ident);
144 if (identMap_.find(primaryIdent) == identMap_.end()) {
145 identMap_[primaryIdent] = cert;
—— Concurrent Priority Queue Implementation ——
folly::ssl::X509UniquePtr getCert(folly::StringPiece cert)
void toLowerAscii(char *str, size_t length)
static std::string getKeyFromIdent(const std::string &ident)