blob: fddfb835a9d0c4f797fd8f82b96db1ab3ecb5428 [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"
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
Alexander Afanasyeve4f8c3b2016-06-23 16:03:48 -070032using namespace ndn::tests;
33
Spyridon Mastorakis429634f2015-02-19 17:35:33 -080034BOOST_FIXTURE_TEST_SUITE(SecurityConfChecker, IdentityManagementFixture)
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070035
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070036BOOST_AUTO_TEST_CASE(CustomizedCheckerTest1)
37{
38 using security::conf::CustomizedChecker;
39 using security::conf::KeyLocatorChecker;
40 using security::conf::RelationKeyLocatorNameChecker;
41
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070042 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -070043 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
44 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070045
46 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -070047 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
48 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070049
50 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data");
51 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070052 m_keyChain.sign(*data1,
53 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
54 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070055
56 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070057 m_keyChain.sign(*data2,
58 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
59 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070060
61 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070062 m_keyChain.sign(*interest1,
63 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
64 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070065
66 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070067 m_keyChain.sign(*interest2,
68 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
69 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070070
71 int8_t result = 0;
72
73
74 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 =
75 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
76 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060077 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070078
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070079 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070080 BOOST_CHECK_EQUAL(result, 0);
81
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070082 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070083 BOOST_CHECK_EQUAL(result, -1);
84
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070085 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070086 BOOST_CHECK_EQUAL(result, 0);
87
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070088 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070089 BOOST_CHECK_EQUAL(result, -1);
90
91
92 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual2 =
93 make_shared<RelationKeyLocatorNameChecker>(identity,
94 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060095 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070096
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070097 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070098 BOOST_CHECK_EQUAL(result, -1);
99
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700100 result = checker2.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700101 BOOST_CHECK_EQUAL(result, -1);
102
103
104 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix1 =
105 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
106 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600107 CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700108
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700109 result = checker3.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700110 BOOST_CHECK_EQUAL(result, 0);
111
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700112 result = checker3.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700113 BOOST_CHECK_EQUAL(result, -1);
114
115
116 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix2 =
117 make_shared<RelationKeyLocatorNameChecker>(identity,
118 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600119 CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700120
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700121 result = checker4.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700122 BOOST_CHECK_EQUAL(result, 0);
123
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700124 result = checker4.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700125 BOOST_CHECK_EQUAL(result, -1);
126
127
128 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict1 =
129 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
130 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600131 CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700132
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700133 result = checker5.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700134 BOOST_CHECK_EQUAL(result, -1);
135
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700136 result = checker5.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700137 BOOST_CHECK_EQUAL(result, -1);
138
139 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict2 =
140 make_shared<RelationKeyLocatorNameChecker>(identity,
141 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600142 CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700143
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700144 result = checker6.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700145 BOOST_CHECK_EQUAL(result, 0);
146
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700147 result = checker6.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700148 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700149}
150
151BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2)
152{
153 using security::conf::CustomizedChecker;
154 using security::conf::KeyLocatorChecker;
155 using security::conf::RegexKeyLocatorNameChecker;
156
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700157 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700158 BOOST_REQUIRE(addIdentity(identity, RsaKeyParams()));
159 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700160
161 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700162 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
163 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700164
165 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
166 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700167 m_keyChain.sign(*data1,
168 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
169 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700170
171 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700172 m_keyChain.sign(*data2,
173 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
174 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700175
176 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700177 m_keyChain.sign(*interest1,
178 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
179 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700180
181 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700182 m_keyChain.sign(*interest2,
183 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
184 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700185
186 int8_t result = 0;
187
188
189 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
190 make_shared<RegexKeyLocatorNameChecker>(
191 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600192 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700193
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700194 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700195 BOOST_CHECK_EQUAL(result, 0);
196
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700197 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700198 BOOST_CHECK_EQUAL(result, -1);
199
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700200 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700201 BOOST_CHECK_EQUAL(result, 0);
202
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700203 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700204 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700205}
206
207BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3)
208{
209 using security::conf::CustomizedChecker;
210 using security::conf::KeyLocatorChecker;
211 using security::conf::RegexKeyLocatorNameChecker;
212
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700213 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700214 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
215 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700216
217 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700218 BOOST_REQUIRE(addIdentity(identity2, EcdsaKeyParams()));
219 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700220
221 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
222 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700223 m_keyChain.sign(*data1,
224 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
225 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700226
227 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700228 m_keyChain.sign(*data2,
229 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
230 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700231
232 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700233 m_keyChain.sign(*interest1,
234 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
235 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700236
237 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700238 m_keyChain.sign(*interest2,
239 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
240 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700241
242 int8_t result = 0;
243
244
245 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
246 make_shared<RegexKeyLocatorNameChecker>(
247 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600248 CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700249
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700250 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700251 BOOST_CHECK_EQUAL(result, 0);
252
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700253 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700254 BOOST_CHECK_EQUAL(result, -1);
255
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700256 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700257 BOOST_CHECK_EQUAL(result, 0);
258
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700259 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700260 BOOST_CHECK_EQUAL(result, -1);
261
262
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600263 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700264
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700265 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700266 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700267}
268
269BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1)
270{
271 using security::conf::HierarchicalChecker;
272
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700273 Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700274 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
275 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700276
277 Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700278 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
279 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700280
281 Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
282 Name packetName2("/SecurityTestConfChecker");
283 Name packetName3("/SecurityTestConfChecker/HierarchicalCheckerTest1");
284
285 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700286 m_keyChain.sign(*data1,
287 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
288 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700289
290 shared_ptr<Data> data2 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700291 m_keyChain.sign(*data2,
292 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
293 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700294
295 shared_ptr<Data> data3 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700296 m_keyChain.sign(*data3,
297 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
298 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700299
300 shared_ptr<Data> data4 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700301 m_keyChain.sign(*data4,
302 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
303 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700304
305 shared_ptr<Data> data5 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700306 m_keyChain.sign(*data5,
307 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
308 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700309
310 shared_ptr<Data> data6 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700311 m_keyChain.sign(*data6,
312 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
313 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700314
315 int8_t result = 0;
316
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600317 HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700318
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700319 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700320 BOOST_CHECK_EQUAL(result, 0);
321
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700322 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700323 BOOST_CHECK_EQUAL(result, -1);
324
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700325 result = checker1.check(*data3);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700326 BOOST_CHECK_EQUAL(result, 0);
327
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700328 result = checker1.check(*data4);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700329 BOOST_CHECK_EQUAL(result, -1);
330
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700331 result = checker1.check(*data5);
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(*data6);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700335 BOOST_CHECK_EQUAL(result, -1);
336
337
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600338 HierarchicalChecker checker2(tlv::SignatureSha256WithRsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700339
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700340 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700341 BOOST_CHECK_EQUAL(result, -1);
342
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700343 result = checker2.check(*data2);
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(*data3);
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(*data4);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700350 BOOST_CHECK_EQUAL(result, 0);
351
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700352 result = checker2.check(*data5);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700353 BOOST_CHECK_EQUAL(result, -1);
354
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700355 result = checker2.check(*data6);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700356 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700357}
358
359BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1)
360{
361 using security::conf::FixedSignerChecker;
362
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700363 Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700364 BOOST_REQUIRE(addIdentity(identity, EcdsaKeyParams()));
365 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700366 shared_ptr<v1::IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700367
368 Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700369 BOOST_REQUIRE(addIdentity(identity2, RsaKeyParams()));
370 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700371 shared_ptr<v1::IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700372
373 Name packetName("/Test/Data");
374
375 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700376 m_keyChain.sign(*data1,
377 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
378 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700379
380 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700381 m_keyChain.sign(*data2,
382 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
383 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700384
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700385 std::vector<shared_ptr<v1::IdentityCertificate> > certSet1;
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700386 certSet1.push_back(cert1);
387
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700388 std::vector<shared_ptr<v1::IdentityCertificate> > certSet2;
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700389 certSet2.push_back(cert2);
390
391
392 int8_t result = 0;
393
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600394 FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700395
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700396 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700397 BOOST_CHECK_EQUAL(result, 1);
398
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700399 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700400 BOOST_CHECK_EQUAL(result, -1);
401
402
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600403 FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700404
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700405 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700406 BOOST_CHECK_EQUAL(result, -1);
407
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700408 result = checker2.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700409 BOOST_CHECK_EQUAL(result, -1);
410
411
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600412 FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700413
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700414 result = checker3.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700415 BOOST_CHECK_EQUAL(result, -1);
416
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700417 result = checker3.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700418 BOOST_CHECK_EQUAL(result, -1);
419
420
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600421 FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700422
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700423 result = checker4.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700424 BOOST_CHECK_EQUAL(result, -1);
425
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700426 result = checker4.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700427 BOOST_CHECK_EQUAL(result, 1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700428}
429
430BOOST_AUTO_TEST_SUITE_END()
431
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800432} // namespace tests
433} // namespace conf
434} // namespace security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700435} // namespace ndn