proxygen
fizz::server::TicketCodec< Storage > Struct Template Reference

#include <TicketCodec.h>

Static Public Member Functions

static Buf encode (ResumptionState state)
 
static ResumptionState decode (Buf encoded, const FizzServerContext *context)
 

Static Public Attributes

static constexpr folly::StringPiece Label {"Fizz Ticket Codec v2"}
 

Detailed Description

template<CertificateStorage Storage>
struct fizz::server::TicketCodec< Storage >

Definition at line 36 of file TicketCodec.h.

Member Function Documentation

template<CertificateStorage Storage>
ResumptionState fizz::server::TicketCodec< Storage >::decode ( Buf  encoded,
const FizzServerContext context 
)
static

Definition at line 47 of file TicketCodec-inl.h.

References fizz::server::FizzServerContext::getCert(), fizz::detail::read(), fizz::server::readClientCertificate(), and uint64_t.

49  {
50  folly::io::Cursor cursor(encoded.get());
51 
52  ResumptionState resState;
53  fizz::detail::read(resState.version, cursor);
54  fizz::detail::read(resState.cipher, cursor);
55  fizz::detail::readBuf<uint16_t>(resState.resumptionSecret, cursor);
56  Buf selfIdentity;
57  fizz::detail::readBuf<uint16_t>(selfIdentity, cursor);
58 
59  resState.clientCert = readClientCertificate(cursor);
60 
61  fizz::detail::read(resState.ticketAgeAdd, cursor);
62  uint64_t seconds;
63  fizz::detail::read(seconds, cursor);
64  Buf alpnBuf;
65  fizz::detail::readBuf<uint8_t>(alpnBuf, cursor);
66  if (!alpnBuf->empty()) {
67  resState.alpn = alpnBuf->moveToFbString().toStdString();
68  }
69 
70  resState.ticketIssueTime = std::chrono::time_point<std::chrono::system_clock>(
71  std::chrono::seconds(seconds));
72  if (context) {
73  resState.serverCert =
74  context->getCert(selfIdentity->moveToFbString().toStdString());
75  }
76  if (cursor.isAtEnd()) {
77  return resState;
78  }
79  fizz::detail::readBuf<uint16_t>(resState.appToken, cursor);
80 
81  return resState;
82 }
context
Definition: CMakeCache.txt:563
std::shared_ptr< const Cert > readClientCertificate(folly::io::Cursor &cursor)
Definition: TicketCodec.cpp:47
size_t read(T &out, folly::io::Cursor &cursor)
Definition: Types-inl.h:258
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
template<CertificateStorage Storage>
Buf fizz::server::TicketCodec< Storage >::encode ( ResumptionState  state)
static

Definition at line 16 of file TicketCodec-inl.h.

References fizz::server::ResumptionState::alpn, fizz::server::appendClientCertificate(), fizz::server::ResumptionState::appToken, fizz::server::ResumptionState::cipher, fizz::server::ResumptionState::clientCert, folly::IOBuf::copyBuffer(), count, folly::IOBuf::create(), fizz::server::ResumptionState::resumptionSecret, fizz::server::ResumptionState::serverCert, fizz::server::ResumptionState::ticketAgeAdd, fizz::server::ResumptionState::ticketIssueTime, uint64_t, fizz::server::ResumptionState::version, and fizz::detail::write().

16  {
17  Buf selfIdentity = folly::IOBuf::create(0);
18  if (resState.serverCert) {
19  selfIdentity = folly::IOBuf::copyBuffer(resState.serverCert->getIdentity());
20  }
21 
22  uint64_t ticketIssueTime = std::chrono::duration_cast<std::chrono::seconds>(
23  resState.ticketIssueTime.time_since_epoch())
24  .count();
25 
26  auto buf = folly::IOBuf::create(60);
27  folly::io::Appender appender(buf.get(), 60);
28 
29  fizz::detail::write(resState.version, appender);
30  fizz::detail::write(resState.cipher, appender);
31  fizz::detail::writeBuf<uint16_t>(resState.resumptionSecret, appender);
32  fizz::detail::writeBuf<uint16_t>(selfIdentity, appender);
33  appendClientCertificate(Storage, resState.clientCert, appender);
34  fizz::detail::write(resState.ticketAgeAdd, appender);
35  fizz::detail::write(ticketIssueTime, appender);
36  if (resState.alpn) {
37  auto alpnBuf = folly::IOBuf::copyBuffer(*resState.alpn);
38  fizz::detail::writeBuf<uint8_t>(alpnBuf, appender);
39  } else {
40  fizz::detail::writeBuf<uint8_t>(nullptr, appender);
41  }
42  fizz::detail::writeBuf<uint16_t>(resState.appToken, appender);
43  return buf;
44 }
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
int * count
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
void appendClientCertificate(CertificateStorage storage, const std::shared_ptr< const Cert > &cert, folly::io::Appender &appender)
Definition: TicketCodec.cpp:26
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

Member Data Documentation

template<CertificateStorage Storage>
constexpr folly::StringPiece fizz::server::TicketCodec< Storage >::Label {"Fizz Ticket Codec v2"}
static

This label can be used to derive the encryption key and should be changed whenever the encoding changes so previous tickets are invalidated.

Definition at line 41 of file TicketCodec.h.


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