blob: f173436406f9be2d8e4e34c082d2353e66480838 [file] [log] [blame]
Yingdi Yu5ec0ee32014-06-24 16:26:09 -07001/* -*- 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 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 {
28
Yingdi Yu3ed09d02014-10-13 16:24:08 -070029BOOST_FIXTURE_TEST_SUITE(SecurityTestConfChecker, security::IdentityManagementFixture)
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070030
31void
32interestChecked(const shared_ptr<const Interest>& interest)
33{
34 BOOST_CHECK(true);
35}
36
37void
38interestCheckFailed(const shared_ptr<const Interest>& interest,
39 const std::string& failureInfo)
40{
41 std::cerr << failureInfo << std::endl;
42 BOOST_CHECK(false);
43}
44
45void
46interestCheckedFalse(const shared_ptr<const Interest>& interest)
47{
48 BOOST_CHECK(false);
49}
50
51void
52interestCheckFailedFalse(const shared_ptr<const Interest>& interest,
53 const std::string& failureInfo)
54{
55 BOOST_CHECK(true);
56}
57
58void
59dataChecked(const shared_ptr<const Data>& interest)
60{
61 BOOST_CHECK(true);
62}
63
64void
65dataCheckFailed(const shared_ptr<const Data>& interest,
66 const std::string& failureInfo)
67{
68 std::cerr << failureInfo << std::endl;
69 BOOST_CHECK(false);
70}
71
72void
73dataCheckedFalse(const shared_ptr<const Data>& interest)
74{
75 BOOST_CHECK(false);
76}
77
78void
79dataCheckFailedFalse(const shared_ptr<const Data>& interest,
80 const std::string& failureInfo)
81{
82 BOOST_CHECK(true);
83}
84
85
86BOOST_AUTO_TEST_CASE(CustomizedCheckerTest1)
87{
88 using security::conf::CustomizedChecker;
89 using security::conf::KeyLocatorChecker;
90 using security::conf::RelationKeyLocatorNameChecker;
91
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070092 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -070093 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
94 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070095
96 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -070097 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
98 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070099
100 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data");
101 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700102 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700103
104 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700105 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700106
107 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700108 m_keyChain.signByIdentity(*interest1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700109
110 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700111 m_keyChain.signByIdentity(*interest2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700112
113 int8_t result = 0;
114
115
116 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 =
117 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
118 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600119 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700120
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600145 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700146
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600161 CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700162
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600177 CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700178
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600193 CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700194
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600208 CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700209
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 Yu5ec0ee32014-06-24 16:26:09 -0700219}
220
221BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2)
222{
223 using security::conf::CustomizedChecker;
224 using security::conf::KeyLocatorChecker;
225 using security::conf::RegexKeyLocatorNameChecker;
226
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700227 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700228 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
229 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700230
231 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700232 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
233 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700234
235 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
236 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700237 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700238
239 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700240 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700241
242 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700243 m_keyChain.signByIdentity(*interest1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700244
245 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700246 m_keyChain.signByIdentity(*interest2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700247
248 int8_t result = 0;
249
250
251 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
252 make_shared<RegexKeyLocatorNameChecker>(
253 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600254 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700255
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 Yu5ec0ee32014-06-24 16:26:09 -0700275}
276
277BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3)
278{
279 using security::conf::CustomizedChecker;
280 using security::conf::KeyLocatorChecker;
281 using security::conf::RegexKeyLocatorNameChecker;
282
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700283 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700284 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
285 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700286
287 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700288 BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
289 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700290
291 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
292 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700293 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700294
295 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700296 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700297
298 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700299 m_keyChain.signByIdentity(*interest1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700300
301 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700302 m_keyChain.signByIdentity(*interest2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700303
304 int8_t result = 0;
305
306
307 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
308 make_shared<RegexKeyLocatorNameChecker>(
309 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600310 CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700311
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600333 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700334
335 result = checker2.check(*data1,
336 bind(dataCheckedFalse, _1),
337 bind(dataCheckFailedFalse, _1, _2));
338 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700339}
340
341BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1)
342{
343 using security::conf::HierarchicalChecker;
344
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700345 Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700346 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
347 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700348
349 Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700350 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
351 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700352
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 Yu3ed09d02014-10-13 16:24:08 -0700358 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700359
360 shared_ptr<Data> data2 = make_shared<Data>(packetName2);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700361 m_keyChain.signByIdentity(*data2, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700362
363 shared_ptr<Data> data3 = make_shared<Data>(packetName3);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700364 m_keyChain.signByIdentity(*data3, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700365
366 shared_ptr<Data> data4 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700367 m_keyChain.signByIdentity(*data4, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700368
369 shared_ptr<Data> data5 = make_shared<Data>(packetName2);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700370 m_keyChain.signByIdentity(*data5, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700371
372 shared_ptr<Data> data6 = make_shared<Data>(packetName3);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700373 m_keyChain.signByIdentity(*data6, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700374
375 int8_t result = 0;
376
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600377 HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700378
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600410 HierarchicalChecker checker2(tlv::SignatureSha256WithRsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700411
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 Yu5ec0ee32014-06-24 16:26:09 -0700441}
442
443BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1)
444{
445 using security::conf::FixedSignerChecker;
446
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700447 Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700448 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
449 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
450 shared_ptr<IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700451
452 Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700453 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
454 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
455 shared_ptr<IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700456
457 Name packetName("/Test/Data");
458
459 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700460 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700461
462 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700463 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700464
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600474 FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700475
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600487 FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700488
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600500 FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700501
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600513 FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700514
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 Yu5ec0ee32014-06-24 16:26:09 -0700524}
525
526BOOST_AUTO_TEST_SUITE_END()
527
528} // namespace ndn