blob: 5a19c2dc65d76452c080b353554f6c64b7c5703d [file] [log] [blame]
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017-2020, 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
21#ifndef NDNCERT_CLIENT_MODULE_HPP
22#define NDNCERT_CLIENT_MODULE_HPP
23
24#include "configuration.hpp"
25#include "request-state.hpp"
26#include "crypto-support/crypto-helper.hpp"
27
28namespace ndn {
29namespace ndncert {
30
31// TODO
32// For each RequesterState, create a validator instance and initialize it with CA's cert
33// The validator instance should be in CaProfile
34
35struct RequesterState {
36 explicit
37 RequesterState(security::v2::KeyChain& keyChain, const CaProfile& caItem, RequestType requestType);
38
39 CaProfile m_caItem;
40 security::v2::KeyChain& m_keyChain;
41 RequestType m_type;
42
43 Name m_identityName;
44 security::Key m_keyPair;
45 std::string m_requestId;
46 Status m_status = Status::NOT_STARTED;
47 std::string m_challengeType;
48 std::string m_challengeStatus;
49 int m_remainingTries = 0;
50 time::system_clock::TimePoint m_freshBefore;
51 Name m_issuedCertName;
52
53 ECDHState m_ecdh;
54 uint8_t m_aesKey[16] = {0};
55
56 bool m_isCertInstalled = false;
57 bool m_isNewlyCreatedIdentity = false;
58 bool m_isNewlyCreatedKey = false;
59};
60
61class Requester : noncopyable
62{
63public:
64 // INFO related helpers
65 static shared_ptr<Interest>
66 genCaProfileInterest(const Name& caName);
67
68 /**
69 * Will first verify the signature of the packet using the key provided inside the profile.
70 * The application should be cautious whether to add CaProfile into the RequesterCaCache.
71 */
72 static boost::optional<CaProfile>
73 onCaProfileResponse(const Data& reply);
74
75 // PROBE related helpers
76 static shared_ptr<Interest>
77 genProbeInterest(const CaProfile& ca, std::vector<std::tuple<std::string, std::string>>&& probeInfo);
78
79 static void
80 onProbeResponse(const Data& reply, const CaProfile& ca,
81 std::vector<Name>& identityNames, std::vector<Name>& otherCas);
82
83 // NEW/REVOKE/RENEW related helpers
84 static shared_ptr<Interest>
85 genNewInterest(RequesterState& state, const Name& identityName,
86 const time::system_clock::TimePoint& notBefore,
87 const time::system_clock::TimePoint& notAfter);
88
89 static shared_ptr<Interest>
90 genRevokeInterest(RequesterState& state, const security::v2::Certificate& certificate);
91
92 static std::list<std::string>
93 onNewRenewRevokeResponse(RequesterState& state, const Data& reply);
94
95 // CHALLENGE helpers
96 static std::vector<std::tuple<std::string, std::string>>
97 selectOrContinueChallenge(RequesterState& state, const std::string& challengeSelected);
98
99 static shared_ptr<Interest>
100 genChallengeInterest(const RequesterState& state,
101 std::vector<std::tuple<std::string, std::string>>&& parameters);
102
103 static void
104 onChallengeResponse(RequesterState& state, const Data& reply);
105
106 static shared_ptr<Interest>
107 genCertFetchInterest(const RequesterState& state);
108
tylerliufeabfdc2020-10-03 15:09:58 -0700109 static shared_ptr<security::v2::Certificate>
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700110 onCertFetchResponse(const Data& reply);
111
tylerliufeabfdc2020-10-03 15:09:58 -0700112 static void
Zhiyi Zhang1d3dcd22020-10-01 22:25:43 -0700113 endSession(RequesterState& state);
114
115private:
116 static void
117 processIfError(const Data& data);
118};
119
120} // namespace ndncert
121} // namespace ndn
122
123#endif // NDNCERT_CLIENT_MODULE_HPP