blob: b8d1ccd6cd51edc6026ddafb44d07397c7c4973d [file] [log] [blame]
Zhiyi Zhanga41c5732017-01-18 14:06:44 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, Regents of the University of California.
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#ifndef NDNCERT_CERTFICATE_REQUEST_HPP
22#define NDNCERT_CERTFICATE_REQUEST_HPP
23
24#include "ndncert-common.hpp"
25#include <ndn-cxx/security/v2/certificate.hpp>
26
27namespace ndn {
28namespace ndncert {
29
30/**
31 * @brief Represents a certificate request instance.
32 *
33 * ChallengeModule should take use of m_challengeStatus, m_challengeInstruction and
34 * m_challengeDefinedField to finish verification.
35 *
36 */
37class CertificateRequest
38{
39public:
40 enum ApplicationStatus {
41 Pending = 0,
42 Verifying = 1,
43 Success = 2,
44 Failure = 3
45 };
46
47public:
48 CertificateRequest(const Name& caName, const std::string& requestId,
49 const security::v2::Certificate& cert);
50
51 CertificateRequest(const Name& caName, const std::string& requestId,
52 const ApplicationStatus& status, const std::string& challengeType,
53 const std::string& challengeStatus, const std::string& challengeDefinedField,
54 const security::v2::Certificate& certBlock);
55
56 const Name&
57 getCaName() const
58 {
59 return m_caName;
60 }
61
62 const std::string&
63 getRequestId() const
64 {
65 return m_requestId;
66 }
67
68 const ApplicationStatus&
69 getStatus() const
70 {
71 return m_status;
72 }
73
74 const std::string&
75 getChallengeType() const
76 {
77 return m_challengeType;
78 }
79
80 const std::string&
81 getChallengeDefinedField() const
82 {
83 return m_challengeDefinedField;
84 }
85
86 const std::string&
87 getChallengeInstruction() const
88 {
89 return m_challengeInstruction;
90 }
91
92 const std::string&
93 getChallengeStatus() const
94 {
95 return m_challengeStatus;
96 }
97
98 const security::v2::Certificate&
99 getCert() const
100 {
101 return m_cert;
102 }
103
104 /**
105 * These setters should only be invoked by ChallengeModule
106 */
107 void
108 setStatus(const ApplicationStatus& status)
109 {
110 m_status = status;
111 }
112
113 void
114 setChallengeType(const std::string& challengeType)
115 {
116 m_challengeType = challengeType;
117 }
118
119 void
120 setChallengeStatus(const std::string& challengeStatus)
121 {
122 m_challengeStatus = challengeStatus;
123 }
124
125 void
126 setChallengeDefinedField(const std::string& challengeDefinedField)
127 {
128 m_challengeDefinedField = challengeDefinedField;
129 }
130
131 void
132 setChallengeInstruction(const std::string& challengeInstruction)
133 {
134 m_challengeInstruction = challengeInstruction;
135 }
136
137private:
138 Name m_caName;
139 std::string m_requestId;
140 ApplicationStatus m_status;
141 std::string m_challengeType;
142
143 /**
144 * @brief Defined by ChallengeModule to indicate the verification status.
145 *
146 * This field will be stored by CA.
147 */
148 std::string m_challengeStatus;
149
150 /**
151 * @brief Defined by ChallengeModule to store secret information.
152 *
153 * This field will be stored by CA.
154 */
155 std::string m_challengeDefinedField;
156
157 /**
158 * @brief Defined by ChallengeModule to indicate end entity the next step.
159 *
160 * This field will be presented to end entity.
161 * This field will NOT be stored by CA.
162 */
163 std::string m_challengeInstruction;
164
165 security::v2::Certificate m_cert;
166};
167
168std::ostream&
169operator<<(std::ostream& os, CertificateRequest::ApplicationStatus status);
170
171std::ostream&
172operator<<(std::ostream& os, const CertificateRequest& request);
173
174} // namespace ndncert
175} // namespace ndn
176
177#endif // NDNCERT_CERTFICATE_REQUEST_HPP