Botan 3.6.1
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_manager_memory.h>
15#endif
16
17namespace Botan::TLS {
18
19#if defined(BOTAN_HAS_HAS_DEFAULT_TLS_CONTEXT)
20
21namespace {
22
23/**
24 * A Credentials_Manager that provides the system's certificate store as trust
25 * store, if available. Otherwise it defaults to "no trusted certificates".
26 */
27class Default_Credentials_Manager : public Credentials_Manager {
28 public:
29 Default_Credentials_Manager() {
30 try {
31 m_cert_store = std::make_unique<System_Certificate_Store>();
32 } catch(const Not_Implemented&) {
33 // This platform does not provide an adapter for the system's trust store.
34 }
35 }
36
37 std::vector<Certificate_Store*> trusted_certificate_authorities(const std::string&, const std::string&) override {
38 if(m_cert_store) {
39 return {m_cert_store.get()};
40 } else {
41 return {};
42 }
43 }
44
45 private:
46 std::unique_ptr<Certificate_Store> m_cert_store;
47};
48
49} // namespace
50
51Context::Context(Server_Information server_info) :
52 m_credentials_manager(std::make_shared<Default_Credentials_Manager>()),
53 m_rng(std::make_shared<AutoSeeded_RNG>()),
54 m_session_manager(std::make_shared<Session_Manager_In_Memory>(m_rng)),
55 m_policy(std::make_shared<Default_Policy>()),
56 m_server_info(std::move(server_info)) {}
57
58#endif
59
60} // namespace Botan::TLS