proxygen
fizz::Protocol Class Reference

#include <Protocol.h>

Static Public Member Functions

template<typename Type >
static void setAead (Type &recordLayer, CipherSuite cipher, folly::ByteRange secret, const Factory &factory, const KeyScheduler &scheduler)
 
static Buf getFinished (folly::ByteRange handshakeWriteSecret, HandshakeContext &handshakeContext)
 
static Buf getKeyUpdated (KeyUpdateRequest request_update)
 
static void checkAllowedExtensions (const EncryptedExtensions &ee, const std::vector< ExtensionType > &requestedExtensions)
 
static void checkAllowedExtensions (const ServerHello &shlo, const std::vector< ExtensionType > &requestedExtensions)
 
static void checkAllowedExtensions (const HelloRetryRequest &hrr)
 
static void checkDuplicateExtensions (const std::vector< Extension > &exts)
 

Detailed Description

Definition at line 17 of file Protocol.h.

Member Function Documentation

static void fizz::Protocol::checkAllowedExtensions ( const EncryptedExtensions ee,
const std::vector< ExtensionType > &  requestedExtensions 
)
inlinestatic

Definition at line 50 of file Protocol.h.

References checkDuplicateExtensions(), fizz::cookie, fizz::EncryptedExtensions::extensions, fizz::illegal_parameter, fizz::key_share, fizz::key_share_old, fizz::pre_shared_key, fizz::psk_key_exchange_modes, fizz::signature_algorithms, fizz::supported_versions, and fizz::toString().

Referenced by fizz::sm::getHrrKeyExchangers(), fizz::sm::negotiatePsk(), and fizz::sm::validateAcceptedEarly().

52  {
53  for (const auto& ext : ee.extensions) {
54  // These extensions are not allowed in EE
55  switch (ext.extension_type) {
63  throw FizzException(
64  "unexpected extension in ee: " + toString(ext.extension_type),
66  default:
67  if (std::find(
68  requestedExtensions.begin(),
69  requestedExtensions.end(),
70  ext.extension_type) == requestedExtensions.end()) {
71  throw FizzException(
72  "unexpected extension in ee: " + toString(ext.extension_type),
74  }
75  break;
76  }
77  }
78  checkDuplicateExtensions(ee.extensions);
79  }
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
static void checkDuplicateExtensions(const std::vector< Extension > &exts)
Definition: Protocol.h:117
static void fizz::Protocol::checkAllowedExtensions ( const ServerHello shlo,
const std::vector< ExtensionType > &  requestedExtensions 
)
inlinestatic

Definition at line 81 of file Protocol.h.

References checkDuplicateExtensions(), fizz::ServerHello::extensions, fizz::illegal_parameter, fizz::key_share, fizz::key_share_old, fizz::pre_shared_key, fizz::supported_versions, and fizz::toString().

83  {
84  for (const auto& ext : shlo.extensions) {
85  if (std::find(
86  requestedExtensions.begin(),
87  requestedExtensions.end(),
88  ext.extension_type) == requestedExtensions.end() ||
89  (ext.extension_type != ExtensionType::key_share &&
90  ext.extension_type != ExtensionType::key_share_old &&
91  ext.extension_type != ExtensionType::pre_shared_key &&
92  ext.extension_type != ExtensionType::supported_versions)) {
93  throw FizzException(
94  "unexpected extension in shlo: " + toString(ext.extension_type),
96  }
97  }
98  checkDuplicateExtensions(shlo.extensions);
99  }
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
static void checkDuplicateExtensions(const std::vector< Extension > &exts)
Definition: Protocol.h:117
static void fizz::Protocol::checkAllowedExtensions ( const HelloRetryRequest hrr)
inlinestatic

Definition at line 101 of file Protocol.h.

References checkDuplicateExtensions(), fizz::cookie, fizz::HelloRetryRequest::extensions, fizz::illegal_parameter, fizz::key_share, fizz::key_share_old, fizz::supported_versions, and fizz::toString().

101  {
102  // HRR is allowed to send 'cookie' unprompted. Otherwise only other allowed
103  // extensions are key_share and supported_versions, which we always send.
104  for (const auto& ext : hrr.extensions) {
105  if (ext.extension_type != ExtensionType::cookie &&
106  ext.extension_type != ExtensionType::key_share &&
107  ext.extension_type != ExtensionType::key_share_old &&
108  ext.extension_type != ExtensionType::supported_versions) {
109  throw FizzException(
110  "unexpected extension in hrr: " + toString(ext.extension_type),
112  }
113  }
114  checkDuplicateExtensions(hrr.extensions);
115  }
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
static void checkDuplicateExtensions(const std::vector< Extension > &exts)
Definition: Protocol.h:117
static void fizz::Protocol::checkDuplicateExtensions ( const std::vector< Extension > &  exts)
inlinestatic

Definition at line 117 of file Protocol.h.

References fizz::illegal_parameter.

Referenced by checkAllowedExtensions(), and fizz::sm::validateClientHello().

117  {
118  std::vector<ExtensionType> extensionList;
119  for (const auto& extension : exts) {
120  extensionList.push_back(extension.extension_type);
121  }
122  std::sort(extensionList.begin(), extensionList.end());
123  if (std::unique(extensionList.begin(), extensionList.end()) !=
124  extensionList.end()) {
125  throw FizzException(
126  "duplicate extension", AlertDescription::illegal_parameter);
127  }
128  }
static Buf fizz::Protocol::getFinished ( folly::ByteRange  handshakeWriteSecret,
HandshakeContext handshakeContext 
)
inlinestatic

Definition at line 33 of file Protocol.h.

References fizz::HandshakeContext::appendToTranscript(), fizz::encodeHandshake(), fizz::finished, fizz::HandshakeContext::getFinishedData(), folly::gen::move, and fizz::Finished::verify_data.

Referenced by fizz::sm::getCertificateRequest(), and fizz::sm::handleCertMsg().

35  {
37  finished.verify_data =
38  handshakeContext.getFinishedData(handshakeWriteSecret);
39  auto encodedFinished = encodeHandshake(std::move(finished));
40  handshakeContext.appendToTranscript(encodedFinished);
41  return encodedFinished;
42  }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static Buf fizz::Protocol::getKeyUpdated ( KeyUpdateRequest  request_update)
inlinestatic

Definition at line 44 of file Protocol.h.

References fizz::encodeHandshake(), folly::gen::move, and fizz::KeyUpdate::request_update.

Referenced by fizz::sm::generateTicket(), and fizz::sm::getMaxEarlyDataSize().

44  {
45  KeyUpdate keyUpdated;
46  keyUpdated.request_update = request_update;
47  return encodeHandshake(std::move(keyUpdated));
48  }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<typename Type >
static void fizz::Protocol::setAead ( Type &  recordLayer,
CipherSuite  cipher,
folly::ByteRange  secret,
const Factory factory,
const KeyScheduler scheduler 
)
inlinestatic

Definition at line 20 of file Protocol.h.

References fizz::KeyScheduler::getTrafficKey(), fizz::Factory::makeAead(), and folly::gen::move.

Referenced by fizz::sm::generateTicket(), fizz::sm::getCertificateRequest(), fizz::sm::getEarlyDataParams(), fizz::sm::getMaxEarlyDataSize(), fizz::sm::handleCertMsg(), and fizz::sm::negotiatePsk().

25  {
26  auto aead = factory.makeAead(cipher);
27  auto trafficKey =
28  scheduler.getTrafficKey(secret, aead->keyLength(), aead->ivLength());
29  aead->setKey(std::move(trafficKey));
30  recordLayer.setAead(secret, std::move(aead));
31  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< folly::FunctionScheduler > scheduler
Definition: FilePoller.cpp:50
CipherSuite cipher

The documentation for this class was generated from the following file: