proxygen
proxygen::SecondaryAuthManager Class Reference

#include <SecondaryAuthManager.h>

Inheritance diagram for proxygen::SecondaryAuthManager:
proxygen::SecondaryAuthManagerBase proxygen::MockSecondaryAuthManager

Public Member Functions

 SecondaryAuthManager (std::unique_ptr< fizz::SelfCert > cert)
 
 SecondaryAuthManager ()=default
 
 ~SecondaryAuthManager () override
 
std::pair< uint16_t, std::unique_ptr< folly::IOBuf > > createAuthRequest (std::unique_ptr< folly::IOBuf > certRequestContext, std::vector< fizz::Extension > extensions) override
 
std::pair< uint16_t, std::unique_ptr< folly::IOBuf > > getAuthenticator (const fizz::AsyncFizzBase &transport, TransportDirection dir, uint16_t requestId, std::unique_ptr< folly::IOBuf > authRequest) override
 
bool validateAuthenticator (const fizz::AsyncFizzBase &transport, TransportDirection dir, uint16_t certId, std::unique_ptr< folly::IOBuf > authenticator) override
 
folly::Optional< uint16_tgetCertId (uint16_t requestId)
 
folly::Optional< std::vector< fizz::CertificateEntry > > getPeerCert (uint16_t certId)
 
- Public Member Functions inherited from proxygen::SecondaryAuthManagerBase
virtual ~SecondaryAuthManagerBase ()=default
 

Private Member Functions

folly::Optional< std::unique_ptr< folly::IOBuf > > verifyContext (std::unique_ptr< folly::IOBuf > authenticator)
 

Private Attributes

uint16_t requestIdCounter_ {0}
 
uint16_t certIdCounter_ {0}
 
std::map< uint16_t, std::unique_ptr< folly::IOBuf > > outstandingRequests_
 
std::unique_ptr< fizz::SelfCertcert_
 
std::map< uint16_t, uint16_trequestCertMap_
 
std::map< uint16_t, std::vector< fizz::CertificateEntry > > receivedCerts_
 

Detailed Description

Definition at line 16 of file SecondaryAuthManager.h.

Constructor & Destructor Documentation

proxygen::SecondaryAuthManager::SecondaryAuthManager ( std::unique_ptr< fizz::SelfCert cert)
explicit

Definition at line 18 of file SecondaryAuthManager.cpp.

References folly::gen::move.

19  {
20  cert_ = std::move(cert);
21 }
std::unique_ptr< fizz::SelfCert > cert_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
proxygen::SecondaryAuthManager::SecondaryAuthManager ( )
default
proxygen::SecondaryAuthManager::~SecondaryAuthManager ( )
override

Definition at line 23 of file SecondaryAuthManager.cpp.

23  {
24 }

Member Function Documentation

std::pair< uint16_t, std::unique_ptr< folly::IOBuf > > proxygen::SecondaryAuthManager::createAuthRequest ( std::unique_ptr< folly::IOBuf certRequestContext,
std::vector< fizz::Extension extensions 
)
overridevirtual

Generate an authenticator request given a certificate_request_context and a set of extensions.

Returns
(request ID, encoded authenticator request)

Implements proxygen::SecondaryAuthManagerBase.

Reimplemented in proxygen::MockSecondaryAuthManager.

Definition at line 27 of file SecondaryAuthManager.cpp.

References folly::IOBufQueue::cacheChainLength(), folly::IOBuf::computeChainDataLength(), fizz::ExportedAuthenticator::getAuthenticatorRequest(), folly::gen::move, uint16_t, and folly::io::detail::Writable< Derived >::writeBE().

Referenced by TEST().

29  {
30  // The certificate_request_context has to include the two octets Request-ID.
31  uint16_t requestId = requestIdCounter_++;
33  auto contextLen =
34  sizeof(requestId) + certRequestContext->computeChainDataLength();
35  QueueAppender appender(&contextQueue, contextLen);
36  appender.writeBE<uint16_t>(requestId);
37  contextQueue.append(std::move(certRequestContext));
38  auto secureContext = contextQueue.move();
40  std::move(secureContext), std::move(extensions));
41  auto authRequestClone = authRequest->clone();
42  outstandingRequests_.insert(
43  std::make_pair(requestId, std::move(authRequest)));
44  return std::make_pair(requestId, std::move(authRequestClone));
45 }
std::map< uint16_t, std::unique_ptr< folly::IOBuf > > outstandingRequests_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static Buf getAuthenticatorRequest(Buf certificateRequestContext, std::vector< fizz::Extension > extensions)
static Options cacheChainLength()
Definition: IOBufQueue.h:83
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
std::pair< uint16_t, std::unique_ptr< folly::IOBuf > > proxygen::SecondaryAuthManager::getAuthenticator ( const fizz::AsyncFizzBase transport,
TransportDirection  dir,
uint16_t  requestId,
std::unique_ptr< folly::IOBuf authRequest 
)
overridevirtual

Generate an authenticator request given the Request-ID and authenticator request..

Returns
(cert ID, encoded authenticator)

Implements proxygen::SecondaryAuthManagerBase.

Reimplemented in proxygen::MockSecondaryAuthManager.

Definition at line 48 of file SecondaryAuthManager.cpp.

References fizz::DOWNSTREAM, fizz::ExportedAuthenticator::getAuthenticator(), folly::gen::move, uint16_t, and fizz::UPSTREAM.

Referenced by TEST().

52  {
53  uint16_t certId = certIdCounter_++;
54  std::unique_ptr<folly::IOBuf> authenticator;
55  if (dir == TransportDirection::UPSTREAM) {
57  transport, fizz::Direction::UPSTREAM, *cert_, std::move(authRequest));
58  } else {
60  transport, fizz::Direction::DOWNSTREAM, *cert_, std::move(authRequest));
61  }
62  requestCertMap_.insert(std::make_pair(requestId, certId));
63  return std::make_pair(certId, std::move(authenticator));
64 }
std::unique_ptr< fizz::SelfCert > cert_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::map< uint16_t, uint16_t > requestCertMap_
static Buf getAuthenticator(const fizz::AsyncFizzBase &transport, Direction dir, const SelfCert &cert, Buf authenticatorRequest)
folly::Optional< uint16_t > proxygen::SecondaryAuthManager::getCertId ( uint16_t  requestId)

Retrieve a Cert-ID given the corresponding Request-ID.

Definition at line 122 of file SecondaryAuthManager.cpp.

References folly::none.

Referenced by TEST().

122  {
123  if (requestCertMap_.find(requestId) == requestCertMap_.end()) {
124  return folly::none;
125  } else {
126  folly::Optional<uint16_t> certId = requestCertMap_[requestId];
127  return certId;
128  }
129 }
std::map< uint16_t, uint16_t > requestCertMap_
constexpr None none
Definition: Optional.h:87
folly::Optional< std::vector< fizz::CertificateEntry > > proxygen::SecondaryAuthManager::getPeerCert ( uint16_t  certId)

Retrieve the peer certificate chain given the corresponding Cert-ID.

Definition at line 132 of file SecondaryAuthManager.cpp.

References folly::gen::move, and folly::none.

Referenced by TEST().

132  {
134  if (receivedCerts_.find(certId) == receivedCerts_.end()) {
135  return folly::none;
136  } else {
137  certChain = std::move(receivedCerts_[certId]);
138  return certChain;
139  }
140 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::map< uint16_t, std::vector< fizz::CertificateEntry > > receivedCerts_
constexpr None none
Definition: Optional.h:87
bool proxygen::SecondaryAuthManager::validateAuthenticator ( const fizz::AsyncFizzBase transport,
TransportDirection  dir,
uint16_t  certId,
std::unique_ptr< folly::IOBuf authenticator 
)
overridevirtual

Validate an authenticator and cache the received certificate along with the Cert-ID if it is valid.

Implements proxygen::SecondaryAuthManagerBase.

Reimplemented in proxygen::MockSecondaryAuthManager.

Definition at line 66 of file SecondaryAuthManager.cpp.

References folly::IOBuf::clone(), fizz::DOWNSTREAM, folly::gen::move, fizz::UPSTREAM, and fizz::ExportedAuthenticator::validateAuthenticator().

Referenced by TEST().

70  {
71  // Verify the certificate_request_context contains the Request-ID of a
72  // previously-sent "CERTIFICATE_REQUEST".
73  auto authClone = authenticator->clone();
74  auto authRequest = verifyContext(std::move(authClone));
75  if (!authRequest) {
76  return false;
77  }
78  // Validate the authenticator with regard to the authenticator request.
80  if (dir == TransportDirection::UPSTREAM) {
82  transport,
84  std::move(*authRequest),
85  std::move(authenticator));
86  } else {
88  transport,
90  std::move(*authRequest),
91  std::move(authenticator));
92  }
93  if (!certs) {
94  return false;
95  } else if ((*certs).size() == 0) {
96  VLOG(4) << "Peer does not have appropriate certificate or does not want to "
97  "provide one, empty authenticator received";
98  } else {
99  receivedCerts_.insert(std::make_pair(certId, std::move(*certs)));
100  }
101  return true;
102 }
static folly::Optional< std::vector< CertificateEntry > > validateAuthenticator(const fizz::AsyncFizzBase &transport, Direction dir, Buf authenticatorRequest, Buf authenticator)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::Optional< std::unique_ptr< folly::IOBuf > > verifyContext(std::unique_ptr< folly::IOBuf > authenticator)
std::unique_ptr< IOBuf > clone() const
Definition: IOBuf.cpp:527
std::map< uint16_t, std::vector< fizz::CertificateEntry > > receivedCerts_
folly::Optional< std::unique_ptr< folly::IOBuf > > proxygen::SecondaryAuthManager::verifyContext ( std::unique_ptr< folly::IOBuf authenticator)
private

Verify if the certificate_request_context of the authenticator contains a Request-ID of a previous CERTIFICATE_REQUEST.

Parameters
authenticatorThe received exported authenticator.
Returns
The authenticator request if verification passes.

Definition at line 105 of file SecondaryAuthManager.cpp.

References fizz::ExportedAuthenticator::getAuthenticatorContext(), folly::gen::move, folly::none, and uint16_t.

106  {
107  auto certRequestContext =
109  std::move(authenticator));
110  folly::io::Cursor cursor(certRequestContext.get());
111  uint16_t requestId = cursor.readBE<uint16_t>();
112  if (outstandingRequests_.find(requestId) == outstandingRequests_.end()) {
113  VLOG(4) << "No previous CERTIFICATE_REQUEST matches the the CERTIFICATE "
114  "with Request-ID="
115  << requestId;
116  return folly::none;
117  }
118  auto authRequest = std::move(outstandingRequests_[requestId]);
119  return authRequest;
120 }
std::map< uint16_t, std::unique_ptr< folly::IOBuf > > outstandingRequests_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static Buf getAuthenticatorContext(Buf authenticator)
constexpr None none
Definition: Optional.h:87

Member Data Documentation

std::unique_ptr<fizz::SelfCert> proxygen::SecondaryAuthManager::cert_
private

Definition at line 69 of file SecondaryAuthManager.h.

uint16_t proxygen::SecondaryAuthManager::certIdCounter_ {0}
private

Definition at line 53 of file SecondaryAuthManager.h.

std::map<uint16_t, std::unique_ptr<folly::IOBuf> > proxygen::SecondaryAuthManager::outstandingRequests_
private

Definition at line 66 of file SecondaryAuthManager.h.

std::map<uint16_t, std::vector<fizz::CertificateEntry> > proxygen::SecondaryAuthManager::receivedCerts_
private

Definition at line 77 of file SecondaryAuthManager.h.

std::map<uint16_t, uint16_t> proxygen::SecondaryAuthManager::requestCertMap_
private

Definition at line 73 of file SecondaryAuthManager.h.

uint16_t proxygen::SecondaryAuthManager::requestIdCounter_ {0}
private

Definition at line 52 of file SecondaryAuthManager.h.


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