12 int getCurveName(EVP_PKEY* key) {
13 auto ecKey = EVP_PKEY_get0_EC_KEY(key);
15 return EC_GROUP_get_curve_name(EC_KEY_get0_group(ecKey));
27 "TLS 1.3, server CertificateVerify";
29 "TLS 1.3, client CertificateVerify";
31 static constexpr
size_t kSigPrefixLen = 64;
32 static constexpr
uint8_t kSigPrefix = 32;
43 size_t sigDataLen = kSigPrefixLen + label.
size() + 1 + toBeSigned.
size();
45 buf->append(sigDataLen);
49 memset(buf->writableData(), kSigPrefix, kSigPrefixLen);
50 offset += kSigPrefixLen;
51 memcpy(buf->writableData() + offset, label.
data(), label.
size());
52 offset += label.
size();
53 memset(buf->writableData() + offset, 0, 1);
55 memcpy(buf->writableData() + offset, toBeSigned.
data(), toBeSigned.
size());
60 const std::vector<folly::ssl::X509UniquePtr>& certs,
61 Buf certificateRequestContext) {
63 std::vector<CertificateEntry> entries;
64 for (
const auto& cert : certs) {
66 int len = i2d_X509(cert.get(),
nullptr);
68 throw std::runtime_error(
"Error computing length");
72 len = i2d_X509(cert.get(), &
dataPtr);
74 throw std::runtime_error(
"Error converting cert to DER");
88 if (certData->empty()) {
89 throw std::runtime_error(
"empty peer cert");
92 auto range = certData->coalesce();
96 throw std::runtime_error(
"could not read cert");
99 VLOG(1) <<
"Did not read to end of certificate";
104 throw std::runtime_error(
"couldn't get pubkey from peer cert");
106 if (EVP_PKEY_id(pubKey.get()) == EVP_PKEY_RSA) {
107 return std::make_unique<PeerCertImpl<KeyType::RSA>>(
std::move(cert));
108 }
else if (EVP_PKEY_id(pubKey.get()) == EVP_PKEY_EC) {
109 switch (getCurveName(pubKey.get())) {
110 case NID_X9_62_prime256v1:
111 return std::make_unique<PeerCertImpl<KeyType::P256>>(
std::move(cert));
113 return std::make_unique<PeerCertImpl<KeyType::P384>>(
std::move(cert));
115 return std::make_unique<PeerCertImpl<KeyType::P521>>(
std::move(cert));
120 throw std::runtime_error(
"unknown peer cert type");
125 std::unique_ptr<SelfCert> selfCertFromDataInternal(
129 const std::vector<std::shared_ptr<CertificateCompressor>>& compressors) {
133 throw std::runtime_error(
"no certificates read");
139 throw std::runtime_error(
"failed to create BIO");
143 PEM_read_bio_PrivateKey(b.get(),
nullptr,
nullptr, password));
146 throw std::runtime_error(
"Failed to read key");
157 const std::vector<std::shared_ptr<CertificateCompressor>>& compressors) {
158 return selfCertFromDataInternal(
166 const std::vector<std::shared_ptr<CertificateCompressor>>& compressors) {
167 return selfCertFromDataInternal(
172 std::vector<folly::ssl::X509UniquePtr> certs,
174 const std::vector<std::shared_ptr<CertificateCompressor>>& compressors) {
177 throw std::runtime_error(
"Failed to read public key");
180 if (EVP_PKEY_id(pubKey.get()) == EVP_PKEY_RSA) {
181 return std::make_unique<SelfCertImpl<KeyType::RSA>>(
183 }
else if (EVP_PKEY_id(pubKey.get()) == EVP_PKEY_EC) {
184 switch (getCurveName(pubKey.get())) {
185 case NID_X9_62_prime256v1:
186 return std::make_unique<SelfCertImpl<KeyType::P256>>(
189 return std::make_unique<SelfCertImpl<KeyType::P384>>(
192 return std::make_unique<SelfCertImpl<KeyType::P521>>(
198 throw std::runtime_error(
"unknown self cert type");
CertificateCompressionAlgorithm algorithm
static std::unique_ptr< SelfCert > makeSelfCert(std::string certData, std::string keyData, const std::vector< std::shared_ptr< CertificateCompressor >> &compressors={})
std::unique_ptr< X509, X509Deleter > X509UniquePtr
static std::unique_ptr< IOBuf > create(std::size_t capacity)
std::unique_ptr< BIO, BioDeleter > BioUniquePtr
IdentityCert(std::string identity)
constexpr detail::Map< Move > move
constexpr size_type size() const
auto begin(TestAdlIterable &instance)
uint32_t uncompressed_length
std::unique_ptr< EVP_PKEY, EvpPkeyDeleter > EvpPkeyUniquePtr
Buf certificate_request_context
Gen range(Value begin, Value end)
std::vector< CertificateEntry > certificate_list
constexpr Iter data() const
static CertificateMsg getCertMessage(const std::vector< folly::ssl::X509UniquePtr > &certs, Buf certificateRequestContext)
folly::ssl::X509UniquePtr getX509() const override
static std::unique_ptr< PeerCert > makePeerCert(Buf certData)
std::unique_ptr< folly::IOBuf > Buf
Container::value_type * dataPtr(Container &cont)
static std::vector< X509UniquePtr > readCertsFromBuffer(ByteRange range)
std::string getIdentity() const override
static Buf prepareSignData(CertificateVerifyContext context, folly::ByteRange toBeSigned)
static CompressedCertificate cloneCompressedCert(const CompressedCertificate &src)
Buf compressed_certificate_message