blob: e75e190360f7d84c1dd099cfc1b2ddc62b7071f8 [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
24#include "client-config.hpp"
25#include "certificate-request.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
33// The validator instance should be in ClientCaItem
34
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>
86 generateProbeInterest(const ClientCaItem& ca, const 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 Zhang5f749a22019-06-12 17:02:33 -070094 const Name& identityName = Name(), const shared_ptr<Data>& probeToken = nullptr);
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 Zhang547c8512019-06-18 23:46:14 -0700117 static std::vector<std::string>
118 parseProbeComponents(const std::string& probe);
119
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -0700120 void
121 endSession();
122
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700123PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800124 ClientConfig m_config;
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800125 security::v2::KeyChain& m_keyChain;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700126
127 ClientCaItem m_ca;
128 security::Key m_key;
129 Name m_identityName;
130
131 std::string m_requestId = "";
Zhiyi Zhang48f23782020-09-28 12:11:24 -0700132 Status m_status = Status::NOT_STARTED;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700133 std::string m_challengeStatus = "";
134 std::string m_challengeType = "";
135 std::string m_certId = "";
Suyong Won19fba4d2020-05-09 13:39:46 -0700136 Name m_issuedCertName;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700137 std::list<std::string> m_challengeList;
138 bool m_isCertInstalled = false;
Zhiyi Zhangad9e04f2020-03-27 12:04:31 -0700139 bool m_isNewlyCreatedIdentity = false;
140 bool m_isNewlyCreatedKey = false;
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700141
142 int m_remainingTries = 0;
143 time::system_clock::TimePoint m_freshBefore;
144
145 ECDHState m_ecdh;
Zhiyi Zhang8da54d62019-11-21 00:03:05 -0800146 uint8_t m_aesKey[16] = {0};
Zhiyi Zhang23564c82017-03-01 10:22:22 -0800147};
148
149} // namespace ndncert
150} // namespace ndn
151
152#endif // NDNCERT_CLIENT_MODULE_HPP