blob: 7e9c7e6c453a0e3d154ba3f159a383c3e84a3978 [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
swa77020643ac2020-03-26 02:24:45 -07003 * Copyright (c) 2017-2020, 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"
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070025#include "crypto-support/crypto-helper.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080026#include "ca-storage.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080027
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 Zhangaf7c2902019-03-14 22:13:21 -070062 setProbeHandler(const ProbeHandler& handler);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080063
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080064 bool
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070065 setStatusUpdateCallback(const StatusUpdateCallback& onUpdateCallback);
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080066
Zhiyi Zhang5f749a22019-06-12 17:02:33 -070067 static JsonSection
68 jsonFromBlock(const Block& block);
69
70 static Block
71 dataContentFromJson(const JsonSection& jsonSection);
72
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080073PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070074 shared_ptr<Data>
75 generateCaConfigMetaData();
76
77 shared_ptr<Data>
78 generateCaConfigData();
79
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080080 void
swa77020643ac2020-03-26 02:24:45 -070081 onInfo(const Interest& request);
82
83 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070084 onProbe(const Interest& request);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080085
86 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070087 onNew(const Interest& request);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080088
89 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070090 onChallenge(const Interest& request);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080091
92 void
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080093 onRegisterFailed(const std::string& reason);
94
95 CertificateRequest
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070096 getCertificateRequest(const Interest& request);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080097
Zhiyi Zhang343cdfb2018-01-17 12:04:28 -080098 security::v2::Certificate
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070099 issueCertificate(const CertificateRequest& certRequest);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800100
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +0800101 void
102 registerPrefix();
103
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700104PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800105 Face& m_face;
106 CaConfig m_config;
107 unique_ptr<CaStorage> m_storage;
108 security::v2::KeyChain& m_keyChain;
109
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -0700110 std::list<RegisteredPrefixHandle> m_registeredPrefixHandles;
111 std::list<InterestFilterHandle> m_interestFilterHandles;
112
113 ECDHState m_ecdh;
Zhiyi Zhang8da54d62019-11-21 00:03:05 -0800114 uint8_t m_aesKey[16] = {0};
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800115};
116
117} // namespace ndncert
118} // namespace ndn
119
120#endif // NDNCERT_CA_MODULE_HPP