blob: e72b19fbcaccb8f643252e22297b6b791152c97c [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
tylerliu182bc532020-09-25 01:54:45 -07003 * 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#include "ca-state.hpp"
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080022#include <ndn-cxx/util/indented-stream.hpp>
23
24namespace ndn {
25namespace ndncert {
26
Zhiyi Zhanga749f442020-09-29 17:19:51 -070027ChallengeState::ChallengeState(const std::string& challengeStatus,
28 const system_clock::TimePoint& challengeTp,
29 size_t remainingTries, time::seconds remainingTime,
30 JsonSection&& challengeSecrets)
31 : m_challengeStatus(challengeStatus)
32 , m_timestamp(challengeTp)
33 , m_remainingTries(remainingTries)
34 , m_remainingTime(remainingTime)
35 , m_secrets(std::move(challengeSecrets))
36{
37}
38
tylerliu8704d032020-06-23 10:18:15 -070039CaState::CaState()
Zhiyi Zhanga749f442020-09-29 17:19:51 -070040 : m_requestType(RequestType::NOTINITIALIZED)
41 , m_status(Status::NOT_STARTED)
42{
43}
Zhiyi Zhang00a4a002017-03-01 10:17:36 -080044
tylerliu8704d032020-06-23 10:18:15 -070045CaState::CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
46 const security::v2::Certificate& cert, Block encryptionKey)
Zhiyi Zhang48f23782020-09-28 12:11:24 -070047 : m_caPrefix(caName)
48 , m_requestId(requestId)
49 , m_requestType(requestType)
50 , m_status(status)
51 , m_cert(cert)
tylerliu8e170d62020-09-30 01:31:53 -070052 , m_encryptionKey(std::move(encryptionKey))
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080053{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070054}
55
tylerliu8704d032020-06-23 10:18:15 -070056CaState::CaState(const Name& caName, const std::string& requestId, RequestType requestType, Status status,
57 const security::v2::Certificate& cert, const std::string& challengeType,
58 const std::string& challengeStatus, const system_clock::TimePoint& challengeTp,
59 size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets,
60 Block encryptionKey)
Zhiyi Zhang48f23782020-09-28 12:11:24 -070061 : m_caPrefix(caName)
62 , m_requestId(requestId)
63 , m_requestType(requestType)
64 , m_status(status)
65 , m_cert(cert)
Zhiyi Zhang156bf352020-09-30 17:45:43 -070066 , m_encryptionKey(std::move(encryptionKey))
Zhiyi Zhang48f23782020-09-28 12:11:24 -070067 , m_challengeType(challengeType)
Zhiyi Zhanga749f442020-09-29 17:19:51 -070068 , m_challengeState(ChallengeState(challengeStatus, challengeTp, remainingTries, remainingTime, std::move(challengeSecrets)))
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070069{
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080070}
71
72std::ostream&
tylerliu8704d032020-06-23 10:18:15 -070073operator<<(std::ostream& os, const CaState& request)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080074{
Zhiyi Zhangd93c0bb2020-10-05 22:06:05 -070075 os << "Request's CA name: " << request.m_caPrefix << "\n";
76 os << "Request's request ID: " << request.m_requestId << "\n";
77 os << "Request's status: " << statusToString(request.m_status) << "\n";
78 os << "Request's challenge type: " << request.m_challengeType << "\n";
Zhiyi Zhanga749f442020-09-29 17:19:51 -070079 if (request.m_challengeState) {
Zhiyi Zhangd93c0bb2020-10-05 22:06:05 -070080 os << "Challenge Status: " << request.m_challengeState->m_challengeStatus << "\n";
81 os << "Challenge remaining tries:" << request.m_challengeState->m_remainingTries << " times\n";
82 os << "Challenge remaining time: " << request.m_challengeState->m_remainingTime.count() << " seconds\n";
83 os << "Challenge last update: " << time::toIsoString(request.m_challengeState->m_timestamp) << "\n";
84 os << "Challenge secret:\n" << convertJson2String(request.m_challengeState->m_secrets) << "\n";
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080085 }
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080086 os << "Certificate:\n";
87 util::IndentedStream os2(os, " ");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070088 os2 << request.m_cert;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080089 return os;
90}
91
Zhiyi Zhang48f23782020-09-28 12:11:24 -070092} // namespace ndncert
93} // namespace ndn