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> |
| 40 | #include <functional> |
| 41 | #include <list> |
| 42 | #include <map> |
| 43 | #include <memory> |
| 44 | #include <set> |
| 45 | #include <string> |
| 46 | #include <unordered_map> |
| 47 | #include <utility> |
| 48 | |
| 49 | #include <ndn-cxx/interest.hpp> |
| 50 | #include <ndn-cxx/data.hpp> |
| 51 | #include <ndn-cxx/name.hpp> |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 52 | #include <ndn-cxx/face.hpp> |
| 53 | #include <ndn-cxx/link.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 54 | #include <ndn-cxx/encoding/block.hpp> |
| 55 | #include <ndn-cxx/lp/nack.hpp> |
| 56 | #include <ndn-cxx/util/backports.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 57 | #include <ndn-cxx/util/signal.hpp> |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 58 | #include <ndn-cxx/security/key-chain.hpp> |
Alexander Afanasyev | 7838cfd | 2020-06-03 14:16:43 -0400 | [diff] [blame] | 59 | #include <ndn-cxx/security/certificate.hpp> |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 60 | |
| 61 | #include <boost/algorithm/string.hpp> |
| 62 | #include <boost/assert.hpp> |
| 63 | #include <boost/noncopyable.hpp> |
| 64 | #include <boost/property_tree/ptree.hpp> |
| 65 | #include <boost/property_tree/json_parser.hpp> |
| 66 | #include <boost/property_tree/info_parser.hpp> |
| 67 | #include <boost/throw_exception.hpp> |
| 68 | |
| 69 | namespace ndn { |
| 70 | namespace ndncert { |
| 71 | |
| 72 | using std::size_t; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 73 | using boost::noncopyable; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 74 | using std::shared_ptr; |
| 75 | using std::unique_ptr; |
| 76 | using std::weak_ptr; |
| 77 | using std::make_shared; |
| 78 | using ndn::make_unique; |
| 79 | using std::enable_shared_from_this; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 80 | using std::function; |
| 81 | using std::bind; |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 82 | using ndn::Interest; |
| 83 | using ndn::Data; |
| 84 | using ndn::Name; |
| 85 | using ndn::PartialName; |
| 86 | using ndn::Block; |
| 87 | using ndn::time::system_clock; |
| 88 | using ndn::time::toUnixTimestamp; |
| 89 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 90 | // JSON format for Certificate Issuer (CA) |
| 91 | const std::string JSON_CA_NAME = "name"; |
| 92 | const std::string JSON_CA_CONFIG = "ca-config"; |
| 93 | const std::string JSON_CA_ECDH = "ecdh-pub"; |
| 94 | const std::string JSON_CA_SALT = "salt"; |
Zhiyi Zhang | ff4bcb6 | 2019-09-08 12:57:42 -0700 | [diff] [blame] | 95 | const std::string JSON_CA_REQUEST_ID = "request-id"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 96 | const std::string JSON_CA_STATUS = "status"; |
| 97 | const std::string JSON_CA_CHALLENGES = "challenges"; |
| 98 | const std::string JSON_CA_CHALLENGE_ID = "challenge-id"; |
| 99 | const std::string JSON_CA_CERT_ID = "certificate-id"; |
| 100 | |
| 101 | // JSON format for Challenge Module |
| 102 | const std::string JSON_CHALLENGE_STATUS = "challenge-status"; |
| 103 | const std::string JSON_CHALLENGE_REMAINING_TRIES = "remaining-tries"; |
| 104 | const std::string JSON_CHALLENGE_REMAINING_TIME = "remaining-time"; |
| 105 | |
| 106 | // JSON format for Certificate Requester |
| 107 | const std::string JSON_CLIENT_PROBE_INFO = "probe-info"; |
| 108 | const std::string JSON_CLIENT_ECDH = "ecdh-pub"; |
| 109 | const std::string JSON_CLIENT_CERT_REQ = "cert-request"; |
| 110 | const std::string JSON_CLIENT_SELECTED_CHALLENGE = "selected-challenge"; |
| 111 | |
| 112 | // NDNCERT Status Enum |
| 113 | enum { |
| 114 | STATUS_BEFORE_CHALLENGE = 0, |
| 115 | STATUS_CHALLENGE = 1, |
| 116 | STATUS_PENDING = 2, |
| 117 | STATUS_SUCCESS = 3, |
| 118 | STATUS_FAILURE = 4, |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 119 | STATUS_NOT_STARTED = 5, |
| 120 | STATUS_ENDED = 6 |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | // Pre-defined challenge status |
| 124 | const std::string CHALLENGE_STATUS_SUCCESS = "success"; |
| 125 | const std::string CHALLENGE_STATUS_FAILURE_TIMEOUT = "failure-timeout"; |
| 126 | const std::string CHALLENGE_STATUS_FAILURE_MAXRETRY = "failure-max-retry"; |
| 127 | const std::string CHALLENGE_STATUS_UNKNOWN_CHALLENGE = "unknown-challenge"; |
| 128 | |
Zhiyi Zhang | 8617a79 | 2017-01-17 16:45:56 -0800 | [diff] [blame] | 129 | } // namespace ndncert |
| 130 | } // namespace ndn |
| 131 | |
Zhiyi Zhang | b6fab0f | 2017-09-21 16:26:27 -0700 | [diff] [blame] | 132 | #endif // NDNCERT_NDNCERT_COMMON_HPP |