blob: 23ad6db958ccc0571395e8ba9ef55fa05f4dd8c8 [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyev7838cfd2020-06-03 14:16:43 -04003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08004 *
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 Zhanga62bf982020-10-26 13:10:02 -070021#ifndef NDNCERT_DETAIL_CA_STATE_HPP
22#define NDNCERT_DETAIL_CA_STATE_HPP
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080023
Zhiyi Zhang062be6d2020-10-14 17:13:43 -070024#include "detail/ndncert-common.hpp"
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070025#include <array>
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080026
27namespace ndn {
28namespace ndncert {
29
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070030typedef std::array<uint8_t, 8> RequestID;
31
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070032enum 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 Zhangee996152020-10-26 13:58:33 -070042/**
43 * @brief Convert request status to string.
44 */
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070045std::string
46statusToString(Status status);
47
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070048/**
Zhiyi Zhangee996152020-10-26 13:58:33 -070049 * @brief The state maintained by the Challenge module.
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070050 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070051struct ChallengeState
52{
Zhiyi Zhang32437282020-10-10 16:15:37 -070053 ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
Zhiyi Zhanga749f442020-09-29 17:19:51 -070054 size_t remainingTries, time::seconds remainingTime,
55 JsonSection&& challengeSecrets);
Zhiyi Zhangee996152020-10-26 13:58:33 -070056 /**
57 * @brief The status of the challenge.
58 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070059 std::string m_challengeStatus;
Zhiyi Zhangee996152020-10-26 13:58:33 -070060 /**
61 * @brief The timestamp of the last update of the challenge state.
62 */
Zhiyi Zhang32437282020-10-10 16:15:37 -070063 time::system_clock::TimePoint m_timestamp;
Zhiyi Zhangee996152020-10-26 13:58:33 -070064 /**
65 * @brief Remaining tries of the challenge.
66 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070067 size_t m_remainingTries;
Zhiyi Zhangee996152020-10-26 13:58:33 -070068 /**
69 * @brief Remaining time of the challenge.
70 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070071 time::seconds m_remainingTime;
Zhiyi Zhangee996152020-10-26 13:58:33 -070072 /**
73 * @brief The secret for the challenge.
74 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070075 JsonSection m_secrets;
76};
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080077
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080078/**
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070079 * @brief Represents a certificate request instance kept by the CA.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080080 *
Zhiyi Zhangee996152020-10-26 13:58:33 -070081 * ChallengeModule should take use of CaState.ChallengeState to keep the challenge state.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080082 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070083class CaState
84{
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080085public:
Zhiyi Zhangee996152020-10-26 13:58:33 -070086 CaState() = default;
87 /**
88 * @brief Used to instantiate a CaState when challenge is not started.
89 */
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070090 CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070091 const security::Certificate& cert, Block m_encryptionKey, uint32_t aesBlockCounter = 0);
Zhiyi Zhangee996152020-10-26 13:58:33 -070092 /**
tylerliuaa7c0922020-10-26 18:20:15 -070093 * @brief Used to instantiate a CaState after challenge is started.
Zhiyi Zhangee996152020-10-26 13:58:33 -070094 */
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070095 CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
tylerliua7bea662020-10-08 18:51:02 -070096 const security::Certificate& cert, const std::string& challengeType,
Zhiyi Zhang32437282020-10-10 16:15:37 -070097 const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
tylerliu8704d032020-06-23 10:18:15 -070098 size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070099 Block m_encryptionKey, uint32_t aesBlockCounter);
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700100
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700101public:
Zhiyi Zhangee996152020-10-26 13:58:33 -0700102 /**
103 * @brief The CA that the request is under.
104 */
Suyong Won256c9062020-05-11 02:45:56 -0700105 Name m_caPrefix;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700106 /**
107 * @brief The ID of the request.
108 */
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -0700109 RequestID m_requestId;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700110 /**
111 * @brief The type of the request.
112 */
113 RequestType m_requestType = RequestType::NOTINITIALIZED;
114 /**
115 * @brief The status of the request.
116 */
117 Status m_status = Status::NOT_STARTED;
118 /**
119 * @brief The self-signed certificate in the request.
120 */
tylerliua7bea662020-10-08 18:51:02 -0700121 security::Certificate m_cert;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700122 /**
123 * @brief The encryption key for the requester.
124 */
tylerliu8e170d62020-09-30 01:31:53 -0700125 Block m_encryptionKey;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700126 /**
127 * @brief The AES block counter for the requester.
128 */
Zhiyi Zhang222810b2020-10-16 21:50:35 -0700129 uint32_t m_aesBlockCounter = 0;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700130
Zhiyi Zhangee996152020-10-26 13:58:33 -0700131 /**
132 * @brief The challenge type.
133 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700134 std::string m_challengeType;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700135 /**
136 * @brief The challenge state.
137 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700138 boost::optional<ChallengeState> m_challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800139};
140
141std::ostream&
tylerliu8704d032020-06-23 10:18:15 -0700142operator<<(std::ostream& os, const CaState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800143
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700144} // namespace ndncert
145} // namespace ndn
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800146
Zhiyi Zhanga62bf982020-10-26 13:10:02 -0700147#endif // NDNCERT_DETAIL_CA_STATE_HPP