9 #include <gtest/gtest.h> 15 using namespace folly;
26 SignatureScheme::ecdsa_secp256r1_sha256;
34 SignatureScheme::ecdsa_secp384r1_sha384;
42 SignatureScheme::ecdsa_secp521r1_sha512;
100 template <
typename T>
104 OpenSSL_add_all_algorithms();
108 using KeyTypes = Types<P256Test, P384Test, P521Test, RSATest>;
114 std::vector<folly::ssl::X509UniquePtr> certs;
121 TEST(CertTest, GetAltIdentity) {
124 std::vector<folly::ssl::X509UniquePtr> certs;
135 TEST(CertTest, GetCertMessage) {
138 std::vector<folly::ssl::X509UniquePtr> certs;
142 ASSERT_EQ(msg.certificate_list.size(), 1);
143 auto& firstCertEntry = msg.certificate_list[0];
144 auto firstCertData = firstCertEntry.cert_data->coalesce();
145 auto firstCertDataPtr = firstCertData.data();
147 d2i_X509(
nullptr, &firstCertDataPtr, firstCertData.size()));
148 CHECK(firstEncodedCert);
151 EXPECT_EQ(X509_cmp(firstEncodedCert.get(), certCopy.get()), 0);
155 TEST(CertTest, PrepareSignData) {
156 std::array<uint8_t, 32> toBeSigned;
157 memset(toBeSigned.data(), 1, toBeSigned.size());
158 auto out = CertUtils::prepareSignData(
159 CertificateVerifyContext::Server,
folly::range(toBeSigned));
160 auto hex =
hexlify(out->moveToFbString());
162 "2020202020202020202020202020202020202020202020202020202020202020" 163 "2020202020202020202020202020202020202020202020202020202020202020" 164 "544c5320312e332c207365727665722043657274696669636174655665726966" 167 "0101010101010101010101010101010101010101010101010101010101010101";
171 TEST(CertTest, MakePeerCertEmpty) {
176 TEST(CertTest, MakePeerCertJunk) {
181 TEST(CertTest, PeerCertGetX509) {
183 auto x509 = peerCert.
getX509();
188 std::vector<folly::ssl::X509UniquePtr> certs;
189 certs.push_back(getCert<TypeParam>());
195 std::vector<folly::ssl::X509UniquePtr> certs;
196 certs.push_back(getCert<TypeParam>());
199 getKey<typename TypeParam::Invalid>(),
std::move(certs)),
204 std::vector<folly::ssl::X509UniquePtr> certs;
205 certs.push_back(getCert<TypeParam>());
209 std::vector<SignatureScheme> expected{TypeParam::Scheme};
215 std::vector<folly::ssl::X509UniquePtr> certs;
216 certs.push_back(getCert<TypeParam>());
221 selfCert.
sign(TypeParam::Scheme, CertificateVerifyContext::Server, tbs);
224 CertificateVerifyContext::Server,
231 std::vector<folly::ssl::X509UniquePtr> certs;
232 certs.push_back(getCert<TypeParam>());
237 selfCert.
sign(TypeParam::Scheme, CertificateVerifyContext::Server, tbs);
238 sig->writableData()[1] ^= 0x20;
242 CertificateVerifyContext::Server,
250 std::vector<folly::ssl::X509UniquePtr> certs;
251 certs.push_back(getCert<TypeParam>());
256 selfCert.
sign(TypeParam::Scheme, CertificateVerifyContext::Server, tbs);
261 CertificateVerifyContext::Server,
269 std::vector<folly::ssl::X509UniquePtr> certs;
270 certs.push_back(getCert<TypeParam>());
275 selfCert.
sign(TypeParam::Scheme, CertificateVerifyContext::Server, tbs);
278 TypeParam::Invalid::Scheme,
279 CertificateVerifyContext::Server,
286 std::vector<folly::ssl::X509UniquePtr> certs;
287 certs.push_back(getCert<TypeParam>());
288 auto msg = CertUtils::getCertMessage(certs,
nullptr);
291 auto peerCert = CertUtils::makePeerCert(
292 std::move(msg.certificate_list.front().cert_data));
296 selfCert.
sign(TypeParam::Scheme, CertificateVerifyContext::Server, tbs);
299 CertificateVerifyContext::Server,
ssl::EvpPkeyUniquePtr getKey< RSATest >()
#define EXPECT_THROW(statement, expected_exception)
constexpr folly::StringPiece kP256Key
#define ASSERT_EQ(val1, val2)
std::unique_ptr< X509, X509Deleter > X509UniquePtr
constexpr folly::StringPiece kRSACertificate
#define EXPECT_EQ(val1, val2)
constexpr folly::StringPiece kP384Certificate
ssl::X509UniquePtr getCert< P384Test >()
constexpr detail::Map< Move > move
std::vector< SignatureScheme > getSigSchemes() const override
std::unique_ptr< EVP_PKEY, EvpPkeyDeleter > EvpPkeyUniquePtr
TYPED_TEST_CASE(SynchronizedTest, SynchronizedTestTypes)
EvpPkeyUniquePtr getPrivateKey(StringPiece key)
std::vector< std::string > getAltIdentities() const override
—— Concurrent Priority Queue Implementation ——
static ssl::X509UniquePtr getCert()
folly::ssl::X509UniquePtr getCert(folly::StringPiece cert)
ssl::X509UniquePtr getCert< P521Test >()
ssl::X509UniquePtr getCert< RSATest >()
Buf sign(SignatureScheme scheme, CertificateVerifyContext context, folly::ByteRange toBeSigned) const override
CertificateMsg getCertMessage(Buf certificateRequestContext=nullptr) const override
void verify(SignatureScheme scheme, CertificateVerifyContext context, folly::ByteRange toBeSigned, folly::ByteRange signature) const override
ssl::EvpPkeyUniquePtr getKey< P256Test >()
TYPED_TEST(SynchronizedTest, Basic)
constexpr Range< Iter > range(Iter first, Iter last)
constexpr detail::Sig< Sig > const sig
ssl::EvpPkeyUniquePtr getKey< P521Test >()
ssl::EvpPkeyUniquePtr getKey< P384Test >()
::testing::Types< P256, P384, P521 > KeyTypes
constexpr folly::StringPiece kRSAKey
#define EXPECT_NE(val1, val2)
ssl::X509UniquePtr getCert< P256Test >()
folly::ssl::X509UniquePtr getX509() const override
constexpr folly::StringPiece kP521Key
bool hexlify(const InputString &input, OutputString &output, bool append_output)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
constexpr folly::StringPiece kP521Certificate
constexpr folly::StringPiece kP384Key
TEST(SequencedExecutor, CPUThreadPoolExecutor)
std::string getIdentity() const override
constexpr folly::StringPiece kP256Certificate