proxygen
fizz::server Namespace Reference

Namespaces

 detail
 
 test
 

Classes

class  AeadCookieCipher
 
class  AeadTicketCipher
 
class  AeadTokenCipher
 
class  AllowAllReplayReplayCache
 
struct  AppToken
 
class  AppTokenValidator
 
class  AsyncFizzServerT
 
struct  AttemptVersionFallback
 
class  CertManager
 
struct  ClockSkewTolerance
 
class  CookieCipher
 
struct  CookieState
 
class  DualTicketCipher
 
class  FizzServer
 
class  FizzServerContext
 
struct  HandshakeLogging
 
class  ReplayCache
 
struct  ReportEarlyHandshakeSuccess
 
struct  ReportHandshakeSuccess
 
struct  ResumptionState
 
class  ServerStateMachine
 
struct  ServerTypes
 
class  SlidingBloomReplayCache
 
class  State
 
struct  StatelessHelloRetryRequest
 
class  TicketCipher
 
struct  TicketCodec
 

Typedefs

using MutateState = folly::Function< void(State &)>
 
using Action = boost::variant< DeliverAppData, WriteToSocket, ReportHandshakeSuccess, ReportEarlyHandshakeSuccess, ReportError, MutateState, WaitForData, AttemptVersionFallback >
 
using Actions = folly::small_vector< Action, 4 >
 
using AsyncActions = boost::variant< Actions, folly::Future< Actions >>
 
using AsyncFizzServer = AsyncFizzServerT< ServerStateMachine >
 
using AES128CookieCipher = AeadCookieCipher< OpenSSLEVPCipher< AESGCM128 >, HkdfImpl< Sha256 >>
 
using AES128TicketCipher = AeadTicketCipher< OpenSSLEVPCipher< AESGCM128 >, TicketCodec< CertificateStorage::X509 >, HkdfImpl< Sha256 >>
 
using AES128TicketIdentityOnlyCipher = AeadTicketCipher< OpenSSLEVPCipher< AESGCM128 >, TicketCodec< CertificateStorage::IdentityOnly >, HkdfImpl< Sha256 >>
 

Enumerations

enum  ClientAuthMode { ClientAuthMode::None, ClientAuthMode::Optional, ClientAuthMode::Required }
 
enum  ReplayCacheResult { NotChecked, NotReplay, MaybeReplay, DefinitelyReplay }
 
enum  StateEnum {
  StateEnum::Uninitialized, StateEnum::ExpectingClientHello, StateEnum::ExpectingCertificate, StateEnum::ExpectingCertificateVerify,
  StateEnum::AcceptingEarlyData, StateEnum::ExpectingFinished, StateEnum::AcceptingData, StateEnum::Closed,
  StateEnum::Error, StateEnum::NUM_STATES
}
 
enum  CertificateStorage : uint8_t { CertificateStorage::None = 0, CertificateStorage::X509 = 1, CertificateStorage::IdentityOnly = 2 }
 

Functions

static std::string getKeyFromIdent (const std::string &ident)
 
Buf getStatelessHelloRetryRequest (ProtocolVersion version, CipherSuite cipher, folly::Optional< NamedGroup > group, Buf cookie)
 
static folly::Optional< NamedGroupgetHrrGroup (const std::vector< NamedGroup > &supportedGroups, const ClientHello &chlo)
 
CookieState getCookieState (const Factory &factory, const std::vector< ProtocolVersion > &supportedVersions, const std::vector< std::vector< CipherSuite >> &supportedCiphers, const std::vector< NamedGroup > &supportedGroups, const ClientHello &chlo, Buf appToken)
 
bool looksLikeV2ClientHello (const folly::IOBufQueue &queue)
 
template<typename T >
folly::Optional< Tnegotiate (const std::vector< std::vector< T >> &serverPref, const std::vector< T > &clientPref)
 
template<typename T >
folly::Optional< Tnegotiate (const std::vector< T > &serverPref, const std::vector< T > &clientPref)
 
std::ostream & operator<< (std::ostream &os, StateEnum state)
 
void appendClientCertificate (CertificateStorage storage, const std::shared_ptr< const Cert > &cert, folly::io::Appender &appender)
 
std::shared_ptr< const CertreadClientCertificate (folly::io::Cursor &cursor)
 

Variables

static const int kBitsPerByte = 0x8
 
static const unsigned int kBucketCount = 12
 
static const unsigned int kHashCount = 4
 

Typedef Documentation

Definition at line 51 of file Actions.h.

using fizz::server::AsyncActions = typedef boost::variant<Actions, folly::Future<Actions>>

Definition at line 52 of file Actions.h.

A lambda that should be invoked on State so that modification can be applied.

Definition at line 24 of file Actions.h.

Enumeration Type Documentation

Enumerator
None 
X509 
IdentityOnly 

Definition at line 17 of file TicketCodec.h.

Different modes of operation for client authentication. The names are self- explanatory.

Enumerator
None 
Optional 
Required 

Definition at line 43 of file FizzServerContext.h.

Enumerator
NotChecked 
NotReplay 
MaybeReplay 
DefinitelyReplay 

Definition at line 17 of file ReplayCache.h.

Function Documentation

void fizz::server::appendClientCertificate ( CertificateStorage  storage,
const std::shared_ptr< const Cert > &  cert,
folly::io::Appender appender 
)

Definition at line 26 of file TicketCodec.cpp.

References folly::IOBuf::copyBuffer(), folly::IOBuf::create(), folly::ssl::OpenSSLCertUtils::derEncode(), IdentityOnly, None, fizz::detail::write(), and X509.

Referenced by fizz::server::TicketCodec< Storage >::encode().

29  {
30  Buf clientCertBuf = folly::IOBuf::create(0);
31  CertificateStorage selectedStorage;
32  if (!cert || storage == CertificateStorage::None) {
33  selectedStorage = CertificateStorage::None;
34  } else if (storage == CertificateStorage::X509 && cert->getX509()) {
35  selectedStorage = CertificateStorage::X509;
36  clientCertBuf = folly::ssl::OpenSSLCertUtils::derEncode(*cert->getX509());
37  } else {
38  selectedStorage = CertificateStorage::IdentityOnly;
39  clientCertBuf = folly::IOBuf::copyBuffer(cert->getIdentity());
40  }
41  fizz::detail::write(selectedStorage, appender);
42  if (selectedStorage != CertificateStorage::None) {
43  fizz::detail::writeBuf<uint16_t>(clientCertBuf, appender);
44  }
45 }
void write(const T &in, folly::io::Appender &appender)
Definition: Types-inl.h:112
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
static std::unique_ptr< IOBuf > derEncode(X509 &)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
CookieState fizz::server::getCookieState ( const Factory factory,
const std::vector< ProtocolVersion > &  supportedVersions,
const std::vector< std::vector< CipherSuite >> &  supportedCiphers,
const std::vector< NamedGroup > &  supportedGroups,
const ClientHello chlo,
Buf  appToken 
)

Negotiate and compute the CookieState to use in response to a ClientHello. This must match the logic inside of the server state machine.

Definition at line 79 of file CookieCipher.cpp.

References fizz::server::CookieState::appToken, fizz::server::CookieState::chloHash, fizz::server::CookieState::cipher, cipher, fizz::ClientHello::cipher_suites, fizz::ClientHello::extensions, getHrrGroup(), fizz::server::CookieState::group, group, fizz::Factory::makeHandshakeContext(), folly::gen::move, negotiate(), fizz::HandshakeStruct< e, t >::originalEncoding, fizz::server::CookieState::version, and version.

Referenced by fizz::sm::getCertificateRequest(), fizz::server::AeadCookieCipher< AeadType, HkdfType >::getStatelessResponse(), and fizz::server::test::TEST_F().

85  {
86  auto clientVersions = getExtension<SupportedVersions>(chlo.extensions);
87  if (!clientVersions) {
88  throw std::runtime_error("no supported versions");
89  }
90  auto version = negotiate(supportedVersions, clientVersions->versions);
91  if (!version) {
92  throw std::runtime_error("version mismatch");
93  }
94 
95  auto cipher = negotiate(supportedCiphers, chlo.cipher_suites);
96  if (!cipher) {
97  throw std::runtime_error("cipher mismatch");
98  }
99 
100  auto group = getHrrGroup(supportedGroups, chlo);
101 
102  CookieState state;
103  state.version = *version;
104  state.cipher = *cipher;
105  state.group = group;
106  state.appToken = std::move(appToken);
107 
108  auto handshakeContext = factory.makeHandshakeContext(*cipher);
109  handshakeContext->appendToTranscript(*chlo.originalEncoding);
110  state.chloHash = handshakeContext->getHandshakeContext();
111 
112  return state;
113 }
static const std::string chlo
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
static folly::Optional< NamedGroup > getHrrGroup(const std::vector< NamedGroup > &supportedGroups, const ClientHello &chlo)
CipherSuite cipher
ProtocolVersion version
Optional< NamedGroup > group
state
Definition: http_parser.c:272
static folly::Optional<NamedGroup> fizz::server::getHrrGroup ( const std::vector< NamedGroup > &  supportedGroups,
const ClientHello chlo 
)
static

Definition at line 47 of file CookieCipher.cpp.

References fizz::ClientHello::extensions, negotiate(), folly::none, and folly::pushmi::operators::share.

Referenced by getCookieState().

49  {
50  auto groupsExt = getExtension<SupportedGroups>(chlo.extensions);
51  if (!groupsExt) {
52  return folly::none;
53  }
54 
55  // Group is negotiated solely based on supported groups, without considering
56  // which shares were sent.
57  auto negotiatedGroup =
58  negotiate(supportedGroups, groupsExt->named_group_list);
59  if (!negotiatedGroup) {
60  // We will deal with any supported group mismatch at the full handshake.
61  return folly::none;
62  }
63 
64  auto clientShares = getExtension<ClientKeyShare>(chlo.extensions);
65  if (!clientShares) {
66  throw std::runtime_error("supported_groups without key_share");
67  }
68 
69  for (const auto& share : clientShares->client_shares) {
70  if (share.group == *negotiatedGroup) {
71  // We already have the right key share.
72  return folly::none;
73  }
74  }
75 
76  return negotiatedGroup;
77 }
static const std::string chlo
PUSHMI_INLINE_VAR constexpr detail::share_fn< TN... > share
Definition: share.h:53
folly::Optional< T > negotiate(const std::vector< std::vector< T >> &serverPref, const std::vector< T > &clientPref)
Definition: Negotiator.h:22
constexpr None none
Definition: Optional.h:87
static std::string fizz::server::getKeyFromIdent ( const std::string ident)
static

Definition at line 93 of file CertManager.cpp.

References string, and folly::toLowerAscii().

Referenced by fizz::server::CertManager::addCert(), and fizz::server::CertManager::addCertIdentity().

93  {
94  if (ident.empty()) {
95  throw std::runtime_error("empty identity");
96  }
97 
98  std::string key;
99  if (ident.front() == '*') {
100  key = std::string(ident, 1);
101  } else {
102  key = ident;
103  }
104  toLowerAscii(key);
105 
106  return key;
107 }
void toLowerAscii(char *str, size_t length)
Definition: String.cpp:601
const char * string
Definition: Conv.cpp:212
Buf fizz::server::getStatelessHelloRetryRequest ( ProtocolVersion  version,
CipherSuite  cipher,
folly::Optional< NamedGroup group,
Buf  cookie 
)

Build a stateless HelloRetryRequest. This is deterministic and will be used to reconstruct the handshake transcript when receiving the second ClientHello.

Definition at line 18 of file CookieCipher.cpp.

References cipher, fizz::HelloRetryRequest::cipher_suite, fizz::Cookie::cookie, folly::IOBuf::create(), fizz::encodeExtension(), fizz::encodeHandshake(), fizz::HelloRetryRequest::extensions, group, fizz::HelloRetryRequest::legacy_session_id_echo, fizz::HelloRetryRequest::legacy_version, folly::gen::move, fizz::HelloRetryRequestKeyShare::selected_group, fizz::ServerSupportedVersions::selected_version, fizz::tls_1_2, and version.

Referenced by fizz::server::AeadCookieCipher< AeadType, HkdfType >::getStatelessResponse(), fizz::sm::setupSchedulerAndContext(), and fizz::server::test::TEST().

22  {
23  Buf encodedHelloRetryRequest;
24 
26  hrr.legacy_version = ProtocolVersion::tls_1_2;
27  hrr.legacy_session_id_echo = folly::IOBuf::create(0);
28  hrr.cipher_suite = cipher;
29 
30  ServerSupportedVersions versionExt;
31  versionExt.selected_version = version;
32  hrr.extensions.push_back(encodeExtension(std::move(versionExt)));
33 
34  if (group) {
35  HelloRetryRequestKeyShare keyShare;
36  keyShare.selected_group = *group;
37  hrr.extensions.push_back(encodeExtension(std::move(keyShare)));
38  }
39 
40  Cookie cookieExt;
41  cookieExt.cookie = std::move(cookie);
42  hrr.extensions.push_back(encodeExtension(std::move(cookieExt)));
43 
44  return encodeHandshake(std::move(hrr));
45 }
Buf encodeHandshake(T &&handshakeMsg)
Definition: Types-inl.h:515
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
StringPiece cookie
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CipherSuite cipher
ProtocolVersion version
Optional< NamedGroup > group
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
Extension encodeExtension(const TokenBindingParameters &params)
Definition: Types.cpp:113
bool fizz::server::looksLikeV2ClientHello ( const folly::IOBufQueue queue)

Definition at line 14 of file FizzServer.cpp.

References folly::IOBufQueue::empty(), folly::IOBufQueue::front(), and uint8_t.

Referenced by fizz::server::FizzServer< ActionMoveVisitor, SM >::newTransportData().

14  {
15  if (queue.empty()) {
16  return false;
17  }
18  folly::io::Cursor cursor(queue.front());
19  if (!cursor.canAdvance(3)) {
20  return false;
21  }
22  uint8_t byte1 = cursor.read<uint8_t>();
23  cursor.skip(1);
24  uint8_t byte3 = cursor.read<uint8_t>();
25  if (byte1 & 0x80 && byte3 == 0x01) {
26  return true;
27  }
28  return false;
29 }
const folly::IOBuf * front() const
Definition: IOBufQueue.h:476
bool empty() const
Definition: IOBufQueue.h:503
template<typename T >
folly::Optional<T> fizz::server::negotiate ( const std::vector< std::vector< T >> &  serverPref,
const std::vector< T > &  clientPref 
)

Negotiate a parameter given a list of server preference tiers and a list of client preferences. Within a server preference tier the client preference will be respected.

Definition at line 22 of file Negotiator.h.

References folly::none.

Referenced by fizz::sm::getCertificate(), getCookieState(), fizz::extensions::TokenBindingServerExtension::getExtensions(), getHrrGroup(), fizz::sm::getResumptionState(), fizz::server::FizzServerContext::negotiateAlpn(), fizz::sm::negotiateCipher(), fizz::sm::negotiateGroup(), fizz::sm::negotiateVersion(), and fizz::server::test::TEST().

24  {
25  for (const auto& prefTier : serverPref) {
26  if (prefTier.size() == 1) {
27  if (std::find(clientPref.begin(), clientPref.end(), prefTier.front()) !=
28  clientPref.end()) {
29  return prefTier.front();
30  }
31  } else {
32  for (const auto& pref : clientPref) {
33  if (std::find(prefTier.begin(), prefTier.end(), pref) !=
34  prefTier.end()) {
35  return pref;
36  }
37  }
38  }
39  }
40  return folly::none;
41 }
constexpr None none
Definition: Optional.h:87
template<typename T >
folly::Optional<T> fizz::server::negotiate ( const std::vector< T > &  serverPref,
const std::vector< T > &  clientPref 
)

Negotatiate a parameter given the server's preference. Client preference is ignored.

Definition at line 48 of file Negotiator.h.

References folly::none.

50  {
51  for (const auto& pref : serverPref) {
52  if (std::find(clientPref.begin(), clientPref.end(), pref) !=
53  clientPref.end()) {
54  return pref;
55  }
56  }
57  return folly::none;
58 }
constexpr None none
Definition: Optional.h:87
std::ostream& fizz::server::operator<< ( std::ostream &  os,
StateEnum  state 
)
inline

Definition at line 429 of file State.h.

References fizz::toString().

429  {
430  os << toString(state);
431  return os;
432 }
folly::StringPiece toString(server::StateEnum state)
state
Definition: http_parser.c:272
std::shared_ptr< const Cert > fizz::server::readClientCertificate ( folly::io::Cursor cursor)

Definition at line 47 of file TicketCodec.cpp.

References IdentityOnly, fizz::CertUtils::makePeerCert(), folly::gen::move, None, fizz::detail::read(), and X509.

Referenced by fizz::server::TicketCodec< Storage >::decode().

47  {
48  CertificateStorage storage;
49  fizz::detail::read(storage, cursor);
50  switch (storage) {
51  case CertificateStorage::None:
52  return nullptr;
53  case CertificateStorage::X509: {
54  Buf clientCertBuf;
55  fizz::detail::readBuf<uint16_t>(clientCertBuf, cursor);
56  return CertUtils::makePeerCert(std::move(clientCertBuf));
57  }
58  case CertificateStorage::IdentityOnly: {
59  Buf ident;
60  fizz::detail::readBuf<uint16_t>(ident, cursor);
61  return std::make_shared<const IdentityCert>(
62  ident->moveToFbString().toStdString());
63  }
64  }
65 
66  return nullptr;
67 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22

Variable Documentation

const int fizz::server::kBitsPerByte = 0x8
static

Definition at line 29 of file SlidingBloomReplayCache.cpp.

const unsigned int fizz::server::kBucketCount = 12
static
const unsigned int fizz::server::kHashCount = 4
static