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 | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 3 | * Copyright (c) 2017-2020, 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 | |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 24 | #include "configuration.hpp" |
Zhiyi Zhang | e232a74 | 2020-09-29 17:34:17 -0700 | [diff] [blame] | 25 | #include "request-state.hpp" |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 26 | #include "crypto-support/crypto-helper.hpp" |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 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 |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 33 | // The validator instance should be in CaConfigItem |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 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 | ~ClientModule(); |
| 51 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 52 | ClientConfig& |
| 53 | getClientConf() |
| 54 | { |
| 55 | return m_config; |
| 56 | } |
| 57 | |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 58 | Status |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 59 | getApplicationStatus() const |
| 60 | { |
| 61 | return m_status; |
| 62 | } |
| 63 | |
| 64 | std::string |
| 65 | getChallengeStatus() const |
| 66 | { |
| 67 | return m_challengeStatus; |
| 68 | } |
| 69 | |
| 70 | shared_ptr<Interest> |
swa770 | 20643ac | 2020-03-26 02:24:45 -0700 | [diff] [blame] | 71 | generateInfoInterest(const Name& caName); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 72 | |
Zhiyi Zhang | caab546 | 2019-10-18 13:41:02 -0700 | [diff] [blame] | 73 | bool |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 74 | verifyInfoResponse(const Data& reply); |
Zhiyi Zhang | caab546 | 2019-10-18 13:41:02 -0700 | [diff] [blame] | 75 | |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 76 | /** |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 77 | * @brief Process the replied PROBE INFO Data packet |
| 78 | * Warning: this function will add a new trust anchor into the application. |
| 79 | * Please invoke this function only when reply can be fully trusted or the CA |
| 80 | * can be verified in later challenge phase. |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 81 | */ |
| 82 | void |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 83 | addCaFromInfoResponse(const Data& reply); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 84 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 85 | shared_ptr<Interest> |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 86 | generateProbeInterest(const CaConfigItem& ca, std::vector<std::tuple<std::string, std::string>>&& probeInfo); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 87 | |
| 88 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 89 | onProbeResponse(const Data& reply); |
| 90 | |
| 91 | shared_ptr<Interest> |
| 92 | generateNewInterest(const time::system_clock::TimePoint& notBefore, |
| 93 | const time::system_clock::TimePoint& notAfter, |
Zhiyi Zhang | b8bbc64 | 2020-09-29 14:08:26 -0700 | [diff] [blame] | 94 | const Name& identityName = Name()); |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 95 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 96 | shared_ptr<Interest> |
tylerliu | 4a00aad | 2020-09-26 02:03:17 -0700 | [diff] [blame] | 97 | generateRevokeInterest(const security::v2::Certificate& certificate); |
| 98 | |
| 99 | std::list<std::string> |
tylerliu | 0e176c3 | 2020-09-29 11:39:46 -0700 | [diff] [blame] | 100 | onNewRenewRevokeResponse(const Data& reply); |
tylerliu | 4a00aad | 2020-09-26 02:03:17 -0700 | [diff] [blame] | 101 | |
| 102 | shared_ptr<Interest> |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 103 | generateChallengeInterest(const Block& paramTLV); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 104 | |
| 105 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 106 | onChallengeResponse(const Data& reply); |
| 107 | |
| 108 | shared_ptr<Interest> |
| 109 | generateDownloadInterest(); |
| 110 | |
| 111 | shared_ptr<Interest> |
| 112 | generateCertFetchInterest(); |
Zhiyi Zhang | 1c0bd37 | 2017-12-18 18:32:55 +0800 | [diff] [blame] | 113 | |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 114 | void |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 115 | onCertFetchResponse(const Data& reply); |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 116 | |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 117 | void |
| 118 | endSession(); |
| 119 | |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 120 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 121 | ClientConfig m_config; |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 122 | security::v2::KeyChain& m_keyChain; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 123 | |
Zhiyi Zhang | 9829da9 | 2020-09-30 16:19:34 -0700 | [diff] [blame] | 124 | CaConfigItem m_ca; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 125 | security::Key m_key; |
| 126 | Name m_identityName; |
| 127 | |
| 128 | std::string m_requestId = ""; |
Zhiyi Zhang | 48f2378 | 2020-09-28 12:11:24 -0700 | [diff] [blame] | 129 | Status m_status = Status::NOT_STARTED; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 130 | std::string m_challengeStatus = ""; |
| 131 | std::string m_challengeType = ""; |
Suyong Won | 19fba4d | 2020-05-09 13:39:46 -0700 | [diff] [blame] | 132 | Name m_issuedCertName; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 133 | std::list<std::string> m_challengeList; |
| 134 | bool m_isCertInstalled = false; |
Zhiyi Zhang | ad9e04f | 2020-03-27 12:04:31 -0700 | [diff] [blame] | 135 | bool m_isNewlyCreatedIdentity = false; |
| 136 | bool m_isNewlyCreatedKey = false; |
Zhiyi Zhang | af7c290 | 2019-03-14 22:13:21 -0700 | [diff] [blame] | 137 | |
| 138 | int m_remainingTries = 0; |
| 139 | time::system_clock::TimePoint m_freshBefore; |
| 140 | |
| 141 | ECDHState m_ecdh; |
Zhiyi Zhang | 8da54d6 | 2019-11-21 00:03:05 -0800 | [diff] [blame] | 142 | uint8_t m_aesKey[16] = {0}; |
Zhiyi Zhang | 23564c8 | 2017-03-01 10:22:22 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | } // namespace ndncert |
| 146 | } // namespace ndn |
| 147 | |
| 148 | #endif // NDNCERT_CLIENT_MODULE_HPP |