proxygen
State.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 
11 #include <folly/futures/Future.h>
12 
15 #include <fizz/protocol/Types.h>
16 #include <fizz/record/Extensions.h>
18 #include <fizz/server/Actions.h>
22 
23 namespace fizz {
24 namespace server {
25 
26 enum class StateEnum {
34  Closed,
35  Error,
37 };
38 
41  std::vector<ProtocolVersion> clientSupportedVersions;
42  std::vector<CipherSuite> clientCiphers;
43  std::vector<ExtensionType> clientExtensions;
46  std::vector<NamedGroup> clientSupportedGroups;
48  std::vector<PskKeyExchangeMode> clientKeyExchangeModes;
49  std::vector<SignatureScheme> clientSignatureAlgorithms;
52 };
53 
58  public:
59  virtual ~AppTokenValidator() = default;
60 
61  virtual bool validate(const ResumptionState&) const = 0;
62 };
63 
64 class State {
65  public:
69  StateEnum state() const {
70  return state_;
71  }
72 
77  return executor_;
78  }
79 
83  const FizzServerContext* context() const {
84  return context_.get();
85  }
86 
90  std::shared_ptr<const Cert> serverCert() const {
91  return serverCert_;
92  }
93 
97  const std::shared_ptr<const Cert>& clientCert() const {
98  return clientCert_;
99  }
100 
105  return version_;
106  }
107 
112  return cipher_;
113  }
114 
119  return group_;
120  }
121 
126  return sigScheme_;
127  }
128 
134  return pskType_;
135  }
136 
141  return pskMode_;
142  }
143 
148  return keyExchangeType_;
149  }
150 
155  return earlyDataType_;
156  }
157 
162  return replayCacheResult_;
163  }
164 
169  return alpn_;
170  }
171 
177  return clientClockSkew_;
178  }
179 
185  return appTokenValidator_.get();
186  }
187 
194  return handshakeLogging_.get();
195  }
196 
204  return keyScheduler_.get();
205  }
206 
214  return readRecordLayer_.get();
215  }
216 
224  return writeRecordLayer_.get();
225  }
226 
232  const Buf& clientHandshakeSecret() const {
233  return *clientHandshakeSecret_;
234  }
235 
242  return extensions_.get();
243  }
244 
248  const std::vector<uint8_t>& resumptionMasterSecret() const {
249  return resumptionMasterSecret_;
250  }
251 
259  return unverifiedCertChain_;
260  }
261 
267  const {
268  return serverCertCompAlgo_;
269  }
270 
276  return earlyExporterMasterSecret_;
277  }
278 
283  return exporterMasterSecret_;
284  }
285 
286  /*
287  * State setters.
288  */
289  auto& state() {
290  return state_;
291  }
292  auto& executor() {
293  return executor_;
294  }
295  auto& context() {
296  return context_;
297  }
298  auto& keyScheduler() {
299  return keyScheduler_;
300  }
301  auto& readRecordLayer() {
302  return readRecordLayer_;
303  }
305  return writeRecordLayer_;
306  }
307  auto& handshakeReadRecordLayer() const {
308  return handshakeReadRecordLayer_;
309  }
310  auto& handshakeContext() const {
311  return handshakeContext_;
312  }
313  auto& serverCert() {
314  return serverCert_;
315  }
316  auto& clientCert() {
317  return clientCert_;
318  }
320  return serverCertCompAlgo_;
321  }
323  return unverifiedCertChain_;
324  }
325  auto& version() {
326  return version_;
327  }
328  auto& cipher() {
329  return cipher_;
330  }
331  auto& group() {
332  return group_;
333  }
334  auto& sigScheme() {
335  return sigScheme_;
336  }
337  auto& pskType() {
338  return pskType_;
339  }
340  auto& pskMode() {
341  return pskMode_;
342  }
343  auto& keyExchangeType() {
344  return keyExchangeType_;
345  }
346  auto& earlyDataType() {
347  return earlyDataType_;
348  }
350  return replayCacheResult_;
351  }
353  return clientHandshakeSecret_;
354  }
355  auto& alpn() {
356  return alpn_;
357  }
358  auto& clientClockSkew() {
359  return clientClockSkew_;
360  }
362  return appTokenValidator_;
363  }
365  return handshakeLogging_;
366  }
367  auto& extensions() {
368  return extensions_;
369  }
371  return resumptionMasterSecret_;
372  }
374  return earlyExporterMasterSecret_;
375  }
377  return exporterMasterSecret_;
378  }
379 
380  private:
382 
384 
385  std::shared_ptr<const FizzServerContext> context_;
386 
387  std::unique_ptr<KeyScheduler> keyScheduler_;
388 
389  std::unique_ptr<ReadRecordLayer> readRecordLayer_;
390  std::unique_ptr<WriteRecordLayer> writeRecordLayer_;
391 
392  // The handshake read record layer, stored here while accepting early data.
393  mutable std::unique_ptr<EncryptedReadRecordLayer> handshakeReadRecordLayer_;
394  mutable std::unique_ptr<HandshakeContext> handshakeContext_;
395 
396  std::shared_ptr<const Cert> serverCert_;
397  std::shared_ptr<const Cert> clientCert_;
399 
402 
415  std::unique_ptr<AppTokenValidator> appTokenValidator_;
416  std::shared_ptr<ServerExtensions> extensions_;
417  std::vector<uint8_t> resumptionMasterSecret_;
418 
419  std::unique_ptr<HandshakeLogging> handshakeLogging_;
420 
423 };
424 } // namespace server
425 
427 
428 namespace server {
429 inline std::ostream& operator<<(std::ostream& os, StateEnum state) {
430  os << toString(state);
431  return os;
432 }
433 } // namespace server
434 } // namespace fizz
auto & extensions()
Definition: State.h:367
folly::Optional< PskKeyExchangeMode > pskMode_
Definition: State.h:408
folly::Optional< CertificateCompressionAlgorithm > serverCertCompAlgo_
Definition: State.h:398
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
ServerExtensions * extensions() const
Definition: State.h:241
auto & version()
Definition: State.h:325
std::vector< CipherSuite > clientCiphers
Definition: State.h:42
folly::Optional< ProtocolVersion > version() const
Definition: State.h:104
folly::Optional< ProtocolVersion > clientRecordVersion
Definition: State.h:44
auto & serverCert()
Definition: State.h:313
folly::Optional< PskKeyExchangeMode > pskMode() const
Definition: State.h:140
const folly::Optional< CertificateCompressionAlgorithm > & serverCertCompAlgo() const
Definition: State.h:266
folly::Optional< bool > clientSessionIdSent
Definition: State.h:50
auto & handshakeReadRecordLayer() const
Definition: State.h:307
auto & earlyExporterMasterSecret()
Definition: State.h:373
std::shared_ptr< const FizzServerContext > context_
Definition: State.h:385
StateEnum state() const
Definition: State.h:69
folly::Optional< Buf > exporterMasterSecret_
Definition: State.h:422
std::unique_ptr< ReadRecordLayer > readRecordLayer_
Definition: State.h:389
folly::Optional< NamedGroup > group_
Definition: State.h:405
std::unique_ptr< HandshakeContext > handshakeContext_
Definition: State.h:394
const folly::Optional< Buf > & earlyExporterMasterSecret() const
Definition: State.h:275
auto & replayCacheResult()
Definition: State.h:349
folly::Optional< EarlyDataType > earlyDataType_
Definition: State.h:410
folly::Optional< SignatureScheme > sigScheme_
Definition: State.h:406
auto & pskMode()
Definition: State.h:340
folly::Optional< PskType > pskType_
Definition: State.h:407
auto & sigScheme()
Definition: State.h:334
std::shared_ptr< const Cert > serverCert_
Definition: State.h:396
folly::Optional< std::vector< NamedGroup > > clientKeyShares
Definition: State.h:47
std::unique_ptr< EncryptedReadRecordLayer > handshakeReadRecordLayer_
Definition: State.h:393
auto & cipher()
Definition: State.h:328
std::vector< PskKeyExchangeMode > clientKeyExchangeModes
Definition: State.h:48
auto & alpn()
Definition: State.h:355
folly::Optional< std::string > alpn_
Definition: State.h:413
auto & executor()
Definition: State.h:292
auto & context()
Definition: State.h:295
KeyScheduler * keyScheduler() const
Definition: State.h:203
const folly::Optional< Buf > & exporterMasterSecret() const
Definition: State.h:282
folly::Optional< KeyExchangeType > keyExchangeType() const
Definition: State.h:147
auto & writeRecordLayer()
Definition: State.h:304
folly::Optional< Random > clientRandom
Definition: State.h:51
auto & handshakeLogging()
Definition: State.h:364
std::shared_ptr< const Cert > clientCert_
Definition: State.h:397
folly::Optional< std::chrono::milliseconds > clientClockSkew() const
Definition: State.h:176
folly::Executor * executor() const
Definition: State.h:76
ReadRecordLayer * readRecordLayer() const
Definition: State.h:213
auto & clientHandshakeSecret()
Definition: State.h:352
const std::shared_ptr< const Cert > & clientCert() const
Definition: State.h:97
const WriteRecordLayer * writeRecordLayer() const
Definition: State.h:223
folly::Optional< std::string > clientSni
Definition: State.h:45
auto & serverCertCompAlgo()
Definition: State.h:319
std::shared_ptr< ServerExtensions > extensions_
Definition: State.h:416
std::ostream & operator<<(std::ostream &os, StateEnum state)
Definition: State.h:429
folly::Optional< ProtocolVersion > clientLegacyVersion
Definition: State.h:40
folly::Optional< ProtocolVersion > version_
Definition: State.h:403
std::vector< ProtocolVersion > clientSupportedVersions
Definition: State.h:41
std::vector< SignatureScheme > clientSignatureAlgorithms
Definition: State.h:49
folly::Optional< ReplayCacheResult > replayCacheResult() const
Definition: State.h:161
Definition: Actions.h:16
folly::Executor * executor_
Definition: State.h:383
folly::Optional< SignatureScheme > sigScheme() const
Definition: State.h:125
auto & group()
Definition: State.h:331
auto & keyExchangeType()
Definition: State.h:343
std::vector< uint8_t > resumptionMasterSecret_
Definition: State.h:417
auto & keyScheduler()
Definition: State.h:298
auto & clientCert()
Definition: State.h:316
folly::Optional< PskType > pskType() const
Definition: State.h:133
const std::vector< uint8_t > & resumptionMasterSecret() const
Definition: State.h:248
HandshakeLogging * handshakeLogging() const
Definition: State.h:193
const folly::Optional< std::vector< std::shared_ptr< const PeerCert > > > & unverifiedCertChain() const
Definition: State.h:258
auto & readRecordLayer()
Definition: State.h:301
folly::Optional< ReplayCacheResult > replayCacheResult_
Definition: State.h:411
auto & unverifiedCertChain()
Definition: State.h:322
std::unique_ptr< KeyScheduler > keyScheduler_
Definition: State.h:387
std::unique_ptr< AppTokenValidator > appTokenValidator_
Definition: State.h:415
auto & resumptionMasterSecret()
Definition: State.h:370
std::unique_ptr< WriteRecordLayer > writeRecordLayer_
Definition: State.h:390
const FizzServerContext * context() const
Definition: State.h:83
std::unique_ptr< HandshakeLogging > handshakeLogging_
Definition: State.h:419
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
std::vector< ExtensionType > clientExtensions
Definition: State.h:43
folly::Optional< NamedGroup > group() const
Definition: State.h:118
const Buf & clientHandshakeSecret() const
Definition: State.h:232
const AppTokenValidator * appTokenValidator() const
Definition: State.h:184
folly::Optional< Buf > clientHandshakeSecret_
Definition: State.h:412
auto & handshakeContext() const
Definition: State.h:310
const folly::Optional< std::string > & alpn() const
Definition: State.h:168
auto & exporterMasterSecret()
Definition: State.h:376
auto & clientClockSkew()
Definition: State.h:358
folly::Optional< std::chrono::milliseconds > clientClockSkew_
Definition: State.h:414
folly::Optional< EarlyDataType > earlyDataType() const
Definition: State.h:154
auto & pskType()
Definition: State.h:337
std::vector< NamedGroup > clientSupportedGroups
Definition: State.h:46
auto & appTokenValidator()
Definition: State.h:361
folly::Optional< Buf > earlyExporterMasterSecret_
Definition: State.h:421
auto & earlyDataType()
Definition: State.h:346
folly::Optional< std::vector< std::shared_ptr< const PeerCert > > > unverifiedCertChain_
Definition: State.h:401
std::shared_ptr< const Cert > serverCert() const
Definition: State.h:90
folly::Optional< KeyExchangeType > keyExchangeType_
Definition: State.h:409
folly::Optional< CipherSuite > cipher() const
Definition: State.h:111
auto & state()
Definition: State.h:289
state
Definition: http_parser.c:272
folly::Optional< CipherSuite > cipher_
Definition: State.h:404