blob: ea26b0ccaf95d18b6e45407170575bc99052d24a [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 Yu3ed09d02014-10-13 16:24:08 -0700105 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700106
107 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700108 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700109
110 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700111 m_keyChain.signByIdentity(*interest1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700112
113 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700114 m_keyChain.signByIdentity(*interest2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700115
116 int8_t result = 0;
117
118
119 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 =
120 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
121 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600122 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700123
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600148 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700149
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600164 CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700165
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600180 CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700181
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600196 CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700197
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600211 CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700212
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 Yu5ec0ee32014-06-24 16:26:09 -0700222}
223
224BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2)
225{
226 using security::conf::CustomizedChecker;
227 using security::conf::KeyLocatorChecker;
228 using security::conf::RegexKeyLocatorNameChecker;
229
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700230 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700231 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
232 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700233
234 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700235 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
236 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700237
238 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
239 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700240 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700241
242 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700243 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700244
245 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700246 m_keyChain.signByIdentity(*interest1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700247
248 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700249 m_keyChain.signByIdentity(*interest2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700250
251 int8_t result = 0;
252
253
254 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
255 make_shared<RegexKeyLocatorNameChecker>(
256 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600257 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700258
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 Yu5ec0ee32014-06-24 16:26:09 -0700278}
279
280BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3)
281{
282 using security::conf::CustomizedChecker;
283 using security::conf::KeyLocatorChecker;
284 using security::conf::RegexKeyLocatorNameChecker;
285
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700286 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700287 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
288 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700289
290 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700291 BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
292 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700293
294 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
295 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700296 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700297
298 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700299 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700300
301 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700302 m_keyChain.signByIdentity(*interest1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700303
304 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700305 m_keyChain.signByIdentity(*interest2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700306
307 int8_t result = 0;
308
309
310 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
311 make_shared<RegexKeyLocatorNameChecker>(
312 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600313 CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700314
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600336 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700337
338 result = checker2.check(*data1,
339 bind(dataCheckedFalse, _1),
340 bind(dataCheckFailedFalse, _1, _2));
341 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700342}
343
344BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1)
345{
346 using security::conf::HierarchicalChecker;
347
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700348 Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700349 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
350 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700351
352 Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700353 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
354 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700355
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 Yu3ed09d02014-10-13 16:24:08 -0700361 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700362
363 shared_ptr<Data> data2 = make_shared<Data>(packetName2);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700364 m_keyChain.signByIdentity(*data2, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700365
366 shared_ptr<Data> data3 = make_shared<Data>(packetName3);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700367 m_keyChain.signByIdentity(*data3, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700368
369 shared_ptr<Data> data4 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700370 m_keyChain.signByIdentity(*data4, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700371
372 shared_ptr<Data> data5 = make_shared<Data>(packetName2);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700373 m_keyChain.signByIdentity(*data5, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700374
375 shared_ptr<Data> data6 = make_shared<Data>(packetName3);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700376 m_keyChain.signByIdentity(*data6, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700377
378 int8_t result = 0;
379
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600380 HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700381
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600413 HierarchicalChecker checker2(tlv::SignatureSha256WithRsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700414
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 Yu5ec0ee32014-06-24 16:26:09 -0700444}
445
446BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1)
447{
448 using security::conf::FixedSignerChecker;
449
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700450 Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700451 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
452 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
453 shared_ptr<IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700454
455 Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700456 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
457 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
458 shared_ptr<IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700459
460 Name packetName("/Test/Data");
461
462 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700463 m_keyChain.signByIdentity(*data1, identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700464
465 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700466 m_keyChain.signByIdentity(*data2, identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700467
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600477 FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700478
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600490 FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700491
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600503 FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700504
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 DiBenedetto54ce6682014-07-22 13:22:57 -0600516 FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700517
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 Yu5ec0ee32014-06-24 16:26:09 -0700527}
528
529BOOST_AUTO_TEST_SUITE_END()
530
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800531} // namespace tests
532} // namespace conf
533} // namespace security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700534} // namespace ndn