nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
tls.h
Go to the documentation of this file.
1#ifndef NANOMMO_PROTOCOL_TLS_H_
2#define NANOMMO_PROTOCOL_TLS_H_
3
4#include <string>
5#include <system_error>
6
7#include "absl/status/statusor.h"
8#include "asio/ip/tcp.hpp"
9#include "asio/ssl/context.hpp"
10#include "asio/ssl/stream.hpp"
11
12namespace nanommo {
13
14using TlsStream = asio::ssl::stream<asio::ip::tcp::socket>;
15
16/// TLS 1.3 for a server, with its certificate and its private key, from PEM
17/// files.
18absl::StatusOr<asio::ssl::context> ServerTls(const std::string& certificate,
19 const std::string& key);
20
21/// TLS 1.3 for a client, which trusts the certificates our authority signed,
22/// and no others.
23absl::StatusOr<asio::ssl::context> ClientTls(const std::string& authority);
24
25/// Has a client's handshake check that the server's certificate names host,
26/// a domain name or an address, in a way HandshakeError can tell apart.
27void ExpectName(TlsStream& stream, const std::string& host);
28
29/// Why a client's handshake with host failed, and what to do about it.
30std::string HandshakeError(TlsStream& stream, const std::string& host,
31 const std::error_code& error);
32
33} // namespace nanommo
34
35#endif // NANOMMO_PROTOCOL_TLS_H_
Definition chat.cc:9
std::string HandshakeError(TlsStream &stream, const std::string &host, const std::error_code &error)
Why a client's handshake with host failed, and what to do about it.
Definition tls.cc:64
asio::ssl::stream< asio::ip::tcp::socket > TlsStream
Definition tls.h:14
absl::StatusOr< asio::ssl::context > ServerTls(const std::string &certificate, const std::string &key)
Definition tls.cc:26
absl::StatusOr< asio::ssl::context > ClientTls(const std::string &authority)
Definition tls.cc:41
void ExpectName(TlsStream &stream, const std::string &host)
Definition tls.cc:52