blob: 5f96fb09513d48b003af0dc2ce1504dbe0b2212b [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 /**
87 * @brief Used to instantiate a CaState when challenge is not started.
88 */
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070089 CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070090 const security::Certificate& cert, Block m_encryptionKey, uint32_t aesBlockCounter = 0);
Zhiyi Zhangee996152020-10-26 13:58:33 -070091 /**
tylerliuaa7c0922020-10-26 18:20:15 -070092 * @brief Used to instantiate a CaState after challenge is started.
Zhiyi Zhangee996152020-10-26 13:58:33 -070093 */
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070094 CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
tylerliua7bea662020-10-08 18:51:02 -070095 const security::Certificate& cert, const std::string& challengeType,
Zhiyi Zhang32437282020-10-10 16:15:37 -070096 const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
tylerliu8704d032020-06-23 10:18:15 -070097 size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070098 Block m_encryptionKey, uint32_t aesBlockCounter);
Zhiyi Zhang5f749a22019-06-12 17:02:33 -070099
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700100public:
Zhiyi Zhangee996152020-10-26 13:58:33 -0700101 /**
102 * @brief The CA that the request is under.
103 */
Suyong Won256c9062020-05-11 02:45:56 -0700104 Name m_caPrefix;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700105 /**
106 * @brief The ID of the request.
107 */
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -0700108 RequestID m_requestId;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700109 /**
110 * @brief The type of the request.
111 */
112 RequestType m_requestType = RequestType::NOTINITIALIZED;
113 /**
114 * @brief The status of the request.
115 */
116 Status m_status = Status::NOT_STARTED;
117 /**
118 * @brief The self-signed certificate in the request.
119 */
tylerliua7bea662020-10-08 18:51:02 -0700120 security::Certificate m_cert;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700121 /**
122 * @brief The encryption key for the requester.
123 */
tylerliu8e170d62020-09-30 01:31:53 -0700124 Block m_encryptionKey;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700125 /**
126 * @brief The AES block counter for the requester.
127 */
Zhiyi Zhang222810b2020-10-16 21:50:35 -0700128 uint32_t m_aesBlockCounter = 0;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700129
Zhiyi Zhangee996152020-10-26 13:58:33 -0700130 /**
131 * @brief The challenge type.
132 */
Zhiyi Zhanga749f442020-09-29 17:19:51 -0700133 std::string m_challengeType;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700134 /**
135 * @brief The challenge state.
136 */
Zhiyi Zhang997669a2020-10-28 21:15:40 -0700137 optional<ChallengeState> m_challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800138};
139
140std::ostream&
tylerliu8704d032020-06-23 10:18:15 -0700141operator<<(std::ostream& os, const CaState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800142
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700143} // namespace ndncert
144} // namespace ndn
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800145
Zhiyi Zhanga62bf982020-10-26 13:10:02 -0700146#endif // NDNCERT_DETAIL_CA_STATE_HPP