PrevUpHomeNext

Botan c++ tls connection


Botan c++ tls connection - Posted on Oct 19, 2024 - See https://botan.randombit.net - Logs Home - d0035

c++ tls/ssl/https, botan, boost asio beast

Botan c++ tls connection

Botan c++ tls/ssl connection (https) with boost asio/beast.

tls stream - use Botan::TLS::Stream

Async Connect

Async Connect:

tls_stream.next_layer().async_connect(resolve_results, handler);

Handler:

[] (std::error_code ec, boost::asio::tcp::endpoint ep)
{
};

Async handshake

Async Handshake:

tls_stream.async_handshake(Botan::TLS::Connection_Side::Client, handler);

Handler:

[] (std::error_code ec)
{
};

tls stream - create Botan::TLS::Stream Object

Construct Botan::TLS::Stream object:

Botan::TLS::Stream tls_stream{tls_context, asio_context};

asio_context is an object of asio::io_context

tls_context is a c++ smart pointer std::shared_pointer of type Botan::TLS::Context

tls context - create Botan::TLS::Context object

tls_context

std::shared_ptr<Botan::TLS::Context> tls_context = std::make_shared<Botan::TLS::Context>(
	cred_man,
	rng,
	sess_man,
	policy,
	server_info
);

cred_man - Botan Credentials Manager - std::shared_ptr smart pointer.

rng - Botan RNG, Random Number Generator - std::shared_ptr smart pointer.

sess_man - Botan TLS Session Manager - std::shared_ptr smart pointer.

policy - Botan TLS Policy - std::shared_ptr smart pointer.

server_info - Botan TLS Server Information.

rng

std::shared_ptr<Botan::RandomNumberGenerator> rng
	= std::make_shared<Botan::AutoSeeded_RNG>();

cred_man

std::shared_ptr<Botan::Credentials_Manager> cred_man
	= std::make_shared<my_credentials_manager>();

my_credentials_manager - You must implement credentials manager to provide how to get system certificate store.

class my_credentials_manager: public Botan::Credentials_Manager
{
	...
};

sess_man

std::shared_ptr<Botan::TLS::Session_Manager> sess_man
=
std::make_shared<Botan::TLS::Session_Manager_In_Memory>(
	rng
);

policy

std::shared_ptr<Botan::TLS::Policy> policy = std::make_shared<Botan::TLS::Policy>();

server_info

Botan::TLS::Server_Information server_info{};

See Also

c++ botan tls + boost asio beast (https client)

cpp/c++

c++ std::exception:

std::cout.write(err.data(), err.size());

std::cout << std::endl;

caught:

  ===================================
  #  The c++ programming language.  #
  #                                 #
  #  Join c++ Discord: yZcauUAUyC   #
  #  Deck                           #
  ===================================

Home: cppfx.xyz

K


PrevUpHomeNext