Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -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 | 23564c8 | 2017-03-01 10:22:22 -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 | #ifndef NDNCERT_CLIENT_MODULE_HPP |
| 22 | #define NDNCERT_CLIENT_MODULE_HPP |
| 23 | |
| 24 | #include "client-config.hpp" |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 25 | #include "crypto-support/crypto-helper.hpp" |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 26 | #include "certificate-request.hpp" |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace ndncert { |
| 30 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 31 | // TODO |
| 32 | // For each CA item in Client.Conf, create a validator instance and initialize it with CA's cert |
| 33 | // The validator instance should be in ClientCaItem |
| 34 | |
| 35 | class ClientModule : noncopyable |
| 36 | { |
| 37 | public: |
| 38 | /** |
| 39 | * @brief Error that can be thrown from ClientModule |
| 40 | */ |
| 41 | class Error : public std::runtime_error |
| 42 | { |
| 43 | public: |
| 44 | using std::runtime_error::runtime_error; |
| 45 | }; |
| 46 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 47 | public: |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 48 | ClientModule(security::v2::KeyChain& keyChain); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 49 | |
Davide Pesavento | 0899478 | 2018-01-22 12:13:41 -0500 | [diff] [blame] | 50 | virtual |
| 51 | ~ClientModule(); |
| 52 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 53 | ClientConfig& |
| 54 | getClientConf() |
| 55 | { |
| 56 | return m_config; |
| 57 | } |
| 58 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 59 | int |
| 60 | getApplicationStatus() const |
| 61 | { |
| 62 | return m_status; |
| 63 | } |
| 64 | |
| 65 | std::string |
| 66 | getChallengeStatus() const |
| 67 | { |
| 68 | return m_challengeStatus; |
| 69 | } |
| 70 | |
| 71 | shared_ptr<Interest> |
| 72 | generateProbeInfoInterest(const Name& caName); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 73 | |
| 74 | /** |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 75 | * @brief Process the replied PROBE INFO Data packet |
| 76 | * Warning: this function will add a new trust anchor into the application. |
| 77 | * Please invoke this function only when reply can be fully trusted or the CA |
| 78 | * can be verified in later challenge phase. |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 79 | */ |
| 80 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 81 | onProbeInfoResponse(const Data& reply); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 82 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 83 | shared_ptr<Interest> |
| 84 | generateProbeInterest(const ClientCaItem& ca, const std::string& probeInfo); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 85 | |
| 86 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 87 | onProbeResponse(const Data& reply); |
| 88 | |
| 89 | shared_ptr<Interest> |
| 90 | generateNewInterest(const time::system_clock::TimePoint& notBefore, |
| 91 | const time::system_clock::TimePoint& notAfter, |
| 92 | const Name& identityName = Name()); |
| 93 | |
| 94 | std::list<std::string> |
| 95 | onNewResponse(const Data& reply); |
| 96 | |
| 97 | shared_ptr<Interest> |
| 98 | generateChallengeInterest(const JsonSection& paramJson); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 99 | |
| 100 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 101 | onChallengeResponse(const Data& reply); |
| 102 | |
| 103 | shared_ptr<Interest> |
| 104 | generateDownloadInterest(); |
| 105 | |
| 106 | shared_ptr<Interest> |
| 107 | generateCertFetchInterest(); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 108 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 109 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 110 | onDownloadResponse(const Data& reply); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 111 | |
| 112 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 113 | onCertFetchResponse(const Data& reply); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 114 | |
| 115 | // helper functions |
| 116 | static JsonSection |
| 117 | getJsonFromData(const Data& data); |
| 118 | |
| 119 | static Block |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 120 | paramFromJson(const JsonSection& json); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 121 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 122 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 123 | const JsonSection |
| 124 | genProbeRequestJson(const std::string& probeInfo); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 125 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 126 | const JsonSection |
| 127 | genNewRequestJson(const std::string& ecdhPub, const security::v2::Certificate& certRequest); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 128 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 129 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 130 | ClientConfig m_config; |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 131 | security::v2::KeyChain& m_keyChain; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame^] | 132 | |
| 133 | ClientCaItem m_ca; |
| 134 | security::Key m_key; |
| 135 | Name m_identityName; |
| 136 | |
| 137 | std::string m_requestId = ""; |
| 138 | int m_status = STATUS_NOT_STARTED; |
| 139 | std::string m_challengeStatus = ""; |
| 140 | std::string m_challengeType = ""; |
| 141 | std::string m_certId = ""; |
| 142 | std::list<std::string> m_challengeList; |
| 143 | bool m_isCertInstalled = false; |
| 144 | |
| 145 | int m_remainingTries = 0; |
| 146 | time::system_clock::TimePoint m_freshBefore; |
| 147 | |
| 148 | ECDHState m_ecdh; |
| 149 | uint8_t m_aesKey[32] = {0}; |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | } // namespace ndncert |
| 153 | } // namespace ndn |
| 154 | |
| 155 | #endif // NDNCERT_CLIENT_MODULE_HPP |