Add check in ca storage and fix name in certificate request hpp
Change-Id: If82dce11c5897fd1df86367233b57a998183b5a7
diff --git a/src/ca-detail/ca-memory.cpp b/src/ca-detail/ca-memory.cpp
index bde895d..14a6f87 100644
--- a/src/ca-detail/ca-memory.cpp
+++ b/src/ca-detail/ca-memory.cpp
@@ -41,6 +41,21 @@
void
CaMemory::addRequest(const CertificateRequest& request)
{
+ for (auto& entry : m_requests) {
+ const auto& existingRequest = entry.second;
+ if (existingRequest.getCert().getKeyName() == request.getCert().getKeyName()) {
+ BOOST_THROW_EXCEPTION(Error("Request for " + request.getCert().getKeyName().toUri() + " already exists"));
+ return;
+ }
+ }
+ for (auto& entry : m_issuedCerts) {
+ const auto& cert = entry.second;
+ if (cert.getKeyName() == request.getCert().getKeyName()) {
+ BOOST_THROW_EXCEPTION(Error("Cert for " + request.getCert().getKeyName().toUri() + " already exists"));
+ return;
+ }
+ }
+
auto search = m_requests.find(request.getRequestId());
if (search == m_requests.end()) {
m_requests[request.getRequestId()] = request;
@@ -73,8 +88,11 @@
auto search = m_issuedCerts.find(certId);
if (search != m_issuedCerts.end()) {
cert = search->second;
+ return cert;
}
- return cert;
+ else {
+ BOOST_THROW_EXCEPTION(Error("Certificate with ID " + certId + " does not exists"));
+ }
}
void
@@ -85,20 +103,14 @@
m_issuedCerts[certId] = cert;
}
else {
- BOOST_THROW_EXCEPTION(Error("Certificate " + cert.getName().toUri() + " does not exists"));
+ BOOST_THROW_EXCEPTION(Error("Certificate " + cert.getName().toUri() + " already exists"));
}
}
void
CaMemory::updateCertificate(const std::string& certId, const security::v2::Certificate& cert)
{
- auto search = m_issuedCerts.find(certId);
- if (search == m_issuedCerts.end()) {
- m_issuedCerts[certId] = cert;
- }
- else {
- BOOST_THROW_EXCEPTION(Error("Certificate " + cert.getName().toUri() + " does not exists"));
- }
+ m_issuedCerts[certId] = cert;
}
void
diff --git a/src/certificate-request.hpp b/src/certificate-request.hpp
index 26fd9da..29e3823 100644
--- a/src/certificate-request.hpp
+++ b/src/certificate-request.hpp
@@ -46,8 +46,8 @@
CertificateRequest(const Name& caName, const std::string& requestId,
const std::string& status, const std::string& challengeType,
- const std::string& challengeDefinedField,
- const security::v2::Certificate& certBlock);
+ const std::string& challengeSecrets,
+ const security::v2::Certificate& cert);
const Name&
getCaName() const