blob: 2c4a1d618011d26356a739efe3a425e7eee92362 [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0dc02012021-11-23 22:55:03 -05002/*
3 * Copyright (c) 2017-2021, 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"
Davide Pesavento0dc02012021-11-23 22:55:03 -050025
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070026#include <array>
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080027
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080028namespace 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,
Zhiyi Zhang84e11842020-11-19 20:03:23 -080037 FAILURE = 4
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070038};
39
Zhiyi Zhangee996152020-10-26 13:58:33 -070040/**
41 * @brief Convert request status to string.
42 */
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070043std::string
44statusToString(Status status);
45
tylerliubb630362020-11-10 11:31:35 -080046/**
47 * @brief Convert request status to string.
48 */
49Status
50statusFromBlock(const Block& block);
51
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070052namespace ca {
53
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070054/**
Zhiyi Zhangee996152020-10-26 13:58:33 -070055 * @brief The state maintained by the Challenge module.
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070056 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070057struct ChallengeState
58{
Zhiyi Zhang32437282020-10-10 16:15:37 -070059 ChallengeState(const std::string& challengeStatus, const time::system_clock::TimePoint& challengeTp,
Zhiyi Zhanga749f442020-09-29 17:19:51 -070060 size_t remainingTries, time::seconds remainingTime,
61 JsonSection&& challengeSecrets);
Zhiyi Zhangee996152020-10-26 13:58:33 -070062 /**
63 * @brief The status of the challenge.
64 */
tylerliu7b9185c2020-11-24 12:15:18 -080065 std::string challengeStatus;
Zhiyi Zhangee996152020-10-26 13:58:33 -070066 /**
67 * @brief The timestamp of the last update of the challenge state.
68 */
tylerliu7b9185c2020-11-24 12:15:18 -080069 time::system_clock::TimePoint timestamp;
Zhiyi Zhangee996152020-10-26 13:58:33 -070070 /**
71 * @brief Remaining tries of the challenge.
72 */
tylerliu7b9185c2020-11-24 12:15:18 -080073 size_t remainingTries;
Zhiyi Zhangee996152020-10-26 13:58:33 -070074 /**
75 * @brief Remaining time of the challenge.
76 */
tylerliu7b9185c2020-11-24 12:15:18 -080077 time::seconds remainingTime;
Zhiyi Zhangee996152020-10-26 13:58:33 -070078 /**
79 * @brief The secret for the challenge.
80 */
tylerliu7b9185c2020-11-24 12:15:18 -080081 JsonSection secrets;
Zhiyi Zhanga749f442020-09-29 17:19:51 -070082};
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080083
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080084/**
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070085 * @brief Represents a certificate request instance kept by the CA.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080086 *
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070087 * ChallengeModule should take use of RequestState.ChallengeState to keep the challenge state.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080088 */
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -080089struct RequestState
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070090{
Zhiyi Zhangee996152020-10-26 13:58:33 -070091 /**
92 * @brief The CA that the request is under.
93 */
tylerliu7b9185c2020-11-24 12:15:18 -080094 Name caPrefix;
Zhiyi Zhangee996152020-10-26 13:58:33 -070095 /**
96 * @brief The ID of the request.
97 */
tylerliu7b9185c2020-11-24 12:15:18 -080098 RequestId requestId;
Zhiyi Zhangee996152020-10-26 13:58:33 -070099 /**
100 * @brief The type of the request.
101 */
tylerliu7b9185c2020-11-24 12:15:18 -0800102 RequestType requestType = RequestType::NOTINITIALIZED;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700103 /**
104 * @brief The status of the request.
105 */
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -0800106 Status status = Status::BEFORE_CHALLENGE;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700107 /**
108 * @brief The self-signed certificate in the request.
109 */
Davide Pesavento0dc02012021-11-23 22:55:03 -0500110 Certificate cert;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700111 /**
112 * @brief The encryption key for the requester.
113 */
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800114 std::array<uint8_t, 16> encryptionKey = {};
Zhiyi Zhangee996152020-10-26 13:58:33 -0700115 /**
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800116 * @brief The last Initialization Vector used by the AES encryption.
Zhiyi Zhangee996152020-10-26 13:58:33 -0700117 */
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800118 std::vector<uint8_t> encryptionIv;
119 /**
120 * @brief The last Initialization Vector used by the other side's AES encryption.
121 */
122 std::vector<uint8_t> decryptionIv;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700123 /**
124 * @brief The challenge type.
125 */
tylerliu7b9185c2020-11-24 12:15:18 -0800126 std::string challengeType;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700127 /**
128 * @brief The challenge state.
129 */
tylerliu7b9185c2020-11-24 12:15:18 -0800130 optional<ChallengeState> challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800131};
132
133std::ostream&
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700134operator<<(std::ostream& os, const RequestState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800135
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700136} // namespace ca
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700137} // namespace ndncert
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800138
tylerliu6563f932020-10-30 11:13:38 -0700139#endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP