Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 1 | /* -*- 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 | |
Zhiyi Zhang | 00a4a00 | 2017-03-01 10:17:36 -0800 | [diff] [blame] | 21 | #ifndef NDNCERT_CERTIFICATE_REQUEST_HPP |
| 22 | #define NDNCERT_CERTIFICATE_REQUEST_HPP |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 23 | |
| 24 | #include "ndncert-common.hpp" |
| 25 | #include <ndn-cxx/security/v2/certificate.hpp> |
| 26 | |
| 27 | namespace ndn { |
| 28 | namespace ndncert { |
| 29 | |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 30 | typedef boost::property_tree::ptree JsonSection; |
| 31 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 32 | /** |
| 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 | */ |
| 39 | class CertificateRequest |
| 40 | { |
| 41 | public: |
Zhiyi Zhang | 00a4a00 | 2017-03-01 10:17:36 -0800 | [diff] [blame] | 42 | CertificateRequest(); |
| 43 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 44 | 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 Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 48 | const std::string& status, const std::string& challengeType, |
Zhiyi Zhang | 1bc2346 | 2017-04-12 14:16:09 -0700 | [diff] [blame] | 49 | const std::string& challengeSecrets, |
| 50 | const security::v2::Certificate& cert); |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 51 | |
| 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 Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 64 | const std::string& |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 65 | getStatus() const |
| 66 | { |
| 67 | return m_status; |
| 68 | } |
| 69 | |
| 70 | const std::string& |
| 71 | getChallengeType() const |
| 72 | { |
| 73 | return m_challengeType; |
| 74 | } |
| 75 | |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 76 | const JsonSection& |
| 77 | getChallengeSecrets() const |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 78 | { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 79 | return m_challengeSecrets; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | const security::v2::Certificate& |
| 83 | getCert() const |
| 84 | { |
| 85 | return m_cert; |
| 86 | } |
| 87 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 88 | void |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 89 | setStatus(const std::string& status) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 90 | { |
| 91 | m_status = status; |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | setChallengeType(const std::string& challengeType) |
| 96 | { |
| 97 | m_challengeType = challengeType; |
| 98 | } |
| 99 | |
| 100 | void |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 101 | setChallengeSecrets(const JsonSection& challengeSecrets) |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 102 | { |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 103 | m_challengeSecrets = challengeSecrets; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 104 | } |
| 105 | |
Zhiyi Zhang | 00a4a00 | 2017-03-01 10:17:36 -0800 | [diff] [blame] | 106 | bool |
| 107 | isEmpty() |
| 108 | { |
| 109 | return m_requestId == ""; |
| 110 | } |
| 111 | |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 112 | private: |
| 113 | Name m_caName; |
| 114 | std::string m_requestId; |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 115 | std::string m_status; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 116 | std::string m_challengeType; |
| 117 | |
| 118 | /** |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 119 | * @brief Defined by ChallengeModule to store secret information. |
| 120 | * |
| 121 | * This field will be stored by CA. |
| 122 | */ |
Zhiyi Zhang | 3b267e6 | 2017-02-09 17:59:34 -0800 | [diff] [blame] | 123 | JsonSection m_challengeSecrets; |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 124 | |
| 125 | security::v2::Certificate m_cert; |
| 126 | }; |
| 127 | |
| 128 | std::ostream& |
Zhiyi Zhang | a41c573 | 2017-01-18 14:06:44 -0800 | [diff] [blame] | 129 | operator<<(std::ostream& os, const CertificateRequest& request); |
| 130 | |
| 131 | } // namespace ndncert |
| 132 | } // namespace ndn |
| 133 | |
Zhiyi Zhang | 00a4a00 | 2017-03-01 10:17:36 -0800 | [diff] [blame] | 134 | #endif // NDNCERT_CERTIFICATE_REQUEST_HPP |