blob: fefc0ff2277755634adb0d3983fc53be2972ffc7 [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
tylerliu8704d032020-06-23 10:18:15 -070021#ifndef NDNCERT_CA_STATE_HPP
22#define NDNCERT_CA_STATE_HPP
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080023
24#include "ndncert-common.hpp"
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080025
26namespace ndn {
27namespace ndncert {
28
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070029// NDNCERT Request status enumeration
30enum 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
41std::string
42statusToString(Status status);
43
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070044/**
45 * @brief The state maintained by the Challenge modules
46 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070047struct ChallengeState
48{
Zhiyi Zhang32437282020-10-10 16:15:37 -070049 ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
Zhiyi Zhanga749f442020-09-29 17:19:51 -070050 size_t remainingTries, time::seconds remainingTime,
51 JsonSection&& challengeSecrets);
52 std::string m_challengeStatus;
Zhiyi Zhang32437282020-10-10 16:15:37 -070053 time::system_clock::TimePoint m_timestamp;
Zhiyi Zhanga749f442020-09-29 17:19:51 -070054 size_t m_remainingTries;
55 time::seconds m_remainingTime;
56 JsonSection m_secrets;
57};
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080058
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080059/**
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070060 * @brief Represents a certificate request instance kept by the CA.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080061 *
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070062 * ChallengeModule should take use of ChallengeState to keep state.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080063 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070064class CaState
65{
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080066public:
tylerliu8704d032020-06-23 10:18:15 -070067 CaState();
68 CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
tylerliua7bea662020-10-08 18:51:02 -070069 const security::Certificate& cert, Block m_encryptionKey);
tylerliu8704d032020-06-23 10:18:15 -070070 CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
tylerliua7bea662020-10-08 18:51:02 -070071 const security::Certificate& cert, const std::string& challengeType,
Zhiyi Zhang32437282020-10-10 16:15:37 -070072 const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
tylerliu8704d032020-06-23 10:18:15 -070073 size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
74 Block m_encryptionKey);
Zhiyi Zhang5f749a22019-06-12 17:02:33 -070075
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070076public:
Suyong Won256c9062020-05-11 02:45:56 -070077 Name m_caPrefix;
Zhiyi Zhanga749f442020-09-29 17:19:51 -070078 std::string m_requestId;
79 RequestType m_requestType;
80 Status m_status;
tylerliua7bea662020-10-08 18:51:02 -070081 security::Certificate m_cert;
tylerliu8e170d62020-09-30 01:31:53 -070082 Block m_encryptionKey;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070083
Zhiyi Zhanga749f442020-09-29 17:19:51 -070084 std::string m_challengeType;
85 boost::optional<ChallengeState> m_challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080086};
87
88std::ostream&
tylerliu8704d032020-06-23 10:18:15 -070089operator<<(std::ostream& os, const CaState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080090
Zhiyi Zhange4891b72020-10-10 15:11:57 -070091} // namespace ndncert
92} // namespace ndn
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080093
Zhiyi Zhange4891b72020-10-10 15:11:57 -070094#endif // NDNCERT_CA_STATE_HPP