Loading...
Searching...
No Matches
common.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2023, Regents of the University of California
4 *
5 * NAC library is free software: you can redistribute it and/or modify it under the
6 * terms of the GNU Lesser General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later version.
8 *
9 * NAC library is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
12 *
13 * You should have received copies of the GNU General Public License and GNU Lesser
14 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
15 * <http://www.gnu.org/licenses/>.
16 *
17 * See AUTHORS.md for complete list of NAC library authors and contributors.
18 */
19
20#ifndef NDN_NAC_COMMON_HPP
21#define NDN_NAC_COMMON_HPP
22
23#include "detail/config.hpp"
24
25#ifdef NAC_WITH_TESTS
26#define NAC_VIRTUAL_WITH_TESTS virtual
27#define NAC_PUBLIC_WITH_TESTS_ELSE_PROTECTED public
28#define NAC_PUBLIC_WITH_TESTS_ELSE_PRIVATE public
29#define NAC_PROTECTED_WITH_TESTS_ELSE_PRIVATE protected
30#else
31#define NAC_VIRTUAL_WITH_TESTS
32#define NAC_PUBLIC_WITH_TESTS_ELSE_PROTECTED protected
33#define NAC_PUBLIC_WITH_TESTS_ELSE_PRIVATE private
34#define NAC_PROTECTED_WITH_TESTS_ELSE_PRIVATE private
35#endif
36
37#include <functional>
38#include <stdexcept>
39
40#include <ndn-cxx/data.hpp>
41#include <ndn-cxx/encoding/buffer-stream.hpp>
42#include <ndn-cxx/face.hpp>
43#include <ndn-cxx/ims/in-memory-storage-persistent.hpp>
44#include <ndn-cxx/interest.hpp>
45#include <ndn-cxx/security/certificate.hpp>
46#include <ndn-cxx/security/key-chain.hpp>
47#include <ndn-cxx/security/signing-info.hpp>
48#include <ndn-cxx/security/transform/public-key.hpp>
49#include <ndn-cxx/security/validation-callback.hpp>
50#include <ndn-cxx/security/validation-error.hpp>
51#include <ndn-cxx/security/validator.hpp>
52
53#include <boost/assert.hpp>
54
55namespace ndn::nac {
56
57using security::Certificate;
58using security::DataValidationFailureCallback;
59using security::DataValidationSuccessCallback;
60using security::Identity;
61using security::Key;
62using security::SafeBag;
63using security::SigningInfo;
64using security::ValidationError;
65using security::Validator;
66using security::extractKeyNameFromCertName;
67using security::transform::PublicKey;
68
69namespace tlv {
70
71using namespace ndn::tlv;
72
73enum {
78};
79
80} // namespace tlv
81
82inline const name::Component ENCRYPTED_BY{"ENCRYPTED-BY"};
83inline const name::Component NAC{"NAC"};
84inline const name::Component KEK{"KEK"};
85inline const name::Component KDK{"KDK"};
86inline const name::Component CK{"CK"};
87
88inline constexpr size_t AES_KEY_SIZE = 32;
89inline constexpr size_t AES_IV_SIZE = 16;
90
91inline constexpr time::seconds DEFAULT_KEK_FRESHNESS_PERIOD = 1_h;
92inline constexpr time::seconds DEFAULT_KDK_FRESHNESS_PERIOD = 1_h;
93inline constexpr time::seconds DEFAULT_CK_FRESHNESS_PERIOD = 1_h;
94
95inline constexpr time::seconds RETRY_DELAY_AFTER_NACK = 1_s;
96inline constexpr time::seconds RETRY_DELAY_KEK_RETRIEVAL = 60_s;
97
98enum class ErrorCode {
101 KekInvalidName = 3,
102
105 KdkInvalidName = 13,
107
110 CkInvalidName = 23,
111
113 TpmKeyNotFound = 102,
115};
116
117using ErrorCallback = std::function<void(const ErrorCode&, const std::string&)>;
118
119class Error : public std::runtime_error
120{
121public:
122 using std::runtime_error::runtime_error;
123};
124
130Name
131convertKekNameToKdkPrefix(const Name& kekName, const ErrorCallback& onFailure);
132
139std::tuple<Name, Name, Name>
140extractKdkInfoFromCkName(const Name& ckDataName, const Name& ckName, const ErrorCallback& onFailure);
141
142} // namespace ndn::nac
143
144#endif // NDN_NAC_COMMON_HPP
@ InitializationVector
Definition common.hpp:76
@ EncryptedPayloadKey
Definition common.hpp:77
const name::Component KDK
Definition common.hpp:85
std::tuple< Name, Name, Name > extractKdkInfoFromCkName(const Name &ckDataName, const Name &ckName, const ErrorCallback &onFailure)
Extract KDK information from name of CK data packet name.
Definition common.cpp:37
constexpr time::seconds DEFAULT_KEK_FRESHNESS_PERIOD
Definition common.hpp:91
Name convertKekNameToKdkPrefix(const Name &kekName, const ErrorCallback &onFailure)
Convert KEK name to KDK prefix:
Definition common.cpp:25
constexpr time::seconds DEFAULT_CK_FRESHNESS_PERIOD
Definition common.hpp:93
constexpr time::seconds DEFAULT_KDK_FRESHNESS_PERIOD
Definition common.hpp:92
std::function< void(const ErrorCode &, const std::string &)> ErrorCallback
Definition common.hpp:117
constexpr size_t AES_IV_SIZE
Definition common.hpp:89
const name::Component ENCRYPTED_BY
Definition common.hpp:82
const name::Component CK
Definition common.hpp:86
const name::Component KEK
Definition common.hpp:84
constexpr time::seconds RETRY_DELAY_KEK_RETRIEVAL
Definition common.hpp:96
constexpr size_t AES_KEY_SIZE
Definition common.hpp:88
const name::Component NAC
Definition common.hpp:83
constexpr time::seconds RETRY_DELAY_AFTER_NACK
Definition common.hpp:95