blob: e9892370163ce0bfb3f6279ca67f8912caf1a88c [file] [log] [blame]
Yingdi Yu5ec0ee32014-06-24 16:26:09 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Spyridon Mastorakis429634f2015-02-19 17:35:33 -08003 * Copyright (c) 2013-2015 Regents of the University of California.
Yingdi Yu5ec0ee32014-06-24 16:26:09 -07004 *
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 Yu3ed09d02014-10-13 16:24:08 -070024#include "identity-management-fixture.hpp"
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070025#include "boost-test.hpp"
26
27namespace ndn {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080028namespace security {
29namespace conf {
30namespace tests {
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070031
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080032BOOST_FIXTURE_TEST_SUITE(SecurityConfChecker, IdentityManagementFixture)
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070033
34void
35interestChecked(const shared_ptr<const Interest>& interest)
36{
37 BOOST_CHECK(true);
38}
39
40void
41interestCheckFailed(const shared_ptr<const Interest>& interest,
42 const std::string& failureInfo)
43{
44 std::cerr << failureInfo << std::endl;
45 BOOST_CHECK(false);
46}
47
48void
49interestCheckedFalse(const shared_ptr<const Interest>& interest)
50{
51 BOOST_CHECK(false);
52}
53
54void
55interestCheckFailedFalse(const shared_ptr<const Interest>& interest,
56 const std::string& failureInfo)
57{
58 BOOST_CHECK(true);
59}
60
61void
62dataChecked(const shared_ptr<const Data>& interest)
63{
64 BOOST_CHECK(true);
65}
66
67void
68dataCheckFailed(const shared_ptr<const Data>& interest,
69 const std::string& failureInfo)
70{
71 std::cerr << failureInfo << std::endl;
72 BOOST_CHECK(false);
73}
74
75void
76dataCheckedFalse(const shared_ptr<const Data>& interest)
77{
78 BOOST_CHECK(false);
79}
80
81void
82dataCheckFailedFalse(const shared_ptr<const Data>& interest,
83 const std::string& failureInfo)
84{
85 BOOST_CHECK(true);
86}
87
88
89BOOST_AUTO_TEST_CASE(CustomizedCheckerTest1)
90{
91 using security::conf::CustomizedChecker;
92 using security::conf::KeyLocatorChecker;
93 using security::conf::RelationKeyLocatorNameChecker;
94
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070095 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -070096 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
97 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070098
99 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700100 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
101 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700102
103 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data");
104 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700105 m_keyChain.sign(*data1,
106 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
107 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700108
109 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700110 m_keyChain.sign(*data2,
111 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
112 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700113
114 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700115 m_keyChain.sign(*interest1,
116 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
117 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700118
119 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700120 m_keyChain.sign(*interest2,
121 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
122 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700123
124 int8_t result = 0;
125
126
127 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 =
128 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
129 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600130 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700131
132 result = checker1.check(*data1,
133 bind(dataChecked, _1),
134 bind(dataCheckFailed, _1, _2));
135 BOOST_CHECK_EQUAL(result, 0);
136
137 result = checker1.check(*data2,
138 bind(dataCheckedFalse, _1),
139 bind(dataCheckFailedFalse, _1, _2));
140 BOOST_CHECK_EQUAL(result, -1);
141
142 result = checker1.check(*interest1,
143 bind(interestChecked, _1),
144 bind(interestCheckFailed, _1, _2));
145 BOOST_CHECK_EQUAL(result, 0);
146
147 result = checker1.check(*interest2,
148 bind(interestCheckedFalse, _1),
149 bind(interestCheckFailedFalse, _1, _2));
150 BOOST_CHECK_EQUAL(result, -1);
151
152
153 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual2 =
154 make_shared<RelationKeyLocatorNameChecker>(identity,
155 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600156 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700157
158 result = checker2.check(*data1,
159 bind(dataCheckedFalse, _1),
160 bind(dataCheckFailedFalse, _1, _2));
161 BOOST_CHECK_EQUAL(result, -1);
162
163 result = checker2.check(*interest1,
164 bind(interestCheckedFalse, _1),
165 bind(interestCheckFailedFalse, _1, _2));
166 BOOST_CHECK_EQUAL(result, -1);
167
168
169 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix1 =
170 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
171 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600172 CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700173
174 result = checker3.check(*data1,
175 bind(dataChecked, _1),
176 bind(dataCheckFailed, _1, _2));
177 BOOST_CHECK_EQUAL(result, 0);
178
179 result = checker3.check(*data2,
180 bind(dataCheckedFalse, _1),
181 bind(dataCheckFailedFalse, _1, _2));
182 BOOST_CHECK_EQUAL(result, -1);
183
184
185 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix2 =
186 make_shared<RelationKeyLocatorNameChecker>(identity,
187 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600188 CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700189
190 result = checker4.check(*data1,
191 bind(dataChecked, _1),
192 bind(dataCheckFailed, _1, _2));
193 BOOST_CHECK_EQUAL(result, 0);
194
195 result = checker4.check(*data2,
196 bind(dataCheckedFalse, _1),
197 bind(dataCheckFailedFalse, _1, _2));
198 BOOST_CHECK_EQUAL(result, -1);
199
200
201 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict1 =
202 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
203 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600204 CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700205
206 result = checker5.check(*data1,
207 bind(dataCheckedFalse, _1),
208 bind(dataCheckFailedFalse, _1, _2));
209 BOOST_CHECK_EQUAL(result, -1);
210
211 result = checker5.check(*data2,
212 bind(dataCheckedFalse, _1),
213 bind(dataCheckFailedFalse, _1, _2));
214 BOOST_CHECK_EQUAL(result, -1);
215
216 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict2 =
217 make_shared<RelationKeyLocatorNameChecker>(identity,
218 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600219 CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700220
221 result = checker6.check(*data1,
222 bind(dataCheckedFalse, _1),
223 bind(dataCheckFailedFalse, _1, _2));
224 BOOST_CHECK_EQUAL(result, 0);
225
226 result = checker6.check(*data2,
227 bind(dataCheckedFalse, _1),
228 bind(dataCheckFailedFalse, _1, _2));
229 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700230}
231
232BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2)
233{
234 using security::conf::CustomizedChecker;
235 using security::conf::KeyLocatorChecker;
236 using security::conf::RegexKeyLocatorNameChecker;
237
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700238 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700239 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
240 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700241
242 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700243 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
244 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700245
246 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
247 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700248 m_keyChain.sign(*data1,
249 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
250 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700251
252 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700253 m_keyChain.sign(*data2,
254 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
255 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700256
257 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700258 m_keyChain.sign(*interest1,
259 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
260 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700261
262 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700263 m_keyChain.sign(*interest2,
264 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
265 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700266
267 int8_t result = 0;
268
269
270 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
271 make_shared<RegexKeyLocatorNameChecker>(
272 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600273 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700274
275 result = checker1.check(*data1,
276 bind(dataChecked, _1),
277 bind(dataCheckFailed, _1, _2));
278 BOOST_CHECK_EQUAL(result, 0);
279
280 result = checker1.check(*data2,
281 bind(dataCheckedFalse, _1),
282 bind(dataCheckFailedFalse, _1, _2));
283 BOOST_CHECK_EQUAL(result, -1);
284
285 result = checker1.check(*interest1,
286 bind(interestChecked, _1),
287 bind(interestCheckFailed, _1, _2));
288 BOOST_CHECK_EQUAL(result, 0);
289
290 result = checker1.check(*interest2,
291 bind(interestCheckedFalse, _1),
292 bind(interestCheckFailedFalse, _1, _2));
293 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700294}
295
296BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3)
297{
298 using security::conf::CustomizedChecker;
299 using security::conf::KeyLocatorChecker;
300 using security::conf::RegexKeyLocatorNameChecker;
301
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700302 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700303 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
304 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700305
306 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700307 BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
308 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700309
310 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
311 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700312 m_keyChain.sign(*data1,
313 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
314 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700315
316 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700317 m_keyChain.sign(*data2,
318 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
319 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700320
321 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700322 m_keyChain.sign(*interest1,
323 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
324 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700325
326 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700327 m_keyChain.sign(*interest2,
328 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
329 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700330
331 int8_t result = 0;
332
333
334 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
335 make_shared<RegexKeyLocatorNameChecker>(
336 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600337 CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700338
339 result = checker1.check(*data1,
340 bind(dataChecked, _1),
341 bind(dataCheckFailed, _1, _2));
342 BOOST_CHECK_EQUAL(result, 0);
343
344 result = checker1.check(*data2,
345 bind(dataCheckedFalse, _1),
346 bind(dataCheckFailedFalse, _1, _2));
347 BOOST_CHECK_EQUAL(result, -1);
348
349 result = checker1.check(*interest1,
350 bind(interestChecked, _1),
351 bind(interestCheckFailed, _1, _2));
352 BOOST_CHECK_EQUAL(result, 0);
353
354 result = checker1.check(*interest2,
355 bind(interestCheckedFalse, _1),
356 bind(interestCheckFailedFalse, _1, _2));
357 BOOST_CHECK_EQUAL(result, -1);
358
359
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600360 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700361
362 result = checker2.check(*data1,
363 bind(dataCheckedFalse, _1),
364 bind(dataCheckFailedFalse, _1, _2));
365 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700366}
367
368BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1)
369{
370 using security::conf::HierarchicalChecker;
371
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700372 Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700373 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
374 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700375
376 Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700377 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
378 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700379
380 Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
381 Name packetName2("/SecurityTestConfChecker");
382 Name packetName3("/SecurityTestConfChecker/HierarchicalCheckerTest1");
383
384 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700385 m_keyChain.sign(*data1,
386 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
387 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700388
389 shared_ptr<Data> data2 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700390 m_keyChain.sign(*data2,
391 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
392 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700393
394 shared_ptr<Data> data3 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700395 m_keyChain.sign(*data3,
396 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
397 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700398
399 shared_ptr<Data> data4 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700400 m_keyChain.sign(*data4,
401 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
402 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700403
404 shared_ptr<Data> data5 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700405 m_keyChain.sign(*data5,
406 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
407 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700408
409 shared_ptr<Data> data6 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700410 m_keyChain.sign(*data6,
411 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
412 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700413
414 int8_t result = 0;
415
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600416 HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700417
418 result = checker1.check(*data1,
419 bind(dataChecked, _1),
420 bind(dataCheckFailed, _1, _2));
421 BOOST_CHECK_EQUAL(result, 0);
422
423 result = checker1.check(*data2,
424 bind(dataCheckedFalse, _1),
425 bind(dataCheckFailedFalse, _1, _2));
426 BOOST_CHECK_EQUAL(result, -1);
427
428 result = checker1.check(*data3,
429 bind(dataChecked, _1),
430 bind(dataCheckFailed, _1, _2));
431 BOOST_CHECK_EQUAL(result, 0);
432
433 result = checker1.check(*data4,
434 bind(dataCheckedFalse, _1),
435 bind(dataCheckFailedFalse, _1, _2));
436 BOOST_CHECK_EQUAL(result, -1);
437
438 result = checker1.check(*data5,
439 bind(dataCheckedFalse, _1),
440 bind(dataCheckFailedFalse, _1, _2));
441 BOOST_CHECK_EQUAL(result, -1);
442
443 result = checker1.check(*data6,
444 bind(dataCheckedFalse, _1),
445 bind(dataCheckFailedFalse, _1, _2));
446 BOOST_CHECK_EQUAL(result, -1);
447
448
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600449 HierarchicalChecker checker2(tlv::SignatureSha256WithRsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700450
451 result = checker2.check(*data1,
452 bind(dataCheckedFalse, _1),
453 bind(dataCheckFailedFalse, _1, _2));
454 BOOST_CHECK_EQUAL(result, -1);
455
456 result = checker2.check(*data2,
457 bind(dataCheckedFalse, _1),
458 bind(dataCheckFailedFalse, _1, _2));
459 BOOST_CHECK_EQUAL(result, -1);
460
461 result = checker2.check(*data3,
462 bind(dataCheckedFalse, _1),
463 bind(dataCheckFailedFalse, _1, _2));
464 BOOST_CHECK_EQUAL(result, -1);
465
466 result = checker2.check(*data4,
467 bind(dataChecked, _1),
468 bind(dataCheckFailed, _1, _2));
469 BOOST_CHECK_EQUAL(result, 0);
470
471 result = checker2.check(*data5,
472 bind(dataCheckedFalse, _1),
473 bind(dataCheckFailedFalse, _1, _2));
474 BOOST_CHECK_EQUAL(result, -1);
475
476 result = checker2.check(*data6,
477 bind(dataCheckedFalse, _1),
478 bind(dataCheckFailedFalse, _1, _2));
479 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700480}
481
482BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1)
483{
484 using security::conf::FixedSignerChecker;
485
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700486 Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700487 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
488 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
489 shared_ptr<IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700490
491 Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700492 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
493 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
494 shared_ptr<IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700495
496 Name packetName("/Test/Data");
497
498 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700499 m_keyChain.sign(*data1,
500 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
501 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700502
503 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700504 m_keyChain.sign(*data2,
505 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
506 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700507
508 std::vector<shared_ptr<IdentityCertificate> > certSet1;
509 certSet1.push_back(cert1);
510
511 std::vector<shared_ptr<IdentityCertificate> > certSet2;
512 certSet2.push_back(cert2);
513
514
515 int8_t result = 0;
516
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600517 FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700518
519 result = checker1.check(*data1,
520 bind(dataChecked, _1),
521 bind(dataCheckFailed, _1, _2));
522 BOOST_CHECK_EQUAL(result, 1);
523
524 result = checker1.check(*data2,
525 bind(dataCheckedFalse, _1),
526 bind(dataCheckFailedFalse, _1, _2));
527 BOOST_CHECK_EQUAL(result, -1);
528
529
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600530 FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700531
532 result = checker2.check(*data1,
533 bind(dataCheckedFalse, _1),
534 bind(dataCheckFailedFalse, _1, _2));
535 BOOST_CHECK_EQUAL(result, -1);
536
537 result = checker2.check(*data2,
538 bind(dataCheckedFalse, _1),
539 bind(dataCheckFailedFalse, _1, _2));
540 BOOST_CHECK_EQUAL(result, -1);
541
542
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600543 FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700544
545 result = checker3.check(*data1,
546 bind(dataCheckedFalse, _1),
547 bind(dataCheckFailedFalse, _1, _2));
548 BOOST_CHECK_EQUAL(result, -1);
549
550 result = checker3.check(*data2,
551 bind(dataCheckedFalse, _1),
552 bind(dataCheckFailedFalse, _1, _2));
553 BOOST_CHECK_EQUAL(result, -1);
554
555
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600556 FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700557
558 result = checker4.check(*data1,
559 bind(dataCheckedFalse, _1),
560 bind(dataCheckFailedFalse, _1, _2));
561 BOOST_CHECK_EQUAL(result, -1);
562
563 result = checker4.check(*data2,
564 bind(dataChecked, _1),
565 bind(dataCheckFailed, _1, _2));
566 BOOST_CHECK_EQUAL(result, 1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700567}
568
569BOOST_AUTO_TEST_SUITE_END()
570
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800571} // namespace tests
572} // namespace conf
573} // namespace security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700574} // namespace ndn