Kea 2.7.5
common_tls.h
Go to the documentation of this file.
1// Copyright (C) 2021-2024 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 <boost/noncopyable.hpp>
22#include <boost/shared_ptr.hpp>
23
24#include <netinet/in.h>
25#include <sys/socket.h>
26
27namespace isc {
28namespace asiolink {
29
32
34class TlsContext;
35
37typedef boost::shared_ptr<TlsContext> TlsContextPtr;
38
40class TlsContextBase : private boost::noncopyable {
41public:
43 virtual ~TlsContextBase() { }
44
48 explicit TlsContextBase(TlsRole role) : role_(role) { }
49
51 TlsRole getRole() const {
52 return (role_);
53 }
54
56
67 static void configure(TlsContextPtr& context,
68 TlsRole role,
69 const std::string& ca_file,
70 const std::string& cert_file,
71 const std::string& key_file,
72 bool cert_required = true);
73
78 virtual bool getCertRequired() const = 0;
79
80protected:
86 virtual void setCertRequired(bool cert_required) = 0;
87
93 virtual void loadCaFile(const std::string& ca_file) = 0;
94
100 virtual void loadCaPath(const std::string& ca_path) = 0;
101
107 virtual void loadCertFile(const std::string& cert_file) = 0;
108
114 virtual void loadKeyFile(const std::string& key_file) = 0;
115
116public:
119};
120
122public:
124 StreamService(const IOServicePtr& io_service, TlsContextPtr& tls_context) :
125 io_service_(io_service), tls_context_(tls_context) {
126 }
127private:
129 IOServicePtr io_service_;
130
132 TlsContextPtr tls_context_;
133};
134
139template <typename Callback, typename TlsStreamImpl>
140class TlsStreamBase : public StreamService, public TlsStreamImpl {
141public:
142
148 TlsStreamBase(const IOServicePtr& service, TlsContextPtr context);
149
151 virtual ~TlsStreamBase() { }
152
154 TlsRole getRole() const {
155 return (role_);
156 }
157
161 virtual void handshake(Callback& callback) = 0;
162
166 virtual void shutdown(Callback& callback) = 0;
167
177 virtual std::string getSubject() = 0;
178
188 virtual std::string getIssuer() = 0;
189
192};
193
194} // namespace asiolink
195} // namespace isc
196
197#endif // COMMON_TLS_H
Defines the logger used by the top-level component of kea-lfc.