blob: 5ba5ad856b3d773741d00899e0f5aba60bfd5314 [file] [log] [blame]
Yingdi Yu5ec0ee32014-06-24 16:26:09 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -07003 * Copyright (c) 2013-2016 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"
Davide Pesaventoeee3e822016-11-26 19:19:34 +010024
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070025#include "boost-test.hpp"
Davide Pesaventoeee3e822016-11-26 19:19:34 +010026#include "identity-management-fixture.hpp"
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070027
28namespace ndn {
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080029namespace security {
30namespace conf {
31namespace tests {
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070032
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070033using namespace ndn::tests;
34
Davide Pesaventoeee3e822016-11-26 19:19:34 +010035BOOST_AUTO_TEST_SUITE(Security)
36BOOST_AUTO_TEST_SUITE(Conf)
37BOOST_FIXTURE_TEST_SUITE(TestChecker, IdentityManagementFixture)
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070038
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070039BOOST_AUTO_TEST_CASE(CustomizedCheckerTest1)
40{
41 using security::conf::CustomizedChecker;
42 using security::conf::KeyLocatorChecker;
43 using security::conf::RelationKeyLocatorNameChecker;
44
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070045 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -070046 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
47 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070048
49 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -070050 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
51 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070052
53 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data");
54 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070055 m_keyChain.sign(*data1,
56 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
57 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070058
59 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070060 m_keyChain.sign(*data2,
61 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
62 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070063
64 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070065 m_keyChain.sign(*interest1,
66 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
67 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070068
69 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070070 m_keyChain.sign(*interest2,
71 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
72 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070073
74 int8_t result = 0;
75
76
77 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 =
78 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
79 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060080 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070081
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070082 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070083 BOOST_CHECK_EQUAL(result, 0);
84
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070085 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070086 BOOST_CHECK_EQUAL(result, -1);
87
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070088 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070089 BOOST_CHECK_EQUAL(result, 0);
90
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070091 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070092 BOOST_CHECK_EQUAL(result, -1);
93
94
95 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual2 =
96 make_shared<RelationKeyLocatorNameChecker>(identity,
97 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060098 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070099
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700100 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700101 BOOST_CHECK_EQUAL(result, -1);
102
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700103 result = checker2.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700104 BOOST_CHECK_EQUAL(result, -1);
105
106
107 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix1 =
108 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
109 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600110 CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700111
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700112 result = checker3.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700113 BOOST_CHECK_EQUAL(result, 0);
114
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700115 result = checker3.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700116 BOOST_CHECK_EQUAL(result, -1);
117
118
119 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix2 =
120 make_shared<RelationKeyLocatorNameChecker>(identity,
121 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600122 CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700123
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700124 result = checker4.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700125 BOOST_CHECK_EQUAL(result, 0);
126
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700127 result = checker4.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700128 BOOST_CHECK_EQUAL(result, -1);
129
130
131 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict1 =
132 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
133 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600134 CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700135
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700136 result = checker5.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700137 BOOST_CHECK_EQUAL(result, -1);
138
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700139 result = checker5.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700140 BOOST_CHECK_EQUAL(result, -1);
141
142 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict2 =
143 make_shared<RelationKeyLocatorNameChecker>(identity,
144 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600145 CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700146
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700147 result = checker6.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700148 BOOST_CHECK_EQUAL(result, 0);
149
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700150 result = checker6.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700151 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700152}
153
154BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2)
155{
156 using security::conf::CustomizedChecker;
157 using security::conf::KeyLocatorChecker;
158 using security::conf::RegexKeyLocatorNameChecker;
159
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700160 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700161 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
162 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700163
164 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700165 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
166 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700167
168 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
169 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700170 m_keyChain.sign(*data1,
171 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
172 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700173
174 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700175 m_keyChain.sign(*data2,
176 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
177 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700178
179 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700180 m_keyChain.sign(*interest1,
181 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
182 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700183
184 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700185 m_keyChain.sign(*interest2,
186 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
187 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700188
189 int8_t result = 0;
190
191
192 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
193 make_shared<RegexKeyLocatorNameChecker>(
194 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600195 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700196
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700197 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700198 BOOST_CHECK_EQUAL(result, 0);
199
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700200 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700201 BOOST_CHECK_EQUAL(result, -1);
202
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700203 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700204 BOOST_CHECK_EQUAL(result, 0);
205
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700206 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700207 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700208}
209
210BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3)
211{
212 using security::conf::CustomizedChecker;
213 using security::conf::KeyLocatorChecker;
214 using security::conf::RegexKeyLocatorNameChecker;
215
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700216 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700217 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
218 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700219
220 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700221 BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
222 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700223
224 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
225 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700226 m_keyChain.sign(*data1,
227 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
228 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700229
230 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700231 m_keyChain.sign(*data2,
232 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
233 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700234
235 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700236 m_keyChain.sign(*interest1,
237 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
238 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700239
240 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700241 m_keyChain.sign(*interest2,
242 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
243 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700244
245 int8_t result = 0;
246
247
248 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
249 make_shared<RegexKeyLocatorNameChecker>(
250 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600251 CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700252
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700253 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700254 BOOST_CHECK_EQUAL(result, 0);
255
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700256 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700257 BOOST_CHECK_EQUAL(result, -1);
258
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700259 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700260 BOOST_CHECK_EQUAL(result, 0);
261
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700262 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700263 BOOST_CHECK_EQUAL(result, -1);
264
265
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600266 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700267
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700268 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700269 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700270}
271
272BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1)
273{
274 using security::conf::HierarchicalChecker;
275
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700276 Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700277 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
278 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700279
280 Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700281 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
282 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700283
284 Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
285 Name packetName2("/SecurityTestConfChecker");
286 Name packetName3("/SecurityTestConfChecker/HierarchicalCheckerTest1");
287
288 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700289 m_keyChain.sign(*data1,
290 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
291 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700292
293 shared_ptr<Data> data2 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700294 m_keyChain.sign(*data2,
295 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
296 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700297
298 shared_ptr<Data> data3 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700299 m_keyChain.sign(*data3,
300 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
301 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700302
303 shared_ptr<Data> data4 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700304 m_keyChain.sign(*data4,
305 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
306 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700307
308 shared_ptr<Data> data5 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700309 m_keyChain.sign(*data5,
310 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
311 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700312
313 shared_ptr<Data> data6 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700314 m_keyChain.sign(*data6,
315 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
316 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700317
318 int8_t result = 0;
319
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600320 HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700321
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700322 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700323 BOOST_CHECK_EQUAL(result, 0);
324
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700325 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700326 BOOST_CHECK_EQUAL(result, -1);
327
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700328 result = checker1.check(*data3);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700329 BOOST_CHECK_EQUAL(result, 0);
330
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700331 result = checker1.check(*data4);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700332 BOOST_CHECK_EQUAL(result, -1);
333
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700334 result = checker1.check(*data5);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700335 BOOST_CHECK_EQUAL(result, -1);
336
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700337 result = checker1.check(*data6);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700338 BOOST_CHECK_EQUAL(result, -1);
339
340
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600341 HierarchicalChecker checker2(tlv::SignatureSha256WithRsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700342
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700343 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700344 BOOST_CHECK_EQUAL(result, -1);
345
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700346 result = checker2.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700347 BOOST_CHECK_EQUAL(result, -1);
348
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700349 result = checker2.check(*data3);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700350 BOOST_CHECK_EQUAL(result, -1);
351
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700352 result = checker2.check(*data4);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700353 BOOST_CHECK_EQUAL(result, 0);
354
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700355 result = checker2.check(*data5);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700356 BOOST_CHECK_EQUAL(result, -1);
357
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700358 result = checker2.check(*data6);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700359 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700360}
361
362BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1)
363{
364 using security::conf::FixedSignerChecker;
365
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700366 Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700367 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
368 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700369 shared_ptr<v1::IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700370
371 Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700372 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
373 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700374 shared_ptr<v1::IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700375
376 Name packetName("/Test/Data");
377
378 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700379 m_keyChain.sign(*data1,
380 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
381 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700382
383 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700384 m_keyChain.sign(*data2,
385 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
386 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700387
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700388 std::vector<shared_ptr<v1::IdentityCertificate> > certSet1;
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700389 certSet1.push_back(cert1);
390
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700391 std::vector<shared_ptr<v1::IdentityCertificate> > certSet2;
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700392 certSet2.push_back(cert2);
393
394
395 int8_t result = 0;
396
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600397 FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700398
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700399 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700400 BOOST_CHECK_EQUAL(result, 1);
401
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700402 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700403 BOOST_CHECK_EQUAL(result, -1);
404
405
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600406 FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700407
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700408 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700409 BOOST_CHECK_EQUAL(result, -1);
410
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700411 result = checker2.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700412 BOOST_CHECK_EQUAL(result, -1);
413
414
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600415 FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700416
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700417 result = checker3.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700418 BOOST_CHECK_EQUAL(result, -1);
419
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700420 result = checker3.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700421 BOOST_CHECK_EQUAL(result, -1);
422
423
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600424 FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700425
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700426 result = checker4.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700427 BOOST_CHECK_EQUAL(result, -1);
428
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700429 result = checker4.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700430 BOOST_CHECK_EQUAL(result, 1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700431}
432
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100433BOOST_AUTO_TEST_SUITE_END() // TestChecker
434BOOST_AUTO_TEST_SUITE_END() // Conf
435BOOST_AUTO_TEST_SUITE_END() // Security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700436
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800437} // namespace tests
438} // namespace conf
439} // namespace security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700440} // namespace ndn