proxygen
fizz::SelfCertImpl< T > Class Template Reference

#include <Certificate.h>

Inheritance diagram for fizz::SelfCertImpl< T >:
fizz::SelfCert folly::AsyncTransportCertificate

Public Member Functions

 SelfCertImpl (folly::ssl::EvpPkeyUniquePtr pkey, std::vector< folly::ssl::X509UniquePtr > certs, const std::vector< std::shared_ptr< fizz::CertificateCompressor >> &compressors={})
 
 ~SelfCertImpl () override=default
 
std::string getIdentity () const override
 
std::vector< std::stringgetAltIdentities () const override
 
std::vector< SignatureSchemegetSigSchemes () const override
 
CertificateMsg getCertMessage (Buf certificateRequestContext=nullptr) const override
 
CompressedCertificate getCompressedCert (CertificateCompressionAlgorithm algo) const override
 
Buf sign (SignatureScheme scheme, CertificateVerifyContext context, folly::ByteRange toBeSigned) const override
 
folly::ssl::X509UniquePtr getX509 () const override
 
template<>
Buf sign (SignatureScheme scheme, CertificateVerifyContext context, folly::ByteRange toBeSigned) const
 
template<>
Buf sign (SignatureScheme scheme, CertificateVerifyContext context, folly::ByteRange toBeSigned) const
 
template<>
Buf sign (SignatureScheme scheme, CertificateVerifyContext context, folly::ByteRange toBeSigned) const
 
template<>
Buf sign (SignatureScheme scheme, CertificateVerifyContext context, folly::ByteRange toBeSigned) const
 
- Public Member Functions inherited from fizz::SelfCert
virtual ~SelfCert ()=default
 
- Public Member Functions inherited from folly::AsyncTransportCertificate
virtual ~AsyncTransportCertificate ()=default
 

Private Attributes

OpenSSLSignature< Tsignature_
 
std::vector< folly::ssl::X509UniquePtrcerts_
 
std::map< CertificateCompressionAlgorithm, CompressedCertificatecompressedCerts_
 

Detailed Description

template<KeyType T>
class fizz::SelfCertImpl< T >

Definition at line 135 of file Certificate.h.

Constructor & Destructor Documentation

template<KeyType T>
fizz::SelfCertImpl< T >::SelfCertImpl ( folly::ssl::EvpPkeyUniquePtr  pkey,
std::vector< folly::ssl::X509UniquePtr certs,
const std::vector< std::shared_ptr< fizz::CertificateCompressor >> &  compressors = {} 
)

Private key is the private key associated with the leaf cert. certs is a list of certs in the chain with the leaf first.

Definition at line 37 of file Certificate-inl.h.

References folly::gen::move.

41  {
42  if (certs.size() == 0) {
43  throw std::runtime_error("Must supply at least 1 cert");
44  }
45  if (X509_check_private_key(certs[0].get(), pkey.get()) != 1) {
46  throw std::runtime_error("Cert does not match private key");
47  }
48  // TODO: more strict validation of chaining requirements.
49  signature_.setKey(std::move(pkey));
50  certs_ = std::move(certs);
51  for (const auto& compressor : compressors) {
52  compressedCerts_[compressor->getAlgorithm()] =
53  compressor->compress(getCertMessage());
54  }
55 }
std::vector< folly::ssl::X509UniquePtr > certs_
Definition: Certificate.h:170
OpenSSLSignature< T > signature_
Definition: Certificate.h:169
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::map< CertificateCompressionAlgorithm, CompressedCertificate > compressedCerts_
Definition: Certificate.h:172
CertificateMsg getCertMessage(Buf certificateRequestContext=nullptr) const override
template<KeyType T>
fizz::SelfCertImpl< T >::~SelfCertImpl ( )
overridedefault

Member Function Documentation

template<KeyType T>
std::vector< std::string > fizz::SelfCertImpl< T >::getAltIdentities ( ) const
overridevirtual

Returns additional identities this certificate can also represent (for example subject alternate names).

Implements fizz::SelfCert.

Definition at line 64 of file Certificate-inl.h.

References folly::ssl::OpenSSLCertUtils::getSubjectAltNames().

Referenced by fizz::test::TEST().

64  {
66 }
std::vector< folly::ssl::X509UniquePtr > certs_
Definition: Certificate.h:170
static std::vector< std::string > getSubjectAltNames(X509 &x509)
template<KeyType T>
CertificateMsg fizz::SelfCertImpl< T >::getCertMessage ( Buf  certificateRequestContext = nullptr) const
overridevirtual

Implements fizz::SelfCert.

Definition at line 69 of file Certificate-inl.h.

References fizz::CertUtils::getCertMessage(), and folly::gen::move.

Referenced by fizz::test::TEST().

70  {
72  certs_, std::move(certificateRequestContext));
73 }
std::vector< folly::ssl::X509UniquePtr > certs_
Definition: Certificate.h:170
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static CertificateMsg getCertMessage(const std::vector< folly::ssl::X509UniquePtr > &certs, Buf certificateRequestContext)
Definition: Certificate.cpp:59
template<KeyType T>
CompressedCertificate fizz::SelfCertImpl< T >::getCompressedCert ( CertificateCompressionAlgorithm  algo) const
overridevirtual

Implements fizz::SelfCert.

Definition at line 76 of file Certificate-inl.h.

References fizz::CertUtils::cloneCompressedCert().

77  {
79 }
std::map< CertificateCompressionAlgorithm, CompressedCertificate > compressedCerts_
Definition: Certificate.h:172
static CompressedCertificate cloneCompressedCert(const CompressedCertificate &src)
template<KeyType T>
std::string fizz::SelfCertImpl< T >::getIdentity ( ) const
overridevirtual

Returns the identity this certificate conveys.

An identity is an opaque string that may be used by the application for authentication or authorization purposes. The exact structure and semantics of the identity string are determined by concrete implementations of AsyncTransport.

Implements folly::AsyncTransportCertificate.

Definition at line 58 of file Certificate-inl.h.

References folly::ssl::OpenSSLCertUtils::getCommonName().

Referenced by fizz::test::TEST().

58  {
60  .value_or("");
61 }
std::vector< folly::ssl::X509UniquePtr > certs_
Definition: Certificate.h:170
static Optional< std::string > getCommonName(X509 &x509)
template<KeyType T>
std::vector< SignatureScheme > fizz::SelfCertImpl< T >::getSigSchemes ( ) const
overridevirtual

Returns the signature schemes this certificate can be used with.

Implements fizz::SelfCert.

Definition at line 82 of file Certificate-inl.h.

Referenced by fizz::test::TYPED_TEST().

82  {
83  return CertUtils::getSigSchemes<T>();
84 }
template<KeyType T>
folly::ssl::X509UniquePtr fizz::SelfCertImpl< T >::getX509 ( ) const
overridevirtual

Returns an X509 structure associated with this Certificate. This may be null.

Implements folly::AsyncTransportCertificate.

Definition at line 232 of file Certificate-inl.h.

232  {
233  X509_up_ref(certs_.front().get());
234  return folly::ssl::X509UniquePtr(certs_.front().get());
235 }
std::vector< folly::ssl::X509UniquePtr > certs_
Definition: Certificate.h:170
std::unique_ptr< X509, X509Deleter > X509UniquePtr
template<>
Buf fizz::SelfCertImpl< KeyType::P256 >::sign ( SignatureScheme  scheme,
CertificateVerifyContext  context,
folly::ByteRange  toBeSigned 
) const
inlinevirtual

Implements fizz::SelfCert.

Definition at line 87 of file Certificate-inl.h.

90  {
91  auto signData = CertUtils::prepareSignData(context, toBeSigned);
92  switch (scheme) {
95  signData->coalesce());
96  default:
97  throw std::runtime_error("Unsupported signature scheme");
98  }
99 }
OpenSSLSignature< T > signature_
Definition: Certificate.h:169
context
Definition: CMakeCache.txt:563
static Buf prepareSignData(CertificateVerifyContext context, folly::ByteRange toBeSigned)
Definition: Certificate.cpp:23
template<>
Buf fizz::SelfCertImpl< KeyType::P384 >::sign ( SignatureScheme  scheme,
CertificateVerifyContext  context,
folly::ByteRange  toBeSigned 
) const
inlinevirtual

Implements fizz::SelfCert.

Definition at line 102 of file Certificate-inl.h.

105  {
106  auto signData = CertUtils::prepareSignData(context, toBeSigned);
107  switch (scheme) {
110  signData->coalesce());
111  default:
112  throw std::runtime_error("Unsupported signature scheme");
113  }
114 }
OpenSSLSignature< T > signature_
Definition: Certificate.h:169
context
Definition: CMakeCache.txt:563
static Buf prepareSignData(CertificateVerifyContext context, folly::ByteRange toBeSigned)
Definition: Certificate.cpp:23
template<>
Buf fizz::SelfCertImpl< KeyType::P521 >::sign ( SignatureScheme  scheme,
CertificateVerifyContext  context,
folly::ByteRange  toBeSigned 
) const
inlinevirtual

Implements fizz::SelfCert.

Definition at line 117 of file Certificate-inl.h.

120  {
121  auto signData = CertUtils::prepareSignData(context, toBeSigned);
122  switch (scheme) {
125  signData->coalesce());
126  default:
127  throw std::runtime_error("Unsupported signature scheme");
128  }
129 }
OpenSSLSignature< T > signature_
Definition: Certificate.h:169
context
Definition: CMakeCache.txt:563
static Buf prepareSignData(CertificateVerifyContext context, folly::ByteRange toBeSigned)
Definition: Certificate.cpp:23
template<>
Buf fizz::SelfCertImpl< KeyType::RSA >::sign ( SignatureScheme  scheme,
CertificateVerifyContext  context,
folly::ByteRange  toBeSigned 
) const
inlinevirtual

Implements fizz::SelfCert.

Definition at line 132 of file Certificate-inl.h.

135  {
136  auto signData = CertUtils::prepareSignData(context, toBeSigned);
137  switch (scheme) {
140  signData->coalesce());
141  default:
142  throw std::runtime_error("Unsupported signature scheme");
143  }
144 }
OpenSSLSignature< T > signature_
Definition: Certificate.h:169
context
Definition: CMakeCache.txt:563
static Buf prepareSignData(CertificateVerifyContext context, folly::ByteRange toBeSigned)
Definition: Certificate.cpp:23
template<KeyType T>
Buf fizz::SelfCertImpl< T >::sign ( SignatureScheme  scheme,
CertificateVerifyContext  context,
folly::ByteRange  toBeSigned 
) const
overridevirtual

Implements fizz::SelfCert.

Referenced by fizz::test::TYPED_TEST().

Member Data Documentation

template<KeyType T>
std::vector<folly::ssl::X509UniquePtr> fizz::SelfCertImpl< T >::certs_
private

Definition at line 170 of file Certificate.h.

template<KeyType T>
std::map<CertificateCompressionAlgorithm, CompressedCertificate> fizz::SelfCertImpl< T >::compressedCerts_
private

Definition at line 172 of file Certificate.h.

template<KeyType T>
OpenSSLSignature<T> fizz::SelfCertImpl< T >::signature_
private

Definition at line 169 of file Certificate.h.


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