Skip to content

Commit

Permalink
Use KeyChain::makeCertificate()
Browse files Browse the repository at this point in the history
Change-Id: Iaf6d643feaecb9b208772067a071fbbafdf7c5a8
  • Loading branch information
Pesa committed Dec 22, 2024
1 parent a721a4d commit 6481e1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
22 changes: 6 additions & 16 deletions src/ca-module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,22 +481,12 @@ CaModule::onChallenge(const Interest& request)
Certificate
CaModule::issueCertificate(const RequestState& requestState)
{
auto period = requestState.cert.getValidityPeriod();
Certificate newCert;

Name certName = requestState.cert.getKeyName();
certName.append("NDNCERT").appendVersion();
newCert.setName(certName);
newCert.setContent(requestState.cert.getContent());
newCert.setFreshnessPeriod(1_h);
NDN_LOG_TRACE("cert request content " << requestState.cert);
SignatureInfo signatureInfo;
signatureInfo.setValidityPeriod(period);
ndn::security::SigningInfo signingInfo(ndn::security::SigningInfo::SIGNER_TYPE_ID,
m_config.caProfile.caPrefix, signatureInfo);
// Note: we should use KeyChain::makeCertificate() in future.
m_keyChain.sign(newCert, signingInfo);
NDN_LOG_TRACE("new cert got signed" << newCert);
ndn::security::MakeCertificateOptions opts;
opts.issuerId = Name::Component("NDNCERT");
opts.validity = requestState.cert.getValidityPeriod();
auto newCert = m_keyChain.makeCertificate(requestState.cert,
signingByIdentity(m_config.caProfile.caPrefix), opts);
NDN_LOG_TRACE("Signed new certificate: " << newCert);
return newCert;
}

Expand Down
27 changes: 9 additions & 18 deletions src/requester-request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,28 +122,19 @@ Request::genNewInterest(const Name& keyName,
const time::system_clock::time_point& notBefore,
const time::system_clock::time_point& notAfter)
{
if (!m_caProfile.caPrefix.isPrefixOf(keyName)) {
if (keyName.empty() || !m_caProfile.caPrefix.isPrefixOf(keyName)) {
return nullptr;
}
if (keyName.empty()) {
return nullptr;
}
else {
const auto& pib = m_keyChain.getPib();
ndn::security::pib::Identity identity;
m_identityName = ndn::security::extractIdentityFromKeyName(keyName);
identity = pib.getIdentity(m_identityName);
m_keyPair = identity.getKey(keyName);
}

m_identityName = ndn::security::extractIdentityFromKeyName(keyName);
auto identity = m_keyChain.getPib().getIdentity(m_identityName);
m_keyPair = identity.getKey(keyName);

// generate certificate request
Certificate certRequest;
certRequest.setName(Name(keyName).append("cert-request").appendVersion());
certRequest.setContentType(ndn::tlv::ContentType_Key);
certRequest.setContent(m_keyPair.getPublicKey());
SignatureInfo signatureInfo;
signatureInfo.setValidityPeriod(ndn::security::ValidityPeriod(notBefore, notAfter));
m_keyChain.sign(certRequest, signingByKey(keyName).setSignatureInfo(signatureInfo));
ndn::security::MakeCertificateOptions opts;
opts.issuerId = Name::Component("cert-request");
opts.validity.emplace(notBefore, notAfter);
auto certRequest = m_keyChain.makeCertificate(m_keyPair, signingByKey(keyName), opts);

// generate Interest packet
Name interestName = m_caProfile.caPrefix;
Expand Down

0 comments on commit 6481e1e

Please sign in to comment.