blob: 0e768dafc65655adc7d063f8fbb31211892923ed [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2017, 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_CA_MODULE_HPP
22#define NDNCERT_CA_MODULE_HPP
23
24#include "ca-config.hpp"
25#include "ca-storage.hpp"
26#include "json-helper.hpp"
27
28namespace ndn {
29namespace ndncert {
30
31class CaModule : noncopyable
32{
33public:
34 /**
35 * @brief Error that can be thrown from CaModule
36 */
37 class Error : public std::runtime_error
38 {
39 public:
40 using std::runtime_error::runtime_error;
41 };
42
43 /**
44 * @brief The function should be able to convert a probe info string to an identity name
45 *
46 * The function should throw exceptions when there is an unexpected probe info.
47 */
48 using ProbeHandler = function<std::string (const std::string&)>;
49
Zhiyi Zhanga63b7372017-05-17 14:14:34 -070050 /**
51 * @brief The function would be invoked whenever the certificate request gets update
52 */
53 using RequestUpdateCallback = function<void (const CertificateRequest&)>;
54
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080055public:
56 CaModule(Face& face, security::v2::KeyChain& keyChain, const std::string& configPath,
Zhiyi Zhang91c846b2017-04-12 14:16:31 -070057 const std::string& storageType = "ca-storage-sqlite3");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080058
59 ~CaModule();
60
61 CaConfig&
62 getCaConf()
63 {
64 return m_config;
65 }
66
67 const unique_ptr<CaStorage>&
68 getCaStorage()
69 {
70 return m_storage;
71 }
72
73 void
74 setProbeHandler(const ProbeHandler& handler)
75 {
76 m_probeHandler = handler;
77 }
78
Zhiyi Zhanga63b7372017-05-17 14:14:34 -070079 void
80 setRequestUpdateCallback(const RequestUpdateCallback& onUpateCallback)
81 {
82 m_requestUpdateCallback = onUpateCallback;
83 }
84
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080085PUBLIC_WITH_TESTS_ELSE_PRIVATE:
86 void
87 handleProbe(const Interest& request, const CaItem& caItem);
88
89 void
90 handleNew(const Interest& request, const CaItem& caItem);
91
92 void
93 handleSelect(const Interest& request, const CaItem& caItem);
94
95 void
96 handleValidate(const Interest& request, const CaItem& caItem);
97
98 void
99 handleStatus(const Interest& request, const CaItem& caItem);
100
101 void
102 handleDownload(const Interest& request, const CaItem& caItem);
103
104 void
105 onRegisterFailed(const std::string& reason);
106
107 CertificateRequest
108 getCertificateRequest(const Interest& request, const Name& caName);
109
110 void
111 issueCertificate(const CertificateRequest& certRequest, const CaItem& caItem);
112
113 static JsonSection
114 jsonFromNameComponent(const Name& name, int pos);
115
116 static Block
117 dataContentFromJson(const JsonSection& jsonSection);
118
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700119PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800120 Face& m_face;
121 CaConfig m_config;
122 unique_ptr<CaStorage> m_storage;
123 security::v2::KeyChain& m_keyChain;
124
125 ProbeHandler m_probeHandler;
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700126 RequestUpdateCallback m_requestUpdateCallback;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800127 std::list<const RegisteredPrefixId*> m_registeredPrefixIds;
128 std::list<const InterestFilterId*> m_interestFilterIds;
129};
130
131} // namespace ndncert
132} // namespace ndn
133
134#endif // NDNCERT_CA_MODULE_HPP