OGLplus  (0.59.0) a C++ wrapper for rendering APIs

context.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MESSAGE_BUS_CONTEXT_HPP
10 #define EAGINE_MESSAGE_BUS_CONTEXT_HPP
11 
12 #include "../flat_map.hpp"
13 #include "../main_ctx_object.hpp"
14 #include "../memory/buffer.hpp"
15 #include "../message_id.hpp"
16 #include "../ssl.hpp"
17 #include "../ssl_api.hpp"
18 #include "context_fwd.hpp"
19 #include "types.hpp"
20 #include "verification.hpp"
21 #include <array>
22 #include <map>
23 #include <random>
24 
25 namespace eagine::msgbus {
26 //------------------------------------------------------------------------------
27 struct context_remote_node {
28  std::array<byte, 256> nonce{};
29  memory::buffer cert_pem;
30  sslp::owned_x509 cert{};
31  sslp::owned_pkey pubkey{};
32  bool verified_key{false};
33 };
34 //------------------------------------------------------------------------------
38 public:
39  context(main_ctx_parent parent);
40 
42  context(context&&) = delete;
43 
45  context(const context&) = delete;
46 
48  auto operator=(context&&) = delete;
49 
51  auto operator=(const context&) = delete;
52 
53  ~context() noexcept;
54 
56  auto ssl() noexcept -> sslp::ssl_api& {
57  return _ssl;
58  }
59 
62 
64  auto verify_certificate(sslp::x509 cert) -> bool;
65 
72 
79 
86  -> bool;
87 
94  return add_remote_certificate_pem(0, blk);
95  }
96 
102  auto get_own_certificate_pem() const noexcept -> memory::const_block {
103  return view(_own_cert_pem);
104  }
105 
111  auto get_ca_certificate_pem() const noexcept -> memory::const_block {
112  return view(_ca_cert_pem);
113  }
114 
120  auto get_remote_certificate_pem(identifier_t) const noexcept
122 
128  auto get_router_certificate_pem() const noexcept -> memory::const_block {
129  return get_remote_certificate_pem(0);
130  }
131 
132  auto get_remote_nonce(identifier_t) const noexcept -> memory::const_block;
133 
135  auto verified_remote_key(identifier_t) const noexcept -> bool;
136 
138  auto default_message_digest() noexcept
139  -> decltype(ssl().message_digest_sha256());
140 
141  auto message_digest_sign_init(
142  sslp::message_digest mdc,
143  sslp::message_digest_type mdt) noexcept
144  -> decltype(ssl().message_digest_sign_init.fake());
145 
146  auto message_digest_verify_init(
147  sslp::message_digest mdc,
148  sslp::message_digest_type mdt,
149  identifier_t node_id) noexcept
150  -> decltype(ssl().message_digest_verify_init.fake());
151 
153  auto get_own_signature(memory::const_block) -> memory::const_block;
154 
155  auto verify_remote_signature(
156  memory::const_block data,
157  memory::const_block sig,
158  identifier_t,
159  bool = false) -> verification_bits;
160 
162  auto verify_remote_signature(memory::const_block sig, identifier_t) -> bool;
163 
164 private:
165  //
166  std::mt19937_64 _rand_engine{std::random_device{}()};
167  flat_map<message_id, message_sequence_t> _msg_id_seq{};
168  //
169  memory::buffer _scratch_space{};
170  memory::buffer _own_cert_pem{};
171  memory::buffer _ca_cert_pem{};
172  //
173  sslp::ssl_api _ssl{};
174  sslp::owned_engine _ssl_engine{};
175  sslp::owned_x509_store _ssl_store{};
176  sslp::owned_x509 _own_cert{};
177  sslp::owned_x509 _ca_cert{};
178  sslp::owned_pkey _own_pkey{};
179  //
180  std::map<identifier_t, context_remote_node> _remotes{};
181 };
182 //------------------------------------------------------------------------------
183 } // namespace eagine::msgbus
184 
185 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
186 #include <eagine/message_bus/context.inl>
187 #endif
188 
189 #endif // EAGINE_MESSAGE_BUS_CONTEXT_HPP
Helper class used to initialize main context objects.
Definition: main_ctx_object.hpp:45
Base class for main context objects.
Definition: main_ctx_object.hpp:71
auto add_ca_certificate_pem(memory::const_block) -> bool
Sets a CA certificate encoded in PEM format.
auto next_sequence_no(message_id) noexcept -> message_sequence_t
Returns the next sequence number value for the specified message type.
basic_block< true > const_block
Alias for const byte memory span.
Definition: block.hpp:32
Class for manipulating and testing a group of enumeration-based bits.
Definition: bitfield.hpp:19
auto get_router_certificate_pem() const noexcept -> memory::const_block
Gets the router certificate encoded in PEM format.
Definition: context.hpp:128
static constexpr auto view(T *addr, S size) noexcept -> const_span< T >
Creates a view starting at the specified pointer and specified length.
Definition: span.hpp:458
Class holding common message bus utility objects.
Definition: context.hpp:37
Non-owning wrapper for C-API opaque handle types.
Definition: handle.hpp:26
auto default_message_digest() noexcept -> decltype(ssl().message_digest_sha256())
Returns the default message digest type.
std::uint32_t message_sequence_t
Alias for message sequence number type.
Definition: types.hpp:22
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
auto operator=(context &&)=delete
Not move assignable.
auto verify_certificate(sslp::x509 cert) -> bool
Verifies the specified x509 certificate.
auto add_remote_certificate_pem(identifier_t node_id, memory::const_block) -> bool
Sets remote bus node certificate encoded in PEM format.
Message bus code is placed in this namespace.
Definition: eagine.hpp:58
auto add_own_certificate_pem(memory::const_block) -> bool
Sets this bus node certificate encoded in PEM format.
auto get_remote_certificate_pem(identifier_t) const noexcept -> memory::const_block
Gets remote bus node certificate encoded in PEM format.
auto ssl() noexcept -> sslp::ssl_api &
Returns a reference to the SSL API wrapper.
Definition: context.hpp:56
auto get_own_certificate_pem() const noexcept -> memory::const_block
Gets this bus node certificate encoded in PEM format.
Definition: context.hpp:102
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
Class storing two identifier values representing class/method pair.
Definition: message_id.hpp:25
auto get_ca_certificate_pem() const noexcept -> memory::const_block
Gets the CA certificate encoded in PEM format.
Definition: context.hpp:111
auto verified_remote_key(identifier_t) const noexcept -> bool
Indicates if the private key of a remote node was verified.
auto add_router_certificate_pem(memory::const_block blk) -> bool
Sets the router certificate encoded in PEM format.
Definition: context.hpp:93
auto get_own_signature(memory::const_block) -> memory::const_block
Signs the specified memory block and returns the signature.

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).