Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 4 | * |
| 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 | |
| 21 | #include "certificate-request.hpp" |
| 22 | #include <ndn-cxx/util/indented-stream.hpp> |
| 23 | |
| 24 | namespace ndn { |
| 25 | namespace ndncert { |
| 26 | |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 27 | ChallengeState::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 | |
| 39 | CertificateRequest::CertificateRequest() |
| 40 | : m_requestType(RequestType::NOTINITIALIZED) |
| 41 | , m_status(Status::NOT_STARTED) |
| 42 | { |
| 43 | } |
Zhiyi Zhang | 00a4a00 | 2017-03-01 10:17:36 -0800 | [diff] [blame] | 44 | |
Zhiyi Zhang | c87d52b | 2020-09-28 22:07:18 -0700 | [diff] [blame] | 45 | CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, RequestType requestType, Status status, |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 46 | const security::v2::Certificate& cert) |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 47 | : m_caPrefix(caName) |
| 48 | , m_requestId(requestId) |
| 49 | , m_requestType(requestType) |
| 50 | , m_status(status) |
| 51 | , m_cert(cert) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 52 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Zhiyi Zhang | c87d52b | 2020-09-28 22:07:18 -0700 | [diff] [blame] | 55 | CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, RequestType requestType, Status status, |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 56 | const security::v2::Certificate& cert, const std::string& challengeType, |
| 57 | const std::string& challengeStatus, const system_clock::TimePoint& challengeTp, |
| 58 | size_t remainingTries, time::seconds remainingTime, JsonSection&& challengeSecrets) |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 59 | : m_caPrefix(caName) |
| 60 | , m_requestId(requestId) |
| 61 | , m_requestType(requestType) |
| 62 | , m_status(status) |
| 63 | , m_cert(cert) |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 64 | , m_challengeType(challengeType) |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 65 | , m_challengeState(ChallengeState(challengeStatus, challengeTp, remainingTries, remainingTime, std::move(challengeSecrets))) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 66 | { |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | std::ostream& |
| 70 | operator<<(std::ostream& os, const CertificateRequest& request) |
| 71 | { |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 72 | os << "Request's CA name:\n"; |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 73 | os << " " << request.m_caPrefix << "\n"; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 74 | os << "Request's request ID:\n"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 75 | os << " " << request.m_requestId << "\n"; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 76 | os << "Request's status:\n"; |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 77 | os << " " << statusToString(request.m_status) << "\n"; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 78 | os << "Request's challenge type:\n"; |
| 79 | os << " " << request.m_challengeType << "\n"; |
| 80 | if (request.m_challengeState) { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 81 | os << "Challenge Status:\n"; |
Zhiyi Zhang | a749f44 | 2020-09-29 17:19:51 -0700 | [diff] [blame^] | 82 | os << " " << request.m_challengeState->m_challengeStatus << "\n"; |
| 83 | os << "Challenge remaining tries:\n"; |
| 84 | os << " " << request.m_challengeState->m_remainingTries << " times\n"; |
| 85 | os << "Challenge remaining time:\n"; |
| 86 | os << " " << request.m_challengeState->m_remainingTime.count() << " seconds\n"; |
| 87 | os << "Challenge last update:\n"; |
| 88 | os << " " << time::toIsoString(request.m_challengeState->m_timestamp) << "\n"; |
| 89 | os << "Challenge secret:\n"; |
| 90 | os << " " << convertJson2String(request.m_challengeState->m_secrets) << "\n"; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 91 | } |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 92 | os << "Certificate:\n"; |
| 93 | util::IndentedStream os2(os, " "); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 94 | os2 << request.m_cert; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 95 | return os; |
| 96 | } |
| 97 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 98 | } // namespace ndncert |
| 99 | } // namespace ndn |