Botan 3.11.0
Crypto and TLS for C&
asio_context.cpp
Go to the documentation of this file.
1/*
2 * TLS Context
3 * (C) 2024 Jack Lloyd
4 * 2024 René Meusel, Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#include <botan/asio_context.h>
10
11#if defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)
12 #include <botan/auto_rng.h>
13 #include <botan/certstor_system.h>
14 #include <botan/tls_session.h>
15 #include <botan/tls_session_manager_memory.h>
16#endif
17
18namespace Botan::TLS {
19
20#if defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)
21
22namespace {
23
24/**
25 * A Credentials_Manager that provides the system's certificate store as trust
26 * store, if available. Otherwise it defaults to "no trusted certificates".
27 */
28class Default_Credentials_Manager : public Credentials_Manager {
29 public:
30 Default_Credentials_Manager() {
31 try {
32 m_cert_store = std::make_unique<System_Certificate_Store>();
33 } catch(const Not_Implemented&) {
34 // This platform does not provide an adapter for the system's trust store.
35 }
36 }
37
38 std::vector<Certificate_Store*> trusted_certificate_authorities(const std::string& /*type*/,
39 const std::string& /*context*/) override {
40 if(m_cert_store) {
41 return {m_cert_store.get()};
42 } else {
43 return {};
44 }
45 }
46
47 private:
48 std::unique_ptr<Certificate_Store> m_cert_store;
49};
50
51} // namespace
52
53Context::Context(Server_Information server_info) :
54 m_credentials_manager(std::make_shared<Default_Credentials_Manager>()),
55 m_rng(std::make_shared<AutoSeeded_RNG>()),
56 m_session_manager(std::make_shared<Session_Manager_In_Memory>(m_rng)),
57 m_policy(std::make_shared<Default_Policy>()),
58 m_server_info(std::move(server_info)) {}
59
60#endif
61
62} // namespace Botan::TLS