blob: 88af9f16cdf1dfdcaf7051d729735a71c0c0eb3d [file] [log] [blame]
Zhiyi Zhangf5246c42017-01-26 09:39:20 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento0dc02012021-11-23 22:55:03 -05002/*
3 * Copyright (c) 2017-2021, 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
Zhiyi Zhang3f20f952020-11-19 19:26:43 -080024#include "detail/ca-configuration.hpp"
Zhiyi Zhangdc25ddf2020-10-20 14:28:55 -070025#include "detail/crypto-helpers.hpp"
Zhiyi Zhang062be6d2020-10-14 17:13:43 -070026#include "detail/ca-storage.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080027
Davide Pesavento0dc02012021-11-23 22:55:03 -050028#include <ndn-cxx/face.hpp>
29#include <ndn-cxx/security/key-chain.hpp>
30
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080031namespace ndncert {
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070032namespace ca {
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080033
tylerliu1f480be2020-11-10 13:02:53 -080034/**
35 * @brief The function would be invoked whenever the certificate request status is updated.
36 * The callback is used to notice the CA application or CA command line tool. The callback is
37 * fired whenever a request instance is created, challenge status is updated, and when certificate
38 * is issued.
39 *
40 * @param RequestState The state of the certificate request whose status is updated.
41 */
Davide Pesavento0dc02012021-11-23 22:55:03 -050042using StatusUpdateCallback = std::function<void(const RequestState&)>;
tylerliu1f480be2020-11-10 13:02:53 -080043
Davide Pesavento0dc02012021-11-23 22:55:03 -050044class CaModule : boost::noncopyable
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080045{
46public:
Davide Pesavento0dc02012021-11-23 22:55:03 -050047 CaModule(ndn::Face& face, ndn::KeyChain& keyChain, const std::string& configPath,
Zhiyi Zhang91c846b2017-04-12 14:16:31 -070048 const std::string& storageType = "ca-storage-sqlite3");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080049
50 ~CaModule();
51
52 CaConfig&
53 getCaConf()
54 {
55 return m_config;
56 }
57
Davide Pesavento0dc02012021-11-23 22:55:03 -050058 const std::unique_ptr<CaStorage>&
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080059 getCaStorage()
60 {
61 return m_storage;
62 }
63
Zhiyi Zhangf6c5d272020-09-28 10:17:32 -070064 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070065 setStatusUpdateCallback(const StatusUpdateCallback& onUpdateCallback);
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080066
Zhiyi Zhang696cd042020-10-07 21:27:36 -070067 Data
68 getCaProfileData();
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070069
tylerliudd359912020-10-20 13:05:22 -070070NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhang696cd042020-10-07 21:27:36 -070071 void
72 onCaProfileDiscovery(const Interest& request);
swa77020643ac2020-03-26 02:24:45 -070073
74 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070075 onProbe(const Interest& request);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080076
77 void
Zhiyi Zhang01e91a32020-09-29 12:10:00 -070078 onNewRenewRevoke(const Interest& request, RequestType requestType);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080079
80 void
tylerliu4a00aad2020-09-26 02:03:17 -070081 onChallenge(const Interest& request);
tylerliu182bc532020-09-25 01:54:45 -070082
83 void
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080084 onRegisterFailed(const std::string& reason);
85
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070086 std::unique_ptr<RequestState>
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070087 getCertificateRequest(const Interest& request);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080088
Davide Pesavento0dc02012021-11-23 22:55:03 -050089 Certificate
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070090 issueCertificate(const RequestState& requestState);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080091
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080092 void
93 registerPrefix();
94
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070095 Data
96 generateErrorDataPacket(const Name& name, ErrorCode error, const std::string& errorInfo);
97
tylerliudd359912020-10-20 13:05:22 -070098NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento0dc02012021-11-23 22:55:03 -050099 ndn::Face& m_face;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800100 CaConfig m_config;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500101 std::unique_ptr<CaStorage> m_storage;
102 ndn::KeyChain& m_keyChain;
Zhiyi Zhanga2c39f72020-10-06 16:45:55 -0700103 uint8_t m_requestIdGenKey[32];
Zhiyi Zhang696cd042020-10-07 21:27:36 -0700104 std::unique_ptr<Data> m_profileData;
tylerliu1f480be2020-11-10 13:02:53 -0800105 /**
106 * StatusUpdate Callback function
107 */
108 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800109
Davide Pesavento0dc02012021-11-23 22:55:03 -0500110 std::list<ndn::RegisteredPrefixHandle> m_registeredPrefixHandles;
111 std::list<ndn::InterestFilterHandle> m_interestFilterHandles;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800112};
113
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -0700114} // namespace ca
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800115} // namespace ndncert
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800116
117#endif // NDNCERT_CA_MODULE_HPP