Kea 3.3.3
common_tls.h
Go to the documentation of this file.
1// Copyright (C) 2021-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7// Do not include this header directly: use crypto_tls.h instead.
8
9#ifndef COMMON_TLS_H
10#define COMMON_TLS_H
11
13
14// Verify that this file was not directly included.
15#ifndef CRYPTO_TLS_H
16#error crypto_tls.h must be included in place of common_tls.h
17#endif
18
20
21#include <cstdint>
22
23#include <boost/noncopyable.hpp>
24#include <boost/shared_ptr.hpp>
25
26#include <netinet/in.h>
27#include <sys/socket.h>
28
29namespace isc {
30namespace asiolink {
31
33enum TlsRole : uint16_t { CLIENT, SERVER };
34
36class TlsContext;
37
39typedef boost::shared_ptr<TlsContext> TlsContextPtr;
40
42class TlsContextBase : private boost::noncopyable {
43public:
45 virtual ~TlsContextBase() { }
46
50 explicit TlsContextBase(TlsRole role) : role_(role) { }
51
53 TlsRole getRole() const {
54 return (role_);
55 }
56
58
69 static void configure(TlsContextPtr& context,
70 TlsRole role,
71 const std::string& ca_file,
72 const std::string& cert_file,
73 const std::string& key_file,
74 bool cert_required = true);
75
80 virtual bool getCertRequired() const = 0;
81
82protected:
88 virtual void setCertRequired(bool cert_required) = 0;
89
95 virtual void loadCaFile(const std::string& ca_file) = 0;
96
102 virtual void loadCaPath(const std::string& ca_path) = 0;
103
109 virtual void loadCertFile(const std::string& cert_file) = 0;
110
116 virtual void loadKeyFile(const std::string& key_file) = 0;
117
118public:
121};
122
124public:
126 StreamService(const IOServicePtr& io_service, TlsContextPtr& tls_context) :
127 io_service_(io_service), tls_context_(tls_context) {
128 }
129private:
131 IOServicePtr io_service_;
132
134 TlsContextPtr tls_context_;
135};
136
141template <typename Callback, typename TlsStreamImpl>
142class TlsStreamBase : public StreamService, public TlsStreamImpl {
143public:
144
150 TlsStreamBase(const IOServicePtr& service, TlsContextPtr context);
151
153 virtual ~TlsStreamBase() { }
154
156 TlsRole getRole() const {
157 return (role_);
158 }
159
163 virtual void handshake(Callback& callback) = 0;
164
168 virtual void shutdown(Callback& callback) = 0;
169
179 virtual std::string getSubject() = 0;
180
190 virtual std::string getIssuer() = 0;
191
194};
195
196} // namespace asiolink
197} // namespace isc
198
199#endif // COMMON_TLS_H
Defines the logger used by the top-level component of kea-lfc.