change request id to be bytes
Change-Id: If980f23259a31acc59d17e3115a27320e94dcacb
diff --git a/src/detail/ca-memory.cpp b/src/detail/ca-memory.cpp
index b647dba..b054cc0 100644
--- a/src/detail/ca-memory.cpp
+++ b/src/detail/ca-memory.cpp
@@ -35,11 +35,11 @@
}
CaState
-CaMemory::getRequest(const std::string& requestId)
+CaMemory::getRequest(const RequestID& requestId)
{
auto search = m_requests.find(requestId);
if (search == m_requests.end()) {
- NDN_THROW(std::runtime_error("Request " + requestId + " doest not exists"));
+ NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) + " doest not exists"));
}
return search->second;
}
@@ -52,7 +52,7 @@
m_requests[request.m_requestId] = request;
}
else {
- NDN_THROW(std::runtime_error("Request " + request.m_requestId + " already exists"));
+ NDN_THROW(std::runtime_error("Request " + toHex(request.m_requestId.data(), request.m_requestId.size()) + " already exists"));
}
}
@@ -64,7 +64,7 @@
}
void
-CaMemory::deleteRequest(const std::string& requestId)
+CaMemory::deleteRequest(const RequestID& requestId)
{
auto search = m_requests.find(requestId);
auto keyName = search->second.m_cert.getKeyName();
diff --git a/src/detail/ca-memory.hpp b/src/detail/ca-memory.hpp
index 842121b..0c2fa34 100644
--- a/src/detail/ca-memory.hpp
+++ b/src/detail/ca-memory.hpp
@@ -37,7 +37,7 @@
* @throw if request cannot be fetched from underlying data storage
*/
CaState
- getRequest(const std::string& requestId) override;
+ getRequest(const RequestID& requestId) override;
/**
* @throw if there is an existing request with the same request ID
@@ -49,7 +49,7 @@
updateRequest(const CaState& request) override;
void
- deleteRequest(const std::string& requestId) override;
+ deleteRequest(const RequestID& requestId) override;
std::list<CaState>
listAllRequests() override;
@@ -58,7 +58,7 @@
listAllRequests(const Name& caName) override;
private:
- std::map<Name, CaState> m_requests;
+ std::map<RequestID, CaState> m_requests;
};
} // namespace ndncert
diff --git a/src/detail/ca-sqlite.cpp b/src/detail/ca-sqlite.cpp
index 468fd2c..8371cf4 100644
--- a/src/detail/ca-sqlite.cpp
+++ b/src/detail/ca-sqlite.cpp
@@ -55,7 +55,7 @@
CREATE TABLE IF NOT EXISTS
CaStates(
id INTEGER PRIMARY KEY,
- request_id TEXT NOT NULL,
+ request_id BLOB NOT NULL,
ca_name BLOB NOT NULL,
request_type INTEGER NOT NULL,
status INTEGER NOT NULL,
@@ -123,7 +123,7 @@
}
CaState
-CaSqlite::getRequest(const std::string& requestId)
+CaSqlite::getRequest(const RequestID& requestId)
{
Sqlite3Statement statement(m_database,
R"_SQLTEXT_(SELECT id, ca_name, status,
@@ -132,7 +132,7 @@
challenge_tp, remaining_tries, remaining_time,
request_type, encryption_key, aes_block_counter
FROM CaStates where request_id = ?)_SQLTEXT_");
- statement.bind(1, requestId, SQLITE_TRANSIENT);
+ statement.bind(1, requestId.data(), requestId.size(), SQLITE_TRANSIENT);
if (statement.step() == SQLITE_ROW) {
Name caName(statement.getBlock(1));
@@ -158,7 +158,7 @@
}
}
else {
- NDN_THROW(std::runtime_error("Request " + requestId + " cannot be fetched from database"));
+ NDN_THROW(std::runtime_error("Request " + toHex(requestId.data(), requestId.size()) + " cannot be fetched from database"));
}
}
@@ -171,7 +171,7 @@
cert_request, challenge_type, challenge_status, challenge_secrets,
challenge_tp, remaining_tries, remaining_time, encryption_key, aes_block_counter)
values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?))_SQLTEXT_");
- statement.bind(1, request.m_requestId, SQLITE_TRANSIENT);
+ statement.bind(1, request.m_requestId.data(), request.m_requestId.size(), SQLITE_TRANSIENT);
statement.bind(2, request.m_caPrefix.wireEncode(), SQLITE_TRANSIENT);
statement.bind(3, static_cast<int>(request.m_status));
statement.bind(4, static_cast<int>(request.m_requestType));
@@ -188,7 +188,7 @@
statement.bind(11, request.m_challengeState->m_remainingTime.count());
}
if (statement.step() != SQLITE_DONE) {
- NDN_THROW(std::runtime_error("Request " + request.m_requestId + " cannot be added to database"));
+ NDN_THROW(std::runtime_error("Request " + toHex(request.m_requestId.data(), request.m_requestId.size()) + " cannot be added to database"));
}
}
@@ -217,7 +217,7 @@
statement.bind(7, 0);
}
statement.bind(8, request.m_aesBlockCounter);
- statement.bind(9, request.m_requestId, SQLITE_TRANSIENT);
+ statement.bind(9, request.m_requestId.data(), request.m_requestId.size(), SQLITE_TRANSIENT);
if (statement.step() != SQLITE_DONE) {
addRequest(request);
@@ -234,7 +234,8 @@
encryption_key, aes_block_counter
FROM CaStates)_SQLTEXT_");
while (statement.step() == SQLITE_ROW) {
- auto requestId = statement.getString(1);
+ RequestID requestId;
+ std::memcpy(requestId.data(), statement.getBlob(1), statement.getSize(1));
Name caName(statement.getBlock(2));
auto status = static_cast<Status>(statement.getInt(3));
auto challengeStatus = statement.getString(4);
@@ -273,7 +274,8 @@
statement.bind(1, caName.wireEncode(), SQLITE_TRANSIENT);
while (statement.step() == SQLITE_ROW) {
- auto requestId = statement.getString(1);
+ RequestID requestId;
+ std::memcpy(requestId.data(), statement.getBlob(1), statement.getSize(1));
Name caName(statement.getBlock(2));
auto status = static_cast<Status>(statement.getInt(3));
auto challengeStatus = statement.getString(4);
@@ -300,11 +302,11 @@
}
void
-CaSqlite::deleteRequest(const std::string& requestId)
+CaSqlite::deleteRequest(const RequestID& requestId)
{
Sqlite3Statement statement(m_database,
R"_SQLTEXT_(DELETE FROM CaStates WHERE request_id = ?)_SQLTEXT_");
- statement.bind(1, requestId, SQLITE_TRANSIENT);
+ statement.bind(1, requestId.data(), requestId.size(), SQLITE_TRANSIENT);
statement.step();
}
diff --git a/src/detail/ca-sqlite.hpp b/src/detail/ca-sqlite.hpp
index 5d12188..f0ffe1f 100644
--- a/src/detail/ca-sqlite.hpp
+++ b/src/detail/ca-sqlite.hpp
@@ -43,7 +43,7 @@
* @throw if request cannot be fetched from underlying data storage
*/
CaState
- getRequest(const std::string& requestId) override;
+ getRequest(const RequestID& requestId) override;
/**
* @throw if there is an existing request with the same request ID
@@ -55,7 +55,7 @@
updateRequest(const CaState& request) override;
void
- deleteRequest(const std::string& requestId) override;
+ deleteRequest(const RequestID& requestId) override;
std::list<CaState>
listAllRequests() override;
diff --git a/src/detail/ca-state.cpp b/src/detail/ca-state.cpp
index 334429a..4dad34d 100644
--- a/src/detail/ca-state.cpp
+++ b/src/detail/ca-state.cpp
@@ -64,7 +64,7 @@
{
}
-CaState::CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
+CaState::CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
const security::Certificate& cert, Block encryptionKey, uint32_t aesBlockCounter)
: m_caPrefix(caName)
, m_requestId(requestId)
@@ -76,7 +76,7 @@
{
}
-CaState::CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
+CaState::CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
const security::Certificate& cert, const std::string& challengeType,
const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
@@ -97,7 +97,7 @@
operator<<(std::ostream& os, const CaState& request)
{
os << "Request's CA name: " << request.m_caPrefix << "\n";
- os << "Request's request ID: " << request.m_requestId << "\n";
+ os << "Request's request ID: " << toHex(request.m_requestId.data(), request.m_requestId.size()) << "\n";
os << "Request's status: " << statusToString(request.m_status) << "\n";
os << "Request's challenge type: " << request.m_challengeType << "\n";
if (request.m_challengeState) {
diff --git a/src/detail/ca-state.hpp b/src/detail/ca-state.hpp
index 9f30b6d..897d98d 100644
--- a/src/detail/ca-state.hpp
+++ b/src/detail/ca-state.hpp
@@ -22,10 +22,13 @@
#define NDNCERT_CA_STATE_HPP
#include "detail/ndncert-common.hpp"
+#include <array>
namespace ndn {
namespace ndncert {
+typedef std::array<uint8_t, 8> RequestID;
+
// NDNCERT Request status enumeration
enum class Status : uint16_t {
BEFORE_CHALLENGE = 0,
@@ -65,9 +68,9 @@
{
public:
CaState();
- CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
+ CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
const security::Certificate& cert, Block m_encryptionKey, uint32_t aesBlockCounter = 0);
- CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
+ CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
const security::Certificate& cert, const std::string& challengeType,
const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
@@ -75,7 +78,7 @@
public:
Name m_caPrefix;
- std::string m_requestId;
+ RequestID m_requestId;
RequestType m_requestType;
Status m_status;
security::Certificate m_cert;
diff --git a/src/detail/ca-storage.hpp b/src/detail/ca-storage.hpp
index 70a0ac9..b5c2ce7 100644
--- a/src/detail/ca-storage.hpp
+++ b/src/detail/ca-storage.hpp
@@ -33,7 +33,7 @@
* @throw if request cannot be fetched from underlying data storage
*/
virtual CaState
- getRequest(const std::string& requestId) = 0;
+ getRequest(const RequestID& requestId) = 0;
/**
* @throw if there is an existing request with the same request ID
@@ -45,7 +45,7 @@
updateRequest(const CaState& request) = 0;
virtual void
- deleteRequest(const std::string& requestId) = 0;
+ deleteRequest(const RequestID& requestId) = 0;
virtual std::list<CaState>
listAllRequests() = 0;
diff --git a/src/detail/new-renew-revoke-encoder.cpp b/src/detail/new-renew-revoke-encoder.cpp
index 3afe2ad..ef67146 100644
--- a/src/detail/new-renew-revoke-encoder.cpp
+++ b/src/detail/new-renew-revoke-encoder.cpp
@@ -55,7 +55,8 @@
void
NewRenewRevokeEncoder::decodeApplicationParameters(const Block& payload, RequestType requestType, std::string& ecdhPub,
- shared_ptr<security::Certificate>& clientCert) {
+ shared_ptr<security::Certificate>& clientCert)
+{
payload.parse();
ecdhPub = readString(payload.get(tlv::EcdhPub));
@@ -74,13 +75,13 @@
Block
NewRenewRevokeEncoder::encodeDataContent(const std::string& ecdhKey, const std::string& salt,
- const CaState& request,
- const std::list<std::string>& challenges)
+ const CaState& request,
+ const std::list<std::string>& challenges)
{
Block response = makeEmptyBlock(ndn::tlv::Content);
response.push_back(makeStringBlock(tlv::EcdhPub, ecdhKey));
response.push_back(makeStringBlock(tlv::Salt, salt));
- response.push_back(makeStringBlock(tlv::RequestId, request.m_requestId));
+ response.push_back(makeBinaryBlock(tlv::RequestId, request.m_requestId.data(), request.m_requestId.size()));
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));
@@ -97,7 +98,8 @@
const auto& salt = readString(content.get(tlv::Salt));
uint64_t saltInt = std::stoull(salt);
const auto& requestStatus = static_cast<Status>(readNonNegativeInteger(content.get(tlv::Status)));
- const auto& requestId = readString(content.get(tlv::RequestId));
+ RequestID requestId;
+ std::memcpy(requestId.data(), content.get(tlv::RequestId).value(), content.get(tlv::RequestId).size());
std::list<std::string> challenges;
for (auto const& element : content.elements()) {
if (element.type() == tlv::Challenge) {
diff --git a/src/detail/new-renew-revoke-encoder.hpp b/src/detail/new-renew-revoke-encoder.hpp
index 70e69aa..8b083d6 100644
--- a/src/detail/new-renew-revoke-encoder.hpp
+++ b/src/detail/new-renew-revoke-encoder.hpp
@@ -37,12 +37,13 @@
static Block
encodeDataContent(const std::string& ecdhKey, const std::string& salt,
- const CaState& request,
- const std::list<std::string>& challenges);
+ const CaState& request,
+ const std::list<std::string>& challenges);
+
struct DecodedData {
std::string ecdhKey;
uint64_t salt;
- std::string requestId;
+ RequestID requestId;
Status requestStatus;
std::list<std::string> challenges;
};