blob: 19f369db1f24c9d6ac654b91d56a16d5f93cfd73 [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/*
Tianyuan Yu13aac732022-03-03 20:59:54 -08003 * Copyright (c) 2017-2022, 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 Zhang84e11842020-11-19 20:03:23 -080022#include "challenge/challenge-module.hpp"
23#include "challenge/challenge-email.hpp"
24#include "challenge/challenge-pin.hpp"
Zhiyi Zhang062be6d2020-10-14 17:13:43 -070025#include "detail/info-encoder.hpp"
tylerliu4140fe82021-01-27 15:45:44 -080026#include "requester-request.hpp"
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040027
Zhiyi Zhang5d80e1e2020-09-25 11:34:54 -070028#include "test-common.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080029
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040030namespace ndncert::tests {
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080031
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070032using namespace ca;
Davide Pesavento0dc02012021-11-23 22:55:03 -050033using ndn::util::DummyClientFace;
34using ndn::security::verifySignature;
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070035
Zhiyi Zhangae123bf2017-04-14 12:24:53 -070036BOOST_FIXTURE_TEST_SUITE(TestCaModule, DatabaseFixture)
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080037
38BOOST_AUTO_TEST_CASE(Initialization)
39{
Davide Pesavento0dc02012021-11-23 22:55:03 -050040 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -070041 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
Zhiyi Zhang44c6a352020-12-14 10:57:17 -080042 BOOST_CHECK_EQUAL(ca.getCaConf().caProfile.caPrefix, "/ndn");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080043
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080044 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070045 BOOST_CHECK_EQUAL(ca.m_registeredPrefixHandles.size(), 1); // removed local discovery registration
Zhiyi Zhang696cd042020-10-07 21:27:36 -070046 BOOST_CHECK_EQUAL(ca.m_interestFilterHandles.size(), 5); // infoMeta, onProbe, onNew, onChallenge, onRevoke
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080047}
48
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070049BOOST_AUTO_TEST_CASE(HandleProfileFetching)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070050{
51 auto identity = addIdentity(Name("/ndn"));
52 auto key = identity.getDefaultKey();
53 auto cert = key.getDefaultCertificate();
54
Davide Pesavento0dc02012021-11-23 22:55:03 -050055 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -070056 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070057 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangcd57da82020-10-08 20:35:40 -070058 auto profileData = ca.getCaProfileData();
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070059
Davide Pesavento0dc02012021-11-23 22:55:03 -050060 Interest interest = ndn::MetadataObject::makeDiscoveryInterest(Name("/ndn/CA/INFO"));
61 std::shared_ptr<Interest> infoInterest = nullptr;
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070062
Zhiyi Zhang696cd042020-10-07 21:27:36 -070063 face.setInterestFilter(
Davide Pesavento0dc02012021-11-23 22:55:03 -050064 ndn::InterestFilter("/ndn/CA/INFO"),
Zhiyi Zhang696cd042020-10-07 21:27:36 -070065 [&](const auto&, const Interest& interest) {
Zhiyi Zhangcd57da82020-10-08 20:35:40 -070066 if (interest.getName() == profileData.getName()) {
67 face.put(profileData);
68 }
69 },
70 nullptr, nullptr);
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070071 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070072
73 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070074 face.onSendData.connect([&](const Data& response) {
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070075 if (count == 0) {
76 count++;
77 auto block = response.getContent();
78 block.parse();
Davide Pesavento0dc02012021-11-23 22:55:03 -050079 infoInterest = std::make_shared<Interest>(Name(block.get(ndn::tlv::Name)).appendSegment(0));
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070080 }
81 else {
82 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -050083 BOOST_CHECK(verifySignature(response, cert));
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070084 auto contentBlock = response.getContent();
85 contentBlock.parse();
Zhiyi Zhangf22ae242020-11-17 10:51:15 -080086 auto caItem = infotlv::decodeDataContent(contentBlock);
Zhiyi Zhang44c6a352020-12-14 10:57:17 -080087 BOOST_CHECK_EQUAL(caItem.caPrefix, "/ndn");
88 BOOST_CHECK_EQUAL(caItem.probeParameterKeys.size(), 1);
89 BOOST_CHECK_EQUAL(caItem.probeParameterKeys.front(), "full name");
90 BOOST_CHECK_EQUAL(caItem.cert->wireEncode(), cert.wireEncode());
91 BOOST_CHECK_EQUAL(caItem.caInfo, "ndn testbed ca");
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070092 }
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070093 });
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080094 face.receive(interest);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080095 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070096 face.receive(*infoInterest);
97 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangcd57da82020-10-08 20:35:40 -070098
Zhiyi Zhangfbcab842020-10-07 15:17:13 -070099 BOOST_CHECK_EQUAL(count, 2);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800100}
101
Zhiyi Zhang6f395812020-09-29 14:42:03 -0700102BOOST_AUTO_TEST_CASE(HandleProbe)
103{
104 auto identity = addIdentity(Name("/ndn"));
105 auto key = identity.getDefaultKey();
106 auto cert = key.getDefaultCertificate();
107
Davide Pesavento0dc02012021-11-23 22:55:03 -0500108 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700109 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
Zhiyi Zhang6f395812020-09-29 14:42:03 -0700110 advanceClocks(time::milliseconds(20), 60);
111
112 Interest interest("/ndn/CA/PROBE");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500113 Block paramTLV = ndn::makeEmptyBlock(ndn::tlv::ApplicationParameters);
114 paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, "name"));
115 paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi"));
Zhiyi Zhang6f395812020-09-29 14:42:03 -0700116 paramTLV.encode();
Zhiyi Zhang6f395812020-09-29 14:42:03 -0700117 interest.setApplicationParameters(paramTLV);
118
119 int count = 0;
120 face.onSendData.connect([&](const Data& response) {
121 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500122 BOOST_CHECK(verifySignature(response, cert));
Zhiyi Zhang6f395812020-09-29 14:42:03 -0700123 Block contentBlock = response.getContent();
124 contentBlock.parse();
tylerliu50d679e2020-10-14 14:08:39 -0700125 Block probeResponse = contentBlock.get(tlv::ProbeResponse);
Zhiyi Zhang6f395812020-09-29 14:42:03 -0700126 probeResponse.parse();
127 Name caName;
Zhiyi Zhang8f1ade32020-10-14 16:42:57 -0700128 caName.wireDecode(probeResponse.get(ndn::tlv::Name));
Zhiyi Zhang8683ec92020-10-07 18:18:35 -0700129 BOOST_CHECK_EQUAL(caName.size(), 2);
Zhiyi Zhang6f395812020-09-29 14:42:03 -0700130 });
131 face.receive(interest);
132
133 advanceClocks(time::milliseconds(20), 60);
134 BOOST_CHECK_EQUAL(count, 1);
135}
136
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700137BOOST_AUTO_TEST_CASE(HandleProbeUsingDefaultHandler)
138{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700139 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700140 auto key = identity.getDefaultKey();
141 auto cert = key.getDefaultCertificate();
142
Davide Pesavento0dc02012021-11-23 22:55:03 -0500143 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700144 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700145 advanceClocks(time::milliseconds(20), 60);
146
swa770de007bc2020-03-24 21:26:21 -0700147 Interest interest("/ndn/CA/PROBE");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500148 Block paramTLV = ndn::makeEmptyBlock(ndn::tlv::ApplicationParameters);
149 paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, "name"));
150 paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi"));
Suyong Won7968f7a2020-05-12 01:01:25 -0700151 paramTLV.encode();
Suyong Won7968f7a2020-05-12 01:01:25 -0700152 interest.setApplicationParameters(paramTLV);
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700153
154 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700155 face.onSendData.connect([&](const Data& response) {
156 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500157 BOOST_CHECK(verifySignature(response, cert));
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700158 auto contentBlock = response.getContent();
159 contentBlock.parse();
tylerliu50d679e2020-10-14 14:08:39 -0700160 auto probeResponseBlock = contentBlock.get(tlv::ProbeResponse);
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700161 probeResponseBlock.parse();
162 Name caPrefix;
Zhiyi Zhang8f1ade32020-10-14 16:42:57 -0700163 caPrefix.wireDecode(probeResponseBlock.get(ndn::tlv::Name));
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700164 BOOST_CHECK(caPrefix != "");
165 });
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700166 face.receive(interest);
167
168 advanceClocks(time::milliseconds(20), 60);
169 BOOST_CHECK_EQUAL(count, 1);
170}
171
Suyong Wone2afeb52020-10-04 03:05:39 +0900172BOOST_AUTO_TEST_CASE(HandleProbeRedirection)
173{
174 auto identity = addIdentity(Name("/ndn"));
175 auto key = identity.getDefaultKey();
176 auto cert = key.getDefaultCertificate();
177
Davide Pesavento0dc02012021-11-23 22:55:03 -0500178 DummyClientFace face(io, m_keyChain, {true, true});
Suyong Wone2afeb52020-10-04 03:05:39 +0900179 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-5", "ca-storage-memory");
Suyong Wone2afeb52020-10-04 03:05:39 +0900180 advanceClocks(time::milliseconds(20), 60);
181
182 Interest interest("/ndn/CA/PROBE");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500183 Block paramTLV = ndn::makeEmptyBlock(ndn::tlv::ApplicationParameters);
184 paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterKey, "name"));
185 paramTLV.push_back(ndn::makeStringBlock(tlv::ParameterValue, "zhiyi"));
Suyong Wone2afeb52020-10-04 03:05:39 +0900186 paramTLV.encode();
Suyong Wone2afeb52020-10-04 03:05:39 +0900187 interest.setApplicationParameters(paramTLV);
188
189 int count = 0;
190 face.onSendData.connect([&](const Data& response) {
191 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500192 BOOST_CHECK(verifySignature(response, cert));
Suyong Wone2afeb52020-10-04 03:05:39 +0900193 Block contentBlock = response.getContent();
194 contentBlock.parse();
195
196 // Test CA sent redirections
Zhiyi Zhang34a8d432020-10-03 22:14:25 -0700197 std::vector<Name> redirectionItems;
198 for (auto item : contentBlock.elements()) {
tylerliu50d679e2020-10-14 14:08:39 -0700199 if (item.type() == tlv::ProbeRedirect) {
Zhiyi Zhang34a8d432020-10-03 22:14:25 -0700200 redirectionItems.push_back(Name(item.blockFromValue()));
201 }
Suyong Wone2afeb52020-10-04 03:05:39 +0900202 }
Zhiyi Zhang34a8d432020-10-03 22:14:25 -0700203 BOOST_CHECK_EQUAL(redirectionItems.size(), 2);
Tianyuan Yu13aac732022-03-03 20:59:54 -0800204 BOOST_CHECK_EQUAL(ndn::security::extractIdentityFromCertName(redirectionItems[0].getPrefix(-1)), "/ndn/edu/ucla");
205 BOOST_CHECK_EQUAL(ndn::security::extractIdentityFromCertName(redirectionItems[1].getPrefix(-1)), "/ndn/edu/ucla/cs/irl");
Suyong Wone2afeb52020-10-04 03:05:39 +0900206 });
207 face.receive(interest);
208 advanceClocks(time::milliseconds(20), 60);
209 BOOST_CHECK_EQUAL(count, 1);
210}
211
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800212BOOST_AUTO_TEST_CASE(HandleNew)
213{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700214 auto identity = addIdentity(Name("/ndn"));
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800215 auto key = identity.getDefaultKey();
216 auto cert = key.getDefaultCertificate();
217
Davide Pesavento0dc02012021-11-23 22:55:03 -0500218 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700219 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800220 advanceClocks(time::milliseconds(20), 60);
221
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700222 CaProfile item;
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800223 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500224 item.cert = std::make_shared<Certificate>(cert);
tylerliu4140fe82021-01-27 15:45:44 -0800225 requester::Request state(m_keyChain, item, RequestType::NEW);
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800226 auto interest = state.genNewInterest(addIdentity(Name("/ndn/zhiyi")).getDefaultKey().getName(),
tylerliu4140fe82021-01-27 15:45:44 -0800227 time::system_clock::now(),
228 time::system_clock::now() + time::days(1));
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800229
230 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700231 face.onSendData.connect([&](const Data& response) {
232 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500233 BOOST_CHECK(verifySignature(response, cert));
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700234 auto contentBlock = response.getContent();
235 contentBlock.parse();
Suyong Won7968f7a2020-05-12 01:01:25 -0700236
tylerliu50d679e2020-10-14 14:08:39 -0700237 BOOST_CHECK(readString(contentBlock.get(tlv::EcdhPub)) != "");
238 BOOST_CHECK(readString(contentBlock.get(tlv::Salt)) != "");
239 BOOST_CHECK(readString(contentBlock.get(tlv::RequestId)) != "");
Suyong Won7968f7a2020-05-12 01:01:25 -0700240
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700241 auto challengeBlockCount = 0;
242 for (auto const& element : contentBlock.elements()) {
tylerliu50d679e2020-10-14 14:08:39 -0700243 if (element.type() == tlv::Challenge) {
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700244 challengeBlockCount++;
Suyong Won7968f7a2020-05-12 01:01:25 -0700245 }
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700246 }
Suyong Won7968f7a2020-05-12 01:01:25 -0700247
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700248 BOOST_CHECK(challengeBlockCount != 0);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700249
tylerliu4140fe82021-01-27 15:45:44 -0800250 auto challengeList = state.onNewRenewRevokeResponse(response);
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -0700251 RequestId requestId;
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -0700252 std::memcpy(requestId.data(), contentBlock.get(tlv::RequestId).value(), contentBlock.get(tlv::RequestId).value_size());
tylerliu7b9185c2020-11-24 12:15:18 -0800253 auto ca_encryption_key = ca.getCaStorage()->getRequest(requestId).encryptionKey;
Zhiyi Zhang6499edd2021-02-17 22:37:21 -0800254 BOOST_CHECK_EQUAL_COLLECTIONS(state.m_aesKey.begin(), state.m_aesKey.end(),
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -0700255 ca_encryption_key.begin(), ca_encryption_key.end());
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700256 });
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700257 face.receive(*interest);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800258
259 advanceClocks(time::milliseconds(20), 60);
260 BOOST_CHECK_EQUAL(count, 1);
261}
262
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700263BOOST_AUTO_TEST_CASE(HandleNewWithInvalidValidityPeriod1)
264{
265 auto identity = addIdentity(Name("/ndn"));
266 auto key = identity.getDefaultKey();
267 auto cert = key.getDefaultCertificate();
268
Davide Pesavento0dc02012021-11-23 22:55:03 -0500269 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700270 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1");
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700271 advanceClocks(time::milliseconds(20), 60);
272
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700273 CaProfile item;
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800274 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500275 item.cert = std::make_shared<Certificate>(cert);
tylerliu4140fe82021-01-27 15:45:44 -0800276 requester::Request state(m_keyChain, item, RequestType::NEW);
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800277 auto client = addIdentity(Name("/ndn/zhiyi"));
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700278 auto current_tp = time::system_clock::now();
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800279 auto interest1 = state.genNewInterest(client.getDefaultKey().getName(), current_tp, current_tp - time::hours(1));
280 auto interest2 = state.genNewInterest(client.getDefaultKey().getName(), current_tp, current_tp + time::days(361));
281 auto interest3 = state.genNewInterest(client.getDefaultKey().getName(),
282 current_tp - time::hours(1), current_tp + time::hours(2));
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700283 face.onSendData.connect([&](const Data& response) {
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700284 auto contentTlv = response.getContent();
285 contentTlv.parse();
tylerliu50d679e2020-10-14 14:08:39 -0700286 auto errorCode = static_cast<ErrorCode>(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode)));
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700287 BOOST_CHECK(errorCode != ErrorCode::NO_ERROR);
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700288 });
Zhiyi Zhang1a735bc2019-07-04 21:36:49 -0700289 face.receive(*interest1);
290 face.receive(*interest2);
291 face.receive(*interest3);
292
293 advanceClocks(time::milliseconds(20), 60);
294}
295
tylerliuf62cfeb2021-01-28 11:01:33 -0800296BOOST_AUTO_TEST_CASE(HandleNewWithServerBadValidity)
297{
298 auto identity = addIdentity(Name("/ndn"));
299 auto key = identity.getDefaultKey();
300
301 //build expired cert
Davide Pesavento0dc02012021-11-23 22:55:03 -0500302 Certificate cert;
tylerliuf62cfeb2021-01-28 11:01:33 -0800303 cert.setName(Name(key.getName()).append("self-sign").appendVersion());
304 cert.setContentType(ndn::tlv::ContentType_Key);
Davide Pesavento6f1a2ab2022-03-17 03:57:21 -0400305 cert.setContent(key.getPublicKey());
tylerliuf62cfeb2021-01-28 11:01:33 -0800306 SignatureInfo signatureInfo;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500307 signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now() - time::days(1),
308 time::system_clock::now() - time::seconds(1)));
tylerliuf62cfeb2021-01-28 11:01:33 -0800309 m_keyChain.sign(cert, signingByKey(key.getName()).setSignatureInfo(signatureInfo));
310 m_keyChain.setDefaultCertificate(key, cert);
311
Davide Pesavento0dc02012021-11-23 22:55:03 -0500312 DummyClientFace face(io, m_keyChain, {true, true});
tylerliuf62cfeb2021-01-28 11:01:33 -0800313 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
314 advanceClocks(time::milliseconds(20), 60);
315
316 CaProfile item;
317 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500318 item.cert = std::make_shared<Certificate>(cert);
tylerliuf62cfeb2021-01-28 11:01:33 -0800319 requester::Request state(m_keyChain, item, RequestType::NEW);
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800320 auto interest = state.genNewInterest(addIdentity(Name("/ndn/zhiyi")).getDefaultKey().getName(),
tylerliuf62cfeb2021-01-28 11:01:33 -0800321 time::system_clock::now(),
322 time::system_clock::now() + time::days(1));
323
324 int count = 0;
325 face.onSendData.connect([&](const Data& response) {
326 auto contentTlv = response.getContent();
327 contentTlv.parse();
328 auto errorCode = static_cast<ErrorCode>(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode)));
329 BOOST_CHECK(errorCode != ErrorCode::NO_ERROR);
330 count ++;
331 });
332 face.receive(*interest);
333
334 advanceClocks(time::milliseconds(20), 60);
335 BOOST_CHECK_EQUAL(count, 1);
336}
337
tylerliu0b6d0db2020-09-28 17:52:02 -0700338BOOST_AUTO_TEST_CASE(HandleNewWithLongSuffix)
339{
340 auto identity = addIdentity(Name("/ndn"));
341 auto key = identity.getDefaultKey();
342 auto cert = key.getDefaultCertificate();
343
Davide Pesavento0dc02012021-11-23 22:55:03 -0500344 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700345 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
tylerliu0b6d0db2020-09-28 17:52:02 -0700346 advanceClocks(time::milliseconds(20), 60);
347
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700348 CaProfile item;
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800349 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500350 item.cert = std::make_shared<Certificate>(cert);
tylerliu4140fe82021-01-27 15:45:44 -0800351 requester::Request state(m_keyChain, item, RequestType::NEW);
tylerliu0b6d0db2020-09-28 17:52:02 -0700352
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800353 auto interest1 = state.genNewInterest(addIdentity(Name("/ndn/a")).getDefaultKey().getName(), time::system_clock::now(),
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700354 time::system_clock::now() + time::days(1));
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800355 auto interest2 = state.genNewInterest(addIdentity(Name("/ndn/a/b")).getDefaultKey().getName(), time::system_clock::now(),
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700356 time::system_clock::now() + time::days(1));
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800357 auto interest3 = state.genNewInterest(addIdentity(Name("/ndn/a/b/c/d")).getDefaultKey().getName(), time::system_clock::now(),
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700358 time::system_clock::now() + time::days(1));
tylerliu0b6d0db2020-09-28 17:52:02 -0700359
tylerliu0b6d0db2020-09-28 17:52:02 -0700360 face.onSendData.connect([&](const Data& response) {
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700361 auto contentTlv = response.getContent();
362 contentTlv.parse();
363 if (interest3->getName().isPrefixOf(response.getName())) {
tylerliu50d679e2020-10-14 14:08:39 -0700364 auto errorCode = static_cast<ErrorCode>(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode)));
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700365 BOOST_CHECK(errorCode != ErrorCode::NO_ERROR);
366 }
367 else {
368 // should successfully get responses
Davide Pesavento0dc02012021-11-23 22:55:03 -0500369 BOOST_CHECK_THROW(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode)), std::runtime_error);
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700370 }
tylerliu0b6d0db2020-09-28 17:52:02 -0700371 });
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700372 face.receive(*interest1);
373 face.receive(*interest2);
374 face.receive(*interest3);
tylerliu0b6d0db2020-09-28 17:52:02 -0700375 advanceClocks(time::milliseconds(20), 60);
tylerliu0b6d0db2020-09-28 17:52:02 -0700376}
377
tylerliu0b6d0db2020-09-28 17:52:02 -0700378BOOST_AUTO_TEST_CASE(HandleNewWithInvalidLength1)
379{
380 auto identity = addIdentity(Name("/ndn"));
381 auto key = identity.getDefaultKey();
382 auto cert = key.getDefaultCertificate();
383
Davide Pesavento0dc02012021-11-23 22:55:03 -0500384 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700385 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1");
tylerliu0b6d0db2020-09-28 17:52:02 -0700386 advanceClocks(time::milliseconds(20), 60);
387
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700388 CaProfile item;
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800389 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500390 item.cert = std::make_shared<Certificate>(cert);
tylerliu4140fe82021-01-27 15:45:44 -0800391 requester::Request state(m_keyChain, item, RequestType::NEW);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700392
tylerliu0b6d0db2020-09-28 17:52:02 -0700393 auto current_tp = time::system_clock::now();
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800394 auto interest1 = state.genNewInterest(identity.getDefaultKey().getName(), current_tp, current_tp + time::days(1));
395 auto interest2 = state.genNewInterest(addIdentity(Name("/ndn/a/b/c/d")).getDefaultKey().getName(),
396 current_tp, current_tp + time::days(1));
tylerliu0b6d0db2020-09-28 17:52:02 -0700397 face.onSendData.connect([&](const Data& response) {
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700398 auto contentTlv = response.getContent();
399 contentTlv.parse();
tylerliu50d679e2020-10-14 14:08:39 -0700400 auto errorCode = static_cast<ErrorCode>(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode)));
Zhiyi Zhang01e91a32020-09-29 12:10:00 -0700401 BOOST_CHECK(errorCode != ErrorCode::NO_ERROR);
tylerliu0b6d0db2020-09-28 17:52:02 -0700402 });
403 face.receive(*interest1);
404 face.receive(*interest2);
405
406 advanceClocks(time::milliseconds(20), 60);
407}
408
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700409BOOST_AUTO_TEST_CASE(HandleChallenge)
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800410{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700411 auto identity = addIdentity(Name("/ndn"));
412 auto key = identity.getDefaultKey();
413 auto cert = key.getDefaultCertificate();
414
Davide Pesavento0dc02012021-11-23 22:55:03 -0500415 DummyClientFace face(io, m_keyChain, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700416 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800417 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700418
419 // generate NEW Interest
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700420 CaProfile item;
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800421 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500422 item.cert = std::make_shared<Certificate>(cert);
tylerliu4140fe82021-01-27 15:45:44 -0800423 requester::Request state(m_keyChain, item, RequestType::NEW);
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700424
Tianyuan Yuca23bb02022-03-09 14:09:14 -0800425 auto newInterest = state.genNewInterest(addIdentity(Name("/ndn/zhiyi")).getDefaultKey().getName(), time::system_clock::now(),
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700426 time::system_clock::now() + time::days(1));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700427
428 // generate CHALLENGE Interest
Davide Pesavento0dc02012021-11-23 22:55:03 -0500429 std::shared_ptr<Interest> challengeInterest;
430 std::shared_ptr<Interest> challengeInterest2;
431 std::shared_ptr<Interest> challengeInterest3;
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800432
433 int count = 0;
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -0700434 face.onSendData.connect([&](const Data& response) {
swa770de007bc2020-03-24 21:26:21 -0700435 if (Name("/ndn/CA/NEW").isPrefixOf(response.getName())) {
tylerliu4140fe82021-01-27 15:45:44 -0800436 auto challengeList = state.onNewRenewRevokeResponse(response);
437 auto paramList = state.selectOrContinueChallenge("pin");
438 challengeInterest = state.genChallengeInterest(std::move(paramList));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700439 }
swa770de007bc2020-03-24 21:26:21 -0700440 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 0) {
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800441 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500442 BOOST_CHECK(verifySignature(response, cert));
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800443
tylerliu4140fe82021-01-27 15:45:44 -0800444 state.onChallengeResponse(response);
Zhiyi Zhang6499edd2021-02-17 22:37:21 -0800445 BOOST_CHECK(state.m_status == Status::CHALLENGE);
446 BOOST_CHECK_EQUAL(state.m_challengeStatus, ChallengePin::NEED_CODE);
tylerliu4140fe82021-01-27 15:45:44 -0800447 auto paramList = state.selectOrContinueChallenge("pin");
448 challengeInterest2 = state.genChallengeInterest(std::move(paramList));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700449 }
swa770de007bc2020-03-24 21:26:21 -0700450 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 1) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700451 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500452 BOOST_CHECK(verifySignature(response, cert));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700453
tylerliu4140fe82021-01-27 15:45:44 -0800454 state.onChallengeResponse(response);
Zhiyi Zhang6499edd2021-02-17 22:37:21 -0800455 BOOST_CHECK(state.m_status == Status::CHALLENGE);
456 BOOST_CHECK_EQUAL(state.m_challengeStatus, ChallengePin::WRONG_CODE);
Davide Pesavento914d05f2019-07-13 16:20:19 -0400457
tylerliu4140fe82021-01-27 15:45:44 -0800458 auto paramList = state.selectOrContinueChallenge("pin");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700459 auto request = ca.getCertificateRequest(*challengeInterest2);
tylerliu7b9185c2020-11-24 12:15:18 -0800460 auto secret = request->challengeState->secrets.get(ChallengePin::PARAMETER_KEY_CODE, "");
tylerliu40226332020-11-11 15:37:16 -0800461 paramList.begin()->second = secret;
tylerliu4140fe82021-01-27 15:45:44 -0800462 challengeInterest3 = state.genChallengeInterest(std::move(paramList));
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700463 }
swa770de007bc2020-03-24 21:26:21 -0700464 else if (Name("/ndn/CA/CHALLENGE").isPrefixOf(response.getName()) && count == 2) {
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700465 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500466 BOOST_CHECK(verifySignature(response, cert));
tylerliu4140fe82021-01-27 15:45:44 -0800467 state.onChallengeResponse(response);
Zhiyi Zhang6499edd2021-02-17 22:37:21 -0800468 BOOST_CHECK(state.m_status == Status::SUCCESS);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700469 }
Davide Pesavento914d05f2019-07-13 16:20:19 -0400470 });
471
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700472 face.receive(*newInterest);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800473 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700474 face.receive(*challengeInterest);
475 advanceClocks(time::milliseconds(20), 60);
476 face.receive(*challengeInterest2);
477 advanceClocks(time::milliseconds(20), 60);
478 face.receive(*challengeInterest3);
479 advanceClocks(time::milliseconds(20), 60);
480 BOOST_CHECK_EQUAL(count, 3);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800481}
482
tylerliu182bc532020-09-25 01:54:45 -0700483BOOST_AUTO_TEST_CASE(HandleRevoke)
484{
485 auto identity = addIdentity(Name("/ndn"));
486 auto key = identity.getDefaultKey();
487 auto cert = key.getDefaultCertificate();
488
Davide Pesavento0dc02012021-11-23 22:55:03 -0500489 DummyClientFace face(io, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700490 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
tylerliu182bc532020-09-25 01:54:45 -0700491 advanceClocks(time::milliseconds(20), 60);
492
493 //generate a certificate
494 auto clientIdentity = m_keyChain.createIdentity("/ndn/qwerty");
495 auto clientKey = clientIdentity.getDefaultKey();
Davide Pesavento0dc02012021-11-23 22:55:03 -0500496 Certificate clientCert;
tylerliu182bc532020-09-25 01:54:45 -0700497 clientCert.setName(Name(clientKey.getName()).append("cert-request").appendVersion());
Zhiyi Zhang8f1ade32020-10-14 16:42:57 -0700498 clientCert.setContentType(ndn::tlv::ContentType_Key);
tylerliu182bc532020-09-25 01:54:45 -0700499 clientCert.setFreshnessPeriod(time::hours(24));
Davide Pesavento6f1a2ab2022-03-17 03:57:21 -0400500 clientCert.setContent(clientKey.getPublicKey());
tylerliu182bc532020-09-25 01:54:45 -0700501 SignatureInfo signatureInfo;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500502 signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now(),
503 time::system_clock::now() + time::hours(10)));
tylerliu182bc532020-09-25 01:54:45 -0700504 m_keyChain.sign(clientCert, signingByKey(clientKey.getName()).setSignatureInfo(signatureInfo));
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -0800505 RequestId requestId = {{101}};
506 RequestState certRequest;
507 certRequest.caPrefix = Name("/ndn");
508 certRequest.requestId = requestId;
509 certRequest.requestType = RequestType::NEW;
510 certRequest.status = Status::SUCCESS;
511 certRequest.cert = clientCert;
tylerliu182bc532020-09-25 01:54:45 -0700512 auto issuedCert = ca.issueCertificate(certRequest);
513
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700514 CaProfile item;
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800515 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500516 item.cert = std::make_shared<Certificate>(cert);
tylerliu4140fe82021-01-27 15:45:44 -0800517 requester::Request state(m_keyChain, item, RequestType::REVOKE);
tylerliu182bc532020-09-25 01:54:45 -0700518
tylerliu4140fe82021-01-27 15:45:44 -0800519 auto interest = state.genRevokeInterest(issuedCert);
tylerliu182bc532020-09-25 01:54:45 -0700520
521 int count = 0;
Zhiyi Zhang46049832020-09-28 17:08:12 -0700522 face.onSendData.connect([&](const Data& response) {
tylerliu182bc532020-09-25 01:54:45 -0700523 count++;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500524 BOOST_CHECK(verifySignature(response, cert));
tylerliu182bc532020-09-25 01:54:45 -0700525 auto contentBlock = response.getContent();
526 contentBlock.parse();
527
tylerliu50d679e2020-10-14 14:08:39 -0700528 BOOST_CHECK(readString(contentBlock.get(tlv::EcdhPub)) != "");
529 BOOST_CHECK(readString(contentBlock.get(tlv::Salt)) != "");
530 BOOST_CHECK(readString(contentBlock.get(tlv::RequestId)) != "");
tylerliu182bc532020-09-25 01:54:45 -0700531
532 auto challengeBlockCount = 0;
533 for (auto const& element : contentBlock.elements()) {
tylerliu50d679e2020-10-14 14:08:39 -0700534 if (element.type() == tlv::Challenge) {
Zhiyi Zhang46049832020-09-28 17:08:12 -0700535 challengeBlockCount++;
536 }
tylerliu182bc532020-09-25 01:54:45 -0700537 }
538
539 BOOST_CHECK(challengeBlockCount != 0);
540
tylerliu4140fe82021-01-27 15:45:44 -0800541 auto challengeList = state.onNewRenewRevokeResponse(response);
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -0700542 RequestId requestId;
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -0700543 std::memcpy(requestId.data(), contentBlock.get(tlv::RequestId).value(), contentBlock.get(tlv::RequestId).value_size());
tylerliu7b9185c2020-11-24 12:15:18 -0800544 auto ca_encryption_key = ca.getCaStorage()->getRequest(requestId).encryptionKey;
Zhiyi Zhang6499edd2021-02-17 22:37:21 -0800545 BOOST_CHECK_EQUAL_COLLECTIONS(state.m_aesKey.begin(), state.m_aesKey.end(),
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -0700546 ca_encryption_key.begin(), ca_encryption_key.end());
tylerliu182bc532020-09-25 01:54:45 -0700547 });
548 face.receive(*interest);
549
550 advanceClocks(time::milliseconds(20), 60);
551 BOOST_CHECK_EQUAL(count, 1);
552}
553
554BOOST_AUTO_TEST_CASE(HandleRevokeWithBadCert)
555{
556 auto identity = addIdentity(Name("/ndn"));
557 auto key = identity.getDefaultKey();
558 auto cert = key.getDefaultCertificate();
559
Davide Pesavento0dc02012021-11-23 22:55:03 -0500560 DummyClientFace face(io, {true, true});
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700561 CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory");
tylerliu182bc532020-09-25 01:54:45 -0700562 advanceClocks(time::milliseconds(20), 60);
563
Zhiyi Zhang3e8ca252020-09-30 17:18:38 -0700564 // generate a certificate
tylerliu182bc532020-09-25 01:54:45 -0700565 auto clientIdentity = m_keyChain.createIdentity("/ndn/qwerty");
566 auto clientKey = clientIdentity.getDefaultKey();
Davide Pesavento0dc02012021-11-23 22:55:03 -0500567 Certificate clientCert;
568 clientCert.setName(Name(clientKey.getName()).append("NDNCERT").append("1473283247810732701"));
Zhiyi Zhang8f1ade32020-10-14 16:42:57 -0700569 clientCert.setContentType(ndn::tlv::ContentType_Key);
tylerliu182bc532020-09-25 01:54:45 -0700570 clientCert.setFreshnessPeriod(time::hours(24));
Davide Pesavento6f1a2ab2022-03-17 03:57:21 -0400571 clientCert.setContent(clientKey.getPublicKey());
tylerliu182bc532020-09-25 01:54:45 -0700572 SignatureInfo signatureInfo;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500573 signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(time::system_clock::now(),
574 time::system_clock::now() + time::hours(10)));
tylerliu182bc532020-09-25 01:54:45 -0700575 m_keyChain.sign(clientCert, signingByKey(clientKey.getName()).setSignatureInfo(signatureInfo));
576
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700577 CaProfile item;
Zhiyi Zhang44c6a352020-12-14 10:57:17 -0800578 item.caPrefix = Name("/ndn");
Davide Pesavento0dc02012021-11-23 22:55:03 -0500579 item.cert = std::make_shared<Certificate>(cert);
tylerliu4140fe82021-01-27 15:45:44 -0800580 requester::Request state(m_keyChain, item, RequestType::NEW);
tylerliu182bc532020-09-25 01:54:45 -0700581
tylerliu4140fe82021-01-27 15:45:44 -0800582 auto interest = state.genRevokeInterest(clientCert);
tylerliu182bc532020-09-25 01:54:45 -0700583
Zhiyi Zhang3e8ca252020-09-30 17:18:38 -0700584 bool receiveData = false;
Zhiyi Zhang46049832020-09-28 17:08:12 -0700585 face.onSendData.connect([&](const Data& response) {
Zhiyi Zhang3e8ca252020-09-30 17:18:38 -0700586 receiveData = true;
587 auto contentTlv = response.getContent();
588 contentTlv.parse();
tylerliu50d679e2020-10-14 14:08:39 -0700589 BOOST_CHECK(static_cast<ErrorCode>(readNonNegativeInteger(contentTlv.get(tlv::ErrorCode))) != ErrorCode::NO_ERROR);
tylerliu182bc532020-09-25 01:54:45 -0700590 });
591 face.receive(*interest);
592
593 advanceClocks(time::milliseconds(20), 60);
Zhiyi Zhang3e8ca252020-09-30 17:18:38 -0700594 BOOST_CHECK_EQUAL(receiveData, true);
tylerliu182bc532020-09-25 01:54:45 -0700595}
596
Davide Pesavento0dc02012021-11-23 22:55:03 -0500597BOOST_AUTO_TEST_SUITE_END() // TestCaModule
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800598
Davide Pesavento0d1d11c2022-04-11 22:11:34 -0400599} // namespace ndncert::tests