Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
| 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" |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 24 | #include "identity-management-fixture.hpp" |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 25 | #include "boost-test.hpp" |
| 26 | |
| 27 | namespace ndn { |
| 28 | |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 29 | BOOST_FIXTURE_TEST_SUITE(SecurityTestConfChecker, security::IdentityManagementFixture) |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 30 | |
| 31 | void |
| 32 | interestChecked(const shared_ptr<const Interest>& interest) |
| 33 | { |
| 34 | BOOST_CHECK(true); |
| 35 | } |
| 36 | |
| 37 | void |
| 38 | interestCheckFailed(const shared_ptr<const Interest>& interest, |
| 39 | const std::string& failureInfo) |
| 40 | { |
| 41 | std::cerr << failureInfo << std::endl; |
| 42 | BOOST_CHECK(false); |
| 43 | } |
| 44 | |
| 45 | void |
| 46 | interestCheckedFalse(const shared_ptr<const Interest>& interest) |
| 47 | { |
| 48 | BOOST_CHECK(false); |
| 49 | } |
| 50 | |
| 51 | void |
| 52 | interestCheckFailedFalse(const shared_ptr<const Interest>& interest, |
| 53 | const std::string& failureInfo) |
| 54 | { |
| 55 | BOOST_CHECK(true); |
| 56 | } |
| 57 | |
| 58 | void |
| 59 | dataChecked(const shared_ptr<const Data>& interest) |
| 60 | { |
| 61 | BOOST_CHECK(true); |
| 62 | } |
| 63 | |
| 64 | void |
| 65 | dataCheckFailed(const shared_ptr<const Data>& interest, |
| 66 | const std::string& failureInfo) |
| 67 | { |
| 68 | std::cerr << failureInfo << std::endl; |
| 69 | BOOST_CHECK(false); |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | dataCheckedFalse(const shared_ptr<const Data>& interest) |
| 74 | { |
| 75 | BOOST_CHECK(false); |
| 76 | } |
| 77 | |
| 78 | void |
| 79 | dataCheckFailedFalse(const shared_ptr<const Data>& interest, |
| 80 | const std::string& failureInfo) |
| 81 | { |
| 82 | BOOST_CHECK(true); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | BOOST_AUTO_TEST_CASE(CustomizedCheckerTest1) |
| 87 | { |
| 88 | using security::conf::CustomizedChecker; |
| 89 | using security::conf::KeyLocatorChecker; |
| 90 | using security::conf::RelationKeyLocatorNameChecker; |
| 91 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 92 | Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 93 | BOOST_REQUIRE(addIdentity(identity, RsaKeyParams())); |
| 94 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 95 | |
| 96 | Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 97 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 98 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 99 | |
| 100 | Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data"); |
| 101 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 102 | m_keyChain.signByIdentity(*data1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 103 | |
| 104 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 105 | m_keyChain.signByIdentity(*data2, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 106 | |
| 107 | shared_ptr<Interest> interest1 = make_shared<Interest>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 108 | m_keyChain.signByIdentity(*interest1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 109 | |
| 110 | shared_ptr<Interest> interest2 = make_shared<Interest>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 111 | m_keyChain.signByIdentity(*interest2, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 112 | |
| 113 | int8_t result = 0; |
| 114 | |
| 115 | |
| 116 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 = |
| 117 | make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1), |
| 118 | KeyLocatorChecker::RELATION_EQUAL); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 119 | CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 120 | |
| 121 | result = checker1.check(*data1, |
| 122 | bind(dataChecked, _1), |
| 123 | bind(dataCheckFailed, _1, _2)); |
| 124 | BOOST_CHECK_EQUAL(result, 0); |
| 125 | |
| 126 | result = checker1.check(*data2, |
| 127 | bind(dataCheckedFalse, _1), |
| 128 | bind(dataCheckFailedFalse, _1, _2)); |
| 129 | BOOST_CHECK_EQUAL(result, -1); |
| 130 | |
| 131 | result = checker1.check(*interest1, |
| 132 | bind(interestChecked, _1), |
| 133 | bind(interestCheckFailed, _1, _2)); |
| 134 | BOOST_CHECK_EQUAL(result, 0); |
| 135 | |
| 136 | result = checker1.check(*interest2, |
| 137 | bind(interestCheckedFalse, _1), |
| 138 | bind(interestCheckFailedFalse, _1, _2)); |
| 139 | BOOST_CHECK_EQUAL(result, -1); |
| 140 | |
| 141 | |
| 142 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual2 = |
| 143 | make_shared<RelationKeyLocatorNameChecker>(identity, |
| 144 | KeyLocatorChecker::RELATION_EQUAL); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 145 | CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 146 | |
| 147 | result = checker2.check(*data1, |
| 148 | bind(dataCheckedFalse, _1), |
| 149 | bind(dataCheckFailedFalse, _1, _2)); |
| 150 | BOOST_CHECK_EQUAL(result, -1); |
| 151 | |
| 152 | result = checker2.check(*interest1, |
| 153 | bind(interestCheckedFalse, _1), |
| 154 | bind(interestCheckFailedFalse, _1, _2)); |
| 155 | BOOST_CHECK_EQUAL(result, -1); |
| 156 | |
| 157 | |
| 158 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix1 = |
| 159 | make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1), |
| 160 | KeyLocatorChecker::RELATION_IS_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 161 | CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 162 | |
| 163 | result = checker3.check(*data1, |
| 164 | bind(dataChecked, _1), |
| 165 | bind(dataCheckFailed, _1, _2)); |
| 166 | BOOST_CHECK_EQUAL(result, 0); |
| 167 | |
| 168 | result = checker3.check(*data2, |
| 169 | bind(dataCheckedFalse, _1), |
| 170 | bind(dataCheckFailedFalse, _1, _2)); |
| 171 | BOOST_CHECK_EQUAL(result, -1); |
| 172 | |
| 173 | |
| 174 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix2 = |
| 175 | make_shared<RelationKeyLocatorNameChecker>(identity, |
| 176 | KeyLocatorChecker::RELATION_IS_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 177 | CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 178 | |
| 179 | result = checker4.check(*data1, |
| 180 | bind(dataChecked, _1), |
| 181 | bind(dataCheckFailed, _1, _2)); |
| 182 | BOOST_CHECK_EQUAL(result, 0); |
| 183 | |
| 184 | result = checker4.check(*data2, |
| 185 | bind(dataCheckedFalse, _1), |
| 186 | bind(dataCheckFailedFalse, _1, _2)); |
| 187 | BOOST_CHECK_EQUAL(result, -1); |
| 188 | |
| 189 | |
| 190 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict1 = |
| 191 | make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1), |
| 192 | KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 193 | CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 194 | |
| 195 | result = checker5.check(*data1, |
| 196 | bind(dataCheckedFalse, _1), |
| 197 | bind(dataCheckFailedFalse, _1, _2)); |
| 198 | BOOST_CHECK_EQUAL(result, -1); |
| 199 | |
| 200 | result = checker5.check(*data2, |
| 201 | bind(dataCheckedFalse, _1), |
| 202 | bind(dataCheckFailedFalse, _1, _2)); |
| 203 | BOOST_CHECK_EQUAL(result, -1); |
| 204 | |
| 205 | shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict2 = |
| 206 | make_shared<RelationKeyLocatorNameChecker>(identity, |
| 207 | KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 208 | CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 209 | |
| 210 | result = checker6.check(*data1, |
| 211 | bind(dataCheckedFalse, _1), |
| 212 | bind(dataCheckFailedFalse, _1, _2)); |
| 213 | BOOST_CHECK_EQUAL(result, 0); |
| 214 | |
| 215 | result = checker6.check(*data2, |
| 216 | bind(dataCheckedFalse, _1), |
| 217 | bind(dataCheckFailedFalse, _1, _2)); |
| 218 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2) |
| 222 | { |
| 223 | using security::conf::CustomizedChecker; |
| 224 | using security::conf::KeyLocatorChecker; |
| 225 | using security::conf::RegexKeyLocatorNameChecker; |
| 226 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 227 | Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 228 | BOOST_REQUIRE(addIdentity(identity, RsaKeyParams())); |
| 229 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 230 | |
| 231 | Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 232 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 233 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 234 | |
| 235 | Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data"); |
| 236 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 237 | m_keyChain.signByIdentity(*data1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 238 | |
| 239 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 240 | m_keyChain.signByIdentity(*data2, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 241 | |
| 242 | shared_ptr<Interest> interest1 = make_shared<Interest>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 243 | m_keyChain.signByIdentity(*interest1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 244 | |
| 245 | shared_ptr<Interest> interest2 = make_shared<Interest>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 246 | m_keyChain.signByIdentity(*interest2, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 247 | |
| 248 | int8_t result = 0; |
| 249 | |
| 250 | |
| 251 | shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 = |
| 252 | make_shared<RegexKeyLocatorNameChecker>( |
| 253 | Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>")); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 254 | CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 255 | |
| 256 | result = checker1.check(*data1, |
| 257 | bind(dataChecked, _1), |
| 258 | bind(dataCheckFailed, _1, _2)); |
| 259 | BOOST_CHECK_EQUAL(result, 0); |
| 260 | |
| 261 | result = checker1.check(*data2, |
| 262 | bind(dataCheckedFalse, _1), |
| 263 | bind(dataCheckFailedFalse, _1, _2)); |
| 264 | BOOST_CHECK_EQUAL(result, -1); |
| 265 | |
| 266 | result = checker1.check(*interest1, |
| 267 | bind(interestChecked, _1), |
| 268 | bind(interestCheckFailed, _1, _2)); |
| 269 | BOOST_CHECK_EQUAL(result, 0); |
| 270 | |
| 271 | result = checker1.check(*interest2, |
| 272 | bind(interestCheckedFalse, _1), |
| 273 | bind(interestCheckFailedFalse, _1, _2)); |
| 274 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3) |
| 278 | { |
| 279 | using security::conf::CustomizedChecker; |
| 280 | using security::conf::KeyLocatorChecker; |
| 281 | using security::conf::RegexKeyLocatorNameChecker; |
| 282 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 283 | Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 284 | BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams())); |
| 285 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 286 | |
| 287 | Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 288 | BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams())); |
| 289 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 290 | |
| 291 | Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data"); |
| 292 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 293 | m_keyChain.signByIdentity(*data1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 294 | |
| 295 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 296 | m_keyChain.signByIdentity(*data2, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 297 | |
| 298 | shared_ptr<Interest> interest1 = make_shared<Interest>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 299 | m_keyChain.signByIdentity(*interest1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 300 | |
| 301 | shared_ptr<Interest> interest2 = make_shared<Interest>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 302 | m_keyChain.signByIdentity(*interest2, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 303 | |
| 304 | int8_t result = 0; |
| 305 | |
| 306 | |
| 307 | shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 = |
| 308 | make_shared<RegexKeyLocatorNameChecker>( |
| 309 | Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>")); |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 310 | CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 311 | |
| 312 | result = checker1.check(*data1, |
| 313 | bind(dataChecked, _1), |
| 314 | bind(dataCheckFailed, _1, _2)); |
| 315 | BOOST_CHECK_EQUAL(result, 0); |
| 316 | |
| 317 | result = checker1.check(*data2, |
| 318 | bind(dataCheckedFalse, _1), |
| 319 | bind(dataCheckFailedFalse, _1, _2)); |
| 320 | BOOST_CHECK_EQUAL(result, -1); |
| 321 | |
| 322 | result = checker1.check(*interest1, |
| 323 | bind(interestChecked, _1), |
| 324 | bind(interestCheckFailed, _1, _2)); |
| 325 | BOOST_CHECK_EQUAL(result, 0); |
| 326 | |
| 327 | result = checker1.check(*interest2, |
| 328 | bind(interestCheckedFalse, _1), |
| 329 | bind(interestCheckFailedFalse, _1, _2)); |
| 330 | BOOST_CHECK_EQUAL(result, -1); |
| 331 | |
| 332 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 333 | CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 334 | |
| 335 | result = checker2.check(*data1, |
| 336 | bind(dataCheckedFalse, _1), |
| 337 | bind(dataCheckFailedFalse, _1, _2)); |
| 338 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1) |
| 342 | { |
| 343 | using security::conf::HierarchicalChecker; |
| 344 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 345 | Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 346 | BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams())); |
| 347 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 348 | |
| 349 | Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 350 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 351 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 352 | |
| 353 | Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data"); |
| 354 | Name packetName2("/SecurityTestConfChecker"); |
| 355 | Name packetName3("/SecurityTestConfChecker/HierarchicalCheckerTest1"); |
| 356 | |
| 357 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 358 | m_keyChain.signByIdentity(*data1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 359 | |
| 360 | shared_ptr<Data> data2 = make_shared<Data>(packetName2); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 361 | m_keyChain.signByIdentity(*data2, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 362 | |
| 363 | shared_ptr<Data> data3 = make_shared<Data>(packetName3); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 364 | m_keyChain.signByIdentity(*data3, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 365 | |
| 366 | shared_ptr<Data> data4 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 367 | m_keyChain.signByIdentity(*data4, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 368 | |
| 369 | shared_ptr<Data> data5 = make_shared<Data>(packetName2); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 370 | m_keyChain.signByIdentity(*data5, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 371 | |
| 372 | shared_ptr<Data> data6 = make_shared<Data>(packetName3); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 373 | m_keyChain.signByIdentity(*data6, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 374 | |
| 375 | int8_t result = 0; |
| 376 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 377 | HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 378 | |
| 379 | result = checker1.check(*data1, |
| 380 | bind(dataChecked, _1), |
| 381 | bind(dataCheckFailed, _1, _2)); |
| 382 | BOOST_CHECK_EQUAL(result, 0); |
| 383 | |
| 384 | result = checker1.check(*data2, |
| 385 | bind(dataCheckedFalse, _1), |
| 386 | bind(dataCheckFailedFalse, _1, _2)); |
| 387 | BOOST_CHECK_EQUAL(result, -1); |
| 388 | |
| 389 | result = checker1.check(*data3, |
| 390 | bind(dataChecked, _1), |
| 391 | bind(dataCheckFailed, _1, _2)); |
| 392 | BOOST_CHECK_EQUAL(result, 0); |
| 393 | |
| 394 | result = checker1.check(*data4, |
| 395 | bind(dataCheckedFalse, _1), |
| 396 | bind(dataCheckFailedFalse, _1, _2)); |
| 397 | BOOST_CHECK_EQUAL(result, -1); |
| 398 | |
| 399 | result = checker1.check(*data5, |
| 400 | bind(dataCheckedFalse, _1), |
| 401 | bind(dataCheckFailedFalse, _1, _2)); |
| 402 | BOOST_CHECK_EQUAL(result, -1); |
| 403 | |
| 404 | result = checker1.check(*data6, |
| 405 | bind(dataCheckedFalse, _1), |
| 406 | bind(dataCheckFailedFalse, _1, _2)); |
| 407 | BOOST_CHECK_EQUAL(result, -1); |
| 408 | |
| 409 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 410 | HierarchicalChecker checker2(tlv::SignatureSha256WithRsa); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 411 | |
| 412 | result = checker2.check(*data1, |
| 413 | bind(dataCheckedFalse, _1), |
| 414 | bind(dataCheckFailedFalse, _1, _2)); |
| 415 | BOOST_CHECK_EQUAL(result, -1); |
| 416 | |
| 417 | result = checker2.check(*data2, |
| 418 | bind(dataCheckedFalse, _1), |
| 419 | bind(dataCheckFailedFalse, _1, _2)); |
| 420 | BOOST_CHECK_EQUAL(result, -1); |
| 421 | |
| 422 | result = checker2.check(*data3, |
| 423 | bind(dataCheckedFalse, _1), |
| 424 | bind(dataCheckFailedFalse, _1, _2)); |
| 425 | BOOST_CHECK_EQUAL(result, -1); |
| 426 | |
| 427 | result = checker2.check(*data4, |
| 428 | bind(dataChecked, _1), |
| 429 | bind(dataCheckFailed, _1, _2)); |
| 430 | BOOST_CHECK_EQUAL(result, 0); |
| 431 | |
| 432 | result = checker2.check(*data5, |
| 433 | bind(dataCheckedFalse, _1), |
| 434 | bind(dataCheckFailedFalse, _1, _2)); |
| 435 | BOOST_CHECK_EQUAL(result, -1); |
| 436 | |
| 437 | result = checker2.check(*data6, |
| 438 | bind(dataCheckedFalse, _1), |
| 439 | bind(dataCheckFailedFalse, _1, _2)); |
| 440 | BOOST_CHECK_EQUAL(result, -1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1) |
| 444 | { |
| 445 | using security::conf::FixedSignerChecker; |
| 446 | |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 447 | Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 448 | BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams())); |
| 449 | Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity); |
| 450 | shared_ptr<IdentityCertificate> cert1 = m_keyChain.getCertificate(certName); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 451 | |
| 452 | Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong"); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 453 | BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams())); |
| 454 | Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2); |
| 455 | shared_ptr<IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 456 | |
| 457 | Name packetName("/Test/Data"); |
| 458 | |
| 459 | shared_ptr<Data> data1 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 460 | m_keyChain.signByIdentity(*data1, identity); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 461 | |
| 462 | shared_ptr<Data> data2 = make_shared<Data>(packetName); |
Yingdi Yu | 3ed09d0 | 2014-10-13 16:24:08 -0700 | [diff] [blame^] | 463 | m_keyChain.signByIdentity(*data2, identity2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 464 | |
| 465 | std::vector<shared_ptr<IdentityCertificate> > certSet1; |
| 466 | certSet1.push_back(cert1); |
| 467 | |
| 468 | std::vector<shared_ptr<IdentityCertificate> > certSet2; |
| 469 | certSet2.push_back(cert2); |
| 470 | |
| 471 | |
| 472 | int8_t result = 0; |
| 473 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 474 | FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 475 | |
| 476 | result = checker1.check(*data1, |
| 477 | bind(dataChecked, _1), |
| 478 | bind(dataCheckFailed, _1, _2)); |
| 479 | BOOST_CHECK_EQUAL(result, 1); |
| 480 | |
| 481 | result = checker1.check(*data2, |
| 482 | bind(dataCheckedFalse, _1), |
| 483 | bind(dataCheckFailedFalse, _1, _2)); |
| 484 | BOOST_CHECK_EQUAL(result, -1); |
| 485 | |
| 486 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 487 | FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 488 | |
| 489 | result = checker2.check(*data1, |
| 490 | bind(dataCheckedFalse, _1), |
| 491 | bind(dataCheckFailedFalse, _1, _2)); |
| 492 | BOOST_CHECK_EQUAL(result, -1); |
| 493 | |
| 494 | result = checker2.check(*data2, |
| 495 | bind(dataCheckedFalse, _1), |
| 496 | bind(dataCheckFailedFalse, _1, _2)); |
| 497 | BOOST_CHECK_EQUAL(result, -1); |
| 498 | |
| 499 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 500 | FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 501 | |
| 502 | result = checker3.check(*data1, |
| 503 | bind(dataCheckedFalse, _1), |
| 504 | bind(dataCheckFailedFalse, _1, _2)); |
| 505 | BOOST_CHECK_EQUAL(result, -1); |
| 506 | |
| 507 | result = checker3.check(*data2, |
| 508 | bind(dataCheckedFalse, _1), |
| 509 | bind(dataCheckFailedFalse, _1, _2)); |
| 510 | BOOST_CHECK_EQUAL(result, -1); |
| 511 | |
| 512 | |
Steve DiBenedetto | 54ce668 | 2014-07-22 13:22:57 -0600 | [diff] [blame] | 513 | FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 514 | |
| 515 | result = checker4.check(*data1, |
| 516 | bind(dataCheckedFalse, _1), |
| 517 | bind(dataCheckFailedFalse, _1, _2)); |
| 518 | BOOST_CHECK_EQUAL(result, -1); |
| 519 | |
| 520 | result = checker4.check(*data2, |
| 521 | bind(dataChecked, _1), |
| 522 | bind(dataCheckFailed, _1, _2)); |
| 523 | BOOST_CHECK_EQUAL(result, 1); |
Yingdi Yu | 5ec0ee3 | 2014-06-24 16:26:09 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | BOOST_AUTO_TEST_SUITE_END() |
| 527 | |
| 528 | } // namespace ndn |