proxygen
fizz::PlaintextWriteRecordLayer Class Reference

#include <PlaintextRecordLayer.h>

Inheritance diagram for fizz::PlaintextWriteRecordLayer:
fizz::WriteRecordLayer fizz::MockPlaintextWriteRecordLayer fizz::test::ConcreteWriteRecordLayer testing::StrictMock< fizz::test::ConcreteWriteRecordLayer > testing::StrictMock< fizz::test::ConcreteWriteRecordLayer > testing::StrictMock< fizz::test::ConcreteWriteRecordLayer >

Public Member Functions

 ~PlaintextWriteRecordLayer () override=default
 
TLSContent write (TLSMessage &&msg) const override
 
virtual TLSContent writeInitialClientHello (Buf encodedClientHello) const
 
EncryptionLevel getEncryptionLevel () const override
 
- Public Member Functions inherited from fizz::WriteRecordLayer
virtual ~WriteRecordLayer ()=default
 
TLSContent writeAlert (Alert &&alert) const
 
TLSContent writeAppData (std::unique_ptr< folly::IOBuf > &&appData) const
 
template<typename... Args>
TLSContent writeHandshake (Buf &&encodedHandshakeMsg, Args &&...args) const
 
void setProtocolVersion (ProtocolVersion version) const
 

Private Member Functions

TLSContent write (TLSMessage msg, ProtocolVersion recordVersion) const
 

Additional Inherited Members

- Protected Attributes inherited from fizz::WriteRecordLayer
ProtocolVersion recordVersion_ {ProtocolVersion::tls_1_2}
 
bool useAdditionalData_ {true}
 

Detailed Description

Definition at line 44 of file PlaintextRecordLayer.h.

Constructor & Destructor Documentation

fizz::PlaintextWriteRecordLayer::~PlaintextWriteRecordLayer ( )
overridedefault

Member Function Documentation

EncryptionLevel fizz::PlaintextWriteRecordLayer::getEncryptionLevel ( ) const
overridevirtual

Returns the current encryption level of the data that the write record layer writes at.

Implements fizz::WriteRecordLayer.

Definition at line 146 of file PlaintextRecordLayer.cpp.

References fizz::Plaintext.

TLSContent fizz::PlaintextWriteRecordLayer::write ( TLSMessage &&  msg) const
overridevirtual

Implements fizz::WriteRecordLayer.

Reimplemented in fizz::MockPlaintextWriteRecordLayer, and fizz::test::ConcreteWriteRecordLayer.

Definition at line 101 of file PlaintextRecordLayer.cpp.

References folly::gen::move, and fizz::detail::write().

101  {
102  return write(std::move(msg), recordVersion_);
103 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
ProtocolVersion recordVersion_
Definition: RecordLayer.h:106
TLSContent write(TLSMessage &&msg) const override
TLSContent fizz::PlaintextWriteRecordLayer::write ( TLSMessage  msg,
ProtocolVersion  recordVersion 
) const
private

Definition at line 112 of file PlaintextRecordLayer.cpp.

References fizz::application_data, fizz::TLSContent::contentType, folly::IOBuf::create(), fizz::TLSContent::data, data, fizz::TLSContent::encryptionLevel, fizz::TLSMessage::fragment, fizz::kPlaintextHeaderSize, folly::gen::move, fizz::Plaintext, fizz::TLSMessage::type, uint16_t, and folly::io::detail::Writable< Derived >::writeBE().

114  {
115  if (msg.type == ContentType::application_data) {
116  throw std::runtime_error("refusing to send plaintext application data");
117  }
118 
119  auto fragment = std::move(msg.fragment);
120  folly::io::Cursor cursor(fragment.get());
121  std::unique_ptr<folly::IOBuf> data;
122  while (!cursor.isAtEnd()) {
123  Buf thisFragment;
124  auto len = cursor.cloneAtMost(thisFragment, kMaxPlaintextRecordSize);
125 
127  folly::io::Appender appender(header.get(), kPlaintextHeaderSize);
128  appender.writeBE(static_cast<ContentTypeType>(msg.type));
129  appender.writeBE(static_cast<ProtocolVersionType>(recordVersion));
130  appender.writeBE<uint16_t>(len);
131 
132  if (!data) {
133  data = std::move(header);
134  } else {
135  data->prependChain(std::move(header));
136  }
137  data->prependChain(std::move(thisFragment));
138  }
139  TLSContent content;
140  content.data = std::move(data);
141  content.contentType = msg.type;
142  content.encryptionLevel = EncryptionLevel::Plaintext;
143  return content;
144 }
static std::unique_ptr< IOBuf > create(std::size_t capacity)
Definition: IOBuf.cpp:229
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr uint16_t kMaxPlaintextRecordSize
static constexpr size_t kPlaintextHeaderSize
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
static constexpr uint64_t data[1]
Definition: Fingerprint.cpp:43
void writeBE(T value)
Definition: Cursor.h:744
TLSContent fizz::PlaintextWriteRecordLayer::writeInitialClientHello ( Buf  encodedClientHello) const
virtual

Write the initial ClientHello handshake message. This is a separate method as the record encoding can be slightly different since the version has not been negotiated yet.

Reimplemented in fizz::MockPlaintextWriteRecordLayer.

Definition at line 105 of file PlaintextRecordLayer.cpp.

References fizz::handshake, folly::gen::move, fizz::tls_1_0, and fizz::detail::write().

Referenced by fizz::sm::getCertificateRequest(), and fizz::server::test::AeadCookieCipherTest::getClientHello().

106  {
107  return write(
108  TLSMessage{ContentType::handshake, std::move(encodedClientHello)},
110 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TLSContent write(TLSMessage &&msg) const override

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