CCF
Loading...
Searching...
No Matches
acme_subsystem.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
6#include "ccf/http_status.h"
8#include "ccf/rest_verb.h"
10#include "http/http_parser.h"
12
13#include <optional>
14
15namespace ccf
16{
18 {
19 protected:
21
22 public:
23 ACMESubsystem(AbstractNodeState& node_state_) : node_state(node_state_) {}
24
26 const ccf::NodeInfoNetwork::RpcInterfaceID& interface_id,
27 std::shared_ptr<ACMEChallengeHandler> h) override
28 {
30 };
31
32 virtual std::optional<const ccf::ACMEClientConfig*> config(
33 const NodeInfoNetwork::RpcInterfaceID& id) override
34 {
35 const auto& acme_cfgs =
36 node_state.get_node_config().network.acme->configurations;
37 const auto& cfgit = acme_cfgs.find(id);
38 if (cfgit == acme_cfgs.end())
39 {
40 return std::nullopt;
41 }
42 else
43 {
44 return &cfgit->second;
45 }
46 }
47
48 virtual ccf::crypto::Pem network_cert() override
49 {
51 }
52
53 // make_http_request is just a convenient way to offer https requests to
54 // custom challenge handlers. This will be removed in the future, when there
55 // are other, equally convenient ways.
56 virtual void make_http_request(
57 const std::string& method,
58 const std::string& url,
59 const http::HeaderMap& headers,
60 const std::vector<uint8_t>& body,
61 std::function<bool(
62 const http_status&,
64 const std::vector<uint8_t>&)> callback,
65 const std::vector<std::string>& ca_certs = {},
66 const std::string& app_protocol = "HTTP1",
67 bool authenticate_as_node_client_certificate = false) override
68 {
69 llhttp_method_t m = http_method_from_str(method.c_str());
71 ::http::Request r(urlobj.path, m);
72 if (!body.empty())
73 {
74 r.set_body(&body);
75 }
76 for (const auto& [k, v] : headers)
77 {
78 r.set_header(k, v);
79 }
81 urlobj,
82 std::move(r),
83 callback,
84 ca_certs,
85 app_protocol,
86 authenticate_as_node_client_certificate);
87 }
88 };
89}
Definition acme_subsystem_interface.h:19
Definition acme_subsystem.h:18
virtual void make_http_request(const std::string &method, const std::string &url, const http::HeaderMap &headers, const std::vector< uint8_t > &body, std::function< bool(const http_status &, const ccf::http::HeaderMap &, const std::vector< uint8_t > &)> callback, const std::vector< std::string > &ca_certs={}, const std::string &app_protocol="HTTP1", bool authenticate_as_node_client_certificate=false) override
Definition acme_subsystem.h:56
ACMESubsystem(AbstractNodeState &node_state_)
Definition acme_subsystem.h:23
virtual ccf::crypto::Pem network_cert() override
Definition acme_subsystem.h:48
AbstractNodeState & node_state
Definition acme_subsystem.h:20
virtual std::optional< const ccf::ACMEClientConfig * > config(const NodeInfoNetwork::RpcInterfaceID &id) override
Definition acme_subsystem.h:32
virtual void install_challenge_handler(const ccf::NodeInfoNetwork::RpcInterfaceID &interface_id, std::shared_ptr< ACMEChallengeHandler > h) override
Definition acme_subsystem.h:25
Definition node_interface.h:23
virtual void install_custom_acme_challenge_handler(const NodeInfoNetwork::RpcInterfaceID &interface_id, std::shared_ptr< ACMEChallengeHandler > h)=0
virtual ccf::crypto::Pem get_network_cert()=0
virtual const ccf::StartupConfig & get_node_config() const =0
virtual void make_http_request(const ::http::URL &url, ::http::Request &&req, std::function< bool(ccf::http_status status, ccf::http::HeaderMap &&, std::vector< uint8_t > &&)> callback, const std::vector< std::string > &ca_certs={}, const std::string &app_protocol="HTTP1", bool use_node_client_certificate=false)=0
Definition pem.h:18
Definition http_builder.h:118
std::map< std::string, std::string, std::less<> > HeaderMap
Definition http_header_map.h:10
Definition app_interface.h:14
llhttp_status http_status
Definition http_status.h:9
URL parse_url_full(const std::string &url)
Definition http_parser.h:145
ccf::NodeInfoNetwork network
Definition startup_config.h:31
std::optional< ACME > acme
ACME configuration.
Definition node_info_network.h:162
std::string RpcInterfaceID
Definition node_info_network.h:87
Definition http_parser.h:136
std::string path
Definition http_parser.h:140