blob: f43231b7cd0d55079ee60e9878be577dd7aaec42 [file] [log] [blame]
Yingdi Yu5ec0ee32014-06-24 16:26:09 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev4c9a3d52017-01-03 17:45:19 -08003 * Copyright (c) 2013-2017 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"
Davide Pesaventoeee3e822016-11-26 19:19:34 +010023
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070024#include "boost-test.hpp"
Davide Pesaventoeee3e822016-11-26 19:19:34 +010025#include "identity-management-fixture.hpp"
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070026
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
Davide Pesaventoeee3e822016-11-26 19:19:34 +010034BOOST_AUTO_TEST_SUITE(Security)
35BOOST_AUTO_TEST_SUITE(Conf)
Alexander Afanasyev70244f42017-01-04 12:47:12 -080036BOOST_FIXTURE_TEST_SUITE(TestChecker, IdentityManagementV1Fixture)
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070037
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070038BOOST_AUTO_TEST_CASE(CustomizedCheckerTest1)
39{
40 using security::conf::CustomizedChecker;
41 using security::conf::KeyLocatorChecker;
42 using security::conf::RelationKeyLocatorNameChecker;
43
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070044 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest1");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080045 addIdentity(identity, RsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -070046 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070047
48 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest1Wrong");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -080049 addIdentity(identity2, RsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -070050 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070051
52 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest1/Data");
53 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070054 m_keyChain.sign(*data1,
55 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
56 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070057
58 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070059 m_keyChain.sign(*data2,
60 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
61 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070062
63 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070064 m_keyChain.sign(*interest1,
65 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
66 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070067
68 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -070069 m_keyChain.sign(*interest2,
70 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
71 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070072
73 int8_t result = 0;
74
75
76 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual1 =
77 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
78 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060079 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070080
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070081 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070082 BOOST_CHECK_EQUAL(result, 0);
83
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070084 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070085 BOOST_CHECK_EQUAL(result, -1);
86
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070087 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070088 BOOST_CHECK_EQUAL(result, 0);
89
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070090 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070091 BOOST_CHECK_EQUAL(result, -1);
92
93
94 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerEqual2 =
95 make_shared<RelationKeyLocatorNameChecker>(identity,
96 KeyLocatorChecker::RELATION_EQUAL);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -060097 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerEqual2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -070098
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -070099 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700100 BOOST_CHECK_EQUAL(result, -1);
101
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700102 result = checker2.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700103 BOOST_CHECK_EQUAL(result, -1);
104
105
106 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix1 =
107 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
108 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600109 CustomizedChecker checker3(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700110
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700111 result = checker3.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700112 BOOST_CHECK_EQUAL(result, 0);
113
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700114 result = checker3.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700115 BOOST_CHECK_EQUAL(result, -1);
116
117
118 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerPrefix2 =
119 make_shared<RelationKeyLocatorNameChecker>(identity,
120 KeyLocatorChecker::RELATION_IS_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600121 CustomizedChecker checker4(tlv::SignatureSha256WithRsa, keyLocatorCheckerPrefix2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700122
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700123 result = checker4.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700124 BOOST_CHECK_EQUAL(result, 0);
125
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700126 result = checker4.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700127 BOOST_CHECK_EQUAL(result, -1);
128
129
130 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict1 =
131 make_shared<RelationKeyLocatorNameChecker>(certName.getPrefix(-1),
132 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600133 CustomizedChecker checker5(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700134
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700135 result = checker5.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700136 BOOST_CHECK_EQUAL(result, -1);
137
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700138 result = checker5.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700139 BOOST_CHECK_EQUAL(result, -1);
140
141 shared_ptr<RelationKeyLocatorNameChecker> keyLocatorCheckerStrict2 =
142 make_shared<RelationKeyLocatorNameChecker>(identity,
143 KeyLocatorChecker::RELATION_IS_STRICT_PREFIX_OF);
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600144 CustomizedChecker checker6(tlv::SignatureSha256WithRsa, keyLocatorCheckerStrict2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700145
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700146 result = checker6.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700147 BOOST_CHECK_EQUAL(result, 0);
148
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700149 result = checker6.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700150 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700151}
152
153BOOST_AUTO_TEST_CASE(CustomizedCheckerTest2)
154{
155 using security::conf::CustomizedChecker;
156 using security::conf::KeyLocatorChecker;
157 using security::conf::RegexKeyLocatorNameChecker;
158
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700159 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest2");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800160 addIdentity(identity, RsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700161 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700162
163 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest2Wrong");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800164 addIdentity(identity2, RsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700165 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700166
167 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest2/Data");
168 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700169 m_keyChain.sign(*data1,
170 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
171 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700172
173 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700174 m_keyChain.sign(*data2,
175 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
176 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700177
178 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700179 m_keyChain.sign(*interest1,
180 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
181 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700182
183 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700184 m_keyChain.sign(*interest2,
185 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
186 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700187
188 int8_t result = 0;
189
190
191 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
192 make_shared<RegexKeyLocatorNameChecker>(
193 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest2>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600194 CustomizedChecker checker1(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700195
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700196 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700197 BOOST_CHECK_EQUAL(result, 0);
198
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700199 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700200 BOOST_CHECK_EQUAL(result, -1);
201
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700202 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700203 BOOST_CHECK_EQUAL(result, 0);
204
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700205 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700206 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700207}
208
209BOOST_AUTO_TEST_CASE(CustomizedCheckerTest3)
210{
211 using security::conf::CustomizedChecker;
212 using security::conf::KeyLocatorChecker;
213 using security::conf::RegexKeyLocatorNameChecker;
214
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700215 Name identity("/SecurityTestConfChecker/CustomizedCheckerTest3");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800216 addIdentity(identity, EcdsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700217 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700218
219 Name identity2("/SecurityTestConfChecker/CustomizedCheckerTest3Wrong");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800220 addIdentity(identity2, EcdsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700221 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700222
223 Name packetName("/SecurityTestConfChecker/CustomizedCheckerTest3/Data");
224 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700225 m_keyChain.sign(*data1,
226 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
227 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700228
229 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700230 m_keyChain.sign(*data2,
231 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
232 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700233
234 shared_ptr<Interest> interest1 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700235 m_keyChain.sign(*interest1,
236 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
237 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700238
239 shared_ptr<Interest> interest2 = make_shared<Interest>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700240 m_keyChain.sign(*interest2,
241 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
242 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700243
244 int8_t result = 0;
245
246
247 shared_ptr<RegexKeyLocatorNameChecker> keyLocatorCheckerRegex1 =
248 make_shared<RegexKeyLocatorNameChecker>(
249 Regex("^<SecurityTestConfChecker><CustomizedCheckerTest3>"));
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600250 CustomizedChecker checker1(tlv::SignatureSha256WithEcdsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700251
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700252 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700253 BOOST_CHECK_EQUAL(result, 0);
254
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700255 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700256 BOOST_CHECK_EQUAL(result, -1);
257
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700258 result = checker1.check(*interest1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700259 BOOST_CHECK_EQUAL(result, 0);
260
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700261 result = checker1.check(*interest2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700262 BOOST_CHECK_EQUAL(result, -1);
263
264
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600265 CustomizedChecker checker2(tlv::SignatureSha256WithRsa, keyLocatorCheckerRegex1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700266
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700267 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700268 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700269}
270
271BOOST_AUTO_TEST_CASE(HierarchicalCheckerTest1)
272{
273 using security::conf::HierarchicalChecker;
274
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700275 Name identity("/SecurityTestConfChecker/HierarchicalCheckerTest1");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800276 addIdentity(identity, EcdsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700277 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700278
279 Name identity2("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800280 addIdentity(identity2, RsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700281 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700282
283 Name packetName("/SecurityTestConfChecker/HierarchicalCheckerTest1/Data");
284 Name packetName2("/SecurityTestConfChecker");
285 Name packetName3("/SecurityTestConfChecker/HierarchicalCheckerTest1");
286
287 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700288 m_keyChain.sign(*data1,
289 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
290 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700291
292 shared_ptr<Data> data2 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700293 m_keyChain.sign(*data2,
294 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
295 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700296
297 shared_ptr<Data> data3 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700298 m_keyChain.sign(*data3,
299 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
300 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700301
302 shared_ptr<Data> data4 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700303 m_keyChain.sign(*data4,
304 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
305 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700306
307 shared_ptr<Data> data5 = make_shared<Data>(packetName2);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700308 m_keyChain.sign(*data5,
309 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
310 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700311
312 shared_ptr<Data> data6 = make_shared<Data>(packetName3);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700313 m_keyChain.sign(*data6,
314 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
315 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700316
317 int8_t result = 0;
318
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600319 HierarchicalChecker checker1(tlv::SignatureSha256WithEcdsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700320
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700321 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700322 BOOST_CHECK_EQUAL(result, 0);
323
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700324 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700325 BOOST_CHECK_EQUAL(result, -1);
326
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700327 result = checker1.check(*data3);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700328 BOOST_CHECK_EQUAL(result, 0);
329
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700330 result = checker1.check(*data4);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700331 BOOST_CHECK_EQUAL(result, -1);
332
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700333 result = checker1.check(*data5);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700334 BOOST_CHECK_EQUAL(result, -1);
335
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700336 result = checker1.check(*data6);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700337 BOOST_CHECK_EQUAL(result, -1);
338
339
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600340 HierarchicalChecker checker2(tlv::SignatureSha256WithRsa);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700341
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700342 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700343 BOOST_CHECK_EQUAL(result, -1);
344
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700345 result = checker2.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700346 BOOST_CHECK_EQUAL(result, -1);
347
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700348 result = checker2.check(*data3);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700349 BOOST_CHECK_EQUAL(result, -1);
350
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700351 result = checker2.check(*data4);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700352 BOOST_CHECK_EQUAL(result, 0);
353
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700354 result = checker2.check(*data5);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700355 BOOST_CHECK_EQUAL(result, -1);
356
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700357 result = checker2.check(*data6);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700358 BOOST_CHECK_EQUAL(result, -1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700359}
360
361BOOST_AUTO_TEST_CASE(FixedSignerCheckerTest1)
362{
363 using security::conf::FixedSignerChecker;
364
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700365 Name identity("/SecurityTestConfChecker/FixedSignerCheckerTest1");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800366 addIdentity(identity, EcdsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700367 Name certName = m_keyChain.getDefaultCertificateNameForIdentity(identity);
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700368 shared_ptr<v1::IdentityCertificate> cert1 = m_keyChain.getCertificate(certName);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700369
370 Name identity2("/SecurityTestConfChecker/FixedSignerCheckerTest1Wrong");
Alexander Afanasyevfc99b512017-01-04 11:10:36 -0800371 addIdentity(identity2, RsaKeyParams());
Yingdi Yu3ed09d02014-10-13 16:24:08 -0700372 Name certName2 = m_keyChain.getDefaultCertificateNameForIdentity(identity2);
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700373 shared_ptr<v1::IdentityCertificate> cert2 = m_keyChain.getCertificate(certName2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700374
375 Name packetName("/Test/Data");
376
377 shared_ptr<Data> data1 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700378 m_keyChain.sign(*data1,
379 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
380 identity));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700381
382 shared_ptr<Data> data2 = make_shared<Data>(packetName);
Yingdi Yu1b0311c2015-06-10 14:58:47 -0700383 m_keyChain.sign(*data2,
384 security::SigningInfo(security::SigningInfo::SIGNER_TYPE_ID,
385 identity2));
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700386
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700387 std::vector<shared_ptr<v1::IdentityCertificate> > certSet1;
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700388 certSet1.push_back(cert1);
389
Alexander Afanasyev2fa59392016-07-29 17:24:23 -0700390 std::vector<shared_ptr<v1::IdentityCertificate> > certSet2;
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700391 certSet2.push_back(cert2);
392
393
394 int8_t result = 0;
395
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600396 FixedSignerChecker checker1(tlv::SignatureSha256WithEcdsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700397
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700398 result = checker1.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700399 BOOST_CHECK_EQUAL(result, 1);
400
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700401 result = checker1.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700402 BOOST_CHECK_EQUAL(result, -1);
403
404
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600405 FixedSignerChecker checker2(tlv::SignatureSha256WithRsa, certSet1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700406
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700407 result = checker2.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700408 BOOST_CHECK_EQUAL(result, -1);
409
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700410 result = checker2.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700411 BOOST_CHECK_EQUAL(result, -1);
412
413
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600414 FixedSignerChecker checker3(tlv::SignatureSha256WithEcdsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700415
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700416 result = checker3.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700417 BOOST_CHECK_EQUAL(result, -1);
418
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700419 result = checker3.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700420 BOOST_CHECK_EQUAL(result, -1);
421
422
Steve DiBenedetto54ce6682014-07-22 13:22:57 -0600423 FixedSignerChecker checker4(tlv::SignatureSha256WithRsa, certSet2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700424
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700425 result = checker4.check(*data1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700426 BOOST_CHECK_EQUAL(result, -1);
427
Zhiyi Zhang044bb7e2016-06-10 00:02:37 -0700428 result = checker4.check(*data2);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700429 BOOST_CHECK_EQUAL(result, 1);
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700430}
431
Davide Pesaventoeee3e822016-11-26 19:19:34 +0100432BOOST_AUTO_TEST_SUITE_END() // TestChecker
433BOOST_AUTO_TEST_SUITE_END() // Conf
434BOOST_AUTO_TEST_SUITE_END() // Security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700435
Spyridon Mastorakis429634f2015-02-19 17:35:33 -0800436} // namespace tests
437} // namespace conf
438} // namespace security
Yingdi Yu5ec0ee32014-06-24 16:26:09 -0700439} // namespace ndn