From a721a4d23bf7c89935bbc920216c27079293f4f5 Mon Sep 17 00:00:00 2001 From: Tianyuan Yu Date: Fri, 20 Dec 2024 20:05:21 -0800 Subject: [PATCH] ca: fallback to CA identity key to sign prefix registrations Change-Id: I19968754b5693a664fd92a28dddd636535b81fa6 --- src/ca-module.cpp | 16 ++++++++++++---- tests/unit-tests/ca-module.t.cpp | 5 +++-- tests/unit-tests/requester.t.cpp | 1 + 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ca-module.cpp b/src/ca-module.cpp index 09c0b9c..b5547e0 100644 --- a/src/ca-module.cpp +++ b/src/ca-module.cpp @@ -74,11 +74,18 @@ CaModule::~CaModule() void CaModule::registerPrefix() { - // register prefixes Name prefix = m_config.caProfile.caPrefix; prefix.append("CA"); - auto prefixId = m_face.registerPrefix(prefix, + ndn::security::pib::Identity identity; + try { + identity = m_keyChain.getPib().getDefaultIdentity(); + } + catch (const ndn::security::Pib::Error&) { + identity = m_keyChain.getPib().getIdentity(m_config.caProfile.caPrefix); + } + + auto prefixHandle = m_face.registerPrefix(prefix, [&] (const Name& name) { // register INFO RDR metadata prefix const auto& metaDataComp = ndn::MetadataObject::getKeywordComponent(); @@ -108,8 +115,9 @@ CaModule::registerPrefix() NDN_LOG_TRACE("Prefix " << name << " got registered"); }, - [this] (auto&&, const auto& reason) { onRegisterFailed(reason); }); - m_registeredPrefixHandles.push_back(prefixId); + [this] (auto&&, const auto& reason) { onRegisterFailed(reason); }, + ndn::signingByIdentity(identity)); + m_registeredPrefixHandles.push_back(prefixHandle); } void diff --git a/tests/unit-tests/ca-module.t.cpp b/tests/unit-tests/ca-module.t.cpp index 9fcee0f..3b0b02b 100644 --- a/tests/unit-tests/ca-module.t.cpp +++ b/tests/unit-tests/ca-module.t.cpp @@ -40,6 +40,7 @@ BOOST_FIXTURE_TEST_SUITE(TestCaModule, IoKeyChainFixture) BOOST_AUTO_TEST_CASE(Initialization) { + m_keyChain.createIdentity(Name("/ndn")); ndn::DummyClientFace face(m_io, m_keyChain, {true, true}); CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory"); BOOST_CHECK_EQUAL(ca.getCaConf().caProfile.caPrefix, "/ndn"); @@ -498,7 +499,7 @@ BOOST_AUTO_TEST_CASE(HandleRevoke) auto key = identity.getDefaultKey(); auto cert = key.getDefaultCertificate(); - ndn::DummyClientFace face(m_io, {true, true}); + ndn::DummyClientFace face(m_io, m_keyChain, {true, true}); CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory"); advanceClocks(time::milliseconds(20), 60); @@ -569,7 +570,7 @@ BOOST_AUTO_TEST_CASE(HandleRevokeWithBadCert) auto key = identity.getDefaultKey(); auto cert = key.getDefaultCertificate(); - ndn::DummyClientFace face(m_io, {true, true}); + ndn::DummyClientFace face(m_io, m_keyChain, {true, true}); CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-1", "ca-storage-memory"); advanceClocks(time::milliseconds(20), 60); diff --git a/tests/unit-tests/requester.t.cpp b/tests/unit-tests/requester.t.cpp index a3fa8d5..03cb3de 100644 --- a/tests/unit-tests/requester.t.cpp +++ b/tests/unit-tests/requester.t.cpp @@ -77,6 +77,7 @@ BOOST_AUTO_TEST_CASE(OnProbeResponse) availableNames.emplace_back("/site1"); availableNames.emplace_back("/site2"); + m_keyChain.createIdentity(Name("/ndn")); ndn::DummyClientFace face(m_io, m_keyChain, {true, true}); ca::CaModule ca(face, m_keyChain, "tests/unit-tests/config-files/config-ca-5", "ca-storage-memory");