blob: b9ca5fbfb4c155179d69d43a384dacfae46b7318 [file] [log] [blame]
Zhiyi Zhang8617a792017-01-17 16:45:56 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -07003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhang8617a792017-01-17 16:45:56 -08004 *
5 * This file is part of ndncert, a certificate management system based on NDN.
6 *
7 * ndncert is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
10 *
11 * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License along with
16 * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ndncert authors and contributors.
19 */
20
Zhiyi Zhangb6fab0f2017-09-21 16:26:27 -070021#ifndef NDNCERT_NDNCERT_COMMON_HPP
22#define NDNCERT_NDNCERT_COMMON_HPP
Zhiyi Zhang8617a792017-01-17 16:45:56 -080023
24#include "ndncert-config.hpp"
25
Zhiyi Zhangdaf2fd72017-01-19 11:31:35 -080026#ifdef HAVE_TESTS
Zhiyi Zhang8617a792017-01-17 16:45:56 -080027#define VIRTUAL_WITH_TESTS virtual
28#define PUBLIC_WITH_TESTS_ELSE_PROTECTED public
29#define PUBLIC_WITH_TESTS_ELSE_PRIVATE public
30#define PROTECTED_WITH_TESTS_ELSE_PRIVATE protected
31#else
32#define VIRTUAL_WITH_TESTS
33#define PUBLIC_WITH_TESTS_ELSE_PROTECTED protected
34#define PUBLIC_WITH_TESTS_ELSE_PRIVATE private
35#define PROTECTED_WITH_TESTS_ELSE_PRIVATE private
36#endif
37
38#include <cstddef>
39#include <cstdint>
Zhiyi Zhang8617a792017-01-17 16:45:56 -080040
41#include <ndn-cxx/interest.hpp>
42#include <ndn-cxx/data.hpp>
43#include <ndn-cxx/name.hpp>
Zhiyi Zhangb6fab0f2017-09-21 16:26:27 -070044#include <ndn-cxx/face.hpp>
45#include <ndn-cxx/link.hpp>
Zhiyi Zhang8617a792017-01-17 16:45:56 -080046#include <ndn-cxx/encoding/block.hpp>
47#include <ndn-cxx/lp/nack.hpp>
Zhiyi Zhangb6fab0f2017-09-21 16:26:27 -070048#include <ndn-cxx/security/key-chain.hpp>
Alexander Afanasyev7838cfd2020-06-03 14:16:43 -040049#include <ndn-cxx/security/certificate.hpp>
Zhiyi Zhang8617a792017-01-17 16:45:56 -080050
51#include <boost/algorithm/string.hpp>
52#include <boost/assert.hpp>
53#include <boost/noncopyable.hpp>
Zhiyi Zhang8617a792017-01-17 16:45:56 -080054#include <boost/throw_exception.hpp>
55
56namespace ndn {
57namespace ndncert {
58
59using std::size_t;
Zhiyi Zhang8617a792017-01-17 16:45:56 -080060using boost::noncopyable;
Zhiyi Zhang8617a792017-01-17 16:45:56 -080061using std::shared_ptr;
62using std::unique_ptr;
63using std::weak_ptr;
64using std::make_shared;
65using ndn::make_unique;
66using std::enable_shared_from_this;
Zhiyi Zhang8617a792017-01-17 16:45:56 -080067using std::function;
68using std::bind;
Zhiyi Zhang8617a792017-01-17 16:45:56 -080069using ndn::Interest;
70using ndn::Data;
71using ndn::Name;
72using ndn::PartialName;
73using ndn::Block;
74using ndn::time::system_clock;
75using ndn::time::toUnixTimestamp;
76
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070077enum : uint32_t {
78 tlv_ca_prefix = 129,
79 tlv_ca_info = 131,
80 tlv_parameter_key = 133,
81 tlv_parameter_value = 135,
82 tlv_ca_certificate = 137,
83 tlv_max_validity_period = 139,
84 tlv_probe_response = 141,
85 tlv_allow_longer_name = 143,
86 tlv_ecdh_pub = 145,
87 tlv_cert_request = 147,
88 tlv_salt = 149,
89 tlv_request_id = 151,
90 tlv_challenge = 153,
91 tlv_status = 155,
92 tlv_initialization_vector = 157,
93 tlv_encrypted_payload = 159,
94 tlv_selected_challenge = 161,
95 tlv_challenge_status = 163,
96 tlv_remaining_tries = 165,
97 tlv_remaining_time = 167,
98 tlv_issued_cert_name = 169,
99 tlv_error_code = 171,
100 tlv_error_info = 173
101};
102
103// Parse CA Configuration file
104const std::string CONFIG_CA_PREFIX = "ca-prefix";
105const std::string CONFIG_CA_INFO = "ca-info";
106const std::string CONFIG_MAX_VALIDITY_PERIOD = "max-validity-period";
107const std::string CONFIG_PROBE_PARAMETERS = "probe-parameters";
108const std::string CONFIG_PROBE_PARAMETER = "probe-parameter-key";
109const std::string CONFIG_SUPPORTED_CHALLENGES = "supported-challenges";
110const std::string CONFIG_CHALLENGE = "challenge";
111
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700112// JSON format for Certificate Issuer (CA)
113const std::string JSON_CA_NAME = "name";
114const std::string JSON_CA_CONFIG = "ca-config";
115const std::string JSON_CA_ECDH = "ecdh-pub";
116const std::string JSON_CA_SALT = "salt";
Zhiyi Zhangff4bcb62019-09-08 12:57:42 -0700117const std::string JSON_CA_REQUEST_ID = "request-id";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700118const std::string JSON_CA_STATUS = "status";
119const std::string JSON_CA_CHALLENGES = "challenges";
120const std::string JSON_CA_CHALLENGE_ID = "challenge-id";
121const std::string JSON_CA_CERT_ID = "certificate-id";
122
123// JSON format for Challenge Module
124const std::string JSON_CHALLENGE_STATUS = "challenge-status";
125const std::string JSON_CHALLENGE_REMAINING_TRIES = "remaining-tries";
126const std::string JSON_CHALLENGE_REMAINING_TIME = "remaining-time";
swa770cf1d8f72020-04-21 23:12:39 -0700127const std::string JSON_CHALLENGE_ISSUED_CERT_NAME = "issued-cert-name";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700128
129// JSON format for Certificate Requester
130const std::string JSON_CLIENT_PROBE_INFO = "probe-info";
131const std::string JSON_CLIENT_ECDH = "ecdh-pub";
132const std::string JSON_CLIENT_CERT_REQ = "cert-request";
133const std::string JSON_CLIENT_SELECTED_CHALLENGE = "selected-challenge";
134
135// NDNCERT Status Enum
136enum {
137 STATUS_BEFORE_CHALLENGE = 0,
138 STATUS_CHALLENGE = 1,
139 STATUS_PENDING = 2,
140 STATUS_SUCCESS = 3,
141 STATUS_FAILURE = 4,
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -0700142 STATUS_NOT_STARTED = 5,
143 STATUS_ENDED = 6
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700144};
145
146// Pre-defined challenge status
147const std::string CHALLENGE_STATUS_SUCCESS = "success";
148const std::string CHALLENGE_STATUS_FAILURE_TIMEOUT = "failure-timeout";
149const std::string CHALLENGE_STATUS_FAILURE_MAXRETRY = "failure-max-retry";
150const std::string CHALLENGE_STATUS_UNKNOWN_CHALLENGE = "unknown-challenge";
151
Zhiyi Zhang8617a792017-01-17 16:45:56 -0800152} // namespace ndncert
153} // namespace ndn
154
Zhiyi Zhangb6fab0f2017-09-21 16:26:27 -0700155#endif // NDNCERT_NDNCERT_COMMON_HPP