blob: 6e85aa9bd1d088e259008135f21cf9671c4993e1 [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 Pesavento6866b902024-12-22 23:11:26 -05003 * Copyright (c) 2017-2024, 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 Zhang062be6d2020-10-14 17:13:43 -070025#include "detail/ca-storage.hpp"
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080026
Davide Pesavento0dc02012021-11-23 22:55:03 -050027#include <ndn-cxx/face.hpp>
28#include <ndn-cxx/security/key-chain.hpp>
29
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040030namespace ndncert::ca {
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080031
tylerliu1f480be2020-11-10 13:02:53 -080032/**
33 * @brief The function would be invoked whenever the certificate request status is updated.
34 * The callback is used to notice the CA application or CA command line tool. The callback is
35 * fired whenever a request instance is created, challenge status is updated, and when certificate
36 * is issued.
37 *
38 * @param RequestState The state of the certificate request whose status is updated.
39 */
Davide Pesavento0dc02012021-11-23 22:55:03 -050040using StatusUpdateCallback = std::function<void(const RequestState&)>;
tylerliu1f480be2020-11-10 13:02:53 -080041
Davide Pesavento0dc02012021-11-23 22:55:03 -050042class CaModule : boost::noncopyable
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080043{
44public:
Davide Pesavento0dc02012021-11-23 22:55:03 -050045 CaModule(ndn::Face& face, ndn::KeyChain& keyChain, const std::string& configPath,
Zhiyi Zhang91c846b2017-04-12 14:16:31 -070046 const std::string& storageType = "ca-storage-sqlite3");
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080047
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080048 CaConfig&
49 getCaConf()
50 {
51 return m_config;
52 }
53
Davide Pesavento0dc02012021-11-23 22:55:03 -050054 const std::unique_ptr<CaStorage>&
Davide Pesavento0d1d11c2022-04-11 22:11:34 -040055 getCaStorage() const
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080056 {
57 return m_storage;
58 }
59
Zhiyi Zhangf6c5d272020-09-28 10:17:32 -070060 void
Davide Pesavento6866b902024-12-22 23:11:26 -050061 setStatusUpdateCallback(StatusUpdateCallback cb)
62 {
63 m_statusUpdateCallback = std::move(cb);
64 }
Zhiyi Zhang7420cf52017-12-18 18:59:21 +080065
Davide Pesavento6866b902024-12-22 23:11:26 -050066 const Data&
Zhiyi Zhang696cd042020-10-07 21:27:36 -070067 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
Davide Pesavento6866b902024-12-22 23:11:26 -050071 registerPrefix();
72
73 void
Zhiyi Zhang696cd042020-10-07 21:27:36 -070074 onCaProfileDiscovery(const Interest& request);
swa77020643ac2020-03-26 02:24:45 -070075
76 void
Zhiyi Zhangaf7c2902019-03-14 22:13:21 -070077 onProbe(const Interest& request);
Zhiyi Zhang1c0bd372017-12-18 18:32:55 +080078
79 void
Zhiyi Zhang01e91a32020-09-29 12:10:00 -070080 onNewRenewRevoke(const Interest& request, RequestType requestType);
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080081
82 void
tylerliu4a00aad2020-09-26 02:03:17 -070083 onChallenge(const Interest& request);
tylerliu182bc532020-09-25 01:54:45 -070084
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 Zhangaafc55e2020-09-28 17:54:48 -070091 Data
Davide Pesavento6866b902024-12-22 23:11:26 -050092 makeErrorPacket(const Name& name, ErrorCode errorCode, std::string_view errorInfo);
Zhiyi Zhangaafc55e2020-09-28 17:54:48 -070093
tylerliudd359912020-10-20 13:05:22 -070094NDNCERT_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Davide Pesavento0dc02012021-11-23 22:55:03 -050095 ndn::Face& m_face;
Davide Pesavento6866b902024-12-22 23:11:26 -050096 ndn::KeyChain& m_keyChain;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -080097 CaConfig m_config;
Davide Pesavento0dc02012021-11-23 22:55:03 -050098 std::unique_ptr<CaStorage> m_storage;
Davide Pesavento6866b902024-12-22 23:11:26 -050099
Zhiyi Zhanga2c39f72020-10-06 16:45:55 -0700100 uint8_t m_requestIdGenKey[32];
Zhiyi Zhang696cd042020-10-07 21:27:36 -0700101 std::unique_ptr<Data> m_profileData;
tylerliu1f480be2020-11-10 13:02:53 -0800102 StatusUpdateCallback m_statusUpdateCallback;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800103
Davide Pesavento6866b902024-12-22 23:11:26 -0500104 std::vector<ndn::ScopedRegisteredPrefixHandle> m_registeredPrefixes;
105 std::vector<ndn::ScopedInterestFilterHandle> m_interestFilters;
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800106};
107
Davide Pesavento0d1d11c2022-04-11 22:11:34 -0400108} // namespace ndncert::ca
Zhiyi Zhangf5246c42017-01-26 09:39:20 -0800109
110#endif // NDNCERT_CA_MODULE_HPP