-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add testCertVerify shared test for use in openssl and other backends
Reviewed By: mingtaoy Differential Revision: D66143703 fbshipit-source-id: bf6e42ca47a6bfb81ecbeca88e796d5d54d3c53a
- Loading branch information
1 parent
f8b7ddb
commit 88cb93d
Showing
4 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
fizz/backend/openssl/crypto/signature/test/PeerCertVerify.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <folly/portability/GTest.h> | ||
|
||
#include <fizz/backend/openssl/certificate/CertUtils.h> | ||
#include <fizz/crypto/test/Signature.h> | ||
#include <fizz/crypto/test/SignatureTestData.h> | ||
|
||
using namespace testing; | ||
|
||
namespace fizz { | ||
namespace openssl { | ||
namespace test { | ||
|
||
class VerifyTest : public Test, | ||
public WithParamInterface<fizz::test::SignatureTestData> {}; | ||
|
||
TEST_P(VerifyTest, PeerCertVerify) { | ||
fizz::test::testCertVerify(GetParam(), openssl::CertUtils::makePeerCert); | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P( | ||
SignatureTestVectors, | ||
VerifyTest, | ||
ValuesIn(fizz::test::kSignatureTestVectors)); | ||
|
||
} // namespace test | ||
} // namespace openssl | ||
} // namespace fizz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <fizz/crypto/test/Signature.h> | ||
|
||
#include <folly/Range.h> | ||
#include <folly/io/IOBuf.h> | ||
#include <folly/portability/GTest.h> | ||
|
||
using namespace testing; | ||
|
||
namespace fizz { | ||
namespace test { | ||
|
||
std::unique_ptr<folly::IOBuf> makeCertBuf(std::string certDer) { | ||
return folly::IOBuf::copyBuffer(certDer.data(), certDer.size()); | ||
} | ||
|
||
void testCertVerify( | ||
SignatureTestData testCase, | ||
std::unique_ptr<PeerCert> (*makePeerCert)(Buf)) { | ||
std::string certDer = folly::unhexlify(testCase.certDer); | ||
std::string msg = folly::unhexlify(testCase.msg); | ||
std::string sig = folly::unhexlify(testCase.sig); | ||
|
||
std::unique_ptr<folly::IOBuf> certBuf = makeCertBuf(certDer); | ||
|
||
if (!testCase.validCert) { | ||
EXPECT_THROW(makePeerCert(makeCertBuf(certDer)), std::runtime_error); | ||
return; | ||
} | ||
|
||
// make sure move works | ||
auto tempPeerCert = makePeerCert(makeCertBuf(certDer)); | ||
|
||
auto peerCert = std::move(tempPeerCert); | ||
|
||
// test getDER() | ||
auto retDer = peerCert->getDER(); | ||
ASSERT_TRUE(retDer.has_value()); | ||
|
||
ASSERT_EQ(memcmp(certDer.c_str(), retDer.value().c_str(), certDer.size()), 0); | ||
|
||
if (!testCase.validSig) { | ||
EXPECT_THROW( | ||
peerCert->verify( | ||
testCase.sigScheme, | ||
fizz::CertificateVerifyContext::Server, | ||
folly::ByteRange( | ||
reinterpret_cast<const unsigned char*>(msg.c_str()), | ||
msg.size()), | ||
folly::ByteRange( | ||
reinterpret_cast<const unsigned char*>(sig.c_str()), | ||
sig.size())), | ||
std::runtime_error); | ||
} else { | ||
EXPECT_NO_THROW(peerCert->verify( | ||
testCase.sigScheme, | ||
fizz::CertificateVerifyContext::Server, | ||
folly::ByteRange( | ||
reinterpret_cast<const unsigned char*>(msg.c_str()), msg.size()), | ||
folly::ByteRange( | ||
reinterpret_cast<const unsigned char*>(sig.c_str()), sig.size()))); | ||
} | ||
} | ||
} // namespace test | ||
} // namespace fizz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (c) 2018-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <folly/portability/GTest.h> | ||
|
||
#include <fizz/crypto/test/SignatureTestData.h> | ||
#include <fizz/protocol/Certificate.h> | ||
|
||
namespace fizz { | ||
namespace test { | ||
|
||
void testCertVerify( | ||
SignatureTestData testCase, | ||
std::unique_ptr<PeerCert> (*makePeerCert)(Buf)); | ||
} // namespace test | ||
} // namespace fizz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters