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