blob: 49fa583a829b6e5fd3e9e7ef68c9f164dd74abd8 [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 Pesavento9510c912024-02-25 17:50:05 -05003 * Copyright (c) 2017-2024, 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>
Davide Pesavento9510c912024-02-25 17:50:05 -050027#include <optional>
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080028
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080029namespace ndncert {
30
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040031using RequestId = std::array<uint8_t, 8>;
Zhiyi Zhang8fdb36b2020-10-18 11:58:51 -070032
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070033enum class Status : uint16_t {
34 BEFORE_CHALLENGE = 0,
35 CHALLENGE = 1,
36 PENDING = 2,
37 SUCCESS = 3,
Davide Pesavento76304d82023-08-10 23:38:06 -040038 FAILURE = 4,
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070039};
40
Zhiyi Zhangee996152020-10-26 13:58:33 -070041/**
42 * @brief Convert request status to string.
43 */
Zhiyi Zhang14f0bc82020-10-12 13:02:23 -070044std::string
45statusToString(Status status);
46
tylerliubb630362020-11-10 11:31:35 -080047/**
48 * @brief Convert request status to string.
49 */
50Status
51statusFromBlock(const Block& block);
52
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070053namespace ca {
54
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070055/**
Zhiyi Zhangee996152020-10-26 13:58:33 -070056 * @brief The state maintained by the Challenge module.
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070057 */
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070058struct ChallengeState
59{
Davide Pesavento76304d82023-08-10 23:38:06 -040060 ChallengeState(const std::string& challengeStatus, const time::system_clock::time_point& challengeTp,
Zhiyi Zhanga749f442020-09-29 17:19:51 -070061 size_t remainingTries, time::seconds remainingTime,
62 JsonSection&& challengeSecrets);
Davide Pesavento76304d82023-08-10 23:38:06 -040063
Zhiyi Zhangee996152020-10-26 13:58:33 -070064 /**
65 * @brief The status of the challenge.
66 */
tylerliu7b9185c2020-11-24 12:15:18 -080067 std::string challengeStatus;
Zhiyi Zhangee996152020-10-26 13:58:33 -070068 /**
69 * @brief The timestamp of the last update of the challenge state.
70 */
Davide Pesavento76304d82023-08-10 23:38:06 -040071 time::system_clock::time_point timestamp;
Zhiyi Zhangee996152020-10-26 13:58:33 -070072 /**
73 * @brief Remaining tries of the challenge.
74 */
tylerliu7b9185c2020-11-24 12:15:18 -080075 size_t remainingTries;
Zhiyi Zhangee996152020-10-26 13:58:33 -070076 /**
77 * @brief Remaining time of the challenge.
78 */
tylerliu7b9185c2020-11-24 12:15:18 -080079 time::seconds remainingTime;
Zhiyi Zhangee996152020-10-26 13:58:33 -070080 /**
81 * @brief The secret for the challenge.
82 */
tylerliu7b9185c2020-11-24 12:15:18 -080083 JsonSection secrets;
Zhiyi Zhanga749f442020-09-29 17:19:51 -070084};
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080085
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080086/**
Zhiyi Zhang97bedb82020-10-10 11:11:35 -070087 * @brief Represents a certificate request instance kept by the CA.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080088 *
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070089 * ChallengeModule should take use of RequestState.ChallengeState to keep the challenge state.
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080090 */
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -080091struct RequestState
Zhiyi Zhang684c67c2020-10-12 14:28:17 -070092{
Zhiyi Zhangee996152020-10-26 13:58:33 -070093 /**
94 * @brief The CA that the request is under.
95 */
tylerliu7b9185c2020-11-24 12:15:18 -080096 Name caPrefix;
Zhiyi Zhangee996152020-10-26 13:58:33 -070097 /**
98 * @brief The ID of the request.
99 */
tylerliu7b9185c2020-11-24 12:15:18 -0800100 RequestId requestId;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700101 /**
102 * @brief The type of the request.
103 */
tylerliu7b9185c2020-11-24 12:15:18 -0800104 RequestType requestType = RequestType::NOTINITIALIZED;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700105 /**
106 * @brief The status of the request.
107 */
Zhiyi Zhang1f5e86e2020-12-04 15:07:57 -0800108 Status status = Status::BEFORE_CHALLENGE;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700109 /**
110 * @brief The self-signed certificate in the request.
111 */
Davide Pesavento0dc02012021-11-23 22:55:03 -0500112 Certificate cert;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700113 /**
114 * @brief The encryption key for the requester.
115 */
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800116 std::array<uint8_t, 16> encryptionKey = {};
Zhiyi Zhangee996152020-10-26 13:58:33 -0700117 /**
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800118 * @brief The last Initialization Vector used by the AES encryption.
Zhiyi Zhangee996152020-10-26 13:58:33 -0700119 */
Zhiyi Zhang4f1c0102020-12-21 15:08:09 -0800120 std::vector<uint8_t> encryptionIv;
121 /**
122 * @brief The last Initialization Vector used by the other side's AES encryption.
123 */
124 std::vector<uint8_t> decryptionIv;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700125 /**
126 * @brief The challenge type.
127 */
tylerliu7b9185c2020-11-24 12:15:18 -0800128 std::string challengeType;
Zhiyi Zhangee996152020-10-26 13:58:33 -0700129 /**
130 * @brief The challenge state.
131 */
Davide Pesavento0d1d11c2022-04-11 22:11:34 -0400132 std::optional<ChallengeState> challengeState;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800133};
134
135std::ostream&
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700136operator<<(std::ostream& os, const RequestState& request);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800137
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700138} // namespace ca
Zhiyi Zhange4891b72020-10-10 15:11:57 -0700139} // namespace ndncert
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800140
tylerliu6563f932020-10-30 11:13:38 -0700141#endif // NDNCERT_DETAIL_CA_REQUEST_STATE_HPP