Botan 3.14.1
Crypto and TLS for C&
ffi_tls_impl.h
Go to the documentation of this file.
1/*
2* (C) 2026 Moritz Schmitt
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_FFI_TLS_IMPL_H_
8#define BOTAN_FFI_TLS_IMPL_H_
9
10#include <botan/ffi_tls.h>
11
12#include <botan/certstor.h>
13#include <botan/credentials_manager.h>
14#include <botan/pk_keys.h>
15#include <botan/tls_policy.h>
16#include <botan/tls_session_manager.h>
17#include <botan/x509cert.h>
18#include <botan/internal/ffi_util.h>
19#include <memory>
20#include <string>
21#include <vector>
22
23namespace Botan_FFI {
24
25/**
26* The Credentials_Manager behind botan_tls_credentials_t.
27*
28* Trust anchors and CRLs live in an in-memory certificate store; further
29* stores (a directory, the system store) are kept as separate objects. The
30* certificate chains are used for server and for client authentication
31* alike. The setters copy certificates and CRLs and share the private keys.
32* The object is not synchronized, but
33* otherwise it may be modified at any time and shared between channels.
34*/
36 public:
38
39 void add_crl(const Botan::X509_CRL& crl);
40
41 void add_store(std::shared_ptr<Botan::Certificate_Store> store);
42
43 /// @p chain is leaf first and not empty; @p key belongs to the leaf
44 void add_cert_chain(std::vector<Botan::X509_Certificate> chain, std::shared_ptr<Botan::Private_Key> key);
45
46 std::vector<Botan::Certificate_Store*> trusted_certificate_authorities(const std::string& type,
47 const std::string& context) override;
48
49 std::vector<Botan::X509_Certificate> find_cert_chain(
50 const std::vector<std::string>& cert_key_types,
51 const std::vector<Botan::AlgorithmIdentifier>& cert_signature_schemes,
52 const std::vector<Botan::X509_DN>& acceptable_CAs,
53 const std::string& type,
54 const std::string& context) override;
55
57
58 std::shared_ptr<Botan::Private_Key> private_key_for(const Botan::X509_Certificate& cert,
59 const std::string& type,
60 const std::string& context) override;
61
62 private:
63 struct Chain {
64 std::vector<Botan::X509_Certificate> certs;
65 std::shared_ptr<Botan::Private_Key> key;
66 };
67
69 std::vector<std::shared_ptr<Botan::Certificate_Store>> m_extra_stores;
70 std::vector<Chain> m_chains;
71};
72
73} // namespace Botan_FFI
74
75extern "C" {
76
77// TLS::Client and TLS::Server take their collaborators as std::shared_ptr,
78// so the handles hold one.
79BOTAN_FFI_DECLARE_SHARED_STRUCT(botan_tls_policy_struct, const Botan::TLS::Policy, 0x19781017);
80BOTAN_FFI_DECLARE_SHARED_STRUCT(botan_tls_credentials_struct, Botan_FFI::FFI_TLS_Credentials, 0x5C3A9E41);
81BOTAN_FFI_DECLARE_SHARED_STRUCT(botan_tls_session_manager_struct, Botan::TLS::Session_Manager, 0xB7D2E60C);
82
83} // extern "C"
84
85#endif
#define BOTAN_TEST_API
Definition api.h:41
virtual std::shared_ptr< Private_Key > private_key_for(const X509_Certificate &cert, const std::string &type, const std::string &context)
std::shared_ptr< Botan::Private_Key > private_key_for(const Botan::X509_Certificate &cert, const std::string &type, const std::string &context) override
Definition ffi_tls.cpp:123
std::vector< Botan::Certificate_Store * > trusted_certificate_authorities(const std::string &type, const std::string &context) override
Definition ffi_tls.cpp:58
void add_crl(const Botan::X509_CRL &crl)
Definition ffi_tls.cpp:40
std::vector< Botan::X509_Certificate > find_cert_chain(const std::vector< std::string > &cert_key_types, const std::vector< Botan::AlgorithmIdentifier > &cert_signature_schemes, const std::vector< Botan::X509_DN > &acceptable_CAs, const std::string &type, const std::string &context) override
Definition ffi_tls.cpp:68
void add_store(std::shared_ptr< Botan::Certificate_Store > store)
Definition ffi_tls.cpp:44
void add_cert_chain(std::vector< Botan::X509_Certificate > chain, std::shared_ptr< Botan::Private_Key > key)
chain is leaf first and not empty; key belongs to the leaf
Definition ffi_tls.cpp:48
void add_trusted_cert(const Botan::X509_Certificate &cert)
Definition ffi_tls.cpp:36
botan_x509_crl_t crl
Definition ffi_tls.h:127
#define BOTAN_FFI_DECLARE_SHARED_STRUCT(NAME, TYPE, MAGIC)
Definition ffi_util.h:169