blob: 719c3f34c9ecd384ae1753162f485435997bcd9d [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/*
Davide Pesavento0d1d11c2022-04-11 22:11:34 -04003 * Copyright (c) 2017-2022, 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
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040031namespace ndncert::ca {
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080032
tylerliu1f480be2020-11-10 13:02:53 -080033/**
34 * @brief The function would be invoked whenever the certificate request status is updated.
35 * The callback is used to notice the CA application or CA command line tool. The callback is
36 * fired whenever a request instance is created, challenge status is updated, and when certificate
37 * is issued.
38 *
39 * @param RequestState The state of the certificate request whose status is updated.
40 */
Davide Pesavento0dc02012021-11-23 22:55:03 -050041using StatusUpdateCallback = std::function<void(const RequestState&)>;
tylerliu1f480be2020-11-10 13:02:53 -080042
Davide Pesavento0dc02012021-11-23 22:55:03 -050043class CaModule : boost::noncopyable
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080044{
45public:
Davide Pesavento0dc02012021-11-23 22:55:03 -050046 CaModule(ndn::Face& face, ndn::KeyChain& keyChain, const std::string& configPath,
Zhiyi Zhang91c846b2017-04-12 14:16:31 -070047 const std::string& storageType = "ca-storage-sqlite3");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080048
49 ~CaModule();
50
51 CaConfig&
52 getCaConf()
53 {
54 return m_config;
55 }
56
Davide Pesavento0dc02012021-11-23 22:55:03 -050057 const std::unique_ptr<CaStorage>&
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040058 getCaStorage() const
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080059 {
60 return m_storage;
61 }
62
Zhiyi Zhangf6c5d272020-09-28 10:17:32 -070063 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070064 setStatusUpdateCallback(const StatusUpdateCallback& onUpdateCallback);
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080065
Zhiyi Zhang696cd042020-10-07 21:27:36 -070066 Data
67 getCaProfileData();
Zhiyi Zhangfc1678a2020-05-12 16:52:14 -070068
tylerliudd359912020-10-20 13:05:22 -070069NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Zhiyi Zhang696cd042020-10-07 21:27:36 -070070 void
71 onCaProfileDiscovery(const Interest& request);
swa77020643ac2020-03-26 02:24:45 -070072
73 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070074 onProbe(const Interest& request);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080075
76 void
Zhiyi Zhang01e91a32020-09-29 12:10:00 -070077 onNewRenewRevoke(const Interest& request, RequestType requestType);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080078
79 void
tylerliu4a00aad2020-09-26 02:03:17 -070080 onChallenge(const Interest& request);
tylerliu182bc532020-09-25 01:54:45 -070081
82 void
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080083 onRegisterFailed(const std::string& reason);
84
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070085 std::unique_ptr<RequestState>
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070086 getCertificateRequest(const Interest& request);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080087
Davide Pesavento0dc02012021-11-23 22:55:03 -050088 Certificate
Zhiyi Zhang32d4b4e2020-10-28 22:10:49 -070089 issueCertificate(const RequestState& requestState);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080090
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080091 void
92 registerPrefix();
93
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070094 Data
95 generateErrorDataPacket(const Name& name, ErrorCode error, const std::string& errorInfo);
96
tylerliudd359912020-10-20 13:05:22 -070097NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento0dc02012021-11-23 22:55:03 -050098 ndn::Face& m_face;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080099 CaConfig m_config;
Davide Pesavento0dc02012021-11-23 22:55:03 -0500100 std::unique_ptr<CaStorage> m_storage;
101 ndn::KeyChain& m_keyChain;
Zhiyi Zhanga2c39f72020-10-06 16:45:55 -0700102 uint8_t m_requestIdGenKey[32];
Zhiyi Zhang696cd042020-10-07 21:27:36 -0700103 std::unique_ptr<Data> m_profileData;
tylerliu1f480be2020-11-10 13:02:53 -0800104 /**
105 * StatusUpdate Callback function
106 */
107 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800108
Davide Pesavento0dc02012021-11-23 22:55:03 -0500109 std::list<ndn::RegisteredPrefixHandle> m_registeredPrefixHandles;
110 std::list<ndn::InterestFilterHandle> m_interestFilterHandles;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800111};
112
Davide Pesavento0d1d11c2022-04-11 22:11:34 -0400113} // namespace ndncert::ca
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800114
115#endif // NDNCERT_CA_MODULE_HPP