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 | 00a4a00 | 2017-03-01 10:17:36 -0800 | [diff] [blame] | 27 | CertificateRequest::CertificateRequest() = default; |
| 28 | |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame^] | 29 | CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int requestType, int status, |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 30 | const security::v2::Certificate& cert) |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 31 | : m_caPrefix(caName) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 32 | , m_requestId(requestId) |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame^] | 33 | , m_requestType(requestType) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 34 | , m_status(status) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 35 | , m_cert(cert) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 36 | { |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 37 | } |
| 38 | |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame^] | 39 | CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int requestType, int status, |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 40 | const std::string& challengeStatus, const std::string& challengeType, |
| 41 | const std::string& challengeTp, int remainingTime, int remainingTries, |
| 42 | const JsonSection& challengeSecrets, const security::v2::Certificate& cert) |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 43 | : m_caPrefix(caName) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 44 | , m_requestId(requestId) |
tylerliu | 182bc53 | 2020-09-25 01:54:45 -0700 | [diff] [blame^] | 45 | , m_requestType(requestType) |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 46 | , m_status(status) |
| 47 | , m_cert(cert) |
| 48 | , m_challengeStatus(challengeStatus) |
| 49 | , m_challengeType(challengeType) |
| 50 | , m_challengeTp(challengeTp) |
| 51 | , m_remainingTime(remainingTime) |
| 52 | , m_remainingTries(remainingTries) |
| 53 | , m_challengeSecrets(challengeSecrets) |
| 54 | { |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Zhiyi Zhang | 5f749a2 | 2019-06-12 17:02:33 -0700 | [diff] [blame] | 57 | void |
| 58 | CertificateRequest::setProbeToken(const shared_ptr<Data>& probeToken) |
| 59 | { |
| 60 | m_probeToken = probeToken; |
| 61 | } |
| 62 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 63 | std::ostream& |
| 64 | operator<<(std::ostream& os, const CertificateRequest& request) |
| 65 | { |
| 66 | os << "Request CA name:\n"; |
Suyong Won | 256c906 | 2020-05-11 02:45:56 -0700 | [diff] [blame] | 67 | os << " " << request.m_caPrefix << "\n"; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 68 | os << "Request ID:\n"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 69 | os << " " << request.m_requestId << "\n"; |
| 70 | if (request.m_status != -1) { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 71 | os << "Request Status:\n"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 72 | os << " " << request.m_status << "\n"; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 73 | } |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 74 | if (request.m_challengeStatus != "") { |
| 75 | os << "Challenge Status:\n"; |
| 76 | os << " " << request.m_challengeStatus << "\n"; |
| 77 | } |
| 78 | if (request.m_challengeType != "") { |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 79 | os << "Request Challenge Type:\n"; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 80 | os << " " << request.m_challengeType << "\n"; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 81 | } |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 82 | os << "Certificate:\n"; |
| 83 | util::IndentedStream os2(os, " "); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 84 | os2 << request.m_cert; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 85 | return os; |
| 86 | } |
| 87 | |
| 88 | } // namespace ndncert |
| 89 | } // namespace ndn |