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