proxygen
AsyncFizzServer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
12 #include <fizz/protocol/Exporter.h>
13 #include <fizz/server/FizzServer.h>
16 
17 namespace fizz {
18 namespace server {
19 
20 template <typename SM>
22  public:
24  public:
25  virtual ~HandshakeCallback() = default;
26 
27  virtual void fizzHandshakeSuccess(AsyncFizzServerT* transport) noexcept = 0;
28 
29  virtual void fizzHandshakeError(
30  AsyncFizzServerT* transport,
31  folly::exception_wrapper ex) noexcept = 0;
32 
33  virtual void fizzHandshakeAttemptFallback(
34  std::unique_ptr<folly::IOBuf> clientHello) = 0;
35  };
36 
37  using UniquePtr =
38  std::unique_ptr<AsyncFizzServerT, folly::DelayedDestruction::Destructor>;
39 
42  const std::shared_ptr<FizzServerContext>& fizzContext,
43  const std::shared_ptr<ServerExtensions>& extensions = nullptr);
44 
45  virtual void accept(HandshakeCallback* callback);
46 
47  bool good() const override;
48  bool readable() const override;
49  bool connecting() const override;
50  bool error() const override;
51  bool isDetachable() const override;
52  void attachEventBase(folly::EventBase* evb) override;
53 
54  folly::ssl::X509UniquePtr getPeerCert() const override;
55  const X509* getSelfCert() const override;
56  bool isReplaySafe() const override;
60 
61  void close() override;
62  void closeWithReset() override;
63  void closeNow() override;
64 
68  const State& getState() const {
69  return state_;
70  }
71 
72  folly::Optional<CipherSuite> getCipher() const override;
73 
74  std::vector<SignatureScheme> getSupportedSigSchemes() const override;
75 
76  Buf getEkm(
78  const Buf& hashedContext,
79  uint16_t length) const override;
80 
81  virtual Buf getEarlyEkm(
82  folly::StringPiece label,
83  const Buf& hashedContext,
84  uint16_t length) const;
85 
86  const Cert* getPeerCertificate() const override;
87  const Cert* getSelfCertificate() const override;
88 
89  protected:
90  void writeAppData(
92  std::unique_ptr<folly::IOBuf>&& buf,
94 
95  void transportError(const folly::AsyncSocketException& ex) override;
96 
97  void transportDataAvailable() override;
98 
99  private:
100  void deliverAllErrors(
101  const folly::AsyncSocketException& ex,
102  bool closeTransport = true);
104 
105  class ActionMoveVisitor : public boost::static_visitor<> {
106  public:
108  : server_(server) {}
109 
110  void operator()(DeliverAppData&);
111  void operator()(WriteToSocket&);
112  void operator()(ReportEarlyHandshakeSuccess&);
113  void operator()(ReportHandshakeSuccess&);
114  void operator()(ReportError&);
115  void operator()(WaitForData&);
116  void operator()(MutateState&);
117  void operator()(AttemptVersionFallback&);
118 
119  private:
121  };
122 
123  HandshakeCallback* handshakeCallback_{nullptr};
124 
125  std::shared_ptr<FizzServerContext> fizzContext_;
126 
127  std::shared_ptr<ServerExtensions> extensions_;
128 
130 
131  ActionMoveVisitor visitor_;
132 
134 };
135 
137 } // namespace server
138 } // namespace fizz
139 
const Cert * getPeerCertificate() const override
flags
Definition: http_parser.h:127
HandshakeCallback * handshakeCallback_
const X509 * getSelfCert() const override
std::unique_ptr< X509, X509Deleter > X509UniquePtr
FizzServer< ActionMoveVisitor, SM > fizzServer_
void deliverAllErrors(const folly::AsyncSocketException &ex, bool closeTransport=true)
void setReplaySafetyCallback(folly::AsyncTransport::ReplaySafetyCallback *callback) override
const Cert * getSelfCertificate() const override
AsyncFizzServerT(folly::AsyncTransportWrapper::UniquePtr socket, const std::shared_ptr< FizzServerContext > &fizzContext, const std::shared_ptr< ServerExtensions > &extensions=nullptr)
void writeAppData(folly::AsyncTransportWrapper::WriteCallback *callback, std::unique_ptr< folly::IOBuf > &&buf, folly::WriteFlags flags=folly::WriteFlags::NONE) override
folly::ssl::X509UniquePtr getPeerCert() const override
requires E e noexcept(noexcept(s.error(std::move(e))))
virtual Buf getEarlyEkm(folly::StringPiece label, const Buf &hashedContext, uint16_t length) const
virtual void accept(HandshakeCallback *callback)
const State & getState() const
std::vector< SignatureScheme > getSupportedSigSchemes() const override
virtual void fizzHandshakeSuccess(AsyncFizzServerT *transport) noexcept=0
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
folly::Optional< CipherSuite > getCipher() const override
Definition: Actions.h:16
bool isDetachable() const override
std::string getApplicationProtocol() const noexceptoverride
virtual void fizzHandshakeAttemptFallback(std::unique_ptr< folly::IOBuf > clientHello)=0
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
void attachEventBase(folly::EventBase *evb) override
std::shared_ptr< ServerExtensions > extensions_
ActionMoveVisitor(AsyncFizzServerT< SM > &server)
std::unique_ptr< AsyncFizzBase, folly::DelayedDestruction::Destructor > UniquePtr
Definition: AsyncFizzBase.h:30
const char * string
Definition: Conv.cpp:212
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
const
Definition: upload.py:398
bool connecting() const override
std::shared_ptr< FizzServerContext > fizzContext_
bool isReplaySafe() const override
virtual void fizzHandshakeError(AsyncFizzServerT *transport, folly::exception_wrapper ex) noexcept=0
void deliverHandshakeError(folly::exception_wrapper ex)
void transportError(const folly::AsyncSocketException &ex) override
StringPiece label
Buf getEkm(folly::StringPiece label, const Buf &hashedContext, uint16_t length) const override