1 #ifndef NDNPH_APP_NDNCERT_COMMON_HPP
2 #define NDNPH_APP_NDNCERT_COMMON_HPP
5 #include "../../core/log.hpp"
6 #include "../../keychain/ec.hpp"
7 #include "../../packet/encrypted-message.hpp"
8 #include "../../port/clock/port.hpp"
9 #include "../../port/mbed-common.hpp"
10 #include <mbedtls/hkdf.h>
12 #ifdef NDNPH_NDNCERT_DEBUG
13 #define NDNPH_NDNCERT_LOG(...) NDNPH_LOG_LINE("ndncert", ##__VA_ARGS__)
15 #define NDNPH_NDNCERT_LOG(...) \
28 using SaltLen = std::integral_constant<size_t, 32>;
37 const uint8_t* salt,
const uint8_t* requestId) {
41 mbedtls_hkdf(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), salt, SaltLen::value,
42 ikm.data(), ikm.size(), requestId, RequestIdLen::value, okm.data(),
49 return m_aes.encrypt<
Encrypted>(region, plaintext, requestId, RequestIdLen::value);
56 EvDecoder::def<TT::InitializationVector>(&encrypted),
57 EvDecoder::def<TT::AuthenticationTag>(&encrypted),
58 EvDecoder::def<TT::EncryptedPayload>(&encrypted));
62 return m_aes.decrypt(region, encrypted, requestId, RequestIdLen::value);
81 namespace packet_struct {
93 if (m_pos >= detail::MaxChallengeParams::value) {
101 if (m_pos >= detail::MaxChallengeParams::value) {
104 auto key = m_target.m_kv[m_pos].first;
117 for (
const auto& p : m_kv) {
118 if (p.first == key) {
128 for (
auto& p : m_kv) {
130 p = std::make_pair(key, value);
144 for (
auto it = m_kv.rbegin(); it != m_kv.rend(); ++it) {
154 std::array<std::pair<tlv::Value, tlv::Value>, detail::MaxChallengeParams::value> m_kv;
162 uint32_t maxValidityPeriod = 0;
181 uint8_t salt[detail::SaltLen::value];
184 uint8_t requestId[detail::RequestIdLen::value];
187 template<
typename ChallengeT>
190 ChallengeT* challenge =
nullptr;
204 uint16_t remainingTries = 0;
Data packet.
Definition: data.hpp:136
Decoded TLV.
Definition: decoder.hpp:13
size_t length
Definition: decoder.hpp:39
const uint8_t * value
Definition: decoder.hpp:40
TLV encoder that accepts items in reverse order.
Definition: encoder.hpp:10
bool prependTlv(uint32_t type, OmitEmptyTag omitEmpty, const Arg &... arg)
Prepend TLV, measuring TLV-LENGTH automatically.
Definition: encoder.hpp:143
Encrypted message structure.
Definition: encrypted-message.hpp:24
static bool decodeValue(const Decoder &input, const E &... defs)
Decode input TLV-VALUE with a sequence of element definitions.
Definition: ev-decoder.hpp:126
Name.
Definition: name.hpp:14
Region-based memory allocator thats owns memory of NDNph objects.
Definition: region.hpp:9
Require SigNonce field in Interest SigInfo.
Definition: sig-info.hpp:114
Require SigTime field in Interest SigInfo.
Definition: sig-info.hpp:192
std::array< uint8_t, keyBits/8 > Key
Definition: mbed-common.hpp:273
EC point associated with a curve.
Definition: mbed-common.hpp:213
Multi-Precision Integer.
Definition: mbed-common.hpp:102
std::array< uint8_t, PvtLen::value > SharedSecret
ECDH shared secret buffer.
Definition: mbed-common.hpp:252
static bool ecdh(const mbedtls_mpi *pvt, const mbedtls_ecp_point *pub, SharedSecret &shared)
Compute ECDH shared secret.
Definition: mbed-common.hpp:255
Symmetric key used in CHALLENGE step.
Definition: common.hpp:33
tlv::Value decrypt(Region ®ion, tlv::Value message, const uint8_t *requestId)
Decrypt from encrypted-message.
Definition: common.hpp:53
tlv::Value encrypt(Region ®ion, tlv::Value plaintext, const uint8_t *requestId)
Encrypt to encrypted-message.
Definition: common.hpp:48
bool makeKey(const mbedtls::Mpi &ecdhPvt, const mbedtls::P256::Point &ecdhPub, const uint8_t *salt, const uint8_t *requestId)
Derive the key.
Definition: common.hpp:36
Definition: common.hpp:85
bool parseValue(const Decoder::Tlv &d)
Definition: common.hpp:100
bool parseKey(const Decoder::Tlv &d)
Definition: common.hpp:92
Parser(ParameterKV &target)
Definition: common.hpp:87
Definition: common.hpp:83
bool set(tlv::Value key, tlv::Value value)
Set a parameter.
Definition: common.hpp:126
void encodeTo(Encoder &encoder) const
Prepend ParameterKey-ParameterValue pairs to Encoder.
Definition: common.hpp:143
void clear()
Clear parameters.
Definition: common.hpp:138
tlv::Value get(tlv::Value key) const
Retrieve parameter value by parameter key.
Definition: common.hpp:116
A sequence of bytes, usually TLV-VALUE.
Definition: value.hpp:11
Decoder makeDecoder() const
Create a Decoder over this value buffer.
Definition: value.hpp:64
#define NDNPH_ASSERT(x)
Definition: common.hpp:30
Definition: input-iterator-pointer-proxy.hpp:5
Policy< R... > makePolicy(R &&... rule)
Create Interest SigInfo validation policy.
Definition: sig-info.hpp:312
@ BEFORE_CHALLENGE
Definition: an.hpp:86
@ EncryptedPayload
Definition: an.hpp:28
@ ParameterValue
Definition: an.hpp:16
@ InitializationVector
Definition: an.hpp:27
@ AuthenticationTag
Definition: an.hpp:36
@ ParameterKey
Definition: an.hpp:15
std::integral_constant< int, 2 > MaxChallengeParams
Definition: common.hpp:26
std::integral_constant< size_t, 8 > RequestIdLen
Definition: common.hpp:29
std::integral_constant< size_t, 16 > AuthenticationTagLen
Definition: common.hpp:30
std::integral_constant< int, 4 > MaxChallenges
Definition: common.hpp:25
ISigPolicy makeISigPolicy()
Definition: common.hpp:76
std::integral_constant< size_t, 32 > SaltLen
Definition: common.hpp:28
Definition: common.hpp:157
Name prefix
CA prefix.
Definition: common.hpp:159
Data cert
CA certificate.
Definition: common.hpp:165
Definition: common.hpp:188
ParameterKV params
Parameter key-value pairs.
Definition: common.hpp:193
Definition: common.hpp:196
Name fwHint
Forwarding hint to retrieve issued certificate.
Definition: common.hpp:216
Name issuedCertName
Issued certificate full name.
Definition: common.hpp:213
ParameterKV params
Parameter key-value pairs.
Definition: common.hpp:210
tlv::Value challengeStatus
Challenge status string.
Definition: common.hpp:201
Definition: common.hpp:168
mbedtls::P256::Point ecdhPub
Client ECDH public key.
Definition: common.hpp:170
Data certRequest
Certificate request.
Definition: common.hpp:173
Definition: common.hpp:176
mbedtls::P256::Point ecdhPub
Server ECDH public key.
Definition: common.hpp:178