blob: 23386a26d4487392b8f1d56157123797f5bf8d96 [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -08003 * Copyright (c) 2017-2018, Regents of the University of California.
Zhiyi Zhangf5246c42017-01-26 09:39:20 -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_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
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080043public:
44 CaModule(Face& face, security::v2::KeyChain& keyChain, const std::string& configPath,
Zhiyi Zhang91c846b2017-04-12 14:16:31 -070045 const std::string& storageType = "ca-storage-sqlite3");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080046
47 ~CaModule();
48
49 CaConfig&
50 getCaConf()
51 {
52 return m_config;
53 }
54
55 const unique_ptr<CaStorage>&
56 getCaStorage()
57 {
58 return m_storage;
59 }
60
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080061 bool
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080062 setProbeHandler(const Name caName, const ProbeHandler& handler);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080063
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080064 bool
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080065 setRecommendCaHandler(const Name caName, const RecommendCaHandler& handler);
66
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080067 bool
68 setStatusUpdateCallback(const Name caName, const StatusUpdateCallback& onUpateCallback);
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080069
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080070PUBLIC_WITH_TESTS_ELSE_PRIVATE:
71 void
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080072 handleLocalhostList(const Interest& query);
73
74 void
75 handleList(const Interest& request, const CaItem& caItem);
76
77 void
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080078 handleProbe(const Interest& request, const CaItem& caItem);
79
80 void
81 handleNew(const Interest& request, const CaItem& caItem);
82
83 void
84 handleSelect(const Interest& request, const CaItem& caItem);
85
86 void
87 handleValidate(const Interest& request, const CaItem& caItem);
88
89 void
90 handleStatus(const Interest& request, const CaItem& caItem);
91
92 void
93 handleDownload(const Interest& request, const CaItem& caItem);
94
95 void
96 onRegisterFailed(const std::string& reason);
97
98 CertificateRequest
99 getCertificateRequest(const Interest& request, const Name& caName);
100
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -0800101 security::v2::Certificate
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800102 issueCertificate(const CertificateRequest& certRequest, const CaItem& caItem);
103
104 static JsonSection
105 jsonFromNameComponent(const Name& name, int pos);
106
107 static Block
108 dataContentFromJson(const JsonSection& jsonSection);
109
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800110 void
111 registerPrefix();
112
Zhiyi Zhanga63b7372017-05-17 14:14:34 -0700113PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800114 Face& m_face;
115 CaConfig m_config;
116 unique_ptr<CaStorage> m_storage;
117 security::v2::KeyChain& m_keyChain;
118
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800119 std::list<const RegisteredPrefixId*> m_registeredPrefixIds;
120 std::list<const InterestFilterId*> m_interestFilterIds;
121};
122
123} // namespace ndncert
124} // namespace ndn
125
126#endif // NDNCERT_CA_MODULE_HPP