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