blob: 095ac1949dcf69035d70cbd333e2a279daab2457 [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento914d05f2019-07-13 16:20:19 -04002/*
swa770de007bc2020-03-24 21:26:21 -07003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08004 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert 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 General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080021#include "ca-module.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080022#include "challenge-module.hpp"
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070023#include "challenge-module/challenge-email.hpp"
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070024#include "challenge-module/challenge-pin.hpp"
25#include "client-module.hpp"
26#include "database-fixture.hpp"
Suyong Won7968f7a2020-05-12 01:01:25 -070027#include "protocol-detail/info.hpp"
Davide Pesavento914d05f2019-07-13 16:20:19 -040028
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080029#include <ndn-cxx/security/signing-helpers.hpp>
30#include <ndn-cxx/security/transform/public-key.hpp>
31#include <ndn-cxx/security/verification-helpers.hpp>
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070032#include <ndn-cxx/util/dummy-client-face.hpp>
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080033
34namespace ndn {
35namespace ndncert {
36namespace tests {
37
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070038BOOST_FIXTURE_TEST_SUITE(TestCaModule, DatabaseFixture)
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080039
40BOOST_AUTO_TEST_CASE(Initialization)
41{
Zhiyi Zhang42d992d2019-07-07 16:46:50 -070042 util::DummyClientFace face(io, {true, true});
43 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Suyong Won44d0cce2020-05-10 04:07:43 -070044 BOOST_CHECK_EQUAL(ca.getCaConf().m_caPrefix, "/ndn");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080045
46 auto identity = addIdentity(Name("/ndn/site2"));
47 auto key = identity.getDefaultKey();
48 auto cert = key.getDefaultCertificate();
49 ca.getCaStorage()->addCertificate("111", cert);
50 BOOST_CHECK_EQUAL(ca.getCaStorage()->getCertificate("111").getIdentity(), Name("/ndn/site2"));
51
52 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070053 BOOST_CHECK_EQUAL(ca.m_registeredPrefixHandles.size(), 2);
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070054 BOOST_CHECK_EQUAL(ca.m_interestFilterHandles.size(), 4); // onInfo, onProbe, onNew, onChallenge
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080055}
56
57BOOST_AUTO_TEST_CASE(HandleProbe)
58{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070059 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080060 auto key = identity.getDefaultKey();
61 auto cert = key.getDefaultCertificate();
62
Zhiyi Zhang42d992d2019-07-07 16:46:50 -070063 util::DummyClientFace face(io, {true, true});
64 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070065 ca.setProbeHandler([&](const Block& probeInfo) {
66 return "example";
67 });
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080068 advanceClocks(time::milliseconds(20), 60);
69
swa770de007bc2020-03-24 21:26:21 -070070 Interest interest("/ndn/CA/PROBE");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070071 interest.setCanBePrefix(false);
Suyong Won44d0cce2020-05-10 04:07:43 -070072
73 Block paramTLV = makeEmptyBlock(tlv::ApplicationParameters);
74 paramTLV.push_back(makeStringBlock(tlv_parameter_key, JSON_CLIENT_PROBE_INFO));
75 paramTLV.push_back(makeStringBlock(tlv_parameter_value, "zhiyi"));
76 paramTLV.encode();
Suyong Won7968f7a2020-05-12 01:01:25 -070077
Suyong Won44d0cce2020-05-10 04:07:43 -070078 interest.setApplicationParameters(paramTLV);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080079
80 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070081 face.onSendData.connect([&](const Data& response) {
82 count++;
83 BOOST_CHECK(security::verifySignature(response, cert));
84 Block contentBlock = response.getContent();
85 contentBlock.parse();
86 Block probeResponse = contentBlock.get(tlv_probe_response);
87 probeResponse.parse();
88 Name caName;
89 caName.wireDecode(probeResponse.get(tlv::Name));
90 BOOST_CHECK_EQUAL(caName, "/ndn/example");
91 });
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070092 face.receive(interest);
93
94 advanceClocks(time::milliseconds(20), 60);
95 BOOST_CHECK_EQUAL(count, 1);
96}
97
swa77020643ac2020-03-26 02:24:45 -070098BOOST_AUTO_TEST_CASE(HandleInfo)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070099{
100 auto identity = addIdentity(Name("/ndn"));
101 auto key = identity.getDefaultKey();
102 auto cert = key.getDefaultCertificate();
103
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700104 util::DummyClientFace face(io, {true, true});
105 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700106 ca.setProbeHandler([&](const Block& probeInfo) {
107 return "example";
108 });
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700109 advanceClocks(time::milliseconds(20), 60);
110
swa77020643ac2020-03-26 02:24:45 -0700111 Interest interest("/ndn/CA/INFO");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700112 interest.setCanBePrefix(false);
113
114 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700115 face.onSendData.connect([&](const Data& response) {
116 count++;
117 BOOST_CHECK(security::verifySignature(response, cert));
118 auto contentBlock = response.getContent();
119 contentBlock.parse();
120 auto caItem = INFO::decodeClientConfigFromContent(contentBlock);
121 BOOST_CHECK_EQUAL(caItem.m_caPrefix, "/ndn");
122 BOOST_CHECK_EQUAL(caItem.m_probe, "");
123 BOOST_CHECK_EQUAL(caItem.m_anchor.wireEncode(), cert.wireEncode());
124 BOOST_CHECK_EQUAL(caItem.m_caInfo, "ndn testbed ca");
125 });
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800126 face.receive(interest);
127
128 advanceClocks(time::milliseconds(20), 60);
129 BOOST_CHECK_EQUAL(count, 1);
130}
131
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700132BOOST_AUTO_TEST_CASE(HandleProbeUsingDefaultHandler)
133{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700134 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700135 auto key = identity.getDefaultKey();
136 auto cert = key.getDefaultCertificate();
137
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700138 util::DummyClientFace face(io, {true, true});
139 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700140 advanceClocks(time::milliseconds(20), 60);
141
swa770de007bc2020-03-24 21:26:21 -0700142 Interest interest("/ndn/CA/PROBE");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700143 interest.setCanBePrefix(false);
Suyong Won7968f7a2020-05-12 01:01:25 -0700144
145 Block paramTLV = makeEmptyBlock(tlv::ApplicationParameters);
146 paramTLV.push_back(makeStringBlock(tlv_parameter_key, JSON_CLIENT_PROBE_INFO));
147 paramTLV.push_back(makeStringBlock(tlv_parameter_value, "zhiyi"));
148 paramTLV.encode();
149
150 interest.setApplicationParameters(paramTLV);
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700151
152 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700153 face.onSendData.connect([&](const Data& response) {
154 count++;
155 BOOST_CHECK(security::verifySignature(response, cert));
156 auto contentBlock = response.getContent();
157 contentBlock.parse();
158 auto probeResponseBlock = contentBlock.get(tlv_probe_response);
159 probeResponseBlock.parse();
160 Name caPrefix;
161 caPrefix.wireDecode(probeResponseBlock.get(tlv::Name));
162 BOOST_CHECK(caPrefix != "");
163 });
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700164 face.receive(interest);
165
166 advanceClocks(time::milliseconds(20), 60);
167 BOOST_CHECK_EQUAL(count, 1);
168}
169
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800170BOOST_AUTO_TEST_CASE(HandleNew)
171{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700172 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800173 auto key = identity.getDefaultKey();
174 auto cert = key.getDefaultCertificate();
175
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700176 util::DummyClientFace face(io, {true, true});
177 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800178 advanceClocks(time::milliseconds(20), 60);
179
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700180 ClientModule client(m_keyChain);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800181 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700182 item.m_caPrefix = Name("/ndn");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800183 item.m_anchor = cert;
184 client.getClientConf().m_caItems.push_back(item);
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700185
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700186 auto interest = client.generateNewInterest(time::system_clock::now(),
Suyong Won7968f7a2020-05-12 01:01:25 -0700187 time::system_clock::now() + time::days(1),
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700188 Name("/ndn/zhiyi"));
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800189
190 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700191 face.onSendData.connect([&](const Data& response) {
192 count++;
193 BOOST_CHECK(security::verifySignature(response, cert));
194 auto contentBlock = response.getContent();
195 contentBlock.parse();
Suyong Won7968f7a2020-05-12 01:01:25 -0700196
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700197 BOOST_CHECK(readString(contentBlock.get(tlv_ecdh_pub)) != "");
198 BOOST_CHECK(readString(contentBlock.get(tlv_salt)) != "");
199 BOOST_CHECK(readString(contentBlock.get(tlv_request_id)) != "");
Suyong Won7968f7a2020-05-12 01:01:25 -0700200
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700201 auto challengeBlockCount = 0;
202 for (auto const& element : contentBlock.elements()) {
203 if (element.type() == tlv_challenge) {
204 challengeBlockCount++;
Suyong Won7968f7a2020-05-12 01:01:25 -0700205 }
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700206 }
Suyong Won7968f7a2020-05-12 01:01:25 -0700207
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700208 BOOST_CHECK(challengeBlockCount != 0);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700209
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700210 client.onNewResponse(response);
211 BOOST_CHECK_EQUAL_COLLECTIONS(client.m_aesKey, client.m_aesKey + sizeof(client.m_aesKey),
212 ca.m_aesKey, ca.m_aesKey + sizeof(ca.m_aesKey));
213 });
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700214 face.receive(*interest);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800215
216 advanceClocks(time::milliseconds(20), 60);
217 BOOST_CHECK_EQUAL(count, 1);
218}
219
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700220BOOST_AUTO_TEST_CASE(HandleNewWithInvalidValidityPeriod1)
221{
222 auto identity = addIdentity(Name("/ndn"));
223 auto key = identity.getDefaultKey();
224 auto cert = key.getDefaultCertificate();
225
226 util::DummyClientFace face(io, {true, true});
227 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test");
228 advanceClocks(time::milliseconds(20), 60);
229
230 ClientModule client(m_keyChain);
231 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700232 item.m_caPrefix = Name("/ndn");
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700233 item.m_anchor = cert;
234 client.getClientConf().m_caItems.push_back(item);
235 auto current_tp = time::system_clock::now();
236 auto interest1 = client.generateNewInterest(current_tp, current_tp - time::hours(1),
237 Name("/ndn/zhiyi"));
238 auto interest2 = client.generateNewInterest(current_tp, current_tp + time::days(361),
239 Name("/ndn/zhiyi"));
240 auto interest3 = client.generateNewInterest(current_tp - time::hours(1),
241 current_tp + time::hours(2),
242 Name("/ndn/zhiyi"));
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700243 face.onSendData.connect([&](const Data& response) {
244 BOOST_CHECK(false);
245 });
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700246 face.receive(*interest1);
247 face.receive(*interest2);
248 face.receive(*interest3);
249
250 advanceClocks(time::milliseconds(20), 60);
251}
252
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700253BOOST_AUTO_TEST_CASE(HandleNewWithProbeToken)
254{
255 auto identity = addIdentity(Name("/ndn"));
256 auto key = identity.getDefaultKey();
257 auto cert = key.getDefaultCertificate();
258
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700259 util::DummyClientFace face(io, {true, true});
260 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhanga1fc6232019-06-13 14:56:59 -0700261 ca.m_config.m_probe = "email";
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700262 advanceClocks(time::milliseconds(20), 60);
263
264 ClientModule client(m_keyChain);
265 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700266 item.m_caPrefix = Name("/ndn");
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700267 item.m_anchor = cert;
268 client.getClientConf().m_caItems.push_back(item);
269
swa770de007bc2020-03-24 21:26:21 -0700270 auto data = make_shared<Data>(Name("/ndn/CA/PROBE/123"));
Suyong Won256c9062020-05-11 02:45:56 -0700271 m_keyChain.sign(*data, signingByIdentity(ca.m_config.m_caPrefix));
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700272
273 auto interest = client.generateNewInterest(time::system_clock::now(),
Suyong Won7968f7a2020-05-12 01:01:25 -0700274 time::system_clock::now() + time::days(1),
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700275 Name("/ndn/zhiyi"), data);
276
277 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700278 face.onSendData.connect([&](const Data& response) {
279 count++;
280 BOOST_CHECK(security::verifySignature(response, cert));
281 });
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700282 face.receive(*interest);
283
284 advanceClocks(time::milliseconds(20), 60);
285 BOOST_CHECK_EQUAL(count, 1);
286}
287
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700288BOOST_AUTO_TEST_CASE(HandleChallenge)
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800289{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700290 auto identity = addIdentity(Name("/ndn"));
291 auto key = identity.getDefaultKey();
292 auto cert = key.getDefaultCertificate();
293
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700294 util::DummyClientFace face(io, {true, true});
295 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800296 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700297
298 // generate NEW Interest
299 ClientModule client(m_keyChain);
300 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700301 item.m_caPrefix = Name("/ndn");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700302 item.m_anchor = cert;
303 client.getClientConf().m_caItems.push_back(item);
304 auto newInterest = client.generateNewInterest(time::system_clock::now(),
Suyong Won7968f7a2020-05-12 01:01:25 -0700305 time::system_clock::now() + time::days(1), Name("/ndn/zhiyi"));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700306
307 // generate CHALLENGE Interest
308 ChallengePin pinChallenge;
309 shared_ptr<Interest> challengeInterest = nullptr;
310 shared_ptr<Interest> challengeInterest2 = nullptr;
311 shared_ptr<Interest> challengeInterest3 = nullptr;
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800312
313 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700314 face.onSendData.connect([&](const Data& response) {
swa770de007bc2020-03-24 21:26:21 -0700315 if (Name("/ndn/CA/NEW").isPrefixOf(response.getName())) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700316 client.onNewResponse(response);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700317 auto paramJson = pinChallenge.getRequirementForChallenge(client.m_status, client.m_challengeStatus);
Suyong Won44d0cce2020-05-10 04:07:43 -0700318 challengeInterest = client.generateChallengeInterest(pinChallenge.genChallengeRequestTLV(client.m_status,
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700319 client.m_challengeStatus,
320 paramJson));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700321 }
swa770de007bc2020-03-24 21:26:21 -0700322 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 0) {
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800323 count++;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700324 BOOST_CHECK(security::verifySignature(response, cert));
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800325
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700326 client.onChallengeResponse(response);
327 BOOST_CHECK_EQUAL(client.m_status, STATUS_CHALLENGE);
328 BOOST_CHECK_EQUAL(client.m_challengeStatus, ChallengePin::NEED_CODE);
Davide Pesavento914d05f2019-07-13 16:20:19 -0400329
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700330 auto paramJson = pinChallenge.getRequirementForChallenge(client.m_status, client.m_challengeStatus);
Suyong Won44d0cce2020-05-10 04:07:43 -0700331 challengeInterest2 = client.generateChallengeInterest(pinChallenge.genChallengeRequestTLV(client.m_status,
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700332 client.m_challengeStatus,
333 paramJson));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700334 }
swa770de007bc2020-03-24 21:26:21 -0700335 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 1) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700336 count++;
337 BOOST_CHECK(security::verifySignature(response, cert));
338
339 client.onChallengeResponse(response);
340 BOOST_CHECK_EQUAL(client.m_status, STATUS_CHALLENGE);
341 BOOST_CHECK_EQUAL(client.m_challengeStatus, ChallengePin::WRONG_CODE);
Davide Pesavento914d05f2019-07-13 16:20:19 -0400342
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700343 auto paramJson = pinChallenge.getRequirementForChallenge(client.m_status, client.m_challengeStatus);
344 auto request = ca.getCertificateRequest(*challengeInterest2);
345 auto secret = request.m_challengeSecrets.get(ChallengePin::JSON_PIN_CODE, "");
Davide Pesavento914d05f2019-07-13 16:20:19 -0400346 for (auto& i : paramJson) {
347 if (i.first == ChallengePin::JSON_PIN_CODE)
348 i.second.put("", secret);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700349 }
Suyong Won44d0cce2020-05-10 04:07:43 -0700350 challengeInterest3 = client.generateChallengeInterest(pinChallenge.genChallengeRequestTLV(client.m_status,
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700351 client.m_challengeStatus,
352 paramJson));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700353 }
swa770de007bc2020-03-24 21:26:21 -0700354 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 2) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700355 count++;
356 BOOST_CHECK(security::verifySignature(response, cert));
357
358 client.onChallengeResponse(response);
359 BOOST_CHECK_EQUAL(client.m_status, STATUS_SUCCESS);
360 BOOST_CHECK_EQUAL(client.m_challengeStatus, CHALLENGE_STATUS_SUCCESS);
361 }
Davide Pesavento914d05f2019-07-13 16:20:19 -0400362 });
363
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700364 face.receive(*newInterest);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800365 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700366 face.receive(*challengeInterest);
367 advanceClocks(time::milliseconds(20), 60);
368 face.receive(*challengeInterest2);
369 advanceClocks(time::milliseconds(20), 60);
370 face.receive(*challengeInterest3);
371 advanceClocks(time::milliseconds(20), 60);
372 BOOST_CHECK_EQUAL(count, 3);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800373}
374
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700375BOOST_AUTO_TEST_SUITE_END() // TestCaModule
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800376
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700377} // namespace tests
378} // namespace ndncert
379} // namespace ndn