security: Support ECDSA verification in all related classes.
This commit also addresses some old issues, such as "using namespace std".
Change-Id: I62b8ff97fb2b6f6cfe04b0ad5866bc0797e6e43b
Refs: #1660
diff --git a/tests/unit-tests/security/test-validator.cpp b/tests/unit-tests/security/test-validator.cpp
index bd91280..f917ae7 100644
--- a/tests/unit-tests/security/test-validator.cpp
+++ b/tests/unit-tests/security/test-validator.cpp
@@ -25,10 +25,10 @@
#include "boost-test.hpp"
-using namespace std;
-
namespace ndn {
+using std::string;
+
BOOST_AUTO_TEST_SUITE(SecurityTestValidator)
void
@@ -204,6 +204,52 @@
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);
+
+ Name rsaIdentity("/SecurityTestValidator/EcdsaSignatureVerification2/rsa");
+ Name rsaCertName = keyChain.createIdentity(rsaIdentity);
+ shared_ptr<IdentityCertificate> rsaCert = keyChain.getCertificate(rsaCertName);
+
+ Name packetName("/Test/Packet/Name");
+
+ shared_ptr<Data> testDataRsa = make_shared<Data>(packetName);
+ keyChain.signByIdentity(*testDataRsa, rsaIdentity);
+ shared_ptr<Data> testDataEcdsa = make_shared<Data>(packetName);
+ keyChain.signByIdentity(*testDataEcdsa, ecdsaIdentity);
+ shared_ptr<Interest> testInterestRsa = make_shared<Interest>(packetName);
+ keyChain.signByIdentity(*testInterestRsa, rsaIdentity);
+ shared_ptr<Interest> testInterestEcdsa = make_shared<Interest>(packetName);
+ keyChain.signByIdentity(*testInterestEcdsa, ecdsaIdentity);
+
+ BOOST_CHECK(Validator::verifySignature(*ecdsaCert, ecdsaCert->getPublicKeyInfo()));
+ BOOST_CHECK_EQUAL(Validator::verifySignature(*ecdsaCert, rsaCert->getPublicKeyInfo()), false);
+ BOOST_CHECK_EQUAL(Validator::verifySignature(*rsaCert, ecdsaCert->getPublicKeyInfo()), false);
+ BOOST_CHECK(Validator::verifySignature(*rsaCert, rsaCert->getPublicKeyInfo()));
+
+ BOOST_CHECK(Validator::verifySignature(*testDataEcdsa, ecdsaCert->getPublicKeyInfo()));
+ BOOST_CHECK_EQUAL(Validator::verifySignature(*testDataEcdsa, rsaCert->getPublicKeyInfo()), false);
+ BOOST_CHECK_EQUAL(Validator::verifySignature(*testDataRsa, ecdsaCert->getPublicKeyInfo()), false);
+ BOOST_CHECK(Validator::verifySignature(*testDataRsa, rsaCert->getPublicKeyInfo()));
+
+ BOOST_CHECK(Validator::verifySignature(*testInterestEcdsa, ecdsaCert->getPublicKeyInfo()));
+ BOOST_CHECK_EQUAL(Validator::verifySignature(*testInterestEcdsa, rsaCert->getPublicKeyInfo()),
+ false);
+ 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()
} // namespace ndn