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, |
Zhiyi Zhang | 84e1184 | 2020-11-19 20:03:23 -0800 | [diff] [blame] | 37 | FAILURE = 4 |
Zhiyi Zhang | 14f0bc8 | 2020-10-12 13:02:23 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 40 | /** |
| 41 | * @brief Convert request status to string. |
| 42 | */ |
Zhiyi Zhang | 14f0bc8 | 2020-10-12 13:02:23 -0700 | [diff] [blame] | 43 | std::string |
| 44 | statusToString(Status status); |
| 45 | |
tylerliu | bb63036 | 2020-11-10 11:31:35 -0800 | [diff] [blame] | 46 | /** |
| 47 | * @brief Convert request status to string. |
| 48 | */ |
| 49 | Status |
| 50 | statusFromBlock(const Block& block); |
| 51 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 52 | namespace ca { |
| 53 | |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 54 | /** |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 55 | * @brief The state maintained by the Challenge module. |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 56 | */ |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 57 | struct ChallengeState |
| 58 | { |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 59 | ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp, |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 60 | size_t remainingTries, time::seconds remainingTime, |
| 61 | JsonSection&& challengeSecrets); |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 62 | /** |
| 63 | * @brief The status of the challenge. |
| 64 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 65 | std::string challengeStatus; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 66 | /** |
| 67 | * @brief The timestamp of the last update of the challenge state. |
| 68 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 69 | time::system_clock::TimePoint timestamp; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 70 | /** |
| 71 | * @brief Remaining tries of the challenge. |
| 72 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 73 | size_t remainingTries; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 74 | /** |
| 75 | * @brief Remaining time of the challenge. |
| 76 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 77 | time::seconds remainingTime; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 78 | /** |
| 79 | * @brief The secret for the challenge. |
| 80 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 81 | JsonSection secrets; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 82 | }; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 83 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 84 | /** |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 85 | * @brief Represents a certificate request instance kept by the CA. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 86 | * |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 87 | * ChallengeModule should take use of RequestState.ChallengeState to keep the challenge state. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 88 | */ |
Zhiyi Zhang | 1f5e86e | 2020-12-04 15:07:57 -0800 | [diff] [blame^] | 89 | struct RequestState |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 90 | { |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 91 | /** |
| 92 | * @brief The CA that the request is under. |
| 93 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 94 | Name caPrefix; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 95 | /** |
| 96 | * @brief The ID of the request. |
| 97 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 98 | RequestId requestId; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 99 | /** |
| 100 | * @brief The type of the request. |
| 101 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 102 | RequestType requestType = RequestType::NOTINITIALIZED; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 103 | /** |
| 104 | * @brief The status of the request. |
| 105 | */ |
Zhiyi Zhang | 1f5e86e | 2020-12-04 15:07:57 -0800 | [diff] [blame^] | 106 | Status status = Status::BEFORE_CHALLENGE; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 107 | /** |
| 108 | * @brief The self-signed certificate in the request. |
| 109 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 110 | security::Certificate cert; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 111 | /** |
| 112 | * @brief The encryption key for the requester. |
| 113 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 114 | std::array<uint8_t, 16> encryptionKey; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 115 | /** |
| 116 | * @brief The AES block counter for the requester. |
| 117 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 118 | uint32_t aesBlockCounter = 0; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 119 | |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 120 | /** |
| 121 | * @brief The challenge type. |
| 122 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 123 | std::string challengeType; |
Zhiyi Zhang | ee99615 | 2020-10-26 13:58:33 -0700 | [diff] [blame] | 124 | /** |
| 125 | * @brief The challenge state. |
| 126 | */ |
tylerliu | 7b9185c | 2020-11-24 12:15:18 -0800 | [diff] [blame] | 127 | optional<ChallengeState> challengeState; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | std::ostream& |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 131 | operator<<(std::ostream& os, const RequestState& request); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 132 | |
Zhiyi Zhang | 32d4b4e | 2020-10-28 22:10:49 -0700 | [diff] [blame] | 133 | } // namespace ca |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 134 | } // namespace ndncert |
| 135 | } // namespace ndn |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 136 | |
tylerliu | 6563f93 | 2020-10-30 11:13:38 -0700 | [diff] [blame] | 137 | #endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP |