tests: Manage identity/certificate creation in test cases through IdentityManagementFixture.
This is the second one of the two commits for issue #1683.
For test cases which create new identities/certificates, the temporary identities/certificates
are managed by IdentityManagementFixture.
Change-Id: I5b42348bd74091a28042aea399484fb4ed1b58f4
Refs: #1683
diff --git a/tests/unit-tests/security/test-conf-checker.cpp b/tests/unit-tests/security/test-conf-checker.cpp
index 23df0cd..f173436 100644
--- a/tests/unit-tests/security/test-conf-checker.cpp
+++ b/tests/unit-tests/security/test-conf-checker.cpp
@@ -21,11 +21,12 @@
#include "security/conf/checker.hpp"
#include "security/key-chain.hpp"
+#include "identity-management-fixture.hpp"
#include "boost-test.hpp"
namespace ndn {
-BOOST_AUTO_TEST_SUITE(SecurityTestConfChecker)
+BOOST_FIXTURE_TEST_SUITE(SecurityTestConfChecker, security::IdentityManagementFixture)
void
interestChecked(const shared_ptr<const Interest>& interest)
@@ -88,26 +89,26 @@
using security::conf::KeyLocatorChecker;
using security::conf::RelationKeyLocatorNameChecker;
- KeyChain keyChain("sqlite3", "file");
-
Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1");
- Name certName = keyChain.createIdentity(identity);
+ BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong");
- Name certName2 = keyChain.createIdentity(identity2);
+ BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data");
shared_ptr<Data> data1 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data1, identity);
+ m_keyChain.signByIdentity(*data1, identity);
shared_ptr<Data> data2 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data2, identity2);
+ m_keyChain.signByIdentity(*data2, identity2);
shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*interest1, identity);
+ m_keyChain.signByIdentity(*interest1, identity);
shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*interest2, identity2);
+ m_keyChain.signByIdentity(*interest2, identity2);
int8_t result = 0;
@@ -215,10 +216,6 @@
bind(dataCheckedFalse, _1),
bind(dataCheckFailedFalse, _1, _2));
BOOST_CHECK_EQUAL(result, -1);
-
-
- keyChain.deleteIdentity(identity);
- keyChain.deleteIdentity(identity2);
}
BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2)
@@ -227,26 +224,26 @@
using security::conf::KeyLocatorChecker;
using security::conf::RegexKeyLocatorNameChecker;
- KeyChain keyChain("sqlite3", "file");
-
Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
- Name certName = keyChain.createIdentity(identity);
+ BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
- Name certName2 = keyChain.createIdentity(identity2);
+ BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
shared_ptr<Data> data1 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data1, identity);
+ m_keyChain.signByIdentity(*data1, identity);
shared_ptr<Data> data2 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data2, identity2);
+ m_keyChain.signByIdentity(*data2, identity2);
shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*interest1, identity);
+ m_keyChain.signByIdentity(*interest1, identity);
shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*interest2, identity2);
+ m_keyChain.signByIdentity(*interest2, identity2);
int8_t result = 0;
@@ -275,9 +272,6 @@
bind(interestCheckedFalse, _1),
bind(interestCheckFailedFalse, _1, _2));
BOOST_CHECK_EQUAL(result, -1);
-
- keyChain.deleteIdentity(identity);
- keyChain.deleteIdentity(identity2);
}
BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3)
@@ -286,28 +280,26 @@
using security::conf::KeyLocatorChecker;
using security::conf::RegexKeyLocatorNameChecker;
- KeyChain keyChain("sqlite3", "file");
-
- EcdsaKeyParams params;
-
Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
- Name certName = keyChain.createIdentity(identity, params);
+ BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
- Name certName2 = keyChain.createIdentity(identity2, params);
+ BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
+ Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
shared_ptr<Data> data1 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data1, identity);
+ m_keyChain.signByIdentity(*data1, identity);
shared_ptr<Data> data2 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data2, identity2);
+ m_keyChain.signByIdentity(*data2, identity2);
shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*interest1, identity);
+ m_keyChain.signByIdentity(*interest1, identity);
shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*interest2, identity2);
+ m_keyChain.signByIdentity(*interest2, identity2);
int8_t result = 0;
@@ -344,47 +336,41 @@
bind(dataCheckedFalse, _1),
bind(dataCheckFailedFalse, _1, _2));
BOOST_CHECK_EQUAL(result, -1);
-
-
- keyChain.deleteIdentity(identity);
- keyChain.deleteIdentity(identity2);
}
BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1)
{
using security::conf::HierarchicalChecker;
- KeyChain keyChain("sqlite3", "file");
-
- EcdsaKeyParams params;
-
Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
- Name certName = keyChain.createIdentity(identity, params);
+ BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
- Name certName2 = keyChain.createIdentity(identity2);
+ BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
Name packetName2("/SecurityTestConfChecker");
Name packetName3("/SecurityTestConfChecker/HierarchicalCheckerTest1");
shared_ptr<Data> data1 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data1, identity);
+ m_keyChain.signByIdentity(*data1, identity);
shared_ptr<Data> data2 = make_shared<Data>(packetName2);
- keyChain.signByIdentity(*data2, identity);
+ m_keyChain.signByIdentity(*data2, identity);
shared_ptr<Data> data3 = make_shared<Data>(packetName3);
- keyChain.signByIdentity(*data3, identity);
+ m_keyChain.signByIdentity(*data3, identity);
shared_ptr<Data> data4 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data4, identity2);
+ m_keyChain.signByIdentity(*data4, identity2);
shared_ptr<Data> data5 = make_shared<Data>(packetName2);
- keyChain.signByIdentity(*data5, identity2);
+ m_keyChain.signByIdentity(*data5, identity2);
shared_ptr<Data> data6 = make_shared<Data>(packetName3);
- keyChain.signByIdentity(*data6, identity2);
+ m_keyChain.signByIdentity(*data6, identity2);
int8_t result = 0;
@@ -452,35 +438,29 @@
bind(dataCheckedFalse, _1),
bind(dataCheckFailedFalse, _1, _2));
BOOST_CHECK_EQUAL(result, -1);
-
-
- keyChain.deleteIdentity(identity);
- keyChain.deleteIdentity(identity2);
}
BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1)
{
using security::conf::FixedSignerChecker;
- KeyChain keyChain("sqlite3", "file");
-
- EcdsaKeyParams params;
-
Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
- Name certName = keyChain.createIdentity(identity, params);
- shared_ptr<IdentityCertificate> cert1 = keyChain.getCertificate(certName);
+ BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
+ shared_ptr<IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
- Name certName2 = keyChain.createIdentity(identity2);
- shared_ptr<IdentityCertificate> cert2 = keyChain.getCertificate(certName2);
+ BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
+ shared_ptr<IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
Name packetName("/Test/Data");
shared_ptr<Data> data1 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data1, identity);
+ m_keyChain.signByIdentity(*data1, identity);
shared_ptr<Data> data2 = make_shared<Data>(packetName);
- keyChain.signByIdentity(*data2, identity2);
+ m_keyChain.signByIdentity(*data2, identity2);
std::vector<shared_ptr<IdentityCertificate> > certSet1;
certSet1.push_back(cert1);
@@ -541,10 +521,6 @@
bind(dataChecked, _1),
bind(dataCheckFailed, _1, _2));
BOOST_CHECK_EQUAL(result, 1);
-
-
- keyChain.deleteIdentity(identity);
- keyChain.deleteIdentity(identity2);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit-tests/security/test-sec-rule.cpp b/tests/unit-tests/security/test-sec-rule.cpp
index 8686b2d..91f9b09 100644
--- a/tests/unit-tests/security/test-sec-rule.cpp
+++ b/tests/unit-tests/security/test-sec-rule.cpp
@@ -22,29 +22,28 @@
#include "security/sec-rule-specific.hpp"
#include "security/sec-rule-relative.hpp"
#include "security/key-chain.hpp"
+#include "identity-management-fixture.hpp"
#include "boost-test.hpp"
namespace ndn {
-BOOST_AUTO_TEST_SUITE(SecurityTestSecRule)
+BOOST_FIXTURE_TEST_SUITE(SecurityTestSecRule, security::IdentityManagementFixture)
BOOST_AUTO_TEST_CASE(SecRuleSpecificTest)
{
- KeyChain keyChain("sqlite3", "file");
-
Name rsaIdentity("/SecurityTestSecRule/Basic/Rsa");
- keyChain.createIdentity(rsaIdentity);
+ BOOST_REQUIRE(addIdentity(rsaIdentity, RsaKeyParams()));
Name ecdsaIdentity("/SecurityTestSecRule/Basic/Ecdsa");
- keyChain.createIdentity(ecdsaIdentity);
+ BOOST_REQUIRE(addIdentity(ecdsaIdentity, EcdsaKeyParams()));
Name dataName("SecurityTestSecRule/Basic");
Data rsaData(dataName);
- keyChain.signByIdentity(rsaData, rsaIdentity);
+ m_keyChain.signByIdentity(rsaData, rsaIdentity);
Data ecdsaData(dataName);
- keyChain.signByIdentity(ecdsaData, ecdsaIdentity);
+ m_keyChain.signByIdentity(ecdsaData, ecdsaIdentity);
Data sha256Data(dataName);
- keyChain.signWithSha256(sha256Data);
+ m_keyChain.signWithSha256(sha256Data);
shared_ptr<Regex> dataRegex =
make_shared<Regex>("^<SecurityTestSecRule><Basic>$");
@@ -59,27 +58,22 @@
BOOST_CHECK(rule.matchSignerName(rsaData));
BOOST_CHECK(rule.matchSignerName(ecdsaData));
BOOST_CHECK_EQUAL(rule.matchSignerName(sha256Data), false);
-
- keyChain.deleteIdentity(rsaIdentity);
- keyChain.deleteIdentity(ecdsaIdentity);
}
BOOST_AUTO_TEST_CASE(SecRuleRelativeTest)
{
- KeyChain keyChain("sqlite3", "file");
-
Name rsaIdentity("/SecurityTestSecRule/Basic/Rsa");
- keyChain.createIdentity(rsaIdentity);
+ BOOST_REQUIRE(addIdentity(rsaIdentity, RsaKeyParams()));
Name ecdsaIdentity("/SecurityTestSecRule/Basic/Ecdsa");
- keyChain.createIdentity(ecdsaIdentity);
+ BOOST_REQUIRE(addIdentity(ecdsaIdentity, EcdsaKeyParams()));
Name dataName("SecurityTestSecRule/Basic");
Data rsaData(dataName);
- keyChain.signByIdentity(rsaData, rsaIdentity);
+ m_keyChain.signByIdentity(rsaData, rsaIdentity);
Data ecdsaData(dataName);
- keyChain.signByIdentity(ecdsaData, ecdsaIdentity);
+ m_keyChain.signByIdentity(ecdsaData, ecdsaIdentity);
Data sha256Data(dataName);
- keyChain.signWithSha256(sha256Data);
+ m_keyChain.signWithSha256(sha256Data);
SecRuleRelative rule("^(<SecurityTestSecRule><Basic>)$",
"^(<SecurityTestSecRule><Basic>)<><KEY><><>$",
@@ -91,9 +85,6 @@
BOOST_CHECK(rule.matchSignerName(rsaData));
BOOST_CHECK(rule.matchSignerName(ecdsaData));
BOOST_CHECK_EQUAL(rule.matchSignerName(sha256Data), false);
-
- keyChain.deleteIdentity(rsaIdentity);
- keyChain.deleteIdentity(ecdsaIdentity);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit-tests/security/test-signed-interest.cpp b/tests/unit-tests/security/test-signed-interest.cpp
index 7c3084e..0435116 100644
--- a/tests/unit-tests/security/test-signed-interest.cpp
+++ b/tests/unit-tests/security/test-signed-interest.cpp
@@ -21,32 +21,27 @@
#include "security/key-chain.hpp"
#include "security/validator.hpp"
-
+#include "identity-management-fixture.hpp"
#include "boost-test.hpp"
-using namespace std;
namespace ndn {
-BOOST_AUTO_TEST_SUITE(SecurityTestSignedInterest)
+BOOST_FIXTURE_TEST_SUITE(SecurityTestSignedInterest, security::IdentityManagementFixture)
BOOST_AUTO_TEST_CASE(SignVerifyInterest)
{
- BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
- KeyChain keyChain("sqlite3", "file");
-
Name identityName("/TestSignedInterest/SignVerify");
identityName.appendVersion();
-
- Name certificateName;
- BOOST_REQUIRE_NO_THROW(certificateName = keyChain.createIdentity(identityName));
+ BOOST_REQUIRE(addIdentity(identityName, RsaKeyParams()));
+ Name certificateName = m_keyChain.getDefaultCertificateNameForIdentity(identityName);
Interest interest("/TestSignedInterest/SignVerify/Interest1");
- BOOST_CHECK_NO_THROW(keyChain.signByIdentity(interest, identityName));
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(interest, identityName));
usleep(100000);
Interest interest11("/TestSignedInterest/SignVerify/Interest1");
- BOOST_CHECK_NO_THROW(keyChain.signByIdentity(interest11, identityName));
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(interest11, identityName));
time::system_clock::TimePoint timestamp1 =
time::fromUnixTimestamp(
@@ -68,18 +63,13 @@
interest2.wireDecode(interestBlock);
shared_ptr<PublicKey> publicKey;
- BOOST_REQUIRE_NO_THROW(publicKey = keyChain.getPublicKeyFromTpm(
- keyChain.getDefaultKeyNameForIdentity(identityName)));
+ BOOST_REQUIRE_NO_THROW(publicKey = m_keyChain.getPublicKeyFromTpm(
+ m_keyChain.getDefaultKeyNameForIdentity(identityName)));
bool result = Validator::verifySignature(interest2, *publicKey);
BOOST_CHECK_EQUAL(result, true);
-
- keyChain.deleteIdentity(identityName);
}
-
-
-
BOOST_AUTO_TEST_SUITE_END()
} // namespace ndn
diff --git a/tests/unit-tests/security/test-validator.cpp b/tests/unit-tests/security/test-validator.cpp
index f917ae7..46bc6a3 100644
--- a/tests/unit-tests/security/test-validator.cpp
+++ b/tests/unit-tests/security/test-validator.cpp
@@ -22,14 +22,14 @@
#include "security/validator-null.hpp"
#include "security/key-chain.hpp"
#include "util/time.hpp"
-
+#include "identity-management-fixture.hpp"
#include "boost-test.hpp"
namespace ndn {
using std::string;
-BOOST_AUTO_TEST_SUITE(SecurityTestValidator)
+BOOST_FIXTURE_TEST_SUITE(SecurityTestValidator, security::IdentityManagementFixture)
void
onValidated(const shared_ptr<const Data>& data)
@@ -45,19 +45,15 @@
BOOST_AUTO_TEST_CASE(Null)
{
- BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
- KeyChain keyChain("sqlite3", "file");
-
Name identity("/TestValidator/Null");
identity.appendVersion();
-
- BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity));
+ BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
Name dataName = identity;
dataName.append("1");
shared_ptr<Data> data = make_shared<Data>(dataName);
- BOOST_CHECK_NO_THROW(keyChain.signByIdentity(*data, identity));
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(*data, identity));
ValidatorNull validator;
@@ -65,8 +61,6 @@
validator.validate(*data,
bind(&onValidated, _1),
bind(&onValidationFailed, _1, _2));
-
- keyChain.deleteIdentity(identity);
}
const uint8_t ecdsaSigInfo[] = {
@@ -94,27 +88,23 @@
BOOST_AUTO_TEST_CASE(RsaSignatureVerification)
{
- BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
- KeyChain keyChain("sqlite3", "file");
-
Name identity("/TestValidator/RsaSignatureVerification");
- BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity));
- Name keyName = keyChain.getDefaultKeyNameForIdentity(identity);
- shared_ptr<PublicKey> publicKey = keyChain.getPublicKey(keyName);
+ BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
+ Name keyName = m_keyChain.getDefaultKeyNameForIdentity(identity);
+ shared_ptr<PublicKey> publicKey = m_keyChain.getPublicKey(keyName);
Name identity2("/TestValidator/RsaSignatureVerification/id2");
- BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity2));
- Name keyName2 = keyChain.getDefaultKeyNameForIdentity(identity2);
- shared_ptr<PublicKey> publicKey2 = keyChain.getPublicKey(keyName2);
-
+ BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
+ Name keyName2 = m_keyChain.getDefaultKeyNameForIdentity(identity2);
+ shared_ptr<PublicKey> publicKey2 = m_keyChain.getPublicKey(keyName2);
Data data("/TestData/1");
- BOOST_CHECK_NO_THROW(keyChain.signByIdentity(data, identity));
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(data, identity));
BOOST_CHECK_EQUAL(Validator::verifySignature(data, *publicKey), true);
BOOST_CHECK_EQUAL(Validator::verifySignature(data, *publicKey2), false);
Interest interest("/TestInterest/1");
- BOOST_CHECK_NO_THROW(keyChain.signByIdentity(interest, identity));
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(interest, identity));
BOOST_CHECK_EQUAL(Validator::verifySignature(interest, *publicKey), true);
BOOST_CHECK_EQUAL(Validator::verifySignature(interest, *publicKey2), false);
@@ -124,9 +114,6 @@
Signature ecdsaSig(ecdsaSigInfoBlock, ecdsaSigValueBlock);
wrongData.setSignature(ecdsaSig);
BOOST_CHECK_EQUAL(Validator::verifySignature(wrongData, *publicKey), false);
-
- keyChain.deleteIdentity(identity);
- keyChain.deleteIdentity(identity2);
}
const uint8_t rsaSigInfo[] = {
@@ -160,36 +147,24 @@
BOOST_AUTO_TEST_CASE(EcdsaSignatureVerification)
{
- BOOST_REQUIRE_NO_THROW(KeyChain("sqlite3", "file"));
- KeyChain keyChain("sqlite3", "file");
-
Name identity("/TestValidator/EcdsaSignatureVerification");
- EcdsaKeyParams params;
- // BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity, params));
- try
- {
- keyChain.createIdentity(identity, params);
- }
- catch (std::runtime_error& e)
- {
- std::cerr << e.what() << std::endl;
- }
- Name keyName = keyChain.getDefaultKeyNameForIdentity(identity);
- shared_ptr<PublicKey> publicKey = keyChain.getPublicKey(keyName);
+ BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
+ Name keyName = m_keyChain.getDefaultKeyNameForIdentity(identity);
+ shared_ptr<PublicKey> publicKey = m_keyChain.getPublicKey(keyName);
Name identity2("/TestValidator/EcdsaSignatureVerification/id2");
- BOOST_REQUIRE_NO_THROW(keyChain.createIdentity(identity2, params));
- Name keyName2 = keyChain.getDefaultKeyNameForIdentity(identity2);
- shared_ptr<PublicKey> publicKey2 = keyChain.getPublicKey(keyName2);
+ BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
+ Name keyName2 = m_keyChain.getDefaultKeyNameForIdentity(identity2);
+ shared_ptr<PublicKey> publicKey2 = m_keyChain.getPublicKey(keyName2);
Data data("/TestData/1");
- BOOST_CHECK_NO_THROW(keyChain.signByIdentity(data, identity));
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(data, identity));
BOOST_CHECK_EQUAL(Validator::verifySignature(data, *publicKey), true);
BOOST_CHECK_EQUAL(Validator::verifySignature(data, *publicKey2), false);
Interest interest("/TestInterest/1");
- BOOST_CHECK_NO_THROW(keyChain.signByIdentity(interest, identity));
+ BOOST_CHECK_NO_THROW(m_keyChain.signByIdentity(interest, identity));
BOOST_CHECK_EQUAL(Validator::verifySignature(interest, *publicKey), true);
BOOST_CHECK_EQUAL(Validator::verifySignature(interest, *publicKey2), false);
@@ -199,35 +174,30 @@
Signature rsaSig(rsaSigInfoBlock, rsaSigValueBlock);
wrongData.setSignature(rsaSig);
BOOST_CHECK_EQUAL(Validator::verifySignature(wrongData, *publicKey), false);
-
- keyChain.deleteIdentity(identity);
- keyChain.deleteIdentity(identity2);
}
BOOST_AUTO_TEST_CASE(EcdsaSignatureVerification2)
{
- KeyChain keyChain("sqlite3", "file");
-
- EcdsaKeyParams params;
-
Name ecdsaIdentity("/SecurityTestValidator/EcdsaSignatureVerification2/ecdsa");
- Name ecdsaCertName = keyChain.createIdentity(ecdsaIdentity, params);
- shared_ptr<IdentityCertificate> ecdsaCert = keyChain.getCertificate(ecdsaCertName);
+ BOOST_REQUIRE(addIdentity(ecdsaIdentity, EcdsaKeyParams()));
+ Name ecdsaCertName = m_keyChain.getDefaultCertificateNameForIdentity(ecdsaIdentity);
+ shared_ptr<IdentityCertificate> ecdsaCert = m_keyChain.getCertificate(ecdsaCertName);
Name rsaIdentity("/SecurityTestValidator/EcdsaSignatureVerification2/rsa");
- Name rsaCertName = keyChain.createIdentity(rsaIdentity);
- shared_ptr<IdentityCertificate> rsaCert = keyChain.getCertificate(rsaCertName);
+ BOOST_REQUIRE(addIdentity(rsaIdentity, RsaKeyParams()));
+ Name rsaCertName = m_keyChain.getDefaultCertificateNameForIdentity(rsaIdentity);
+ shared_ptr<IdentityCertificate> rsaCert = m_keyChain.getCertificate(rsaCertName);
Name packetName("/Test/Packet/Name");
shared_ptr<Data> testDataRsa = make_shared<Data>(packetName);
- keyChain.signByIdentity(*testDataRsa, rsaIdentity);
+ m_keyChain.signByIdentity(*testDataRsa, rsaIdentity);
shared_ptr<Data> testDataEcdsa = make_shared<Data>(packetName);
- keyChain.signByIdentity(*testDataEcdsa, ecdsaIdentity);
+ m_keyChain.signByIdentity(*testDataEcdsa, ecdsaIdentity);
shared_ptr<Interest> testInterestRsa = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*testInterestRsa, rsaIdentity);
+ m_keyChain.signByIdentity(*testInterestRsa, rsaIdentity);
shared_ptr<Interest> testInterestEcdsa = make_shared<Interest>(packetName);
- keyChain.signByIdentity(*testInterestEcdsa, ecdsaIdentity);
+ m_keyChain.signByIdentity(*testInterestEcdsa, ecdsaIdentity);
BOOST_CHECK(Validator::verifySignature(*ecdsaCert, ecdsaCert->getPublicKeyInfo()));
BOOST_CHECK_EQUAL(Validator::verifySignature(*ecdsaCert, rsaCert->getPublicKeyInfo()), false);
@@ -245,9 +215,6 @@
BOOST_CHECK_EQUAL(Validator::verifySignature(*testInterestRsa, ecdsaCert->getPublicKeyInfo()),
false);
BOOST_CHECK(Validator::verifySignature(*testInterestRsa, rsaCert->getPublicKeyInfo()));
-
- keyChain.deleteIdentity(ecdsaIdentity);
- keyChain.deleteIdentity(rsaIdentity);
}
BOOST_AUTO_TEST_SUITE_END()