merge encoding for NEW/REVOKE
Change-Id: Ife673f8f2fd20f0543aad9c759de05978de85e9a
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index 8cd8475..70aa887 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -24,9 +24,8 @@
#include "protocol-detail/challenge.hpp"
#include "protocol-detail/error.hpp"
#include "protocol-detail/info.hpp"
-#include "protocol-detail/new.hpp"
+#include "protocol-detail/new-renew-revoke.hpp"
#include "protocol-detail/probe.hpp"
-#include "protocol-detail/revoke.hpp"
#include <ndn-cxx/metadata-object.hpp>
#include <ndn-cxx/security/signing-helpers.hpp>
#include <ndn-cxx/security/verification-helpers.hpp>
@@ -347,18 +346,10 @@
Data result;
result.setName(request.getName());
result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD);
- if (requestType == RequestType::NEW) {
- result.setContent(NEW::encodeDataContent(myEcdhPubKeyBase64,
- std::to_string(saltInt),
- requestState,
- m_config.m_caItem.m_supportedChallenges));
- }
- else if (requestType == RequestType::REVOKE) {
- result.setContent(REVOKE::encodeDataContent(myEcdhPubKeyBase64,
+ result.setContent(NEW_RENEW_REVOKE::encodeDataContent(myEcdhPubKeyBase64,
std::to_string(saltInt),
requestState,
m_config.m_caItem.m_supportedChallenges));
- }
m_keyChain.sign(result, signingByIdentity(m_config.m_caItem.m_caPrefix));
m_face.put(result);
if (m_config.m_statusUpdateCallback) {
diff --git a/src/client-module.cpp b/src/client-module.cpp
index 46405bb..ffda468 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -32,9 +32,8 @@
#include "crypto-support/enc-tlv.hpp"
#include "protocol-detail/challenge.hpp"
#include "protocol-detail/info.hpp"
-#include "protocol-detail/new.hpp"
+#include "protocol-detail/new-renew-revoke.hpp"
#include "protocol-detail/probe.hpp"
-#include "protocol-detail/revoke.hpp"
#include "protocol-detail/error.hpp"
#include "ndncert-common.hpp"
@@ -208,7 +207,7 @@
interest->setMustBeFresh(true);
interest->setCanBePrefix(false);
interest->setApplicationParameters(
- NEW::encodeApplicationParameters(m_ecdh.getBase64PubKey(), certRequest));
+ NEW_RENEW_REVOKE::encodeApplicationParameters(RequestType::NEW, m_ecdh.getBase64PubKey(), certRequest));
// sign the Interest packet
m_keyChain.sign(*interest, signingByKey(m_key.getName()));
@@ -274,7 +273,7 @@
interest->setMustBeFresh(true);
interest->setCanBePrefix(false);
interest->setApplicationParameters(
- REVOKE::encodeApplicationParameters(m_ecdh.getBase64PubKey(), certificate));
+ NEW_RENEW_REVOKE::encodeApplicationParameters(RequestType::REVOKE, m_ecdh.getBase64PubKey(), certificate));
// return the Interest packet
return interest;
diff --git a/src/protocol-detail/new.cpp b/src/protocol-detail/new-renew-revoke.cpp
similarity index 77%
rename from src/protocol-detail/new.cpp
rename to src/protocol-detail/new-renew-revoke.cpp
index cd7b39c..0a941b1 100644
--- a/src/protocol-detail/new.cpp
+++ b/src/protocol-detail/new-renew-revoke.cpp
@@ -18,7 +18,7 @@
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
-#include "new.hpp"
+#include "new-renew-revoke.hpp"
#include "../ndncert-common.hpp"
#include <ndn-cxx/security/transform/base64-encode.hpp>
#include <ndn-cxx/security/transform/buffer-source.hpp>
@@ -31,7 +31,7 @@
_LOG_INIT(ndncert.client);
Block
-NEW::encodeApplicationParameters(const std::string& ecdhPub, const security::v2::Certificate& certRequest)
+NEW_RENEW_REVOKE::encodeApplicationParameters(RequestType requestType, const std::string& ecdhPub, const security::v2::Certificate& certRequest)
{
Block request = makeEmptyBlock(tlv::ApplicationParameters);
std::stringstream ss;
@@ -46,15 +46,19 @@
}
request.push_back(makeStringBlock(tlv_ecdh_pub, ecdhPub));
- request.push_back(makeNestedBlock(tlv_cert_request, certRequest));
+ if (requestType == RequestType::NEW || requestType == RequestType::RENEW) {
+ request.push_back(makeNestedBlock(tlv_cert_request, certRequest));
+ } else if (requestType == RequestType::REVOKE) {
+ request.push_back(makeNestedBlock(tlv_cert_to_revoke, certRequest));
+ }
request.encode();
return request;
}
Block
-NEW::encodeDataContent(const std::string& ecdhKey, const std::string& salt,
- const RequestState& request,
- const std::list<std::string>& challenges)
+NEW_RENEW_REVOKE::encodeDataContent(const std::string& ecdhKey, const std::string& salt,
+ const RequestState& request,
+ const std::list<std::string>& challenges)
{
Block response = makeEmptyBlock(tlv::Content);
response.push_back(makeStringBlock(tlv_ecdh_pub, ecdhKey));
diff --git a/src/protocol-detail/revoke.hpp b/src/protocol-detail/new-renew-revoke.hpp
similarity index 80%
rename from src/protocol-detail/revoke.hpp
rename to src/protocol-detail/new-renew-revoke.hpp
index 9f02c43..aac51d2 100644
--- a/src/protocol-detail/revoke.hpp
+++ b/src/protocol-detail/new-renew-revoke.hpp
@@ -18,18 +18,18 @@
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
-#ifndef NDNCERT_PROTOCOL_DETAIL_REVOKE_HPP
-#define NDNCERT_PROTOCOL_DETAIL_REVOKE_HPP
+#ifndef NDNCERT_PROTOCOL_DETAIL_NEW_RENEW_REVOKE_HPP
+#define NDNCERT_PROTOCOL_DETAIL_NEW_RENEW_REVOKE_HPP
#include "../request-state.hpp"
namespace ndn {
namespace ndncert {
-class REVOKE {
+class NEW_RENEW_REVOKE {
public:
static Block
- encodeApplicationParameters(const std::string& ecdhPub, const security::v2::Certificate& certToRevoke);
+ encodeApplicationParameters(RequestType requestType, const std::string& ecdhPub, const security::v2::Certificate& certRequest);
static Block
encodeDataContent(const std::string& ecdhKey, const std::string& salt,
@@ -40,4 +40,4 @@
} // namespace ndncert
} // namespace ndn
-#endif // NDNCERT_PROTOCOL_DETAIL_REVOKE_HPP
\ No newline at end of file
+#endif // NDNCERT_PROTOCOL_DETAIL_NEW_RENEW_REVOKE_HPP
\ No newline at end of file
diff --git a/src/protocol-detail/new.hpp b/src/protocol-detail/new.hpp
deleted file mode 100644
index 353ebc2..0000000
--- a/src/protocol-detail/new.hpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
- *
- * This file is part of ndncert, a certificate management system based on NDN.
- *
- * ndncert is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received copies of the GNU General Public License along with
- * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndncert authors and contributors.
- */
-
-#ifndef NDNCERT_PROTOCOL_DETAIL_NEW_HPP
-#define NDNCERT_PROTOCOL_DETAIL_NEW_HPP
-
-#include "../request-state.hpp"
-
-namespace ndn {
-namespace ndncert {
-
-class NEW {
-public:
- /**
- * Encode Client's certificate request into a ApplicationParameters TLV for NEW Interest.
- * For client side use.
- */
- static Block
- encodeApplicationParameters(const std::string& ecdhPub, const security::v2::Certificate& certRequest);
-
- /**
- * Encode CA's response of NEW Interest into a content TLV for NEW Data packet.
- * For CA side use.
- */
- static Block
- encodeDataContent(const std::string& ecdhKey, const std::string& salt,
- const RequestState& request,
- const std::list<std::string>& challenges);
-};
-
-} // namespace ndncert
-} // namespace ndn
-
-#endif // NDNCERT_PROTOCOL_DETAIL_HPP
\ No newline at end of file
diff --git a/src/protocol-detail/revoke.cpp b/src/protocol-detail/revoke.cpp
deleted file mode 100644
index 0123b3f..0000000
--- a/src/protocol-detail/revoke.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2017-2020, Regents of the University of California.
- *
- * This file is part of ndncert, a certificate management system based on NDN.
- *
- * ndncert is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received copies of the GNU General Public License along with
- * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndncert authors and contributors.
- */
-
-#include "revoke.hpp"
-#include "../ndncert-common.hpp"
-#include <ndn-cxx/security/transform/base64-encode.hpp>
-#include <ndn-cxx/security/transform/buffer-source.hpp>
-#include <ndn-cxx/security/transform/stream-sink.hpp>
-#include <ndn-cxx/util/logger.hpp>
-
-namespace ndn {
-namespace ndncert {
-
-_LOG_INIT(ndncert.client);
-
-Block
-REVOKE::encodeApplicationParameters(const std::string& ecdhPub, const security::v2::Certificate& certToRevoke)
-{
- Block request = makeEmptyBlock(tlv::ApplicationParameters);
- std::stringstream ss;
- try {
- security::transform::bufferSource(certToRevoke.wireEncode().wire(), certToRevoke.wireEncode().size())
- >> security::transform::base64Encode(false)
- >> security::transform::streamSink(ss);
- }
- catch (const security::transform::Error& e) {
- _LOG_ERROR("Cannot convert self-signed cert into BASE64 string " << e.what());
- return request;
- }
-
- request.push_back(makeStringBlock(tlv_ecdh_pub, ecdhPub));
- request.push_back(makeNestedBlock(tlv_cert_to_revoke, certToRevoke));
- request.encode();
- return request;
-}
-
-Block
-REVOKE::encodeDataContent(const std::string& ecdhKey, const std::string& salt,
- const RequestState& request,
- const std::list<std::string>& challenges)
-{
- Block response = makeEmptyBlock(tlv::Content);
- response.push_back(makeStringBlock(tlv_ecdh_pub, ecdhKey));
- response.push_back(makeStringBlock(tlv_salt, salt));
- response.push_back(makeStringBlock(tlv_request_id, request.m_requestId));
- response.push_back(makeNonNegativeIntegerBlock(tlv_status, static_cast<size_t>(request.m_status)));
- for (const auto& entry: challenges) {
- response.push_back(makeStringBlock(tlv_challenge, entry));
- }
- response.encode();
- return response;
-}
-
-} // namespace ndncert
-} // namespace ndn
\ No newline at end of file