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 | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 21 | #ifndef NDNCERT_CA_STATE_HPP |
| 22 | #define NDNCERT_CA_STATE_HPP |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 23 | |
| 24 | #include "ndncert-common.hpp" |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | |
Zhiyi Zhang | 14f0bc8 | 2020-10-12 13:02:23 -0700 | [diff] [blame] | 29 | // NDNCERT Request status enumeration |
| 30 | enum class Status : uint16_t { |
| 31 | BEFORE_CHALLENGE = 0, |
| 32 | CHALLENGE = 1, |
| 33 | PENDING = 2, |
| 34 | SUCCESS = 3, |
| 35 | FAILURE = 4, |
| 36 | NOT_STARTED = 5, |
| 37 | ENDED = 6 |
| 38 | }; |
| 39 | |
| 40 | // Convert request status to string |
| 41 | std::string |
| 42 | statusToString(Status status); |
| 43 | |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 44 | /** |
| 45 | * @brief The state maintained by the Challenge modules |
| 46 | */ |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 47 | struct ChallengeState |
| 48 | { |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 49 | ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp, |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 50 | size_t remainingTries, time::seconds remainingTime, |
| 51 | JsonSection&& challengeSecrets); |
| 52 | std::string m_challengeStatus; |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 53 | time::system_clock::TimePoint m_timestamp; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 54 | size_t m_remainingTries; |
| 55 | time::seconds m_remainingTime; |
| 56 | JsonSection m_secrets; |
| 57 | }; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 58 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 59 | /** |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 60 | * @brief Represents a certificate request instance kept by the CA. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 61 | * |
Zhiyi Zhang | 97bedb8 | 2020-10-10 11:11:35 -0700 | [diff] [blame] | 62 | * ChallengeModule should take use of ChallengeState to keep state. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 63 | */ |
Zhiyi Zhang | 684c67c | 2020-10-12 14:28:17 -0700 | [diff] [blame] | 64 | class CaState |
| 65 | { |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 66 | public: |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 67 | CaState(); |
| 68 | CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status, |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 69 | const security::Certificate& cert, Block m_encryptionKey); |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 70 | CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status, |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 71 | const security::Certificate& cert, const std::string& challengeType, |
Zhiyi Zhang | 3243728 | 2020-10-10 16:15:37 -0700 | [diff] [blame] | 72 | const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp, |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 73 | size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets, |
| 74 | Block m_encryptionKey); |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 75 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 76 | public: |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 77 | Name m_caPrefix; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 78 | std::string m_requestId; |
| 79 | RequestType m_requestType; |
| 80 | Status m_status; |
tylerliu | a7bea66 | 2020-10-08 18:51:02 -0700 | [diff] [blame] | 81 | security::Certificate m_cert; |
tylerliu | 8e170d6 | 2020-09-30 01:31:53 -0700 | [diff] [blame] | 82 | Block m_encryptionKey; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 83 | |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame] | 84 | std::string m_challengeType; |
| 85 | boost::optional<ChallengeState> m_challengeState; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | std::ostream& |
tylerliu | 8704d03 | 2020-06-23 10:18:15 -0700 | [diff] [blame] | 89 | operator<<(std::ostream& os, const CaState& request); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 90 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 91 | } // namespace ndncert |
| 92 | } // namespace ndn |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 93 | |
Zhiyi Zhang | e4891b7 | 2020-10-10 15:11:57 -0700 | [diff] [blame] | 94 | #endif // NDNCERT_CA_STATE_HPP |