Skip to content

Commit

Permalink
ca: fallback to CA identity key to sign prefix registrations
Browse files Browse the repository at this point in the history
Change-Id: I19968754b5693a664fd92a28dddd636535b81fa6
  • Loading branch information
tianyuan129 authored and Pesa committed Dec 22, 2024
1 parent cde062e commit a721a4d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/ca-module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/unit-tests/ca-module.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions tests/unit-tests/requester.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit a721a4d

Please sign in to comment.