blob: 4a4c4b467fbcc89a42d9344e9a319bfc2ea3cf6a [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
21#include "certificate-request.hpp"
22#include <ndn-cxx/util/indented-stream.hpp>
23
24namespace ndn {
25namespace ndncert {
26
Zhiyi Zhang00a4a002017-03-01 10:17:36 -080027CertificateRequest::CertificateRequest() = default;
28
tylerliu182bc532020-09-25 01:54:45 -070029CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int requestType, int status,
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080030 const security::v2::Certificate& cert)
Suyong Won256c9062020-05-11 02:45:56 -070031 : m_caPrefix(caName)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080032 , m_requestId(requestId)
tylerliu182bc532020-09-25 01:54:45 -070033 , m_requestType(requestType)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080034 , m_status(status)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070035 , m_cert(cert)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080036{
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070037}
38
tylerliu182bc532020-09-25 01:54:45 -070039CertificateRequest::CertificateRequest(const Name& caName, const std::string& requestId, int requestType, int status,
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070040 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 Won256c9062020-05-11 02:45:56 -070043 : m_caPrefix(caName)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070044 , m_requestId(requestId)
tylerliu182bc532020-09-25 01:54:45 -070045 , m_requestType(requestType)
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070046 , 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 Zhanga41c5732017-01-18 14:06:44 -080055}
56
Zhiyi Zhang5f749a22019-06-12 17:02:33 -070057void
58CertificateRequest::setProbeToken(const shared_ptr<Data>& probeToken)
59{
60 m_probeToken = probeToken;
61}
62
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080063std::ostream&
64operator<<(std::ostream& os, const CertificateRequest& request)
65{
66 os << "Request CA name:\n";
Suyong Won256c9062020-05-11 02:45:56 -070067 os << " " << request.m_caPrefix << "\n";
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080068 os << "Request ID:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070069 os << " " << request.m_requestId << "\n";
70 if (request.m_status != -1) {
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080071 os << "Request Status:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070072 os << " " << request.m_status << "\n";
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080073 }
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070074 if (request.m_challengeStatus != "") {
75 os << "Challenge Status:\n";
76 os << " " << request.m_challengeStatus << "\n";
77 }
78 if (request.m_challengeType != "") {
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080079 os << "Request Challenge Type:\n";
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070080 os << " " << request.m_challengeType << "\n";
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080081 }
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080082 os << "Certificate:\n";
83 util::IndentedStream os2(os, " ");
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070084 os2 << request.m_cert;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080085 return os;
86}
87
88} // namespace ndncert
89} // namespace ndn