still one error left
Change-Id: Id89dd6c85e02032b788d6cf97fc8b3ae9964b757
diff --git a/tests/unit-tests/ca-memory.t.cpp b/tests/unit-tests/ca-memory.t.cpp
index 86c150e..4d6c9cc 100644
--- a/tests/unit-tests/ca-memory.t.cpp
+++ b/tests/unit-tests/ca-memory.t.cpp
@@ -40,7 +40,9 @@
// add operation
RequestId requestId = {1,2,3,4,5,6,7,8};
- RequestState request1(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert1, makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"));
+ std::array<uint8_t, 16> aesKey1;
+ RequestState request1(Name("/ndn/site1"), requestId, RequestType::NEW,
+ Status::BEFORE_CHALLENGE, cert1, std::move(aesKey1));
BOOST_CHECK_NO_THROW(storage.addRequest(request1));
// get operation
@@ -48,15 +50,17 @@
BOOST_CHECK_EQUAL(request1.m_cert, result.m_cert);
BOOST_CHECK(request1.m_status == result.m_status);
BOOST_CHECK_EQUAL(request1.m_caPrefix, result.m_caPrefix);
- BOOST_CHECK_EQUAL(request1.m_encryptionKey, result.m_encryptionKey);
+ BOOST_CHECK_EQUAL_COLLECTIONS(request1.m_encryptionKey.begin(), request1.m_encryptionKey.end(),
+ result.m_encryptionKey.begin(), result.m_encryptionKey.end());
JsonSection json;
json.put("code", "1234");
// update operation
+ std::array<uint8_t, 16> aesKey2;
RequestState request2(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert1,
"email", "test", time::system_clock::now(), 3, time::seconds(3600),
- std::move(json), makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"), 0);
+ std::move(json), std::move(aesKey2), 0);
storage.updateRequest(request2);
result = storage.getRequest(requestId);
BOOST_CHECK_EQUAL(request2.m_cert, result.m_cert);
@@ -67,7 +71,9 @@
auto key2 = identity2.getDefaultKey();
auto cert2 = key2.getDefaultCertificate();
RequestId requestId2 = {8,7,6,5,4,3,2,1};
- RequestState request3(Name("/ndn/site2"), requestId2, RequestType::NEW, Status::BEFORE_CHALLENGE, cert2, makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"));
+ std::array<uint8_t, 16> aesKey3;
+ RequestState request3(Name("/ndn/site2"), requestId2, RequestType::NEW, Status::BEFORE_CHALLENGE,
+ cert2, std::move(aesKey3));
storage.addRequest(request3);
// list operation
diff --git a/tests/unit-tests/ca-module.t.cpp b/tests/unit-tests/ca-module.t.cpp
index d346014..97727c0 100644
--- a/tests/unit-tests/ca-module.t.cpp
+++ b/tests/unit-tests/ca-module.t.cpp
@@ -260,8 +260,8 @@
RequestId requestId;
std::memcpy(requestId.data(), contentBlock.get(tlv::RequestId).value(), contentBlock.get(tlv::RequestId).value_size());
auto ca_encryption_key = ca.getCaStorage()->getRequest(requestId).m_encryptionKey;
- BOOST_CHECK_EQUAL_COLLECTIONS(state.m_aesKey, state.m_aesKey + sizeof(state.m_aesKey),
- ca_encryption_key.value(), ca_encryption_key.value() + ca_encryption_key.value_size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(state.m_aesKey.begin(), state.m_aesKey.end(),
+ ca_encryption_key.begin(), ca_encryption_key.end());
});
face.receive(*interest);
@@ -468,7 +468,8 @@
time::system_clock::now() + time::hours(10)));
m_keyChain.sign(clientCert, signingByKey(clientKey.getName()).setSignatureInfo(signatureInfo));
RequestId requestId = {1,2,3,4,5,6,7,8};
- RequestState certRequest(Name("/ndn"), requestId, RequestType::NEW, Status::SUCCESS, clientCert, makeEmptyBlock(ndn::tlv::ContentType_Key));
+ std::array<uint8_t, 16> aesKey;
+ RequestState certRequest(Name("/ndn"), requestId, RequestType::NEW, Status::SUCCESS, clientCert, std::move(aesKey));
auto issuedCert = ca.issueCertificate(certRequest);
CaProfile item;
@@ -502,8 +503,8 @@
RequestId requestId;
std::memcpy(requestId.data(), contentBlock.get(tlv::RequestId).value(), contentBlock.get(tlv::RequestId).value_size());
auto ca_encryption_key = ca.getCaStorage()->getRequest(requestId).m_encryptionKey;
- BOOST_CHECK_EQUAL_COLLECTIONS(state.m_aesKey, state.m_aesKey + sizeof(state.m_aesKey),
- ca_encryption_key.value(), ca_encryption_key.value() + ca_encryption_key.value_size());
+ BOOST_CHECK_EQUAL_COLLECTIONS(state.m_aesKey.begin(), state.m_aesKey.end(),
+ ca_encryption_key.begin(), ca_encryption_key.end());
});
face.receive(*interest);
diff --git a/tests/unit-tests/ca-sqlite.t.cpp b/tests/unit-tests/ca-sqlite.t.cpp
index 5f8e49e..ee1a2c5 100644
--- a/tests/unit-tests/ca-sqlite.t.cpp
+++ b/tests/unit-tests/ca-sqlite.t.cpp
@@ -39,7 +39,8 @@
// add operation
RequestId requestId = {1,2,3,4,5,6,7,8};
- RequestState request1(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert1, makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"));
+ std::array<uint8_t, 16> aesKey1;
+ RequestState request1(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert1, std::move(aesKey1));
storage.addRequest(request1);
// get operation
@@ -47,14 +48,16 @@
BOOST_CHECK_EQUAL(request1.m_cert, result.m_cert);
BOOST_CHECK(request1.m_status == result.m_status);
BOOST_CHECK_EQUAL(request1.m_caPrefix, result.m_caPrefix);
- BOOST_CHECK_EQUAL(request1.m_encryptionKey, result.m_encryptionKey);
+ BOOST_CHECK_EQUAL_COLLECTIONS(request1.m_encryptionKey.begin(), request1.m_encryptionKey.end(),
+ result.m_encryptionKey.begin(), result.m_encryptionKey.end());
// update operation
JsonSection json;
json.put("test", "4567");
+ std::array<uint8_t, 16> aesKey2;
RequestState request2(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert1,
"email", "test", time::system_clock::now(), 3, time::seconds(3600),
- std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
+ std::move(json), std::move(aesKey2), 0);
storage.updateRequest(request2);
result = storage.getRequest(requestId);
BOOST_CHECK_EQUAL(request2.m_cert, result.m_cert);
@@ -65,7 +68,9 @@
auto key2 = identity2.getDefaultKey();
auto cert2 = key2.getDefaultCertificate();
RequestId requestId2 = {8,7,6,5,4,3,2,1};
- RequestState request3(Name("/ndn/site2"), requestId2, RequestType::NEW, Status::BEFORE_CHALLENGE, cert2, makeStringBlock(ndn::tlv::ContentType_Key, "PretendItIsAKey"));
+ std::array<uint8_t, 16> aesKey3;
+ RequestState request3(Name("/ndn/site2"), requestId2, RequestType::NEW,
+ Status::BEFORE_CHALLENGE, cert2, std::move(aesKey3));
storage.addRequest(request3);
// list operation
@@ -91,7 +96,9 @@
// add operation
RequestId requestId = {1,2,3,4,5,6,7,8};
- RequestState request1(Name("/ndn/site1"),requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert1, makeEmptyBlock(ndn::tlv::ContentType_Key));
+ std::array<uint8_t, 16> aesKey;
+ RequestState request1(Name("/ndn/site1"),requestId, RequestType::NEW,
+ Status::BEFORE_CHALLENGE, cert1, std::move(aesKey));
BOOST_CHECK_NO_THROW(storage.addRequest(request1));
// add again
BOOST_CHECK_THROW(storage.addRequest(request1), std::runtime_error);
diff --git a/tests/unit-tests/challenge-credential.t.cpp b/tests/unit-tests/challenge-credential.t.cpp
index 8a301df..93a52d0 100644
--- a/tests/unit-tests/challenge-credential.t.cpp
+++ b/tests/unit-tests/challenge-credential.t.cpp
@@ -54,7 +54,9 @@
auto keyA = identityA.getDefaultKey();
auto certA = key.getDefaultCertificate();
RequestId requestId = {1,2,3,4,5,6,7,8};
- ca::RequestState state(Name("/example"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, certA, makeEmptyBlock(ndn::tlv::ContentType_Key));
+ std::array<uint8_t, 16> aesKey;
+ ca::RequestState state(Name("/example"), requestId, RequestType::NEW,
+ Status::BEFORE_CHALLENGE, certA, std::move(aesKey));
// create requester's credential
auto identityB = addIdentity(Name("/trust/cert"));
diff --git a/tests/unit-tests/challenge-email.t.cpp b/tests/unit-tests/challenge-email.t.cpp
index ccf51cf..5801bca 100644
--- a/tests/unit-tests/challenge-email.t.cpp
+++ b/tests/unit-tests/challenge-email.t.cpp
@@ -45,8 +45,9 @@
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- RequestId requestId = {1,2,3,4,5,6,7,8};
- ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert, makeEmptyBlock(ndn::tlv::ContentType_Key));
+ RequestId requestId = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::array<uint8_t, 16> aesKey;
+ ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert, std::move(aesKey));
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_EMAIL));
@@ -95,8 +96,9 @@
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- RequestId requestId = {1,2,3,4,5,6,7,8};
- ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert, makeEmptyBlock(ndn::tlv::ContentType_Key));
+ RequestId requestId = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::array<uint8_t, 16> aesKey;
+ ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert, std::move(aesKey));
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_EMAIL));
@@ -117,10 +119,11 @@
auto cert = key.getDefaultCertificate();
JsonSection json;
json.put(ChallengeEmail::PARAMETER_KEY_CODE, "4567");
- RequestId requestId = {1,2,3,4,5,6,7,8};
+ RequestId requestId = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::array<uint8_t, 16> aesKey;
ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert,
- "email", ChallengeEmail::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
+ "email", ChallengeEmail::NEED_CODE, time::system_clock::now(),
+ 3, time::seconds(3600), std::move(json), std::move(aesKey), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
@@ -140,10 +143,11 @@
auto cert = key.getDefaultCertificate();
JsonSection json;
json.put(ChallengeEmail::PARAMETER_KEY_CODE, "4567");
- RequestId requestId = {1,2,3,4,5,6,7,8};
+ RequestId requestId = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::array<uint8_t, 16> aesKey;
ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert,
- "email", ChallengeEmail::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(json), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
+ "email", ChallengeEmail::NEED_CODE, time::system_clock::now(),
+ 3, time::seconds(3600), std::move(json), std::move(aesKey), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengeEmail::PARAMETER_KEY_CODE));
diff --git a/tests/unit-tests/challenge-pin.t.cpp b/tests/unit-tests/challenge-pin.t.cpp
index e1bfad1..f790bad 100644
--- a/tests/unit-tests/challenge-pin.t.cpp
+++ b/tests/unit-tests/challenge-pin.t.cpp
@@ -38,8 +38,9 @@
auto identity = addIdentity(Name("/ndn/site1"));
auto key = identity.getDefaultKey();
auto cert = key.getDefaultCertificate();
- RequestId requestId = {1,2,3,4,5,6,7,8};
- ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert, makeEmptyBlock(ndn::tlv::ContentType_Key));
+ RequestId requestId = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::array<uint8_t, 16> aesKey;
+ ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::BEFORE_CHALLENGE, cert, std::move(aesKey));
ChallengePin challenge;
challenge.handleChallengeRequest(makeEmptyBlock(tlv::EncryptedPayload), request);
@@ -56,10 +57,11 @@
auto cert = key.getDefaultCertificate();
JsonSection secret;
secret.add(ChallengePin::PARAMETER_KEY_CODE, "12345");
- RequestId requestId = {1,2,3,4,5,6,7,8};
+ RequestId requestId = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::array<uint8_t, 16> aesKey;
ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert,
- "pin", ChallengePin::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(secret), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
+ "pin", ChallengePin::NEED_CODE, time::system_clock::now(),
+ 3, time::seconds(3600), std::move(secret), std::move(aesKey), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
@@ -79,10 +81,11 @@
auto cert = key.getDefaultCertificate();
JsonSection secret;
secret.add(ChallengePin::PARAMETER_KEY_CODE, "12345");
- RequestId requestId = {1,2,3,4,5,6,7,8};
+ RequestId requestId = {1, 2, 3, 4, 5, 6, 7, 8};
+ std::array<uint8_t, 16> aesKey;
ca::RequestState request(Name("/ndn/site1"), requestId, RequestType::NEW, Status::CHALLENGE, cert,
- "pin", ChallengePin::NEED_CODE, time::system_clock::now(),
- 3, time::seconds(3600), std::move(secret), makeEmptyBlock(ndn::tlv::ContentType_Key), 0);
+ "pin", ChallengePin::NEED_CODE, time::system_clock::now(),
+ 3, time::seconds(3600), std::move(secret), std::move(aesKey), 0);
Block paramTLV = makeEmptyBlock(tlv::EncryptedPayload);
paramTLV.push_back(makeStringBlock(tlv::ParameterKey, ChallengePin::PARAMETER_KEY_CODE));
diff --git a/tests/unit-tests/protocol-encoders.t.cpp b/tests/unit-tests/protocol-encoders.t.cpp
index 184b608..6382194 100644
--- a/tests/unit-tests/protocol-encoders.t.cpp
+++ b/tests/unit-tests/protocol-encoders.t.cpp
@@ -141,29 +141,33 @@
BOOST_CHECK_EQUAL(static_cast<size_t>(s), static_cast<size_t>(Status::BEFORE_CHALLENGE));
}
-// BOOST_AUTO_TEST_CASE(ChallengeEncoding)
-// {
-// time::system_clock::TimePoint t = time::system_clock::now();
-// requester::ProfileStorage caCache;
-// caCache.load("tests/unit-tests/config-files/config-client-1");
-// security::Certificate certRequest = *caCache.m_caItems.front().m_cert;
-// RequestId id = {102};
-// ca::RequestState state(Name("/ndn/ucla"), id, RequestType::NEW, Status::PENDING,
-// certRequest, "hahaha", "Just a test", t, 3, time::seconds(321), JsonSection(),
-// Block(), 0);
-// auto b = ChallengeEncoder::encodeDataContent(state);
-// b.push_back(makeNestedBlock(tlv::IssuedCertName, Name("/ndn/ucla/a/b/c")));
+BOOST_AUTO_TEST_CASE(ChallengeEncoding)
+{
+ const uint8_t key[] = {0x23, 0x70, 0xe3, 0x20, 0xd4, 0x34, 0x42, 0x08,
+ 0xe0, 0xff, 0x56, 0x83, 0xf2, 0x43, 0xb2, 0x13};
+ time::system_clock::TimePoint t = time::system_clock::now();
+ requester::ProfileStorage caCache;
+ caCache.load("tests/unit-tests/config-files/config-client-1");
+ security::Certificate certRequest = *caCache.m_caItems.front().m_cert;
+ RequestId id = {102};
+ std::array<uint8_t, 16> aesKey;
+ std::memcpy(aesKey.data(), key, sizeof(key));
+ ca::RequestState state(Name("/ndn/ucla"), id, RequestType::NEW, Status::PENDING,
+ certRequest, "pin", "test", t, 3, time::seconds(321), JsonSection(),
+ std::move(aesKey), 0);
+ auto b = ChallengeEncoder::encodeDataContent(state, Name("/ndn/ucla/a/b/c"));
-// requester::RequestContext context(m_keyChain, caCache.m_caItems.front(), RequestType::NEW);
-// ChallengeEncoder::decodeDataContent(b, context);
+ requester::RequestContext context(m_keyChain, caCache.m_caItems.front(), RequestType::NEW);
+ std::memcpy(context.m_aesKey.data(), key, sizeof(key));
+ ChallengeEncoder::decodeDataContent(b, context);
-// BOOST_CHECK_EQUAL(static_cast<size_t>(context.m_status), static_cast<size_t>(Status::PENDING));
-// BOOST_CHECK_EQUAL(context.m_challengeStatus, "Just a test");
-// BOOST_CHECK_EQUAL(context.m_remainingTries, 3);
-// BOOST_ASSERT(context.m_freshBefore > time::system_clock::now() + time::seconds(321) - time::milliseconds(100));
-// BOOST_ASSERT(context.m_freshBefore < time::system_clock::now() + time::seconds(321) + time::milliseconds(100));
-// BOOST_CHECK_EQUAL(context.m_issuedCertName, "/ndn/ucla/a/b/c");
-// }
+ BOOST_CHECK_EQUAL(static_cast<size_t>(context.m_status), static_cast<size_t>(Status::PENDING));
+ BOOST_CHECK_EQUAL(context.m_challengeStatus, "test");
+ BOOST_CHECK_EQUAL(context.m_remainingTries, 3);
+ BOOST_ASSERT(context.m_freshBefore > time::system_clock::now() + time::seconds(321) - time::milliseconds(100));
+ BOOST_ASSERT(context.m_freshBefore < time::system_clock::now() + time::seconds(321) + time::milliseconds(100));
+ BOOST_CHECK_EQUAL(context.m_issuedCertName, "/ndn/ucla/a/b/c");
+}
BOOST_AUTO_TEST_SUITE_END()