blob: a11caf00d85dffb8d7b63243e8d8ac7e28d03e7e [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/*
Davide Pesavento76304d82023-08-10 23:38:06 -04003 * Copyright (c) 2017-2023, 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
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040030using RequestId = std::array<uint8_t, 8>;
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,
Davide Pesavento76304d82023-08-10 23:38:06 -040037 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{
Davide Pesavento76304d82023-08-10 23:38:06 -040059 ChallengeState(const std::string& challengeStatus, const time::system_clock::time_point& challengeTp,
Zhiyi Zhanga749f442020-09-29 17:19:51 -070060 size_t remainingTries, time::seconds remainingTime,
61 JsonSection&& challengeSecrets);
Davide Pesavento76304d82023-08-10 23:38:06 -040062
Zhiyi Zhangee996152020-10-26 13:58:33 -070063 /**
64 * @brief The status of the challenge.
65 */
tylerliu7b9185c2020-11-24 12:15:18 -080066 std::string challengeStatus;
Zhiyi Zhangee996152020-10-26 13:58:33 -070067 /**
68 * @brief The timestamp of the last update of the challenge state.
69 */
Davide Pesavento76304d82023-08-10 23:38:06 -040070 time::system_clock::time_point timestamp;
Zhiyi Zhangee996152020-10-26 13:58:33 -070071 /**
72 * @brief Remaining tries of the challenge.
73 */
tylerliu7b9185c2020-11-24 12:15:18 -080074 size_t remainingTries;
Zhiyi Zhangee996152020-10-26 13:58:33 -070075 /**
76 * @brief Remaining time of the challenge.
77 */
tylerliu7b9185c2020-11-24 12:15:18 -080078 time::seconds remainingTime;
Zhiyi Zhangee996152020-10-26 13:58:33 -070079 /**
80 * @brief The secret for the challenge.
81 */
tylerliu7b9185c2020-11-24 12:15:18 -080082 JsonSection secrets;
Zhiyi Zhanga749f442020-09-29 17:19:51 -070083};
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080084
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080085/**
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070086 * @brief Represents a certificate request instance kept by the CA.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080087 *
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070088 * ChallengeModule should take use of RequestState.ChallengeState to keep the challenge state.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080089 */
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -080090struct RequestState
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070091{
Zhiyi Zhangee996152020-10-26 13:58:33 -070092 /**
93 * @brief The CA that the request is under.
94 */
tylerliu7b9185c2020-11-24 12:15:18 -080095 Name caPrefix;
Zhiyi Zhangee996152020-10-26 13:58:33 -070096 /**
97 * @brief The ID of the request.
98 */
tylerliu7b9185c2020-11-24 12:15:18 -080099 RequestId requestId;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700100 /**
101 * @brief The type of the request.
102 */
tylerliu7b9185c2020-11-24 12:15:18 -0800103 RequestType requestType = RequestType::NOTINITIALIZED;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700104 /**
105 * @brief The status of the request.
106 */
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -0800107 Status status = Status::BEFORE_CHALLENGE;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700108 /**
109 * @brief The self-signed certificate in the request.
110 */
Davide Pesavento0dc02012021-11-23 22:55:03 -0500111 Certificate cert;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700112 /**
113 * @brief The encryption key for the requester.
114 */
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800115 std::array<uint8_t, 16> encryptionKey = {};
Zhiyi Zhangee996152020-10-26 13:58:33 -0700116 /**
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800117 * @brief The last Initialization Vector used by the AES encryption.
Zhiyi Zhangee996152020-10-26 13:58:33 -0700118 */
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800119 std::vector<uint8_t> encryptionIv;
120 /**
121 * @brief The last Initialization Vector used by the other side's AES encryption.
122 */
123 std::vector<uint8_t> decryptionIv;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700124 /**
125 * @brief The challenge type.
126 */
tylerliu7b9185c2020-11-24 12:15:18 -0800127 std::string challengeType;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700128 /**
129 * @brief The challenge state.
130 */
Davide Pesavento0d1d11c2022-04-11 22:11:34 -0400131 std::optional<ChallengeState> challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800132};
133
134std::ostream&
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700135operator<<(std::ostream& os, const RequestState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800136
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700137} // namespace ca
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700138} // namespace ndncert
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800139
tylerliu6563f932020-10-30 11:13:38 -0700140#endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP