Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 7838cfd | 2020-06-03 14:16:43 -0400 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -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 | |
tylerliu | 6563f93 | 2020-10-30 11:13:38 -0700 | [diff] [blame] | 21 | #ifndef NDNCERT_DETAIL_CA_REQUEST_STATE_HPP |
| 22 | #define NDNCERT_DETAIL_CA_REQUEST_STATE_HPP |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 23 | |
Zhiyi Zhang | 062be6d | 2020-10-14 17:13:43 -0700 | [diff] [blame] | 24 | #include "detail/ndncert-common.hpp" |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 25 | #include <array> |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame] | 30 | typedef std::array<uint8_t, 8> RequestId; |
Zhiyi Zhang | 8fdb36b | 2020-10-18 11:58:51 -0700 | [diff] [blame] | 31 | |
Zhiyi Zhang | 14f0bc8 | 2020-10-12 13:02:23 -0700 | [diff] [blame] | 32 | enum class Status : uint16_t { |
| 33 | BEFORE_CHALLENGE = 0, |
| 34 | CHALLENGE = 1, |
| 35 | PENDING = 2, |
| 36 | SUCCESS = 3, |
| 37 | FAILURE = 4, |
| 38 | NOT_STARTED = 5, |
| 39 | ENDED = 6 |
| 40 | }; |
| 41 | |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 42 | /** |
| 43 | * @brief Convert request status to string. |
| 44 | */ |
Zhiyi Zhang | 14f0bc8 | 2020-10-12 13:02:23 -0700 | [diff] [blame] | 45 | std::string |
| 46 | statusToString(Status status); |
| 47 | |
tylerliu | bb63036 | 2020-11-10 11:31:35 -0800 | [diff] [blame] | 48 | /** |
| 49 | * @brief Convert request status to string. |
| 50 | */ |
| 51 | Status |
| 52 | statusFromBlock(const Block& block); |
| 53 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 54 | namespace ca { |
| 55 | |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 56 | /** |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 57 | * @brief The state maintained by the Challenge module. |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 58 | */ |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 59 | struct ChallengeState |
| 60 | { |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 61 | ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp, |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 62 | size_t remainingTries, time::seconds remainingTime, |
| 63 | JsonSection&& challengeSecrets); |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 64 | /** |
| 65 | * @brief The status of the challenge. |
| 66 | */ |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 67 | std::string m_challengeStatus; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 68 | /** |
| 69 | * @brief The timestamp of the last update of the challenge state. |
| 70 | */ |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 71 | time::system_clock::TimePoint m_timestamp; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 72 | /** |
| 73 | * @brief Remaining tries of the challenge. |
| 74 | */ |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 75 | size_t m_remainingTries; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 76 | /** |
| 77 | * @brief Remaining time of the challenge. |
| 78 | */ |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 79 | time::seconds m_remainingTime; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 80 | /** |
| 81 | * @brief The secret for the challenge. |
| 82 | */ |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 83 | JsonSection m_secrets; |
| 84 | }; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 85 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 86 | /** |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 87 | * @brief Represents a certificate request instance kept by the CA. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 88 | * |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 89 | * ChallengeModule should take use of RequestState.ChallengeState to keep the challenge state. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 90 | */ |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 91 | class RequestState |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 92 | { |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 93 | public: |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 94 | /** |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 95 | * @brief Used to instantiate a RequestState when challenge is not started. |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 96 | */ |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame] | 97 | RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status, |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 98 | const security::Certificate& cert, std::array<uint8_t, 16>&& m_encryptionKey, uint32_t aesBlockCounter = 0); |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 99 | /** |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 100 | * @brief Used to instantiate a RequestState after challenge is started. |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 101 | */ |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame] | 102 | RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status, |
Zhiyi Zhang | 4c259db | 2020-10-30 09:36:01 -0700 | [diff] [blame] | 103 | const security::Certificate& cert, const std::string& challengeType, |
| 104 | const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp, |
| 105 | size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets, |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 106 | std::array<uint8_t, 16>&& m_encryptionKey, uint32_t aesBlockCounter); |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 107 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 108 | public: |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 109 | /** |
| 110 | * @brief The CA that the request is under. |
| 111 | */ |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 112 | Name m_caPrefix; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 113 | /** |
| 114 | * @brief The ID of the request. |
| 115 | */ |
Zhiyi Zhang | c9ada1b | 2020-10-29 19:13:15 -0700 | [diff] [blame] | 116 | RequestId m_requestId; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 117 | /** |
| 118 | * @brief The type of the request. |
| 119 | */ |
| 120 | RequestType m_requestType = RequestType::NOTINITIALIZED; |
| 121 | /** |
| 122 | * @brief The status of the request. |
| 123 | */ |
| 124 | Status m_status = Status::NOT_STARTED; |
| 125 | /** |
| 126 | * @brief The self-signed certificate in the request. |
| 127 | */ |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 128 | security::Certificate m_cert; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 129 | /** |
| 130 | * @brief The encryption key for the requester. |
| 131 | */ |
Zhiyi Zhang | 1f9551b | 2020-10-30 10:30:43 -0700 | [diff] [blame] | 132 | std::array<uint8_t, 16> m_encryptionKey; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 133 | /** |
| 134 | * @brief The AES block counter for the requester. |
| 135 | */ |
Zhiyi Zhang | 222810b | 2020-10-16 21:50:35 -0700 | [diff] [blame] | 136 | uint32_t m_aesBlockCounter = 0; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 137 | |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 138 | /** |
| 139 | * @brief The challenge type. |
| 140 | */ |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 141 | std::string m_challengeType; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 142 | /** |
| 143 | * @brief The challenge state. |
| 144 | */ |
Zhiyi Zhang | 997669a | 2020-10-28 21:15:40 -0700 | [diff] [blame] | 145 | optional<ChallengeState> m_challengeState; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | std::ostream& |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 149 | operator<<(std::ostream& os, const RequestState& request); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 150 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 151 | } // namespace ca |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 152 | } // namespace ndncert |
| 153 | } // namespace ndn |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 154 | |
tylerliu | 6563f93 | 2020-10-30 11:13:38 -0700 | [diff] [blame] | 155 | #endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP |