proxygen
FizzServerContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
12 #include <fizz/protocol/Factory.h>
13 #include <fizz/record/Types.h>
16 #include <fizz/server/Negotiator.h>
19 
20 namespace fizz {
21 namespace server {
22 
35  std::chrono::milliseconds before;
36  std::chrono::milliseconds after;
37 };
38 
44 
46  public:
48  virtual ~FizzServerContext() = default;
49 
53  void setSupportedVersions(std::vector<ProtocolVersion> versions) {
54  supportedVersions_ = std::move(versions);
55  }
56  const auto& getSupportedVersions() const {
57  return supportedVersions_;
58  }
59 
63  void setSupportedCiphers(std::vector<std::vector<CipherSuite>> ciphers) {
64  supportedCiphers_ = std::move(ciphers);
65  }
66  const auto& getSupportedCiphers() const {
67  return supportedCiphers_;
68  }
69 
73  void setSupportedSigSchemes(std::vector<SignatureScheme> schemes) {
74  supportedSigSchemes_ = std::move(schemes);
75  }
76  const auto& getSupportedSigSchemes() const {
77  return supportedSigSchemes_;
78  }
79 
83  void setSupportedGroups(std::vector<NamedGroup> groups) {
84  supportedGroups_ = std::move(groups);
85  }
86  const auto& getSupportedGroups() const {
87  return supportedGroups_;
88  }
89 
93  void setSupportedPskModes(std::vector<PskKeyExchangeMode> modes) {
94  supportedPskModes_ = std::move(modes);
95  }
96  const auto& getSupportedPskModes() const {
97  return supportedPskModes_;
98  }
99 
104  clientAuthMode_ = authmode;
105  }
106 
108  return clientAuthMode_;
109  }
110 
116  void setVersionFallbackEnabled(bool enabled) {
117  versionFallbackEnabled_ = enabled;
118  }
120  return versionFallbackEnabled_;
121  }
122 
126  void setSupportedAlpns(std::vector<std::string> protocols) {
127  supportedAlpns_ = std::move(protocols);
128  }
129 
135  const std::vector<std::string>& clientProtocols,
136  const folly::Optional<std::string>& zeroRttAlpn) const {
137  // If we support the zero rtt protocol we select it.
138  if (zeroRttAlpn &&
139  std::find(
140  supportedAlpns_.begin(), supportedAlpns_.end(), *zeroRttAlpn) !=
141  supportedAlpns_.end()) {
142  return zeroRttAlpn;
143  }
144  return negotiate(supportedAlpns_, clientProtocols);
145  }
146 
150  void setTicketCipher(std::shared_ptr<TicketCipher> ticketCipher) {
151  ticketCipher_ = std::move(ticketCipher);
152  }
153  const TicketCipher* getTicketCipher() const {
154  return ticketCipher_.get();
155  }
156 
161  void setCookieCipher(std::shared_ptr<CookieCipher> cookieCipher) {
162  cookieCipher_ = std::move(cookieCipher);
163  }
164  const CookieCipher* getCookieCipher() const {
165  return cookieCipher_.get();
166  }
167 
171  void setCertManager(std::unique_ptr<CertManager> manager) {
172  certManager_ = std::move(manager);
173  }
174 
179  std::shared_ptr<const CertificateVerifier> verifier) {
180  clientCertVerifier_ = std::move(verifier);
181  }
182 
183  const std::shared_ptr<const CertificateVerifier>& getClientCertVerifier()
184  const {
185  return clientCertVerifier_;
186  }
187 
194  const std::vector<SignatureScheme>& peerSigSchemes) const {
195  return certManager_->getCert(sni, supportedSigSchemes_, peerSigSchemes);
196  }
197 
202  std::shared_ptr<SelfCert> getCert(const std::string& identity) const {
203  return certManager_->getCert(identity);
204  }
205 
210  bool acceptEarlyData,
211  ClockSkewTolerance clockSkewTolerance,
212  const std::shared_ptr<ReplayCache>& replayCache) {
213  acceptEarlyData_ = acceptEarlyData;
214  clockSkewTolerance_ = clockSkewTolerance;
215  replayCache_ = replayCache;
216  }
217 
219  if (earlyDataFbOnly_ &&
220  (version != ProtocolVersion::tls_1_3_20_fb &&
221  version != ProtocolVersion::tls_1_3_21_fb &&
222  version != ProtocolVersion::tls_1_3_22_fb &&
223  version != ProtocolVersion::tls_1_3_23_fb &&
224  version != ProtocolVersion::tls_1_3_26_fb)) {
225  return false;
226  }
227  return acceptEarlyData_;
228  }
230  return clockSkewTolerance_;
231  }
233  return replayCache_.get();
234  }
235 
236  void setEarlyDataFbOnly(bool fbOnly) {
237  earlyDataFbOnly_ = fbOnly;
238  }
239 
245  void setMaxEarlyDataSize(uint32_t maxEarlyDataSize) {
246  maxEarlyDataSize_ = maxEarlyDataSize;
247  }
249  return maxEarlyDataSize_;
250  }
251 
255  void setFactory(std::unique_ptr<Factory> factory) {
256  factory_ = std::move(factory);
257  }
258  const Factory* getFactory() const {
259  return factory_.get();
260  }
261 
269  void setSendNewSessionTicket(bool sendNewSessionTicket) {
270  sendNewSessionTicket_ = sendNewSessionTicket;
271  }
272  bool getSendNewSessionTicket() const {
273  return sendNewSessionTicket_;
274  }
275 
282  std::vector<CertificateCompressionAlgorithm> algos) {
283  supportedCompressionAlgos_ = algos;
284  }
285  const auto& getSupportedCompressionAlgorithms() const {
286  return supportedCompressionAlgos_;
287  }
288 
289  private:
290  std::unique_ptr<Factory> factory_;
291 
292  std::shared_ptr<TicketCipher> ticketCipher_;
293  std::shared_ptr<CookieCipher> cookieCipher_;
294 
295  std::unique_ptr<CertManager> certManager_;
296  std::shared_ptr<const CertificateVerifier> clientCertVerifier_;
297 
298  std::vector<ProtocolVersion> supportedVersions_ = {ProtocolVersion::tls_1_3};
299  std::vector<std::vector<CipherSuite>> supportedCiphers_ = {
300  {
302 #if FOLLY_OPENSSL_IS_110
304 #endif // FOLLY_OPENSSL_IS_110
305  },
307  };
308  std::vector<SignatureScheme> supportedSigSchemes_ = {
311  std::vector<NamedGroup> supportedGroups_ = {NamedGroup::x25519,
313  std::vector<PskKeyExchangeMode> supportedPskModes_ = {
316  std::vector<std::string> supportedAlpns_;
317 
318  bool versionFallbackEnabled_{false};
320 
321  bool acceptEarlyData_{false};
324  std::shared_ptr<ReplayCache> replayCache_;
325 
326  std::vector<CertificateCompressionAlgorithm> supportedCompressionAlgos_;
327 
328  bool earlyDataFbOnly_{false};
329 
330  bool sendNewSessionTicket_{true};
331 };
332 } // namespace server
333 } // namespace fizz
folly::Optional< std::pair< std::shared_ptr< SelfCert >, SignatureScheme > > getCert(const folly::Optional< std::string > &sni, const std::vector< SignatureScheme > &peerSigSchemes) const
const auto & getSupportedCompressionAlgorithms() const
const auto & getSupportedSigSchemes() const
void setEarlyDataSettings(bool acceptEarlyData, ClockSkewTolerance clockSkewTolerance, const std::shared_ptr< ReplayCache > &replayCache)
const auto & getSupportedPskModes() const
void setSupportedGroups(std::vector< NamedGroup > groups)
LogLevel max
Definition: LogLevel.cpp:31
std::vector< std::string > supportedAlpns_
const TicketCipher * getTicketCipher() const
folly::Optional< T > negotiate(const std::vector< std::vector< T >> &serverPref, const std::vector< T > &clientPref)
Definition: Negotiator.h:22
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::vector< CertificateCompressionAlgorithm > supportedCompressionAlgos_
SignatureScheme
Definition: Types.h:257
STL namespace.
const auto & getSupportedVersions() const
std::shared_ptr< ReplayCache > replayCache_
void setMaxEarlyDataSize(uint32_t maxEarlyDataSize)
std::shared_ptr< SelfCert > getCert(const std::string &identity) const
void setSupportedVersions(std::vector< ProtocolVersion > versions)
void setSendNewSessionTicket(bool sendNewSessionTicket)
void setVersionFallbackEnabled(bool enabled)
void setSupportedPskModes(std::vector< PskKeyExchangeMode > modes)
ProtocolVersion
Definition: Types.h:24
void setSupportedAlpns(std::vector< std::string > protocols)
ClockSkewTolerance clockSkewTolerance_
ProtocolVersion version
bool getAcceptEarlyData(ProtocolVersion version) const
folly::Optional< std::string > negotiateAlpn(const std::vector< std::string > &clientProtocols, const folly::Optional< std::string > &zeroRttAlpn) const
void setClientAuthMode(ClientAuthMode authmode)
const Factory * getFactory() const
void setTicketCipher(std::shared_ptr< TicketCipher > ticketCipher)
std::unique_ptr< Factory > factory_
Definition: Actions.h:16
void setFactory(std::unique_ptr< Factory > factory)
void setSupportedCiphers(std::vector< std::vector< CipherSuite >> ciphers)
const CookieCipher * getCookieCipher() const
std::shared_ptr< CookieCipher > cookieCipher_
ReplayCache * getReplayCache() const
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Definition: Memory.h:259
const std::shared_ptr< const CertificateVerifier > & getClientCertVerifier() const
std::chrono::milliseconds after
StringPiece sni
const char * string
Definition: Conv.cpp:212
ClockSkewTolerance getClockSkewTolerance() const
ClientAuthMode getClientAuthMode() const
const auto & getSupportedCiphers() const
void setSupportedCompressionAlgorithms(std::vector< CertificateCompressionAlgorithm > algos)
void setCookieCipher(std::shared_ptr< CookieCipher > cookieCipher)
std::chrono::milliseconds before
std::shared_ptr< TicketCipher > ticketCipher_
void setSupportedSigSchemes(std::vector< SignatureScheme > schemes)
const auto & getSupportedGroups() const
void setClientCertVerifier(std::shared_ptr< const CertificateVerifier > verifier)
std::shared_ptr< const CertificateVerifier > clientCertVerifier_
std::unique_ptr< CertManager > certManager_
void setCertManager(std::unique_ptr< CertManager > manager)