blob: 96c50baa9a0a6bb19d4d6dbf36f6d5ec8a146074 [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
Zhiyi Zhang48f23782020-09-28 12:11:24 -070038#include <cstddef>
39#include <cstdint>
Zhiyi Zhange537dd52020-10-01 18:02:24 -070040#include <tuple>
41#include <ndn-cxx/encoding/tlv.hpp>
Zhiyi Zhang48f23782020-09-28 12:11:24 -070042#include <ndn-cxx/data.hpp>
43#include <ndn-cxx/encoding/block.hpp>
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070044#include <ndn-cxx/encoding/block-helpers.hpp>
Zhiyi Zhang48f23782020-09-28 12:11:24 -070045#include <ndn-cxx/face.hpp>
46#include <ndn-cxx/interest.hpp>
47#include <ndn-cxx/link.hpp>
48#include <ndn-cxx/lp/nack.hpp>
49#include <ndn-cxx/name.hpp>
50#include <ndn-cxx/security/key-chain.hpp>
tylerliua7bea662020-10-08 18:51:02 -070051#include <ndn-cxx/security/certificate.hpp>
Zhiyi Zhang523f0c22020-09-29 14:19:20 -070052#include <ndn-cxx/util/logger.hpp>
Zhiyi Zhangc87d52b2020-09-28 22:07:18 -070053#include <boost/algorithm/string.hpp>
54#include <boost/assert.hpp>
55#include <boost/noncopyable.hpp>
56#include <boost/throw_exception.hpp>
Zhiyi Zhanga749f442020-09-29 17:19:51 -070057#include <boost/property_tree/info_parser.hpp>
58#include <boost/property_tree/json_parser.hpp>
59#include <boost/property_tree/ptree.hpp>
Zhiyi Zhang8617a792017-01-17 16:45:56 -080060
61namespace ndn {
62namespace ndncert {
63
Zhiyi Zhang8617a792017-01-17 16:45:56 -080064using boost::noncopyable;
Zhiyi Zhang8617a792017-01-17 16:45:56 -080065
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070066enum : uint32_t {
67 tlv_ca_prefix = 129,
68 tlv_ca_info = 131,
69 tlv_parameter_key = 133,
70 tlv_parameter_value = 135,
71 tlv_ca_certificate = 137,
72 tlv_max_validity_period = 139,
73 tlv_probe_response = 141,
Zhiyi Zhang38e1a9e2020-10-01 15:12:15 -070074 tlv_max_suffix_length = 143,
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070075 tlv_ecdh_pub = 145,
76 tlv_cert_request = 147,
77 tlv_salt = 149,
78 tlv_request_id = 151,
79 tlv_challenge = 153,
80 tlv_status = 155,
81 tlv_initialization_vector = 157,
82 tlv_encrypted_payload = 159,
83 tlv_selected_challenge = 161,
84 tlv_challenge_status = 163,
85 tlv_remaining_tries = 165,
86 tlv_remaining_time = 167,
87 tlv_issued_cert_name = 169,
88 tlv_error_code = 171,
Zhiyi Zhangb8cb0472020-05-05 20:55:05 -070089 tlv_error_info = 173,
tylerliu182bc532020-09-25 01:54:45 -070090 tlv_authentication_tag = 175,
Zhiyi Zhange537dd52020-10-01 18:02:24 -070091 tlv_cert_to_revoke = 177,
92 tlv_probe_redirect = 179
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -070093};
94
95// Parse CA Configuration file
96const std::string CONFIG_CA_PREFIX = "ca-prefix";
97const std::string CONFIG_CA_INFO = "ca-info";
98const std::string CONFIG_MAX_VALIDITY_PERIOD = "max-validity-period";
Zhiyi Zhangfde50112020-10-01 16:36:33 -070099const std::string CONFIG_MAX_SUFFIX_LENGTH = "max-suffix-length";
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700100const std::string CONFIG_PROBE_PARAMETERS = "probe-parameters";
101const std::string CONFIG_PROBE_PARAMETER = "probe-parameter-key";
102const std::string CONFIG_SUPPORTED_CHALLENGES = "supported-challenges";
103const std::string CONFIG_CHALLENGE = "challenge";
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700104const std::string CONFIG_CERTIFICATE = "certificate";
105const std::string CONFIG_REDIRECTION = "redirect-to";
tylerliu8d9e7122020-10-06 18:57:06 -0700106const std::string CONFIG_NAME_ASSIGNMENT = "name-assignment";
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700107typedef boost::property_tree::ptree JsonSection;
Zhiyi Zhangfde50112020-10-01 16:36:33 -0700108
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700109// JSON and string translation for Config file parsing
110std::string
111convertJson2String(const JsonSection& json);
Zhiyi Zhang0453dbb2020-04-28 22:39:17 -0700112
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700113JsonSection
114convertString2Json(const std::string& jsonContent);
115
116// NDNCERT Request status enumeration
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700117enum class Status : uint16_t {
118 BEFORE_CHALLENGE = 0,
119 CHALLENGE = 1,
120 PENDING = 2,
121 SUCCESS = 3,
122 FAILURE = 4,
123 NOT_STARTED = 5,
124 ENDED = 6
125};
126
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700127// Convert request status to string
128std::string
129statusToString(Status status);
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700130
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700131// NDNCERT error code
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -0700132enum class ErrorCode : uint16_t {
Zhiyi Zhang46049832020-09-28 17:08:12 -0700133 NO_ERROR = 0,
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700134 BAD_INTEREST_FORMAT = 1,
135 BAD_PARAMETER_FORMAT = 2,
136 BAD_SIGNATURE = 3,
137 INVALID_PARAMETER = 4,
138 NAME_NOT_ALLOWED = 5,
139 BAD_VALIDITY_PERIOD = 6,
140 OUT_OF_TRIES = 7,
141 OUT_OF_TIME = 8,
142 NO_AVAILABLE_NAMES = 9
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700143};
144
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700145// Convert error code to string
146std::string
147errorCodeToString(ErrorCode code);
148
149// NDNCERT request type
Zhiyi Zhangc87d52b2020-09-28 22:07:18 -0700150enum class RequestType : uint16_t {
151 NOTINITIALIZED = 0,
152 NEW = 1,
153 RENEW = 2,
154 REVOKE = 3
155};
156
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700157// Convert request type to string
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700158std::string
Zhiyi Zhang4b118092020-10-10 10:28:38 -0700159requestTypeToString(RequestType type);
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700160
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700161} // namespace ndncert
162} // namespace ndn
Zhiyi Zhang8617a792017-01-17 16:45:56 -0800163
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700164#endif // NDNCERT_NDNCERT_COMMON_HPP