proxygen
SSLContextConfig.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <folly/Optional.h>
21 #include <set>
22 #include <string>
23 #include <vector>
24 
36 namespace wangle {
37 
39  SSLContextConfig() = default;
40  ~SSLContextConfig() = default;
41 
42  struct CertificateInfo {
43  CertificateInfo(const std::string& crtPath,
44  const std::string& kyPath,
45  const std::string& passwdPath)
46  : certPath(crtPath), keyPath(kyPath), passwordPath(passwdPath) {}
50  };
51 
52  static const std::string& getDefaultCiphers() {
53  static const std::string& defaultCiphers =
55  return defaultCiphers;
56  }
57 
59  // What keys do we want to offload
60  // Currently supported values: "rsa", "ec" (can also be empty)
61  // Note that the corresponding thrift IDL has a list instead
62  std::set<std::string> offloadType;
63  // Whether this set of keys need local fallback
64  bool localFallback{false};
65  // An identifier for the service to which we are offloading.
66  std::string serviceId{"default"};
67  // Whether we want to offload certificates
68  bool enableCertOffload{false};
69  };
70 
75  const std::string& keyPath,
76  const std::string& passwordPath) {
77  certificates.clear();
78  addCertificate(certPath, keyPath, passwordPath);
79  }
80 
82  const std::string& keyPath,
83  const std::string& passwordPath) {
84  certificates.emplace_back(certPath, keyPath, passwordPath);
85  }
86 
91  void setNextProtocols(const std::list<std::string>& inNextProtocols) {
92  nextProtocols.clear();
93  nextProtocols.emplace_back(1, inNextProtocols);
94  }
95 
96  typedef std::function<bool(char const* server_name)> SNINoMatchFn;
97 
98  std::vector<CertificateInfo> certificates;
105  std::string eccCurveName{"prime256v1"};
106 
107  // Weighted lists of NPN strings to advertise
108  std::list<folly::SSLContext::NextProtocolsItem>
110  bool isLocalPrivateKey{true};
111  // Should this SSLContextConfig be the default for SNI purposes
112  bool isDefault{false};
113  // Callback function to invoke when there are no matching certificates
114  // (will only be invoked once)
115  SNINoMatchFn sniNoMatchFn;
116  // File containing trusted CA's to validate client certificates
118  // Verification method to use for client certificates.
120  folly::SSLContext::SSLVerifyPeerEnum::VERIFY_REQ_CLIENT_CERT};
121  // Key offload configuration
123  // A namespace to use for sessions generated from this context so that
124  // they will not be shared between other sessions generated from the
125  // same context. If not specified the common name for the certificates set
126  // in the context will be used by default.
128 };
129 
130 } // namespace wangle
folly::Optional< std::string > sessionContext
std::function< bool(char const *server_name)> SNINoMatchFn
CertificateInfo(const std::string &crtPath, const std::string &kyPath, const std::string &passwdPath)
folly::SSLContext::SSLVerifyPeerEnum clientVerification
std::vector< CertificateInfo > certificates
void setCertificate(const std::string &certPath, const std::string &keyPath, const std::string &passwordPath)
static constexpr auto kCipherList
Definition: SSLOptions.h:76
void addCertificate(const std::string &certPath, const std::string &keyPath, const std::string &passwordPath)
const char * string
Definition: Conv.cpp:212
void setNextProtocols(const std::list< std::string > &inNextProtocols)
void join(const Delim &delimiter, Iterator begin, Iterator end, String &output)
Definition: String-inl.h:498
static const std::string & getDefaultCiphers()
std::list< folly::SSLContext::NextProtocolsItem > nextProtocols
KeyOffloadParams keyOffloadParams
folly::SSLContext::SSLVersion sslVersion