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 
15 #include <fizz/protocol/Types.h>
17 
18 namespace fizz {
19 namespace client {
20 
21 enum class StateEnum {
29  Error,
31 };
32 
43 
52  std::shared_ptr<const Cert> serverCert;
53  std::shared_ptr<const Cert> clientCert;
56 };
57 
58 class State {
59  public:
63  StateEnum state() const {
64  return state_;
65  }
66 
70  const FizzClientContext* context() const {
71  return context_.get();
72  }
73 
77  std::shared_ptr<const Cert> serverCert() const {
78  return serverCert_;
79  }
80 
84  std::shared_ptr<const Cert> clientCert() const {
85  return clientCert_;
86  }
87 
93  return clientAuthRequested_;
94  }
95 
100  return clientAuthSigScheme_;
101  }
102 
107  return version_;
108  }
109 
114  return cipher_;
115  }
116 
121  return group_;
122  }
123 
128  return sigScheme_;
129  }
130 
136  return pskType_;
137  }
138 
143  return pskMode_;
144  }
145 
150  return keyExchangeType_;
151  }
152 
157  return earlyDataType_;
158  }
159 
164  return earlyDataParams_;
165  }
166 
171  return alpn_;
172  }
173 
178  return sni_;
179  }
180 
185  const {
186  return serverCertCompAlgo_;
187  }
188 
193  const CertificateVerifier* verifier() const {
194  return verifier_.get();
195  }
196 
200  const Random& clientRandom() const {
201  return *clientRandom_;
202  }
203 
208  const Buf& legacySessionId() const {
209  return *legacySessionId_;
210  }
211 
215  bool sentCCS() const {
216  return sentCCS_;
217  }
218 
226  return keyScheduler_.get();
227  }
228 
236  return readRecordLayer_.get();
237  }
238 
246  return writeRecordLayer_.get();
247  }
248 
255  return earlyWriteRecordLayer_.get();
256  }
257 
263  const Buf& encodedClientHello() const {
264  return *encodedClientHello_;
265  }
266 
274  const {
275  return requestedExtensions_;
276  }
277 
283  const Buf& clientHandshakeSecret() const {
284  return *clientHandshakeSecret_;
285  }
286 
292  const Buf& serverHandshakeSecret() const {
293  return *serverHandshakeSecret_;
294  }
295 
301  const Buf& resumptionSecret() const {
302  return *resumptionSecret_;
303  }
304 
310  const std::vector<std::shared_ptr<const PeerCert>>& unverifiedCertChain()
311  const {
312  return *unverifiedCertChain_;
313  }
314 
320  std::shared_ptr<const SelfCert> selectedClientCert() const {
321  return selectedClientCert_;
322  }
323 
328  return exporterMasterSecret_;
329  }
330 
337  return attemptedPsk_;
338  }
339 
340  /*
341  * Get the extensions interface to add extensions to ClientHello and check the
342  * extensions negotiated by server.
343  */
345  return extensions_.get();
346  }
347 
348  auto& state() {
349  return state_;
350  }
351 
352  auto& context() {
353  return context_;
354  }
355 
356  auto& verifier() {
357  return verifier_;
358  }
359 
360  auto& keyScheduler() {
361  return keyScheduler_;
362  }
363 
364  auto& readRecordLayer() {
365  return readRecordLayer_;
366  }
367 
369  return writeRecordLayer_;
370  }
371 
373  return earlyWriteRecordLayer_;
374  }
375 
376  auto& handshakeContext() const {
377  return handshakeContext_;
378  }
379 
380  auto& serverCert() {
381  return serverCert_;
382  }
383 
384  auto& clientCert() {
385  return clientCert_;
386  }
387 
389  return selectedClientCert_;
390  }
391 
393  return clientAuthRequested_;
394  }
395 
397  return clientAuthSigScheme_;
398  }
399 
400  auto& version() {
401  return version_;
402  }
403 
404  auto& cipher() {
405  return cipher_;
406  }
407 
408  auto& group() {
409  return group_;
410  }
411 
412  auto& sigScheme() {
413  return sigScheme_;
414  }
415 
416  auto& pskType() {
417  return pskType_;
418  }
419 
420  auto& pskMode() {
421  return pskMode_;
422  }
423 
424  auto& keyExchangeType() {
425  return keyExchangeType_;
426  }
427 
428  auto& earlyDataType() {
429  return earlyDataType_;
430  }
431 
432  auto& earlyDataParams() {
433  return earlyDataParams_;
434  }
435 
436  auto& alpn() {
437  return alpn_;
438  }
439 
440  auto& sni() {
441  return sni_;
442  }
443 
445  return serverCertCompAlgo_;
446  }
447 
448  auto& clientRandom() {
449  return clientRandom_;
450  }
451 
452  auto& legacySessionId() {
453  return legacySessionId_;
454  }
455 
456  auto& sentCCS() {
457  return sentCCS_;
458  }
459 
461  return encodedClientHello_;
462  }
463 
464  auto& keyExchangers() const {
465  return keyExchangers_;
466  }
467 
469  return requestedExtensions_;
470  }
471 
473  return clientHandshakeSecret_;
474  }
475 
477  return serverHandshakeSecret_;
478  }
479 
481  return resumptionSecret_;
482  }
483 
485  return unverifiedCertChain_;
486  }
487 
488  auto& attemptedPsk() {
489  return attemptedPsk_;
490  }
491 
493  return exporterMasterSecret_;
494  }
495 
496  auto& extensions() {
497  return extensions_;
498  }
499 
500  private:
502 
503  std::shared_ptr<const FizzClientContext> context_;
504 
505  std::shared_ptr<const CertificateVerifier> verifier_;
506 
507  std::unique_ptr<KeyScheduler> keyScheduler_;
508 
509  std::unique_ptr<ReadRecordLayer> readRecordLayer_;
510  std::unique_ptr<WriteRecordLayer> writeRecordLayer_;
511  std::unique_ptr<EncryptedWriteRecordLayer> earlyWriteRecordLayer_;
512 
513  mutable std::unique_ptr<HandshakeContext> handshakeContext_;
514 
515  std::shared_ptr<const Cert> serverCert_;
516  std::shared_ptr<const Cert> clientCert_;
517  std::shared_ptr<const SelfCert> selectedClientCert_;
518 
521 
533 
535 
538  bool sentCCS_{false};
543 
547 
552  std::shared_ptr<ClientExtensions> extensions_;
553 };
554 } // namespace client
555 
558 
559 namespace client {
560 inline std::ostream& operator<<(std::ostream& os, StateEnum state) {
561  os << toString(state);
562  return os;
563 }
564 
565 inline std::ostream& operator<<(std::ostream& os, ClientAuthType auth) {
566  os << toString(auth);
567  return os;
568 }
569 } // namespace client
570 } // namespace fizz
auto & extensions()
Definition: State.h:496
ClientAuthType
Definition: State.h:42
auto & requestedExtensions()
Definition: State.h:468
std::shared_ptr< const Cert > serverCert
Definition: State.h:52
const Buf & encodedClientHello() const
Definition: State.h:263
std::unique_ptr< HandshakeContext > handshakeContext_
Definition: State.h:513
auto & exporterMasterSecret()
Definition: State.h:492
auto & handshakeContext() const
Definition: State.h:376
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
auto & clientAuthRequested()
Definition: State.h:392
auto & pskMode()
Definition: State.h:420
auto & sigScheme()
Definition: State.h:412
folly::Optional< std::string > sni_
Definition: State.h:531
const Buf & clientHandshakeSecret() const
Definition: State.h:283
folly::Optional< std::vector< ExtensionType > > requestedExtensions_
Definition: State.h:542
std::shared_ptr< const FizzClientContext > context_
Definition: State.h:503
folly::Optional< Buf > legacySessionId_
Definition: State.h:537
folly::Optional< EarlyDataType > earlyDataType() const
Definition: State.h:156
folly::Optional< CertificateCompressionAlgorithm > serverCertCompAlgo_
Definition: State.h:532
folly::Optional< KeyExchangeType > keyExchangeType_
Definition: State.h:528
std::unique_ptr< EncryptedWriteRecordLayer > earlyWriteRecordLayer_
Definition: State.h:511
std::shared_ptr< const SelfCert > selectedClientCert() const
Definition: State.h:320
auto & sni()
Definition: State.h:440
auto & readRecordLayer()
Definition: State.h:364
folly::Optional< NamedGroup > group() const
Definition: State.h:120
folly::Optional< CipherSuite > cipher_
Definition: State.h:523
auto & resumptionSecret()
Definition: State.h:480
CipherSuite
Definition: Types.h:153
folly::Optional< EarlyDataParams > earlyDataParams_
Definition: State.h:534
std::unique_ptr< ReadRecordLayer > readRecordLayer_
Definition: State.h:509
auto & keyScheduler()
Definition: State.h:360
const Buf & legacySessionId() const
Definition: State.h:208
auto & alpn()
Definition: State.h:436
StateEnum state() const
Definition: State.h:63
ReadRecordLayer * readRecordLayer() const
Definition: State.h:235
folly::Optional< PskKeyExchangeMode > pskMode() const
Definition: State.h:142
auto & version()
Definition: State.h:400
std::shared_ptr< const CertificateVerifier > verifier_
Definition: State.h:505
std::ostream & operator<<(std::ostream &os, StateEnum state)
Definition: State.h:560
std::shared_ptr< const Cert > clientCert
Definition: State.h:53
const Buf & serverHandshakeSecret() const
Definition: State.h:292
folly::Optional< ProtocolVersion > version() const
Definition: State.h:106
folly::Optional< PskType > pskType_
Definition: State.h:526
std::shared_ptr< const SelfCert > selectedClientCert_
Definition: State.h:517
folly::Optional< PskKeyExchangeMode > pskMode_
Definition: State.h:527
auto & legacySessionId()
Definition: State.h:452
const std::vector< std::shared_ptr< const PeerCert > > & unverifiedCertChain() const
Definition: State.h:310
folly::Optional< std::vector< std::shared_ptr< const PeerCert > > > unverifiedCertChain_
Definition: State.h:549
auto & clientCert()
Definition: State.h:384
const Buf & resumptionSecret() const
Definition: State.h:301
folly::Optional< CipherSuite > cipher() const
Definition: State.h:113
auto & pskType()
Definition: State.h:416
const folly::Optional< std::string > & alpn() const
Definition: State.h:170
auto & state()
Definition: State.h:348
ProtocolVersion
Definition: Types.h:24
auto & unverifiedCertChain()
Definition: State.h:484
const Random & clientRandom() const
Definition: State.h:200
std::shared_ptr< const Cert > clientCert() const
Definition: State.h:84
auto & keyExchangers() const
Definition: State.h:464
auto & earlyWriteRecordLayer()
Definition: State.h:372
folly::Optional< SignatureScheme > sigScheme() const
Definition: State.h:127
auto & clientAuthSigScheme()
Definition: State.h:396
folly::Optional< CachedPsk > attemptedPsk_
Definition: State.h:550
auto & earlyDataParams()
Definition: State.h:432
auto & verifier()
Definition: State.h:356
auto & attemptedPsk()
Definition: State.h:488
folly::Optional< KeyExchangeType > keyExchangeType() const
Definition: State.h:149
folly::Optional< ClientAuthType > clientAuthRequested_
Definition: State.h:519
auto & serverCertCompAlgo()
Definition: State.h:444
const folly::Optional< std::string > & sni() const
Definition: State.h:177
Optional< std::string > sni_
const folly::Optional< EarlyDataParams > & earlyDataParams() const
Definition: State.h:163
ClientExtensions * extensions() const
Definition: State.h:344
folly::Optional< PskType > pskType() const
Definition: State.h:135
auto & group()
Definition: State.h:408
const WriteRecordLayer * writeRecordLayer() const
Definition: State.h:245
const folly::Optional< CertificateCompressionAlgorithm > & serverCertCompAlgo() const
Definition: State.h:184
auto & clientRandom()
Definition: State.h:448
folly::Optional< std::string > alpn_
Definition: State.h:530
std::unique_ptr< WriteRecordLayer > writeRecordLayer_
Definition: State.h:510
auto & serverHandshakeSecret()
Definition: State.h:476
Definition: Actions.h:16
KeyScheduler * keyScheduler() const
Definition: State.h:225
auto & selectedClientCert()
Definition: State.h:388
std::shared_ptr< ClientExtensions > extensions_
Definition: State.h:552
folly::Optional< Random > clientRandom_
Definition: State.h:536
std::array< uint8_t, 32 > Random
Definition: Types.h:184
auto & serverCert()
Definition: State.h:380
folly::Optional< SignatureScheme > sigScheme_
Definition: State.h:525
folly::Optional< SignatureScheme > clientAuthSigScheme_
Definition: State.h:520
auto & encodedClientHello()
Definition: State.h:460
folly::Optional< Buf > serverHandshakeSecret_
Definition: State.h:545
auto & earlyDataType()
Definition: State.h:428
folly::Optional< Buf > resumptionSecret_
Definition: State.h:546
folly::Optional< Buf > exporterMasterSecret_
Definition: State.h:551
bool sentCCS() const
Definition: State.h:215
folly::Optional< SignatureScheme > clientAuthSigScheme() const
Definition: State.h:99
std::unique_ptr< KeyScheduler > keyScheduler_
Definition: State.h:507
std::shared_ptr< const Cert > serverCert_
Definition: State.h:515
const folly::Optional< std::vector< ExtensionType > > & requestedExtensions() const
Definition: State.h:273
folly::Optional< ProtocolVersion > version_
Definition: State.h:522
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
auto & cipher()
Definition: State.h:404
std::shared_ptr< const Cert > serverCert() const
Definition: State.h:77
std::shared_ptr< const CertificateVerifier > verifier_
std::shared_ptr< const Cert > clientCert_
Definition: State.h:516
auto & writeRecordLayer()
Definition: State.h:368
const FizzClientContext * context() const
Definition: State.h:70
const CertificateVerifier * verifier() const
Definition: State.h:193
auto & sentCCS()
Definition: State.h:456
folly::Optional< std::string > alpn
Definition: State.h:54
auto & keyExchangeType()
Definition: State.h:424
auto & context()
Definition: State.h:352
folly::Optional< Buf > clientHandshakeSecret_
Definition: State.h:544
folly::Optional< Buf > encodedClientHello_
Definition: State.h:539
folly::Optional< NamedGroup > group_
Definition: State.h:524
folly::Optional< ClientAuthType > clientAuthRequested() const
Definition: State.h:92
const WriteRecordLayer * earlyWriteRecordLayer() const
Definition: State.h:254
const folly::Optional< Buf > & exporterMasterSecret() const
Definition: State.h:327
auto & clientHandshakeSecret()
Definition: State.h:472
folly::Optional< std::map< NamedGroup, std::unique_ptr< KeyExchange > > > keyExchangers_
Definition: State.h:541
ProtocolVersion version
Definition: State.h:50
state
Definition: http_parser.c:272
folly::Optional< EarlyDataType > earlyDataType_
Definition: State.h:529
const folly::Optional< CachedPsk > & attemptedPsk() const
Definition: State.h:336