blob: fd881296916a58a81a7a9e6a8c995fe37d319e38 [file] [log] [blame]
Zhiyi Zhang23564c82017-03-01 10:22:22 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -07003 * Copyright (c) 2017-2020, Regents of the University of California.
Zhiyi Zhang23564c82017-03-01 10:22:22 -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
21#ifndef NDNCERT_CLIENT_MODULE_HPP
22#define NDNCERT_CLIENT_MODULE_HPP
23
Zhiyi Zhang9829da92020-09-30 16:19:34 -070024#include "configuration.hpp"
Zhiyi Zhange232a742020-09-29 17:34:17 -070025#include "request-state.hpp"
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -070026#include "crypto-support/crypto-helper.hpp"
Zhiyi Zhang23564c82017-03-01 10:22:22 -080027
28namespace ndn {
29namespace ndncert {
30
Zhiyi Zhang23564c82017-03-01 10:22:22 -080031// TODO
32// For each CA item in Client.Conf, create a validator instance and initialize it with CA's cert
Zhiyi Zhang9829da92020-09-30 16:19:34 -070033// The validator instance should be in CaConfigItem
Zhiyi Zhang23564c82017-03-01 10:22:22 -080034
35class ClientModule : noncopyable
36{
37public:
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 Zhang23564c82017-03-01 10:22:22 -080047public:
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070048 ClientModule(security::v2::KeyChain& keyChain);
Zhiyi Zhang23564c82017-03-01 10:22:22 -080049
Davide Pesavento08994782018-01-22 12:13:41 -050050 ~ClientModule();
51
Zhiyi Zhang23564c82017-03-01 10:22:22 -080052 ClientConfig&
53 getClientConf()
54 {
55 return m_config;
56 }
57
Zhiyi Zhang48f23782020-09-28 12:11:24 -070058 Status
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070059 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>
swa77020643ac2020-03-26 02:24:45 -070071 generateInfoInterest(const Name& caName);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080072
Zhiyi Zhangcaab5462019-10-18 13:41:02 -070073 bool
Suyong Won19fba4d2020-05-09 13:39:46 -070074 verifyInfoResponse(const Data& reply);
Zhiyi Zhangcaab5462019-10-18 13:41:02 -070075
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080076 /**
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070077 * @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 Zhang1c0bd372017-12-18 18:32:55 +080081 */
82 void
Suyong Won19fba4d2020-05-09 13:39:46 -070083 addCaFromInfoResponse(const Data& reply);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080084
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070085 shared_ptr<Interest>
Zhiyi Zhang9829da92020-09-30 16:19:34 -070086 generateProbeInterest(const CaConfigItem& ca, std::vector<std::tuple<std::string, std::string>>&& probeInfo);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080087
88 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070089 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 Zhangb8bbc642020-09-29 14:08:26 -070094 const Name& identityName = Name());
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070095
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070096 shared_ptr<Interest>
tylerliu4a00aad2020-09-26 02:03:17 -070097 generateRevokeInterest(const security::v2::Certificate& certificate);
98
99 std::list<std::string>
tylerliu0e176c32020-09-29 11:39:46 -0700100 onNewRenewRevokeResponse(const Data& reply);
tylerliu4a00aad2020-09-26 02:03:17 -0700101
102 shared_ptr<Interest>
Suyong Won19fba4d2020-05-09 13:39:46 -0700103 generateChallengeInterest(const Block& paramTLV);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800104
105 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700106 onChallengeResponse(const Data& reply);
107
108 shared_ptr<Interest>
109 generateDownloadInterest();
110
111 shared_ptr<Interest>
112 generateCertFetchInterest();
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800113
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800114 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700115 onCertFetchResponse(const Data& reply);
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800116
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -0700117 void
118 endSession();
119
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700120PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800121 ClientConfig m_config;
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800122 security::v2::KeyChain& m_keyChain;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700123
Zhiyi Zhang9829da92020-09-30 16:19:34 -0700124 CaConfigItem m_ca;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700125 security::Key m_key;
126 Name m_identityName;
127
128 std::string m_requestId = "";
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700129 Status m_status = Status::NOT_STARTED;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700130 std::string m_challengeStatus = "";
131 std::string m_challengeType = "";
Suyong Won19fba4d2020-05-09 13:39:46 -0700132 Name m_issuedCertName;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700133 std::list<std::string> m_challengeList;
134 bool m_isCertInstalled = false;
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -0700135 bool m_isNewlyCreatedIdentity = false;
136 bool m_isNewlyCreatedKey = false;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700137
138 int m_remainingTries = 0;
139 time::system_clock::TimePoint m_freshBefore;
140
141 ECDHState m_ecdh;
Zhiyi Zhang8da54d62019-11-21 00:03:05 -0800142 uint8_t m_aesKey[16] = {0};
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800143};
144
145} // namespace ndncert
146} // namespace ndn
147
148#endif // NDNCERT_CLIENT_MODULE_HPP