blob: 7fa9f23740ad89fbfeb9f23570e961ef4c6bf824 [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
tylerliu6563f932020-10-30 11:13:38 -070021#ifndef NDNCERT_DETAIL_CA_REQUEST_STATE_HPP
22#define NDNCERT_DETAIL_CA_REQUEST_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 Zhangc9ada1b2020-10-29 19:13:15 -070030typedef std::array<uint8_t, 8> RequestId;
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070031
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 Zhang32d4b4e2020-10-28 22:10:49 -070048namespace ca {
49
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070050/**
Zhiyi Zhangee996152020-10-26 13:58:33 -070051 * @brief The state maintained by the Challenge module.
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070052 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070053struct ChallengeState
54{
Zhiyi Zhang32437282020-10-10 16:15:37 -070055 ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
Zhiyi Zhanga749f442020-09-29 17:19:51 -070056 size_t remainingTries, time::seconds remainingTime,
57 JsonSection&& challengeSecrets);
Zhiyi Zhangee996152020-10-26 13:58:33 -070058 /**
59 * @brief The status of the challenge.
60 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070061 std::string m_challengeStatus;
Zhiyi Zhangee996152020-10-26 13:58:33 -070062 /**
63 * @brief The timestamp of the last update of the challenge state.
64 */
Zhiyi Zhang32437282020-10-10 16:15:37 -070065 time::system_clock::TimePoint m_timestamp;
Zhiyi Zhangee996152020-10-26 13:58:33 -070066 /**
67 * @brief Remaining tries of the challenge.
68 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070069 size_t m_remainingTries;
Zhiyi Zhangee996152020-10-26 13:58:33 -070070 /**
71 * @brief Remaining time of the challenge.
72 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070073 time::seconds m_remainingTime;
Zhiyi Zhangee996152020-10-26 13:58:33 -070074 /**
75 * @brief The secret for the challenge.
76 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -070077 JsonSection m_secrets;
78};
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080079
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080080/**
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070081 * @brief Represents a certificate request instance kept by the CA.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080082 *
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070083 * ChallengeModule should take use of RequestState.ChallengeState to keep the challenge state.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080084 */
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070085class RequestState
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070086{
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080087public:
Zhiyi Zhangee996152020-10-26 13:58:33 -070088 /**
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070089 * @brief Used to instantiate a RequestState when challenge is not started.
Zhiyi Zhangee996152020-10-26 13:58:33 -070090 */
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -070091 RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status,
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -070092 const security::Certificate& cert, std::array<uint8_t, 16>&& m_encryptionKey, uint32_t aesBlockCounter = 0);
Zhiyi Zhangee996152020-10-26 13:58:33 -070093 /**
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070094 * @brief Used to instantiate a RequestState after challenge is started.
Zhiyi Zhangee996152020-10-26 13:58:33 -070095 */
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -070096 RequestState(const Name& caName, const RequestId& requestId, RequestType requestType, Status status,
Zhiyi Zhang4c259db2020-10-30 09:36:01 -070097 const security::Certificate& cert, const std::string& challengeType,
98 const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
99 size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -0700100 std::array<uint8_t, 16>&& m_encryptionKey, uint32_t aesBlockCounter);
Zhiyi Zhang5f749a22019-06-12 17:02:33 -0700101
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700102public:
Zhiyi Zhangee996152020-10-26 13:58:33 -0700103 /**
104 * @brief The CA that the request is under.
105 */
Suyong Won256c9062020-05-11 02:45:56 -0700106 Name m_caPrefix;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700107 /**
108 * @brief The ID of the request.
109 */
Zhiyi Zhangc9ada1b2020-10-29 19:13:15 -0700110 RequestId m_requestId;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700111 /**
112 * @brief The type of the request.
113 */
114 RequestType m_requestType = RequestType::NOTINITIALIZED;
115 /**
116 * @brief The status of the request.
117 */
118 Status m_status = Status::NOT_STARTED;
119 /**
120 * @brief The self-signed certificate in the request.
121 */
tylerliua7bea662020-10-08 18:51:02 -0700122 security::Certificate m_cert;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700123 /**
124 * @brief The encryption key for the requester.
125 */
Zhiyi Zhang1f9551b2020-10-30 10:30:43 -0700126 std::array<uint8_t, 16> m_encryptionKey;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700127 /**
128 * @brief The AES block counter for the requester.
129 */
Zhiyi Zhang222810b2020-10-16 21:50:35 -0700130 uint32_t m_aesBlockCounter = 0;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700131
Zhiyi Zhangee996152020-10-26 13:58:33 -0700132 /**
133 * @brief The challenge type.
134 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700135 std::string m_challengeType;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700136 /**
137 * @brief The challenge state.
138 */
Zhiyi Zhang997669a2020-10-28 21:15:40 -0700139 optional<ChallengeState> m_challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800140};
141
142std::ostream&
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700143operator<<(std::ostream& os, const RequestState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800144
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700145} // namespace ca
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700146} // namespace ndncert
147} // namespace ndn
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800148
tylerliu6563f932020-10-30 11:13:38 -0700149#endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP