Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 4 | * |
| 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 Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 21 | #ifndef NDNCERT_NDNCERT_COMMON_HPP |
| 22 | #define NDNCERT_NDNCERT_COMMON_HPP |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 23 | |
| 24 | #include "ndncert-config.hpp" |
| 25 | |
Zhiyi Zhang | daf2fd7 | 2017-01-19 11:31:35 -0800 | [diff] [blame] | 26 | #ifdef HAVE_TESTS |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 27 | #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 Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 40 | |
| 41 | #include <ndn-cxx/interest.hpp> |
| 42 | #include <ndn-cxx/data.hpp> |
| 43 | #include <ndn-cxx/name.hpp> |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 44 | #include <ndn-cxx/face.hpp> |
| 45 | #include <ndn-cxx/link.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 46 | #include <ndn-cxx/encoding/block.hpp> |
| 47 | #include <ndn-cxx/lp/nack.hpp> |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 48 | #include <ndn-cxx/security/key-chain.hpp> |
Zhiyi Zhang | ef6b36a | 2020-09-22 21:20:59 -0700 | [diff] [blame] | 49 | #include <ndn-cxx/security/v2/certificate.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 50 | |
| 51 | #include <boost/algorithm/string.hpp> |
| 52 | #include <boost/assert.hpp> |
| 53 | #include <boost/noncopyable.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 54 | #include <boost/throw_exception.hpp> |
| 55 | |
| 56 | namespace ndn { |
| 57 | namespace ndncert { |
| 58 | |
| 59 | using std::size_t; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 60 | using boost::noncopyable; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 61 | using std::shared_ptr; |
| 62 | using std::unique_ptr; |
| 63 | using std::weak_ptr; |
| 64 | using std::make_shared; |
| 65 | using ndn::make_unique; |
| 66 | using std::enable_shared_from_this; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 67 | using std::function; |
| 68 | using std::bind; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 69 | using ndn::Interest; |
| 70 | using ndn::Data; |
| 71 | using ndn::Name; |
| 72 | using ndn::PartialName; |
| 73 | using ndn::Block; |
| 74 | using ndn::time::system_clock; |
| 75 | using ndn::time::toUnixTimestamp; |
| 76 | |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 77 | enum : 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, |
Zhiyi Zhang | b8cb047 | 2020-05-05 20:55:05 -0700 | [diff] [blame] | 100 | tlv_error_info = 173, |
| 101 | tlv_authentication_tag = 175 |
Zhiyi Zhang | 0453dbb | 2020-04-28 22:39:17 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | // Parse CA Configuration file |
| 105 | const std::string CONFIG_CA_PREFIX = "ca-prefix"; |
| 106 | const std::string CONFIG_CA_INFO = "ca-info"; |
| 107 | const std::string CONFIG_MAX_VALIDITY_PERIOD = "max-validity-period"; |
| 108 | const std::string CONFIG_PROBE_PARAMETERS = "probe-parameters"; |
| 109 | const std::string CONFIG_PROBE_PARAMETER = "probe-parameter-key"; |
| 110 | const std::string CONFIG_SUPPORTED_CHALLENGES = "supported-challenges"; |
| 111 | const std::string CONFIG_CHALLENGE = "challenge"; |
| 112 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 113 | // JSON format for Certificate Issuer (CA) |
| 114 | const std::string JSON_CA_NAME = "name"; |
| 115 | const std::string JSON_CA_CONFIG = "ca-config"; |
| 116 | const std::string JSON_CA_ECDH = "ecdh-pub"; |
| 117 | const std::string JSON_CA_SALT = "salt"; |
Zhiyi Zhang | ff4bcb6 | 2019-09-08 12:57:42 -0700 | [diff] [blame] | 118 | const std::string JSON_CA_REQUEST_ID = "request-id"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 119 | const std::string JSON_CA_STATUS = "status"; |
| 120 | const std::string JSON_CA_CHALLENGES = "challenges"; |
| 121 | const std::string JSON_CA_CHALLENGE_ID = "challenge-id"; |
| 122 | const std::string JSON_CA_CERT_ID = "certificate-id"; |
| 123 | |
| 124 | // JSON format for Challenge Module |
| 125 | const std::string JSON_CHALLENGE_STATUS = "challenge-status"; |
| 126 | const std::string JSON_CHALLENGE_REMAINING_TRIES = "remaining-tries"; |
| 127 | const std::string JSON_CHALLENGE_REMAINING_TIME = "remaining-time"; |
swa770 | cf1d8f7 | 2020-04-21 23:12:39 -0700 | [diff] [blame] | 128 | const std::string JSON_CHALLENGE_ISSUED_CERT_NAME = "issued-cert-name"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 129 | |
| 130 | // JSON format for Certificate Requester |
| 131 | const std::string JSON_CLIENT_PROBE_INFO = "probe-info"; |
| 132 | const std::string JSON_CLIENT_ECDH = "ecdh-pub"; |
| 133 | const std::string JSON_CLIENT_CERT_REQ = "cert-request"; |
| 134 | const std::string JSON_CLIENT_SELECTED_CHALLENGE = "selected-challenge"; |
| 135 | |
| 136 | // NDNCERT Status Enum |
| 137 | enum { |
| 138 | STATUS_BEFORE_CHALLENGE = 0, |
| 139 | STATUS_CHALLENGE = 1, |
| 140 | STATUS_PENDING = 2, |
| 141 | STATUS_SUCCESS = 3, |
| 142 | STATUS_FAILURE = 4, |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 143 | STATUS_NOT_STARTED = 5, |
| 144 | STATUS_ENDED = 6 |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | // Pre-defined challenge status |
| 148 | const std::string CHALLENGE_STATUS_SUCCESS = "success"; |
| 149 | const std::string CHALLENGE_STATUS_FAILURE_TIMEOUT = "failure-timeout"; |
| 150 | const std::string CHALLENGE_STATUS_FAILURE_MAXRETRY = "failure-max-retry"; |
| 151 | const std::string CHALLENGE_STATUS_UNKNOWN_CHALLENGE = "unknown-challenge"; |
| 152 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 153 | } // namespace ndncert |
| 154 | } // namespace ndn |
| 155 | |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 156 | #endif // NDNCERT_NDNCERT_COMMON_HPP |