Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 2 | /** |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | dfa52c4 | 2014-04-24 21:10:11 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 22 | #include "security/key-chain.hpp" |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 23 | #include "security/validator.hpp" |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 24 | #include "security/signing-helpers.hpp" |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 25 | |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 26 | #include "boost-test.hpp" |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 27 | #include "dummy-keychain.hpp" |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 28 | #include "../util/test-home-environment-fixture.hpp" |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 29 | #include "key-chain-fixture.hpp" |
| 30 | #include "identity-management-fixture.hpp" |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 31 | |
| 32 | #include <boost/filesystem.hpp> |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 33 | #include <boost/algorithm/string.hpp> |
| 34 | #include <fstream> |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 35 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 36 | namespace ndn { |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 37 | namespace security { |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 38 | namespace tests { |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 39 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 40 | using namespace ndn::tests; |
| 41 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 42 | BOOST_FIXTURE_TEST_SUITE(SecurityKeyChain, util::TestHomeEnvironmentFixture) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 44 | template<class Path> |
Alexander Afanasyev | cf49055 | 2016-06-27 22:51:36 -0700 | [diff] [blame^] | 45 | class TestHomeAndPibFixture : public TestHomeFixture<Path> |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 46 | { |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 47 | public: |
| 48 | TestHomeAndPibFixture() |
| 49 | { |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 50 | unsetenv("NDN_CLIENT_PIB"); |
| 51 | unsetenv("NDN_CLIENT_TPM"); |
| 52 | } |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | struct PibPathSqlite3File |
| 56 | { |
| 57 | const std::string PATH = "build/keys-sqlite3-file/"; |
| 58 | }; |
| 59 | |
| 60 | BOOST_FIXTURE_TEST_CASE(ConstructorNormalConfig, TestHomeAndPibFixture<PibPathSqlite3File>) |
| 61 | { |
| 62 | createClientConf({"pib=pib-sqlite3:%PATH%", "tpm=tpm-file:%PATH%"}); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 63 | |
| 64 | BOOST_REQUIRE_NO_THROW(KeyChain()); |
| 65 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 66 | KeyChain keyChain; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 67 | BOOST_CHECK_EQUAL(keyChain.getPib().getPibLocator(), "pib-sqlite3:" + m_pibDir); |
| 68 | BOOST_CHECK_EQUAL(keyChain.getPib().getTpmLocator(), "tpm-file:" + m_pibDir); |
| 69 | BOOST_CHECK_EQUAL(keyChain.getTpm().getTpmLocator(), "tpm-file:" + m_pibDir); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 72 | struct PibPathSqlite3Empty |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 73 | { |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 74 | const std::string PATH = "build/keys-sqlite3-empty/"; |
| 75 | }; |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 77 | BOOST_FIXTURE_TEST_CASE(ConstructorEmptyConfig, TestHomeAndPibFixture<PibPathSqlite3Empty>) |
| 78 | { |
| 79 | createClientConf({"pib=pib-sqlite3:%PATH%"}); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 80 | |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 81 | #if defined(NDN_CXX_HAVE_OSX_SECURITY) |
| 82 | std::string oldHOME; |
| 83 | if (std::getenv("OLD_HOME")) |
| 84 | oldHOME = std::getenv("OLD_HOME"); |
| 85 | |
| 86 | std::string HOME; |
| 87 | if (std::getenv("HOME")) |
| 88 | HOME = std::getenv("HOME"); |
| 89 | |
| 90 | if (!oldHOME.empty()) |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 91 | setenv("HOME", oldHOME.c_str(), true); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 92 | else |
| 93 | unsetenv("HOME"); |
| 94 | #endif |
| 95 | |
| 96 | BOOST_REQUIRE_NO_THROW(KeyChain()); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 97 | KeyChain keyChain; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 98 | BOOST_CHECK_EQUAL(keyChain.getPib().getPibLocator(), "pib-sqlite3:" + m_pibDir); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 99 | |
| 100 | #if defined(NDN_CXX_HAVE_OSX_SECURITY) |
| 101 | BOOST_CHECK_EQUAL(keyChain.getPib().getTpmLocator(), "tpm-osxkeychain:"); |
| 102 | BOOST_CHECK_EQUAL(keyChain.getTpm().getTpmLocator(), "tpm-osxkeychain:"); |
| 103 | #else |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 104 | BOOST_CHECK_EQUAL(keyChain.getPib().getTpmLocator(), "tpm-file:"); |
| 105 | BOOST_CHECK_EQUAL(keyChain.getTpm().getTpmLocator(), "tpm-file:"); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 106 | #endif |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 107 | |
| 108 | #if defined(NDN_CXX_HAVE_OSX_SECURITY) |
| 109 | if (!HOME.empty()) |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 110 | setenv("HOME", HOME.c_str(), true); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 111 | else |
| 112 | unsetenv("HOME"); |
| 113 | #endif |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 116 | struct PibPathEmptyFile |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 117 | { |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 118 | const std::string PATH = "build/keys-empty-file/"; |
| 119 | }; |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 120 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 121 | BOOST_FIXTURE_TEST_CASE(ConstructorEmpty2Config, TestHomeAndPibFixture<PibPathEmptyFile>) |
| 122 | { |
| 123 | createClientConf({"tpm=tpm-file:%PATH%"}); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 124 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 125 | BOOST_REQUIRE_NO_THROW(KeyChain()); |
| 126 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 127 | KeyChain keyChain; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(keyChain.getPib().getPibLocator(), "pib-sqlite3:"); |
| 129 | BOOST_CHECK_EQUAL(keyChain.getPib().getTpmLocator(), "tpm-file:" + m_pibDir); |
| 130 | BOOST_CHECK_EQUAL(keyChain.getTpm().getTpmLocator(), "tpm-file:" + m_pibDir); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 133 | BOOST_FIXTURE_TEST_CASE(ConstructorMalConfig, TestHomeAndPibFixture<DefaultPibDir>) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 134 | { |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 135 | createClientConf({"pib=lord", "tpm=ring"}); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 136 | |
| 137 | BOOST_REQUIRE_THROW(KeyChain(), KeyChain::Error); // Wrong configuration. Error expected. |
| 138 | } |
| 139 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 140 | BOOST_FIXTURE_TEST_CASE(ConstructorMal2Config, TestHomeAndPibFixture<DefaultPibDir>) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 141 | { |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 142 | createClientConf({"pib=pib-sqlite3:%PATH%", "tpm=just-wrong"}); |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 143 | BOOST_REQUIRE_THROW(KeyChain(), KeyChain::Error); // Wrong configuration. Error expected. |
| 144 | } |
| 145 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 146 | BOOST_FIXTURE_TEST_CASE(ExportIdentity, IdentityManagementFixture) |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 147 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 148 | Name identity("/TestKeyChain/ExportIdentity/"); |
| 149 | identity.appendVersion(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 150 | addIdentity(identity); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 151 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 152 | shared_ptr<SecuredBag> exported = m_keyChain.exportIdentity(identity, "1234"); |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame] | 153 | |
| 154 | Block block = exported->wireEncode(); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 155 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 156 | Name keyName = m_keyChain.getDefaultKeyNameForIdentity(identity); |
| 157 | Name certName = m_keyChain.getDefaultCertificateNameForKey(keyName); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 158 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 159 | m_keyChain.deleteIdentity(identity); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 160 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 161 | BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(identity), false); |
| 162 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName), false); |
| 163 | BOOST_CHECK_EQUAL(m_keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE), false); |
| 164 | BOOST_CHECK_EQUAL(m_keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC), false); |
| 165 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName), false); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 166 | |
Yingdi Yu | 64c3fb4 | 2014-02-26 17:30:04 -0800 | [diff] [blame] | 167 | SecuredBag imported; |
| 168 | imported.wireDecode(block); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 169 | m_keyChain.importIdentity(imported, "1234"); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 170 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 171 | BOOST_CHECK(m_keyChain.doesIdentityExist(identity)); |
| 172 | BOOST_CHECK(m_keyChain.doesPublicKeyExist(keyName)); |
| 173 | BOOST_CHECK(m_keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PRIVATE)); |
| 174 | BOOST_CHECK(m_keyChain.doesKeyExistInTpm(keyName, KEY_CLASS_PUBLIC)); |
| 175 | BOOST_CHECK(m_keyChain.doesCertificateExist(certName)); |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 178 | BOOST_FIXTURE_TEST_CASE(PrepareIdentityCertificate, IdentityManagementFixture) |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 179 | { |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 180 | Name identity("/TestKeyChain/PrepareIdentityCertificate/"); |
| 181 | identity.appendVersion(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 182 | addIdentity(identity); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 183 | |
Junxiao Shi | 8ca4325 | 2015-06-11 21:29:43 -0700 | [diff] [blame] | 184 | std::vector<CertificateSubjectDescription> subjectDescription; |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 185 | Name lowerIdentity = identity; |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 186 | lowerIdentity.append("Lower").appendVersion(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 187 | Name lowerKeyName = m_keyChain.generateRsaKeyPair(lowerIdentity, true); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 188 | shared_ptr<IdentityCertificate> idCert = |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 189 | m_keyChain.prepareUnsignedIdentityCertificate(lowerKeyName, identity, |
| 190 | time::system_clock::now(), |
| 191 | time::system_clock::now() + time::days(365), |
| 192 | subjectDescription); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 193 | BOOST_CHECK(static_cast<bool>(idCert)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 194 | BOOST_CHECK_EQUAL(idCert->getName().getPrefix(5), |
| 195 | Name().append(identity).append("KEY").append("Lower")); |
Junxiao Shi | 8ca4325 | 2015-06-11 21:29:43 -0700 | [diff] [blame] | 196 | BOOST_CHECK(idCert->getFreshnessPeriod() >= time::milliseconds::zero()); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 197 | |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 198 | shared_ptr<IdentityCertificate> idCert11 = |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 199 | m_keyChain.prepareUnsignedIdentityCertificate(lowerKeyName, identity, |
| 200 | time::system_clock::now(), |
| 201 | time::system_clock::now() + time::days(365), |
| 202 | subjectDescription, |
| 203 | lowerIdentity); |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 204 | BOOST_CHECK(static_cast<bool>(idCert11)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 205 | BOOST_CHECK_EQUAL(idCert11->getName().getPrefix(6), |
Yingdi Yu | 0eb5d72 | 2014-06-10 15:06:25 -0700 | [diff] [blame] | 206 | Name().append(lowerIdentity).append("KEY")); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 207 | |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 208 | Name anotherIdentity("/TestKeyChain/PrepareIdentityCertificate/Another/"); |
| 209 | anotherIdentity.appendVersion(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 210 | Name anotherKeyName = m_keyChain.generateRsaKeyPair(anotherIdentity, true); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 211 | shared_ptr<IdentityCertificate> idCert2 = |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 212 | m_keyChain.prepareUnsignedIdentityCertificate(anotherKeyName, identity, |
| 213 | time::system_clock::now(), |
| 214 | time::system_clock::now() + time::days(365), |
| 215 | subjectDescription); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 216 | BOOST_CHECK(static_cast<bool>(idCert2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 217 | BOOST_CHECK_EQUAL(idCert2->getName().getPrefix(5), Name().append(anotherIdentity).append("KEY")); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 218 | |
| 219 | |
| 220 | Name wrongKeyName1; |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 221 | shared_ptr<IdentityCertificate> idCert3 = |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 222 | m_keyChain.prepareUnsignedIdentityCertificate(wrongKeyName1, identity, |
| 223 | time::system_clock::now(), |
| 224 | time::system_clock::now() + time::days(365), |
| 225 | subjectDescription); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 226 | BOOST_CHECK_EQUAL(static_cast<bool>(idCert3), false); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 227 | |
| 228 | |
| 229 | Name wrongKeyName2("/TestKeyChain/PrepareIdentityCertificate"); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 230 | shared_ptr<IdentityCertificate> idCert4 = |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 231 | m_keyChain.prepareUnsignedIdentityCertificate(wrongKeyName2, identity, |
| 232 | time::system_clock::now(), |
| 233 | time::system_clock::now() + time::days(365), |
| 234 | subjectDescription); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 235 | BOOST_CHECK_EQUAL(static_cast<bool>(idCert4), false); |
Alexander Afanasyev | b1db7c6 | 2014-04-03 14:57:25 -0700 | [diff] [blame] | 236 | |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 237 | |
| 238 | Name wrongKeyName3("/TestKeyChain/PrepareIdentityCertificate/ksk-1234"); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 239 | shared_ptr<IdentityCertificate> idCert5 = |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 240 | m_keyChain.prepareUnsignedIdentityCertificate(wrongKeyName3, identity, |
| 241 | time::system_clock::now(), |
| 242 | time::system_clock::now() + time::days(365), |
| 243 | subjectDescription); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 244 | BOOST_CHECK_EQUAL(static_cast<bool>(idCert5), false); |
Yingdi Yu | c55680b | 2014-02-26 12:31:35 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 247 | BOOST_FIXTURE_TEST_CASE(Delete, IdentityManagementFixture) |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 248 | { |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 249 | Name identity("/TestSecPublicInfoSqlite3/Delete"); |
| 250 | identity.appendVersion(); |
| 251 | |
| 252 | Name certName1; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 253 | BOOST_REQUIRE_NO_THROW(certName1 = m_keyChain.createIdentity(identity)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 254 | |
| 255 | Name keyName1 = IdentityCertificate::certificateNameToPublicKeyName(certName1); |
| 256 | Name keyName2; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 257 | BOOST_REQUIRE_NO_THROW(keyName2 = m_keyChain.generateRsaKeyPairAsDefault(identity)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 258 | |
| 259 | shared_ptr<IdentityCertificate> cert2; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 260 | BOOST_REQUIRE_NO_THROW(cert2 = m_keyChain.selfSign(keyName2)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 261 | Name certName2 = cert2->getName(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 262 | BOOST_REQUIRE_NO_THROW(m_keyChain.addCertificateAsKeyDefault(*cert2)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 263 | |
| 264 | Name keyName3; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 265 | BOOST_REQUIRE_NO_THROW(keyName3 = m_keyChain.generateRsaKeyPairAsDefault(identity)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 266 | |
| 267 | shared_ptr<IdentityCertificate> cert3; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 268 | BOOST_REQUIRE_NO_THROW(cert3 = m_keyChain.selfSign(keyName3)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 269 | Name certName3 = cert3->getName(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 270 | BOOST_REQUIRE_NO_THROW(m_keyChain.addCertificateAsKeyDefault(*cert3)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 271 | shared_ptr<IdentityCertificate> cert4; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 272 | BOOST_REQUIRE_NO_THROW(cert4 = m_keyChain.selfSign(keyName3)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 273 | Name certName4 = cert4->getName(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 274 | BOOST_REQUIRE_NO_THROW(m_keyChain.addCertificateAsKeyDefault(*cert4)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 275 | shared_ptr<IdentityCertificate> cert5; |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 276 | BOOST_REQUIRE_NO_THROW(cert5 = m_keyChain.selfSign(keyName3)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 277 | Name certName5 = cert5->getName(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 278 | BOOST_REQUIRE_NO_THROW(m_keyChain.addCertificateAsKeyDefault(*cert5)); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 279 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 280 | BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(identity), true); |
| 281 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName1), true); |
| 282 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName2), true); |
| 283 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName3), true); |
| 284 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName1), true); |
| 285 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName2), true); |
| 286 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName3), true); |
| 287 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName4), true); |
| 288 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName5), true); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 289 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 290 | BOOST_REQUIRE_NO_THROW(m_keyChain.deleteCertificate(certName5)); |
| 291 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName5), false); |
| 292 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName3), true); |
| 293 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName4), true); |
| 294 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName3), true); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 295 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 296 | BOOST_REQUIRE_NO_THROW(m_keyChain.deleteKey(keyName3)); |
| 297 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName4), false); |
| 298 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName3), false); |
| 299 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName3), false); |
| 300 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName2), true); |
| 301 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName1), true); |
| 302 | BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(identity), true); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 303 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 304 | BOOST_REQUIRE_NO_THROW(m_keyChain.deleteIdentity(identity)); |
| 305 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName2), false); |
| 306 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName2), false); |
| 307 | BOOST_CHECK_EQUAL(m_keyChain.doesCertificateExist(certName1), false); |
| 308 | BOOST_CHECK_EQUAL(m_keyChain.doesPublicKeyExist(keyName1), false); |
| 309 | BOOST_CHECK_EQUAL(m_keyChain.doesIdentityExist(identity), false); |
Yingdi Yu | 4154634 | 2014-11-30 23:37:53 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 312 | BOOST_AUTO_TEST_CASE(KeyChainWithCustomTpmAndPib) |
| 313 | { |
| 314 | BOOST_REQUIRE_NO_THROW((KeyChain("pib-dummy", "tpm-dummy"))); |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 315 | BOOST_REQUIRE_NO_THROW((KeyChain("pib-dummy2", "tpm-dummy2"))); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 316 | BOOST_REQUIRE_NO_THROW((KeyChain("dummy", "dummy"))); |
| 317 | BOOST_REQUIRE_NO_THROW((KeyChain("dummy:", "dummy:"))); |
| 318 | BOOST_REQUIRE_NO_THROW((KeyChain("dummy:/something", "dummy:/something"))); |
| 319 | |
| 320 | KeyChain keyChain("dummy", "dummy"); |
Alexander Afanasyev | 34a3763 | 2015-01-16 17:37:36 -0800 | [diff] [blame] | 321 | BOOST_CHECK_EQUAL(keyChain.getPib().getPibLocator(), "pib-dummy:"); |
| 322 | BOOST_CHECK_EQUAL(keyChain.getPib().getTpmLocator(), "tpm-dummy:"); |
| 323 | BOOST_CHECK_EQUAL(keyChain.getTpm().getTpmLocator(), "tpm-dummy:"); |
Alexander Afanasyev | 0711380 | 2015-01-15 19:14:36 -0800 | [diff] [blame] | 324 | BOOST_CHECK_EQUAL(keyChain.getDefaultIdentity(), "/dummy/key"); |
| 325 | } |
| 326 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 327 | BOOST_FIXTURE_TEST_CASE(GeneralSigningInterface, IdentityManagementFixture) |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 328 | { |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 329 | Name id("/id"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 330 | Name certName = m_keyChain.createIdentity(id); |
| 331 | shared_ptr<IdentityCertificate> idCert = m_keyChain.getCertificate(certName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 332 | Name keyName = idCert->getPublicKeyName(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 333 | m_keyChain.setDefaultIdentity(id); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 334 | |
| 335 | Name id2("/id2"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 336 | Name cert2Name = m_keyChain.createIdentity(id2); |
| 337 | shared_ptr<IdentityCertificate> id2Cert = m_keyChain.getCertificate(cert2Name); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 338 | |
| 339 | // SigningInfo is set to default |
| 340 | Data data1("/data1"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 341 | m_keyChain.sign(data1); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 342 | BOOST_CHECK(Validator::verifySignature(data1, idCert->getPublicKeyInfo())); |
| 343 | BOOST_CHECK_EQUAL(data1.getSignature().getKeyLocator().getName(), certName.getPrefix(-1)); |
| 344 | |
| 345 | Interest interest1("/interest1"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 346 | m_keyChain.sign(interest1); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 347 | BOOST_CHECK(Validator::verifySignature(interest1, idCert->getPublicKeyInfo())); |
| 348 | SignatureInfo sigInfo1(interest1.getName()[-2].blockFromValue()); |
| 349 | BOOST_CHECK_EQUAL(sigInfo1.getKeyLocator().getName(), certName.getPrefix(-1)); |
| 350 | |
| 351 | // SigningInfo is set to Identity |
| 352 | Data data2("/data2"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 353 | m_keyChain.sign(data2, SigningInfo(SigningInfo::SIGNER_TYPE_ID, id2)); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 354 | BOOST_CHECK(Validator::verifySignature(data2, id2Cert->getPublicKeyInfo())); |
| 355 | BOOST_CHECK_EQUAL(data2.getSignature().getKeyLocator().getName(), cert2Name.getPrefix(-1)); |
| 356 | |
| 357 | Interest interest2("/interest2"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 358 | m_keyChain.sign(interest2, SigningInfo(SigningInfo::SIGNER_TYPE_ID, id2)); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 359 | BOOST_CHECK(Validator::verifySignature(interest2, id2Cert->getPublicKeyInfo())); |
| 360 | SignatureInfo sigInfo2(interest2.getName()[-2].blockFromValue()); |
| 361 | BOOST_CHECK_EQUAL(sigInfo2.getKeyLocator().getName(), cert2Name.getPrefix(-1)); |
| 362 | |
| 363 | // SigningInfo is set to Key |
| 364 | Data data3("/data3"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 365 | m_keyChain.sign(data3, SigningInfo(SigningInfo::SIGNER_TYPE_KEY, keyName)); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 366 | BOOST_CHECK(Validator::verifySignature(data3, idCert->getPublicKeyInfo())); |
| 367 | BOOST_CHECK_EQUAL(data3.getSignature().getKeyLocator().getName(), certName.getPrefix(-1)); |
| 368 | |
| 369 | Interest interest3("/interest3"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 370 | m_keyChain.sign(interest3); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 371 | BOOST_CHECK(Validator::verifySignature(interest3, idCert->getPublicKeyInfo())); |
| 372 | SignatureInfo sigInfo3(interest1.getName()[-2].blockFromValue()); |
| 373 | BOOST_CHECK_EQUAL(sigInfo3.getKeyLocator().getName(), certName.getPrefix(-1)); |
| 374 | |
| 375 | // SigningInfo is set to Cert |
| 376 | Data data4("/data4"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 377 | m_keyChain.sign(data4, SigningInfo(SigningInfo::SIGNER_TYPE_CERT, certName)); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 378 | BOOST_CHECK(Validator::verifySignature(data4, idCert->getPublicKeyInfo())); |
| 379 | BOOST_CHECK_EQUAL(data4.getSignature().getKeyLocator().getName(), certName.getPrefix(-1)); |
| 380 | |
| 381 | Interest interest4("/interest4"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 382 | m_keyChain.sign(interest4, SigningInfo(SigningInfo::SIGNER_TYPE_CERT, certName)); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 383 | BOOST_CHECK(Validator::verifySignature(interest4, idCert->getPublicKeyInfo())); |
| 384 | SignatureInfo sigInfo4(interest4.getName()[-2].blockFromValue()); |
| 385 | BOOST_CHECK_EQUAL(sigInfo4.getKeyLocator().getName(), certName.getPrefix(-1)); |
| 386 | |
| 387 | |
| 388 | // SigningInfo is set to DigestSha256 |
| 389 | Data data5("/data5"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 390 | m_keyChain.sign(data5, SigningInfo(SigningInfo::SIGNER_TYPE_SHA256)); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 391 | BOOST_CHECK(Validator::verifySignature(data5, DigestSha256(data5.getSignature()))); |
| 392 | |
| 393 | Interest interest5("/interest4"); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 394 | m_keyChain.sign(interest5, SigningInfo(SigningInfo::SIGNER_TYPE_SHA256)); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 395 | BOOST_CHECK(Validator::verifySignature(interest5, |
| 396 | DigestSha256(Signature(interest5.getName()[-2].blockFromValue(), |
| 397 | interest5.getName()[-1].blockFromValue())))); |
| 398 | } |
| 399 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 400 | BOOST_FIXTURE_TEST_CASE(EcdsaSigningByIdentityNoCert, IdentityManagementFixture) |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 401 | { |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 402 | Data data("/test/data"); |
| 403 | |
| 404 | Name nonExistingIdentity = Name("/non-existing/identity").appendVersion(); |
| 405 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 406 | BOOST_CHECK_NO_THROW(m_keyChain.sign(data, signingByIdentity(nonExistingIdentity))); |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 407 | BOOST_CHECK_EQUAL(data.getSignature().getType(), |
| 408 | KeyChain::getSignatureType(KeyChain::DEFAULT_KEY_PARAMS.getKeyType(), |
| 409 | DIGEST_ALGORITHM_SHA256)); |
| 410 | BOOST_CHECK(nonExistingIdentity.isPrefixOf(data.getSignature().getKeyLocator().getName())); |
| 411 | |
| 412 | Name ecdsaIdentity = Name("/ndn/test/ecdsa").appendVersion(); |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 413 | Name ecdsaKeyName = m_keyChain.generateEcdsaKeyPairAsDefault(ecdsaIdentity, false, 256); |
| 414 | BOOST_CHECK_NO_THROW(m_keyChain.sign(data, signingByIdentity(ecdsaIdentity))); |
José Quevedo | 641de4c | 2016-01-29 00:11:24 +0000 | [diff] [blame] | 415 | BOOST_CHECK_EQUAL(data.getSignature().getType(), |
| 416 | KeyChain::getSignatureType(EcdsaKeyParams().getKeyType(), DIGEST_ALGORITHM_SHA256)); |
| 417 | BOOST_CHECK(ecdsaIdentity.isPrefixOf(data.getSignature().getKeyLocator().getName())); |
| 418 | } |
| 419 | |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 420 | BOOST_AUTO_TEST_SUITE_END() |
| 421 | |
Yingdi Yu | f56c68f | 2014-04-24 21:50:13 -0700 | [diff] [blame] | 422 | } // namespace tests |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 423 | } // namespace security |
Yingdi Yu | 8dceb1d | 2014-02-18 12:45:10 -0800 | [diff] [blame] | 424 | } // namespace ndn |