Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2016 Regents of the University of California. |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 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. |
| 20 | */ |
| 21 | |
| 22 | #include "security/conf/checker.hpp" |
| 23 | #include "security/key-chain.hpp" |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame^] | 24 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 25 | #include "boost-test.hpp" |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame^] | 26 | #include "identity-management-fixture.hpp" |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 27 | |
| 28 | namespace ndn { |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 29 | namespace security { |
| 30 | namespace conf { |
| 31 | namespace tests { |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 32 | |
Alexander Afanasyev | e4f8c3b | 2016-06-23 16:03:48 -0700 | [diff] [blame] | 33 | using namespace ndn::tests; |
| 34 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame^] | 35 | BOOST_AUTO_TEST_SUITE(Security) |
| 36 | BOOST_AUTO_TEST_SUITE(Conf) |
| 37 | BOOST_FIXTURE_TEST_SUITE(TestChecker, IdentityManagementFixture) |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 38 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 39 | BOOST_AUTO_TEST_CASE(CustomizedCheckerTest1) |
| 40 | { |
| 41 | using security::conf::CustomizedChecker; |
| 42 | using security::conf::KeyLocatorChecker; |
| 43 | using security::conf::RelationKeyLocatorNameChecker; |
| 44 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 45 | Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 46 | BOOST_REQUIRE(addIdentity(identity, RsaKeyParams())); |
| 47 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 48 | |
| 49 | Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 50 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 51 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 52 | |
| 53 | Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data"); |
| 54 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 55 | m_keyChain.sign(*data1, |
| 56 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 57 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 58 | |
| 59 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 60 | m_keyChain.sign(*data2, |
| 61 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 62 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 63 | |
| 64 | shared_ptr<Interest> interest1 = make_shared<Interest>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 65 | m_keyChain.sign(*interest1, |
| 66 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 67 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 68 | |
| 69 | shared_ptr<Interest> interest2 = make_shared<Interest>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 70 | m_keyChain.sign(*interest2, |
| 71 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 72 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 73 | |
| 74 | int8_t result = 0; |
| 75 | |
| 76 | |
| 77 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 = |
| 78 | make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1), |
| 79 | KeyLocatorChecker::RELATION_EQUAL); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 80 | CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 81 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 82 | result = checker1.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL(result, 0); |
| 84 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 85 | result = checker1.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 86 | BOOST_CHECK_EQUAL(result, -1); |
| 87 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 88 | result = checker1.check(*interest1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 89 | BOOST_CHECK_EQUAL(result, 0); |
| 90 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 91 | result = checker1.check(*interest2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 92 | BOOST_CHECK_EQUAL(result, -1); |
| 93 | |
| 94 | |
| 95 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual2 = |
| 96 | make_shared<RelationKeyLocatorNameChecker>(identity, |
| 97 | KeyLocatorChecker::RELATION_EQUAL); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 98 | CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 99 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 100 | result = checker2.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 101 | BOOST_CHECK_EQUAL(result, -1); |
| 102 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 103 | result = checker2.check(*interest1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 104 | BOOST_CHECK_EQUAL(result, -1); |
| 105 | |
| 106 | |
| 107 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix1 = |
| 108 | make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1), |
| 109 | KeyLocatorChecker::RELATION_IS_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 110 | CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 111 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 112 | result = checker3.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 113 | BOOST_CHECK_EQUAL(result, 0); |
| 114 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 115 | result = checker3.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 116 | BOOST_CHECK_EQUAL(result, -1); |
| 117 | |
| 118 | |
| 119 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix2 = |
| 120 | make_shared<RelationKeyLocatorNameChecker>(identity, |
| 121 | KeyLocatorChecker::RELATION_IS_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 122 | CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 123 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 124 | result = checker4.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 125 | BOOST_CHECK_EQUAL(result, 0); |
| 126 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 127 | result = checker4.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 128 | BOOST_CHECK_EQUAL(result, -1); |
| 129 | |
| 130 | |
| 131 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict1 = |
| 132 | make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1), |
| 133 | KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 134 | CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 135 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 136 | result = checker5.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 137 | BOOST_CHECK_EQUAL(result, -1); |
| 138 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 139 | result = checker5.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 140 | BOOST_CHECK_EQUAL(result, -1); |
| 141 | |
| 142 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict2 = |
| 143 | make_shared<RelationKeyLocatorNameChecker>(identity, |
| 144 | KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 145 | CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 146 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 147 | result = checker6.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 148 | BOOST_CHECK_EQUAL(result, 0); |
| 149 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 150 | result = checker6.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 151 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2) |
| 155 | { |
| 156 | using security::conf::CustomizedChecker; |
| 157 | using security::conf::KeyLocatorChecker; |
| 158 | using security::conf::RegexKeyLocatorNameChecker; |
| 159 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 160 | Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 161 | BOOST_REQUIRE(addIdentity(identity, RsaKeyParams())); |
| 162 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 163 | |
| 164 | Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 165 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 166 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 167 | |
| 168 | Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data"); |
| 169 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 170 | m_keyChain.sign(*data1, |
| 171 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 172 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 173 | |
| 174 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 175 | m_keyChain.sign(*data2, |
| 176 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 177 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 178 | |
| 179 | shared_ptr<Interest> interest1 = make_shared<Interest>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 180 | m_keyChain.sign(*interest1, |
| 181 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 182 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 183 | |
| 184 | shared_ptr<Interest> interest2 = make_shared<Interest>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 185 | m_keyChain.sign(*interest2, |
| 186 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 187 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 188 | |
| 189 | int8_t result = 0; |
| 190 | |
| 191 | |
| 192 | shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 = |
| 193 | make_shared<RegexKeyLocatorNameChecker>( |
| 194 | Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>")); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 195 | CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 196 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 197 | result = checker1.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 198 | BOOST_CHECK_EQUAL(result, 0); |
| 199 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 200 | result = checker1.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 201 | BOOST_CHECK_EQUAL(result, -1); |
| 202 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 203 | result = checker1.check(*interest1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 204 | BOOST_CHECK_EQUAL(result, 0); |
| 205 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 206 | result = checker1.check(*interest2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 207 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3) |
| 211 | { |
| 212 | using security::conf::CustomizedChecker; |
| 213 | using security::conf::KeyLocatorChecker; |
| 214 | using security::conf::RegexKeyLocatorNameChecker; |
| 215 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 216 | Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 217 | BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams())); |
| 218 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 219 | |
| 220 | Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 221 | BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams())); |
| 222 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 223 | |
| 224 | Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data"); |
| 225 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 226 | m_keyChain.sign(*data1, |
| 227 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 228 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 229 | |
| 230 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 231 | m_keyChain.sign(*data2, |
| 232 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 233 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 234 | |
| 235 | shared_ptr<Interest> interest1 = make_shared<Interest>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 236 | m_keyChain.sign(*interest1, |
| 237 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 238 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 239 | |
| 240 | shared_ptr<Interest> interest2 = make_shared<Interest>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 241 | m_keyChain.sign(*interest2, |
| 242 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 243 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 244 | |
| 245 | int8_t result = 0; |
| 246 | |
| 247 | |
| 248 | shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 = |
| 249 | make_shared<RegexKeyLocatorNameChecker>( |
| 250 | Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>")); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 251 | CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 252 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 253 | result = checker1.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 254 | BOOST_CHECK_EQUAL(result, 0); |
| 255 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 256 | result = checker1.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 257 | BOOST_CHECK_EQUAL(result, -1); |
| 258 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 259 | result = checker1.check(*interest1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 260 | BOOST_CHECK_EQUAL(result, 0); |
| 261 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 262 | result = checker1.check(*interest2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 263 | BOOST_CHECK_EQUAL(result, -1); |
| 264 | |
| 265 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 266 | CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 267 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 268 | result = checker2.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 269 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1) |
| 273 | { |
| 274 | using security::conf::HierarchicalChecker; |
| 275 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 276 | Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 277 | BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams())); |
| 278 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 279 | |
| 280 | Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 281 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 282 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 283 | |
| 284 | Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data"); |
| 285 | Name packetName2("/SecurityTestConfChecker"); |
| 286 | Name packetName3("/SecurityTestConfChecker/HierarchicalCheckerTest1"); |
| 287 | |
| 288 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 289 | m_keyChain.sign(*data1, |
| 290 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 291 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 292 | |
| 293 | shared_ptr<Data> data2 = make_shared<Data>(packetName2); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 294 | m_keyChain.sign(*data2, |
| 295 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 296 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 297 | |
| 298 | shared_ptr<Data> data3 = make_shared<Data>(packetName3); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 299 | m_keyChain.sign(*data3, |
| 300 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 301 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 302 | |
| 303 | shared_ptr<Data> data4 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 304 | m_keyChain.sign(*data4, |
| 305 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 306 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 307 | |
| 308 | shared_ptr<Data> data5 = make_shared<Data>(packetName2); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 309 | m_keyChain.sign(*data5, |
| 310 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 311 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 312 | |
| 313 | shared_ptr<Data> data6 = make_shared<Data>(packetName3); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 314 | m_keyChain.sign(*data6, |
| 315 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 316 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 317 | |
| 318 | int8_t result = 0; |
| 319 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 320 | HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 321 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 322 | result = checker1.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 323 | BOOST_CHECK_EQUAL(result, 0); |
| 324 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 325 | result = checker1.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 326 | BOOST_CHECK_EQUAL(result, -1); |
| 327 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 328 | result = checker1.check(*data3); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 329 | BOOST_CHECK_EQUAL(result, 0); |
| 330 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 331 | result = checker1.check(*data4); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 332 | BOOST_CHECK_EQUAL(result, -1); |
| 333 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 334 | result = checker1.check(*data5); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 335 | BOOST_CHECK_EQUAL(result, -1); |
| 336 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 337 | result = checker1.check(*data6); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 338 | BOOST_CHECK_EQUAL(result, -1); |
| 339 | |
| 340 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 341 | HierarchicalChecker checker2(tlv::SignatureSha256WithRsa); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 342 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 343 | result = checker2.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 344 | BOOST_CHECK_EQUAL(result, -1); |
| 345 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 346 | result = checker2.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 347 | BOOST_CHECK_EQUAL(result, -1); |
| 348 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 349 | result = checker2.check(*data3); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 350 | BOOST_CHECK_EQUAL(result, -1); |
| 351 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 352 | result = checker2.check(*data4); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 353 | BOOST_CHECK_EQUAL(result, 0); |
| 354 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 355 | result = checker2.check(*data5); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 356 | BOOST_CHECK_EQUAL(result, -1); |
| 357 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 358 | result = checker2.check(*data6); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 359 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1) |
| 363 | { |
| 364 | using security::conf::FixedSignerChecker; |
| 365 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 366 | Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 367 | BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams())); |
| 368 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 369 | shared_ptr<v1::IdentityCertificate> cert1 = m_keyChain.getCertificate(certName); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 370 | |
| 371 | Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame] | 372 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 373 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 374 | shared_ptr<v1::IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 375 | |
| 376 | Name packetName("/Test/Data"); |
| 377 | |
| 378 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 379 | m_keyChain.sign(*data1, |
| 380 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 381 | identity)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 382 | |
| 383 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 1b0311c | 2015-06-10 14:58:47 -0700 | [diff] [blame] | 384 | m_keyChain.sign(*data2, |
| 385 | security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID, |
| 386 | identity2)); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 387 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 388 | std::vector<shared_ptr<v1::IdentityCertificate> > certSet1; |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 389 | certSet1.push_back(cert1); |
| 390 | |
Alexander Afanasyev | 2fa5939 | 2016-07-29 17:24:23 -0700 | [diff] [blame] | 391 | std::vector<shared_ptr<v1::IdentityCertificate> > certSet2; |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 392 | certSet2.push_back(cert2); |
| 393 | |
| 394 | |
| 395 | int8_t result = 0; |
| 396 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 397 | FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 398 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 399 | result = checker1.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 400 | BOOST_CHECK_EQUAL(result, 1); |
| 401 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 402 | result = checker1.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 403 | BOOST_CHECK_EQUAL(result, -1); |
| 404 | |
| 405 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 406 | FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 407 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 408 | result = checker2.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 409 | BOOST_CHECK_EQUAL(result, -1); |
| 410 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 411 | result = checker2.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 412 | BOOST_CHECK_EQUAL(result, -1); |
| 413 | |
| 414 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 415 | FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 416 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 417 | result = checker3.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 418 | BOOST_CHECK_EQUAL(result, -1); |
| 419 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 420 | result = checker3.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 421 | BOOST_CHECK_EQUAL(result, -1); |
| 422 | |
| 423 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 424 | FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 425 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 426 | result = checker4.check(*data1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 427 | BOOST_CHECK_EQUAL(result, -1); |
| 428 | |
Zhiyi Zhang | 044bb7e | 2016-06-10 00:02:37 -0700 | [diff] [blame] | 429 | result = checker4.check(*data2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 430 | BOOST_CHECK_EQUAL(result, 1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Davide Pesavento | eee3e82 | 2016-11-26 19:19:34 +0100 | [diff] [blame^] | 433 | BOOST_AUTO_TEST_SUITE_END() // TestChecker |
| 434 | BOOST_AUTO_TEST_SUITE_END() // Conf |
| 435 | BOOST_AUTO_TEST_SUITE_END() // Security |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 436 | |
Spyridon Mastorakis | 429634f | 2015-02-19 17:35:33 -0800 | [diff] [blame] | 437 | } // namespace tests |
| 438 | } // namespace conf |
| 439 | } // namespace security |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 440 | } // namespace ndn |