proxygen
fizz::ReadRecordLayer Class Referenceabstract

#include <RecordLayer.h>

Inheritance diagram for fizz::ReadRecordLayer:
fizz::EncryptedReadRecordLayer fizz::PlaintextReadRecordLayer fizz::MockEncryptedReadRecordLayer fizz::MockPlaintextReadRecordLayer fizz::test::ConcreteReadRecordLayer testing::StrictMock< fizz::test::ConcreteReadRecordLayer > testing::StrictMock< fizz::test::ConcreteReadRecordLayer > testing::StrictMock< fizz::test::ConcreteReadRecordLayer >

Public Member Functions

virtual ~ReadRecordLayer ()=default
 
virtual folly::Optional< TLSMessageread (folly::IOBufQueue &buf)=0
 
virtual folly::Optional< ParamreadEvent (folly::IOBufQueue &socketBuf)
 
virtual bool hasUnparsedHandshakeData () const
 
virtual EncryptionLevel getEncryptionLevel () const =0
 

Static Public Member Functions

static folly::Optional< ParamdecodeHandshakeMessage (folly::IOBufQueue &buf)
 

Private Attributes

folly::IOBufQueue unparsedHandshakeData_
 

Detailed Description

Definition at line 24 of file RecordLayer.h.

Constructor & Destructor Documentation

virtual fizz::ReadRecordLayer::~ReadRecordLayer ( )
virtualdefault

Member Function Documentation

folly::Optional< Param > fizz::ReadRecordLayer::decodeHandshakeMessage ( folly::IOBufQueue buf)
static

Definition at line 93 of file RecordLayer.cpp.

References fizz::certificate, fizz::certificate_request, fizz::certificate_verify, folly::IOBufQueue::chainLength(), fizz::client_hello, fizz::compressed_certificate, fizz::encrypted_extensions, fizz::end_of_early_data, fizz::finished, folly::IOBufQueue::front(), fizz::key_update, fizz::kMaxHandshakeSize, folly::gen::move, fizz::new_session_ticket, folly::none, fizz::parse< ServerHello >(), fizz::detail::readBits24(), fizz::server_hello, and folly::IOBufQueue::split().

Referenced by fizz::ExportedAuthenticator::getAuthenticatorContext(), readEvent(), and fizz::ExportedAuthenticator::validate().

94  {
95  folly::io::Cursor cursor(buf.front());
96 
97  if (!cursor.canAdvance(kHandshakeHeaderSize)) {
98  return folly::none;
99  }
100 
101  auto handshakeType =
102  static_cast<HandshakeType>(cursor.readBE<HandshakeTypeType>());
103  auto length = detail::readBits24(cursor);
104 
105  if (length > kMaxHandshakeSize) {
106  throw std::runtime_error("handshake record too big");
107  }
108  if (buf.chainLength() < (cursor - buf.front()) + length) {
109  return folly::none;
110  }
111 
112  Buf handshakeMsg;
113  cursor.clone(handshakeMsg, length);
114  auto original = buf.split(kHandshakeHeaderSize + length);
115 
116  switch (handshakeType) {
118  return parse<ClientHello>(std::move(handshakeMsg), std::move(original));
120  return parse<ServerHello>(std::move(handshakeMsg), std::move(original));
122  return parse<EndOfEarlyData>(
123  std::move(handshakeMsg), std::move(original));
125  return parse<NewSessionTicket>(
126  std::move(handshakeMsg), std::move(original));
128  return parse<EncryptedExtensions>(
129  std::move(handshakeMsg), std::move(original));
131  return parse<CertificateMsg>(
132  std::move(handshakeMsg), std::move(original));
134  return parse<CompressedCertificate>(
135  std::move(handshakeMsg), std::move(original));
137  return parse<CertificateRequest>(
138  std::move(handshakeMsg), std::move(original));
140  return parse<CertificateVerify>(
141  std::move(handshakeMsg), std::move(original));
143  return parse<Finished>(std::move(handshakeMsg), std::move(original));
145  return parse<KeyUpdate>(std::move(handshakeMsg), std::move(original));
146  default:
147  throw std::runtime_error("unknown handshake type");
148  };
149 }
std::unique_ptr< folly::IOBuf > split(size_t n)
Definition: IOBufQueue.h:420
const folly::IOBuf * front() const
Definition: IOBufQueue.h:476
size_t chainLength() const
Definition: IOBufQueue.h:492
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Param parse< ServerHello >(Buf handshakeMsg, Buf original)
Definition: RecordLayer.cpp:75
constexpr size_t kMaxHandshakeSize
Definition: Types.h:78
typename std::underlying_type< HandshakeType >::type HandshakeTypeType
Definition: RecordLayer.cpp:13
static constexpr size_t kHandshakeHeaderSize
Definition: RecordLayer.cpp:15
uint32_t readBits24(folly::io::Cursor &cursor)
Definition: Types-inl.h:210
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
HandshakeType
Definition: Types.h:62
constexpr None none
Definition: Optional.h:87
virtual EncryptionLevel fizz::ReadRecordLayer::getEncryptionLevel ( ) const
pure virtual

Returns the current encryption level of the data that the read record layer can process.

Implemented in fizz::EncryptedReadRecordLayer, and fizz::PlaintextReadRecordLayer.

bool fizz::ReadRecordLayer::hasUnparsedHandshakeData ( ) const
virtual

Check if there is decrypted but unparsed handshake data buffered.

Definition at line 151 of file RecordLayer.cpp.

References folly::IOBufQueue::empty(), and unparsedHandshakeData_.

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

151  {
152  return !unparsedHandshakeData_.empty();
153 }
bool empty() const
Definition: IOBufQueue.h:503
folly::IOBufQueue unparsedHandshakeData_
Definition: RecordLayer.h:55
virtual folly::Optional<TLSMessage> fizz::ReadRecordLayer::read ( folly::IOBufQueue buf)
pure virtual

Reads a fragment from the record layer. Returns an empty optional if insuficient data available. Throws if data malformed. On success, advances buf the amount read.

Implemented in fizz::EncryptedReadRecordLayer, and fizz::PlaintextReadRecordLayer.

Referenced by readEvent().

folly::Optional< Param > fizz::ReadRecordLayer::readEvent ( folly::IOBufQueue socketBuf)
virtual

Get a message from the record layer. Returns none if insufficient data was available on the socket. Throws on parse error.

Definition at line 18 of file RecordLayer.cpp.

References fizz::alert, fizz::AppData, folly::IOBufQueue::append(), fizz::application_data, folly::apply_visitor(), decodeHandshakeMessage(), folly::IOBufQueue::empty(), fizz::handshake, folly::gen::move, folly::none, read(), fizz::toString(), message::type, and unparsedHandshakeData_.

Referenced by fizz::server::AeadCookieCipher< AeadType, HkdfType >::getTokenOrRetry(), fizz::client::ClientStateMachine::processSocketData(), and fizz::server::ServerStateMachine::processSocketData().

19  {
22  if (param) {
23  VLOG(8) << "Received handshake message "
24  << toString(boost::apply_visitor(EventVisitor(), *param));
25  return param;
26  }
27  }
28 
29  while (true) {
30  // Read one record. We read one record at a time since records could cause
31  // a change in the record layer.
32  auto message = read(socketBuf);
33  if (!message) {
34  return folly::none;
35  }
36 
39  throw std::runtime_error("spliced handshake data");
40  }
41 
42  switch (message->type) {
43  case ContentType::alert:
44  return Param(decode<Alert>(std::move(message->fragment)));
48  if (param) {
49  VLOG(8) << "Received handshake message "
50  << toString(boost::apply_visitor(EventVisitor(), *param));
51  return param;
52  } else {
53  // If we read handshake data but didn't have enough to get a full
54  // message we immediately try to read another record.
55  // TODO: add limits on number of records we buffer
56  continue;
57  }
58  }
60  return Param(AppData(std::move(message->fragment)));
61  default:
62  throw std::runtime_error("unknown content type");
63  }
64  }
65 }
Definition: test.c:42
folly::StringPiece toString(StateEnum state)
Definition: State.cpp:16
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
boost::variant< ClientHello, ServerHello, EndOfEarlyData, HelloRetryRequest, EncryptedExtensions, CertificateRequest, CompressedCertificate, CertificateMsg, CertificateVerify, Finished, NewSessionTicket, KeyUpdate, Alert, Accept, Connect, AppData, AppWrite, EarlyAppWrite, WriteNewSessionTicket > Param
Definition: Params.h:90
bool empty() const
Definition: IOBufQueue.h:503
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
enum http_parser_type type
Definition: test.c:45
static folly::Optional< Param > decodeHandshakeMessage(folly::IOBufQueue &buf)
Definition: RecordLayer.cpp:93
decltype(auto) apply_visitor(Visitor &&visitor, const DiscriminatedPtr< Args... > &variant)
folly::IOBufQueue unparsedHandshakeData_
Definition: RecordLayer.h:55
virtual folly::Optional< TLSMessage > read(folly::IOBufQueue &buf)=0
constexpr None none
Definition: Optional.h:87

Member Data Documentation

folly::IOBufQueue fizz::ReadRecordLayer::unparsedHandshakeData_
private
Initial value:

Definition at line 55 of file RecordLayer.h.

Referenced by hasUnparsedHandshakeData(), and readEvent().


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