20 if (!password || !data || size < 1) {
21 LOG(ERROR) <<
"invalid password buffer, size is " <<
size;
26 if (userPassword.empty()) {
27 LOG(ERROR) <<
"empty private key password";
30 auto length =
std::min(static_cast<int>(userPassword.size()), size - 1);
31 memcpy(password, userPassword.data(), length);
32 password[length] =
'\0';
40 throw std::runtime_error(
41 folly::to<std::string>(
"couldn't read cert file: ", filename));
46 throw std::runtime_error(
47 folly::to<std::string>(
"couldn't read any cert from: ", filename));
58 if (!passwordFilename.empty()) {
64 }
catch (std::runtime_error& e) {
66 "Failed to read private key from file: {}, password file: {}",
69 std::throw_with_nested(std::runtime_error(ex));
78 throw std::runtime_error(
"couldn't create bio");
87 PEM_read_bio_PrivateKey(keyBio.get(),
nullptr,
nullptr,
nullptr));
91 throw std::runtime_error(
"couldn't read private key");
98 const std::list<folly::SSLContext::NextProtocolsItem>&
list) {
100 auto maxWeight = list.front().weight;
101 auto protoList = &list.front().protocols;
102 for (
const auto& item : list) {
103 if (item.weight > maxWeight) {
104 protoList = &item.protocols;
107 return std::vector<std::string>(protoList->begin(), protoList->end());
bool readFile(int fd, Container &out, size_t num_bytes=std::numeric_limits< size_t >::max())
std::unique_ptr< BIO, BioDeleter > BioUniquePtr
static folly::ssl::EvpPkeyUniquePtr readPrivateKey(const std::string &filename, const std::string &passwordFilename)
std::string sformat(StringPiece fmt, Args &&...args)
static std::vector< std::string > getAlpnsFromNpnList(const std::list< folly::SSLContext::NextProtocolsItem > &list)
std::unique_ptr< EVP_PKEY, EvpPkeyDeleter > EvpPkeyUniquePtr
static std::vector< folly::ssl::X509UniquePtr > readChainFile(const std::string &filename)
constexpr auto size(C const &c) -> decltype(c.size())
Encoder::MutableCompressedList list
static folly::ssl::EvpPkeyUniquePtr decryptPrivateKey(const std::string &data, folly::PasswordInFile *pf)
Range< const unsigned char * > ByteRange
static std::vector< X509UniquePtr > readCertsFromBuffer(ByteRange range)
static int passwordCallback(char *password, int size, int, void *data)
static constexpr uint64_t data[1]