blob: cbf1442294f52d244d2450a9d84e7885d657f4d6 [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 -070032// NDNCERT Request status enumeration
33enum class Status : uint16_t {
34 BEFORE_CHALLENGE = 0,
35 CHALLENGE = 1,
36 PENDING = 2,
37 SUCCESS = 3,
38 FAILURE = 4,
39 NOT_STARTED = 5,
40 ENDED = 6
41};
42
43// Convert request status to string
44std::string
45statusToString(Status status);
46
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070047/**
48 * @brief The state maintained by the Challenge modules
49 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070050struct ChallengeState
51{
Zhiyi Zhang32437282020-10-10 16:15:37 -070052 ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
Zhiyi Zhanga749f442020-09-29 17:19:51 -070053 size_t remainingTries, time::seconds remainingTime,
54 JsonSection&& challengeSecrets);
55 std::string m_challengeStatus;
Zhiyi Zhang32437282020-10-10 16:15:37 -070056 time::system_clock::TimePoint m_timestamp;
Zhiyi Zhanga749f442020-09-29 17:19:51 -070057 size_t m_remainingTries;
58 time::seconds m_remainingTime;
59 JsonSection m_secrets;
60};
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080061
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080062/**
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070063 * @brief Represents a certificate request instance kept by the CA.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080064 *
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070065 * ChallengeModule should take use of ChallengeState to keep state.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080066 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070067class CaState
68{
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080069public:
tylerliu8704d032020-06-23 10:18:15 -070070 CaState();
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070071 CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070072 const security::Certificate& cert, Block m_encryptionKey, uint32_t aesBlockCounter = 0);
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070073 CaState(const Name& caName, const RequestID& requestId, RequestType requestType, Status status,
tylerliua7bea662020-10-08 18:51:02 -070074 const security::Certificate& cert, const std::string& challengeType,
Zhiyi Zhang32437282020-10-10 16:15:37 -070075 const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
tylerliu8704d032020-06-23 10:18:15 -070076 size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
Zhiyi Zhang222810b2020-10-16 21:50:35 -070077 Block m_encryptionKey, uint32_t aesBlockCounter);
Zhiyi Zhang5f749a22019-06-12 17:02:33 -070078
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070079public:
Suyong Won256c9062020-05-11 02:45:56 -070080 Name m_caPrefix;
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070081 RequestID m_requestId;
Zhiyi Zhanga749f442020-09-29 17:19:51 -070082 RequestType m_requestType;
83 Status m_status;
tylerliua7bea662020-10-08 18:51:02 -070084 security::Certificate m_cert;
tylerliu8e170d62020-09-30 01:31:53 -070085 Block m_encryptionKey;
Zhiyi Zhang222810b2020-10-16 21:50:35 -070086 uint32_t m_aesBlockCounter = 0;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070087
Zhiyi Zhanga749f442020-09-29 17:19:51 -070088 std::string m_challengeType;
89 boost::optional<ChallengeState> m_challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080090};
91
92std::ostream&
tylerliu8704d032020-06-23 10:18:15 -070093operator<<(std::ostream& os, const CaState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080094
Zhiyi Zhange4891b72020-10-10 15:11:57 -070095} // namespace ndncert
96} // namespace ndn
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080097
Zhiyi Zhanga62bf982020-10-26 13:10:02 -070098#endif // NDNCERT_DETAIL_CA_STATE_HPP