blob: d14b74d8d257382bc62a2a957874d118bfff3cc9 [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -08003 * Copyright (c) 2017-2018, 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
Zhiyi Zhang00a4a002017-03-01 10:17:36 -080021#ifndef NDNCERT_CERTIFICATE_REQUEST_HPP
22#define NDNCERT_CERTIFICATE_REQUEST_HPP
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080023
24#include "ndncert-common.hpp"
25#include <ndn-cxx/security/v2/certificate.hpp>
26
27namespace ndn {
28namespace ndncert {
29
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080030typedef boost::property_tree::ptree JsonSection;
31
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080032/**
33 * @brief Represents a certificate request instance.
34 *
35 * ChallengeModule should take use of m_challengeStatus, m_challengeInstruction and
36 * m_challengeDefinedField to finish verification.
37 *
38 */
39class CertificateRequest
40{
41public:
Zhiyi Zhang00a4a002017-03-01 10:17:36 -080042 CertificateRequest();
43
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080044 CertificateRequest(const Name& caName, const std::string& requestId,
45 const security::v2::Certificate& cert);
46
47 CertificateRequest(const Name& caName, const std::string& requestId,
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080048 const std::string& status, const std::string& challengeType,
Zhiyi Zhang1bc23462017-04-12 14:16:09 -070049 const std::string& challengeSecrets,
50 const security::v2::Certificate& cert);
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080051
52 const Name&
53 getCaName() const
54 {
55 return m_caName;
56 }
57
58 const std::string&
59 getRequestId() const
60 {
61 return m_requestId;
62 }
63
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080064 const std::string&
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080065 getStatus() const
66 {
67 return m_status;
68 }
69
70 const std::string&
71 getChallengeType() const
72 {
73 return m_challengeType;
74 }
75
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080076 const JsonSection&
77 getChallengeSecrets() const
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080078 {
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080079 return m_challengeSecrets;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080080 }
81
82 const security::v2::Certificate&
83 getCert() const
84 {
85 return m_cert;
86 }
87
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080088 void
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080089 setCert(security::v2::Certificate cert)
90 {
91 m_cert = std::move(cert);
92 }
93
94 void
Zhiyi Zhang3b267e62017-02-09 17:59:34 -080095 setStatus(const std::string& status)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -080096 {
97 m_status = status;
98 }
99
100 void
101 setChallengeType(const std::string& challengeType)
102 {
103 m_challengeType = challengeType;
104 }
105
106 void
Zhiyi Zhang3b267e62017-02-09 17:59:34 -0800107 setChallengeSecrets(const JsonSection& challengeSecrets)
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800108 {
Zhiyi Zhang3b267e62017-02-09 17:59:34 -0800109 m_challengeSecrets = challengeSecrets;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800110 }
111
Zhiyi Zhang00a4a002017-03-01 10:17:36 -0800112 bool
113 isEmpty()
114 {
115 return m_requestId == "";
116 }
117
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800118private:
119 Name m_caName;
120 std::string m_requestId;
Zhiyi Zhang3b267e62017-02-09 17:59:34 -0800121 std::string m_status;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800122 std::string m_challengeType;
123
124 /**
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800125 * @brief Defined by ChallengeModule to store secret information.
126 *
127 * This field will be stored by CA.
128 */
Zhiyi Zhang3b267e62017-02-09 17:59:34 -0800129 JsonSection m_challengeSecrets;
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800130
131 security::v2::Certificate m_cert;
132};
133
134std::ostream&
Zhiyi Zhanga41c5732017-01-18 14:06:44 -0800135operator<<(std::ostream& os, const CertificateRequest& request);
136
137} // namespace ndncert
138} // namespace ndn
139
Zhiyi Zhang00a4a002017-03-01 10:17:36 -0800140#endif // NDNCERT_CERTIFICATE_REQUEST_HPP