blob: 40cb3d693092e9cea2ec043d2ad6c25dd106e7f0 [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"
Suyong Won7968f7a2020-05-12 01:01:25 -070026#include "protocol-detail/info.hpp"
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070027#include "test-common.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080028
29namespace ndn {
30namespace ndncert {
31namespace tests {
32
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070033BOOST_FIXTURE_TEST_SUITE(TestCaModule, DatabaseFixture)
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080034
35BOOST_AUTO_TEST_CASE(Initialization)
36{
Zhiyi Zhang42d992d2019-07-07 16:46:50 -070037 util::DummyClientFace face(io, {true, true});
38 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Suyong Won44d0cce2020-05-10 04:07:43 -070039 BOOST_CHECK_EQUAL(ca.getCaConf().m_caPrefix, "/ndn");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080040
41 auto identity = addIdentity(Name("/ndn/site2"));
42 auto key = identity.getDefaultKey();
43 auto cert = key.getDefaultCertificate();
44 ca.getCaStorage()->addCertificate("111", cert);
45 BOOST_CHECK_EQUAL(ca.getCaStorage()->getCertificate("111").getIdentity(), Name("/ndn/site2"));
46
47 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070048 BOOST_CHECK_EQUAL(ca.m_registeredPrefixHandles.size(), 2);
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070049 BOOST_CHECK_EQUAL(ca.m_interestFilterHandles.size(), 4); // onInfo, onProbe, onNew, onChallenge
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080050}
51
52BOOST_AUTO_TEST_CASE(HandleProbe)
53{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070054 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080055 auto key = identity.getDefaultKey();
56 auto cert = key.getDefaultCertificate();
57
Zhiyi Zhang42d992d2019-07-07 16:46:50 -070058 util::DummyClientFace face(io, {true, true});
59 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070060 ca.setProbeHandler([&](const Block& probeInfo) {
61 return "example";
62 });
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080063 advanceClocks(time::milliseconds(20), 60);
64
swa770de007bc2020-03-24 21:26:21 -070065 Interest interest("/ndn/CA/PROBE");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070066 interest.setCanBePrefix(false);
Suyong Won44d0cce2020-05-10 04:07:43 -070067
68 Block paramTLV = makeEmptyBlock(tlv::ApplicationParameters);
69 paramTLV.push_back(makeStringBlock(tlv_parameter_key, JSON_CLIENT_PROBE_INFO));
70 paramTLV.push_back(makeStringBlock(tlv_parameter_value, "zhiyi"));
71 paramTLV.encode();
Suyong Won7968f7a2020-05-12 01:01:25 -070072
Suyong Won44d0cce2020-05-10 04:07:43 -070073 interest.setApplicationParameters(paramTLV);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080074
75 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070076 face.onSendData.connect([&](const Data& response) {
77 count++;
78 BOOST_CHECK(security::verifySignature(response, cert));
79 Block contentBlock = response.getContent();
80 contentBlock.parse();
81 Block probeResponse = contentBlock.get(tlv_probe_response);
82 probeResponse.parse();
83 Name caName;
84 caName.wireDecode(probeResponse.get(tlv::Name));
85 BOOST_CHECK_EQUAL(caName, "/ndn/example");
86 });
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070087 face.receive(interest);
88
89 advanceClocks(time::milliseconds(20), 60);
90 BOOST_CHECK_EQUAL(count, 1);
91}
92
swa77020643ac2020-03-26 02:24:45 -070093BOOST_AUTO_TEST_CASE(HandleInfo)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070094{
95 auto identity = addIdentity(Name("/ndn"));
96 auto key = identity.getDefaultKey();
97 auto cert = key.getDefaultCertificate();
98
Zhiyi Zhang42d992d2019-07-07 16:46:50 -070099 util::DummyClientFace face(io, {true, true});
100 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700101 ca.setProbeHandler([&](const Block& probeInfo) {
102 return "example";
103 });
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700104 advanceClocks(time::milliseconds(20), 60);
105
swa77020643ac2020-03-26 02:24:45 -0700106 Interest interest("/ndn/CA/INFO");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700107 interest.setCanBePrefix(false);
108
109 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700110 face.onSendData.connect([&](const Data& response) {
111 count++;
112 BOOST_CHECK(security::verifySignature(response, cert));
113 auto contentBlock = response.getContent();
114 contentBlock.parse();
115 auto caItem = INFO::decodeClientConfigFromContent(contentBlock);
116 BOOST_CHECK_EQUAL(caItem.m_caPrefix, "/ndn");
117 BOOST_CHECK_EQUAL(caItem.m_probe, "");
118 BOOST_CHECK_EQUAL(caItem.m_anchor.wireEncode(), cert.wireEncode());
119 BOOST_CHECK_EQUAL(caItem.m_caInfo, "ndn testbed ca");
120 });
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800121 face.receive(interest);
122
123 advanceClocks(time::milliseconds(20), 60);
124 BOOST_CHECK_EQUAL(count, 1);
125}
126
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700127BOOST_AUTO_TEST_CASE(HandleProbeUsingDefaultHandler)
128{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700129 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700130 auto key = identity.getDefaultKey();
131 auto cert = key.getDefaultCertificate();
132
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700133 util::DummyClientFace face(io, {true, true});
134 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700135 advanceClocks(time::milliseconds(20), 60);
136
swa770de007bc2020-03-24 21:26:21 -0700137 Interest interest("/ndn/CA/PROBE");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700138 interest.setCanBePrefix(false);
Suyong Won7968f7a2020-05-12 01:01:25 -0700139
140 Block paramTLV = makeEmptyBlock(tlv::ApplicationParameters);
141 paramTLV.push_back(makeStringBlock(tlv_parameter_key, JSON_CLIENT_PROBE_INFO));
142 paramTLV.push_back(makeStringBlock(tlv_parameter_value, "zhiyi"));
143 paramTLV.encode();
144
145 interest.setApplicationParameters(paramTLV);
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700146
147 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700148 face.onSendData.connect([&](const Data& response) {
149 count++;
150 BOOST_CHECK(security::verifySignature(response, cert));
151 auto contentBlock = response.getContent();
152 contentBlock.parse();
153 auto probeResponseBlock = contentBlock.get(tlv_probe_response);
154 probeResponseBlock.parse();
155 Name caPrefix;
156 caPrefix.wireDecode(probeResponseBlock.get(tlv::Name));
157 BOOST_CHECK(caPrefix != "");
158 });
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700159 face.receive(interest);
160
161 advanceClocks(time::milliseconds(20), 60);
162 BOOST_CHECK_EQUAL(count, 1);
163}
164
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800165BOOST_AUTO_TEST_CASE(HandleNew)
166{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700167 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800168 auto key = identity.getDefaultKey();
169 auto cert = key.getDefaultCertificate();
170
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700171 util::DummyClientFace face(io, {true, true});
172 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800173 advanceClocks(time::milliseconds(20), 60);
174
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700175 ClientModule client(m_keyChain);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800176 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700177 item.m_caPrefix = Name("/ndn");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800178 item.m_anchor = cert;
179 client.getClientConf().m_caItems.push_back(item);
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700180
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700181 auto interest = client.generateNewInterest(time::system_clock::now(),
Suyong Won7968f7a2020-05-12 01:01:25 -0700182 time::system_clock::now() + time::days(1),
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700183 Name("/ndn/zhiyi"));
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800184
185 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700186 face.onSendData.connect([&](const Data& response) {
187 count++;
188 BOOST_CHECK(security::verifySignature(response, cert));
189 auto contentBlock = response.getContent();
190 contentBlock.parse();
Suyong Won7968f7a2020-05-12 01:01:25 -0700191
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700192 BOOST_CHECK(readString(contentBlock.get(tlv_ecdh_pub)) != "");
193 BOOST_CHECK(readString(contentBlock.get(tlv_salt)) != "");
194 BOOST_CHECK(readString(contentBlock.get(tlv_request_id)) != "");
Suyong Won7968f7a2020-05-12 01:01:25 -0700195
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700196 auto challengeBlockCount = 0;
197 for (auto const& element : contentBlock.elements()) {
198 if (element.type() == tlv_challenge) {
199 challengeBlockCount++;
Suyong Won7968f7a2020-05-12 01:01:25 -0700200 }
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700201 }
Suyong Won7968f7a2020-05-12 01:01:25 -0700202
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700203 BOOST_CHECK(challengeBlockCount != 0);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700204
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700205 client.onNewResponse(response);
206 BOOST_CHECK_EQUAL_COLLECTIONS(client.m_aesKey, client.m_aesKey + sizeof(client.m_aesKey),
207 ca.m_aesKey, ca.m_aesKey + sizeof(ca.m_aesKey));
208 });
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700209 face.receive(*interest);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800210
211 advanceClocks(time::milliseconds(20), 60);
212 BOOST_CHECK_EQUAL(count, 1);
213}
214
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700215BOOST_AUTO_TEST_CASE(HandleNewWithInvalidValidityPeriod1)
216{
217 auto identity = addIdentity(Name("/ndn"));
218 auto key = identity.getDefaultKey();
219 auto cert = key.getDefaultCertificate();
220
221 util::DummyClientFace face(io, {true, true});
222 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test");
223 advanceClocks(time::milliseconds(20), 60);
224
225 ClientModule client(m_keyChain);
226 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700227 item.m_caPrefix = Name("/ndn");
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700228 item.m_anchor = cert;
229 client.getClientConf().m_caItems.push_back(item);
230 auto current_tp = time::system_clock::now();
231 auto interest1 = client.generateNewInterest(current_tp, current_tp - time::hours(1),
232 Name("/ndn/zhiyi"));
233 auto interest2 = client.generateNewInterest(current_tp, current_tp + time::days(361),
234 Name("/ndn/zhiyi"));
235 auto interest3 = client.generateNewInterest(current_tp - time::hours(1),
236 current_tp + time::hours(2),
237 Name("/ndn/zhiyi"));
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700238 face.onSendData.connect([&](const Data& response) {
239 BOOST_CHECK(false);
240 });
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700241 face.receive(*interest1);
242 face.receive(*interest2);
243 face.receive(*interest3);
244
245 advanceClocks(time::milliseconds(20), 60);
246}
247
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700248BOOST_AUTO_TEST_CASE(HandleNewWithProbeToken)
249{
250 auto identity = addIdentity(Name("/ndn"));
251 auto key = identity.getDefaultKey();
252 auto cert = key.getDefaultCertificate();
253
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700254 util::DummyClientFace face(io, {true, true});
255 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhanga1fc6232019-06-13 14:56:59 -0700256 ca.m_config.m_probe = "email";
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700257 advanceClocks(time::milliseconds(20), 60);
258
259 ClientModule client(m_keyChain);
260 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700261 item.m_caPrefix = Name("/ndn");
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700262 item.m_anchor = cert;
263 client.getClientConf().m_caItems.push_back(item);
264
swa770de007bc2020-03-24 21:26:21 -0700265 auto data = make_shared<Data>(Name("/ndn/CA/PROBE/123"));
Suyong Won256c9062020-05-11 02:45:56 -0700266 m_keyChain.sign(*data, signingByIdentity(ca.m_config.m_caPrefix));
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700267
268 auto interest = client.generateNewInterest(time::system_clock::now(),
Suyong Won7968f7a2020-05-12 01:01:25 -0700269 time::system_clock::now() + time::days(1),
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700270 Name("/ndn/zhiyi"), data);
271
272 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700273 face.onSendData.connect([&](const Data& response) {
274 count++;
275 BOOST_CHECK(security::verifySignature(response, cert));
276 });
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700277 face.receive(*interest);
278
279 advanceClocks(time::milliseconds(20), 60);
280 BOOST_CHECK_EQUAL(count, 1);
281}
282
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700283BOOST_AUTO_TEST_CASE(HandleChallenge)
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800284{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700285 auto identity = addIdentity(Name("/ndn"));
286 auto key = identity.getDefaultKey();
287 auto cert = key.getDefaultCertificate();
288
Zhiyi Zhang42d992d2019-07-07 16:46:50 -0700289 util::DummyClientFace face(io, {true, true});
290 CaModule ca(face, m_keyChain, "tests/unit-tests/ca.conf.test", "ca-storage-memory");
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800291 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700292
293 // generate NEW Interest
294 ClientModule client(m_keyChain);
295 ClientCaItem item;
Suyong Won256c9062020-05-11 02:45:56 -0700296 item.m_caPrefix = Name("/ndn");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700297 item.m_anchor = cert;
298 client.getClientConf().m_caItems.push_back(item);
299 auto newInterest = client.generateNewInterest(time::system_clock::now(),
Suyong Won7968f7a2020-05-12 01:01:25 -0700300 time::system_clock::now() + time::days(1), Name("/ndn/zhiyi"));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700301
302 // generate CHALLENGE Interest
303 ChallengePin pinChallenge;
304 shared_ptr<Interest> challengeInterest = nullptr;
305 shared_ptr<Interest> challengeInterest2 = nullptr;
306 shared_ptr<Interest> challengeInterest3 = nullptr;
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800307
308 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700309 face.onSendData.connect([&](const Data& response) {
swa770de007bc2020-03-24 21:26:21 -0700310 if (Name("/ndn/CA/NEW").isPrefixOf(response.getName())) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700311 client.onNewResponse(response);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700312 auto paramJson = pinChallenge.getRequirementForChallenge(client.m_status, client.m_challengeStatus);
Suyong Won44d0cce2020-05-10 04:07:43 -0700313 challengeInterest = client.generateChallengeInterest(pinChallenge.genChallengeRequestTLV(client.m_status,
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700314 client.m_challengeStatus,
315 paramJson));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700316 }
swa770de007bc2020-03-24 21:26:21 -0700317 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 0) {
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800318 count++;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700319 BOOST_CHECK(security::verifySignature(response, cert));
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800320
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700321 client.onChallengeResponse(response);
322 BOOST_CHECK_EQUAL(client.m_status, STATUS_CHALLENGE);
323 BOOST_CHECK_EQUAL(client.m_challengeStatus, ChallengePin::NEED_CODE);
Davide Pesavento914d05f2019-07-13 16:20:19 -0400324
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700325 auto paramJson = pinChallenge.getRequirementForChallenge(client.m_status, client.m_challengeStatus);
Suyong Won44d0cce2020-05-10 04:07:43 -0700326 challengeInterest2 = client.generateChallengeInterest(pinChallenge.genChallengeRequestTLV(client.m_status,
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700327 client.m_challengeStatus,
328 paramJson));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700329 }
swa770de007bc2020-03-24 21:26:21 -0700330 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 1) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700331 count++;
332 BOOST_CHECK(security::verifySignature(response, cert));
333
334 client.onChallengeResponse(response);
335 BOOST_CHECK_EQUAL(client.m_status, STATUS_CHALLENGE);
336 BOOST_CHECK_EQUAL(client.m_challengeStatus, ChallengePin::WRONG_CODE);
Davide Pesavento914d05f2019-07-13 16:20:19 -0400337
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700338 auto paramJson = pinChallenge.getRequirementForChallenge(client.m_status, client.m_challengeStatus);
339 auto request = ca.getCertificateRequest(*challengeInterest2);
340 auto secret = request.m_challengeSecrets.get(ChallengePin::JSON_PIN_CODE, "");
Davide Pesavento914d05f2019-07-13 16:20:19 -0400341 for (auto& i : paramJson) {
342 if (i.first == ChallengePin::JSON_PIN_CODE)
343 i.second.put("", secret);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700344 }
Suyong Won44d0cce2020-05-10 04:07:43 -0700345 challengeInterest3 = client.generateChallengeInterest(pinChallenge.genChallengeRequestTLV(client.m_status,
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700346 client.m_challengeStatus,
347 paramJson));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700348 }
swa770de007bc2020-03-24 21:26:21 -0700349 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 2) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700350 count++;
351 BOOST_CHECK(security::verifySignature(response, cert));
352
353 client.onChallengeResponse(response);
354 BOOST_CHECK_EQUAL(client.m_status, STATUS_SUCCESS);
355 BOOST_CHECK_EQUAL(client.m_challengeStatus, CHALLENGE_STATUS_SUCCESS);
356 }
Davide Pesavento914d05f2019-07-13 16:20:19 -0400357 });
358
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700359 face.receive(*newInterest);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800360 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700361 face.receive(*challengeInterest);
362 advanceClocks(time::milliseconds(20), 60);
363 face.receive(*challengeInterest2);
364 advanceClocks(time::milliseconds(20), 60);
365 face.receive(*challengeInterest3);
366 advanceClocks(time::milliseconds(20), 60);
367 BOOST_CHECK_EQUAL(count, 3);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800368}
369
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700370BOOST_AUTO_TEST_SUITE_END() // TestCaModule
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800371
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700372} // namespace tests
373} // namespace ndncert
374} // namespace ndn