Kea  1.9.9-git
common_tls.h
Go to the documentation of this file.
1 // Copyright (C) 2021 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 
19 #include <cryptolink/cryptolink.h>
20 
21 #include <boost/noncopyable.hpp>
22 #include <boost/shared_ptr.hpp>
23 
24 #include <netinet/in.h>
25 #include <sys/socket.h>
26 
27 namespace isc {
28 namespace asiolink {
29 
31 enum TlsRole { CLIENT, SERVER };
32 
34 class TlsContext;
35 
37 typedef boost::shared_ptr<TlsContext> TlsContextPtr;
38 
40 class TlsContextBase : private boost::noncopyable {
41 public:
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 
80 protected:
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 
116 public:
119 };
120 
125 template <typename Callback, typename TlsStreamImpl>
126 class TlsStreamBase : public TlsStreamImpl {
127 public:
128 
134  TlsStreamBase(IOService& service, TlsContextPtr context);
135 
137  virtual ~TlsStreamBase() { }
138 
140  TlsRole getRole() const {
141  return (role_);
142  }
143 
147  virtual void handshake(Callback& callback) = 0;
148 
152  virtual void shutdown(Callback& callback) = 0;
153 
163  virtual std::string getSubject() = 0;
164 
174  virtual std::string getIssuer() = 0;
175 
178 };
179 
180 } // namespace asiolink
181 } // namespace isc
182 
183 #endif // COMMON_TLS_H
Defines the logger used by the top-level component of kea-dhcp-ddns.