28 using namespace folly;
31 const char*
kTestCa =
"folly/io/async/test/certs/ca-cert.pem";
35 ----BEGIN EC PRIVATE KEY----- 36 MHcCAQEEIBskFwVZ9miFN+SKCFZPe9WEuFGmP+fsecLUnsTN6bOcoAoGCCqGSM49 37 AwEHoUQDQgAE7/f4YYOYunAM/VkmjDYDg3AWUgyyTIraWmmQZsnu0bYNV/lLLfNz 38 CtHggxGSwEtEe40nNb9C8wQmHUvb7VBBlw== 39 -----END EC PRIVATE KEY----- 42 -----BEGIN CERTIFICATE----- 43 MIIDXDCCAkSgAwIBAgIBAjANBgkqhkiG9w0BAQsFADBQMQswCQYDVQQGEwJVUzEL 44 MAkGA1UECAwCQ0ExDTALBgNVBAoMBEFzb3gxJTAjBgNVBAMMHEFzb3ggQ2VydGlm 45 aWNhdGlvbiBBdXRob3JpdHkwHhcNMTcwMjEzMjMyMTAzWhcNNDQwNzAxMjMyMTAz 46 WjAwMQswCQYDVQQGEwJVUzENMAsGA1UECgwEQXNveDESMBAGA1UEAwwJMTI3LjAu 47 MC4xMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7/f4YYOYunAM/VkmjDYDg3AW 48 UgyyTIraWmmQZsnu0bYNV/lLLfNzCtHggxGSwEtEe40nNb9C8wQmHUvb7VBBl6OC 49 ASowggEmMAkGA1UdEwQCMAAwLAYJYIZIAYb4QgENBB8WHU9wZW5TU0wgR2VuZXJh 50 dGVkIENlcnRpZmljYXRlMB0GA1UdDgQWBBRx1kmdZEfXHmWLHpSDI0Lh8hmfwzAf 51 BgNVHSMEGDAWgBQX3ykJKb97nxp/6UZJyDvts7noezAxBgNVHREEKjAoghJhbm90 52 aGVyZXhhbXBsZS5jb22CEioudGhpcmRleGFtcGxlLmNvbTB4BggrBgEFBQcBAQRs 53 MGowaAYIKwYBBQUHMAKGXGh0dHBzOi8vcGhhYnJpY2F0b3IuZmIuY29tL2RpZmZ1 54 c2lvbi9GQkNPREUvYnJvd3NlL21hc3Rlci90aS90ZXN0X2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 126 Rw7ydBokxHWsmVJczuRmEovXcTmgIphti234e7usKjw8M5mGwYfa 127 -----END CERTIFICATE----- 137 SSLerr(SSL_F_SSL3_READ_BYTES, SSL_R_SSL_HANDSHAKE_FAILURE);
147 throw std::runtime_error(
"Couldn't create BIO");
150 if (BIO_read_filename(bio.get(), filename.c_str()) != 1) {
151 throw std::runtime_error(
"Couldn't read cert file: " + filename);
154 PEM_read_bio_X509(bio.get(),
nullptr,
nullptr,
nullptr));
161 throw std::runtime_error(
"Couldn't create BIO");
164 PEM_read_bio_X509(bio.get(),
nullptr,
nullptr,
nullptr));
169 const std::vector<folly::ssl::X509UniquePtr>& certs) {
182 EXPECT_EQ(
"127.0.0.1", identity.value());
185 EXPECT_EQ(
"anotherexample.com", altNames[0]);
186 EXPECT_EQ(
"*.thirdexample.com", altNames[1]);
193 EXPECT_EQ(identity.value(),
"Asox Company");
209 "C = US, ST = CA, O = Asox, CN = Asox Certification Authority");
211 EXPECT_EQ(subj.value(),
"C = US, O = Asox, CN = 127.0.0.1");
218 EXPECT_EQ(notBefore,
"Feb 13 23:21:03 2017 GMT");
220 EXPECT_EQ(notAfter,
"Jul 1 23:21:03 2044 GMT");
229 " Version: 3 (0x2)\n Serial Number: 2 (0x2)\n" 230 " Issuer: C = US, ST = CA, O = Asox, CN = Asox Certification Authority\n" 231 " Validity\n Not Before: Feb 13 23:21:03 2017 GMT\n" 232 " Not After : Jul 1 23:21:03 2044 GMT\n" 233 " Subject: C = US, O = Asox, CN = 127.0.0.1\n" 234 " X509v3 extensions:\n" 235 " X509v3 Basic Constraints: \n" 237 " Netscape Comment: \n" 238 " OpenSSL Generated Certificate\n" 239 " X509v3 Subject Key Identifier: \n" 240 " 71:D6:49:9D:64:47:D7:1E:65:8B:1E:94:83:23:42:E1:F2:19:9F:C3\n" 241 " X509v3 Authority Key Identifier: \n" 242 " keyid:17:DF:29:09:29:BF:7B:9F:1A:7F:E9:46:49:C8:3B:ED:B3:B9:E8:7B\n\n" 243 " X509v3 Subject Alternative Name: \n" 244 " DNS:anotherexample.com, DNS:*.thirdexample.com\n" 245 " Authority Information Access: \n" 246 " CA Issuers - URI:https://phabricator.fb.com/diffusion/FBCODE/browse/master/ti/test_certs/ca_cert.pem?view=raw\n\n");
285 std::vector<std::string> bufs(
287 folly::to<std::string>(kTestKey,
"\n\n", kTestCertWithSan,
"\n")});
288 for (
auto& buf : bufs) {
303 "b84e951d6c4e6cc70346357fab43d7ed73a07b0f");
308 "364d3a6a0b10d0635ce59b40c0b7f505ab2cd9fd0a06661cdc61d9cb8c9c9821");
317 auto rc = X509_STORE_CTX_init(ctx.get(), store.get(), x509.get(),
nullptr);
319 rc = X509_verify_cert(ctx.get());
325 "-----BEGIN CERTIFICATE-----\n" 327 "-----END CERTIFICATE-----\n";
INSTANTIATE_TEST_CASE_P(, CodeLocationForTESTP, Values(0))
static void validateTestCertWithSAN(X509 *x509)
#define EXPECT_THROW(statement, expected_exception)
#define ASSERT_EQ(val1, val2)
static folly::Optional< std::string > toString(X509 &x509)
std::unique_ptr< X509, X509Deleter > X509UniquePtr
const std::string kTestCertWithSan
std::unique_ptr< BIO, BioDeleter > BioUniquePtr
std::string sformat(StringPiece fmt, Args &&...args)
const std::string kTestKey
static std::array< uint8_t, SHA_DIGEST_LENGTH > getDigestSha1(X509 &x509)
static std::array< uint8_t, SHA256_DIGEST_LENGTH > getDigestSha256(X509 &x509)
#define EXPECT_EQ(val1, val2)
static Optional< std::string > getSubject(X509 &x509)
static X509StoreUniquePtr readStoreFromBuffer(ByteRange range)
static X509UniquePtr derDecode(ByteRange)
constexpr size_type size() const
const char * kTestCertWithoutSan
—— Concurrent Priority Queue Implementation ——
static folly::ssl::X509UniquePtr readCertFromFile(const std::string &filename)
TEST_P(CodeLocationForTESTP, Verify)
std::string stripLeftMargin(std::string s)
static folly::ssl::X509UniquePtr readCertFromData(const folly::StringPiece data)
static std::vector< std::string > getSubjectAltNames(X509 &x509)
static X509StoreUniquePtr readStoreFromFile(std::string caFile)
static Optional< std::string > getIssuer(X509 &x509)
static std::string getNotAfterTime(X509 &x509)
const std::string kTestCertBundle
constexpr Iter data() const
constexpr Range< Iter > range(Iter first, Iter last)
static void validateTestCertBundle(const std::vector< folly::ssl::X509UniquePtr > &certs)
static Optional< std::string > getCommonName(X509 &x509)
detail::RangeEnumerator< Range > enumerate(Range &&r)
#define EXPECT_TRUE(condition)
std::unique_ptr< X509_STORE_CTX, X509StoreCtxDeleter > X509StoreCtxUniquePtr
#define EXPECT_NE(val1, val2)
static std::vector< X509UniquePtr > readCertsFromBuffer(ByteRange range)
static std::unique_ptr< IOBuf > derEncode(X509 &)
#define ASSERT_NE(val1, val2)
Range< const char * > StringPiece
bool hexlify(const InputString &input, OutputString &output, bool append_output)
static constexpr uint64_t data[1]
static std::string getNotBeforeTime(X509 &x509)