9 #ifndef BOTAN_BOOST_TLS_H
10 #define BOTAN_BOOST_TLS_H
14 #if defined(WITH_BOTAN) && defined(WITH_BOTAN_BOOST)
23 #include <botan/asio_stream.h>
29 inline Botan::TLS::Connection_Side roleToImpl(
TlsRole role) {
41 class TlsContext :
public TlsContextBase {
48 virtual ~TlsContext();
53 explicit TlsContext(
TlsRole role);
56 Botan::TLS::Context& getContext();
62 virtual bool getCertRequired()
const;
69 virtual void setCertRequired(
bool cert_required);
74 virtual void loadCaFile(
const std::string& ca_file);
79 virtual void loadCaPath(
const std::string& ca_path);
84 virtual void loadCertFile(
const std::string& cert_file);
89 virtual void loadKeyFile(
const std::string& key_file);
92 std::unique_ptr<TlsContextImpl> impl_;
95 friend class TlsContextBase;
99 typedef Botan::TLS::Stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
108 template <
typename Callback,
typename TlsStreamImpl>
111 : TlsStreamImpl(service.get_io_service(), context->getContext()),
112 role_(context->getRole()) {
118 template <
typename Callback>
119 class TlsStream :
public TlsStreamBase<Callback, TlsStreamImpl>
124 typedef TlsStreamBase<Callback, TlsStreamImpl> Base;
132 : Base(service, context) {
136 virtual ~TlsStream() { }
141 virtual void handshake(Callback& callback) {
142 Base::async_handshake(roleToImpl(Base::getRole()), callback);
148 virtual void shutdown(Callback& callback) {
149 Base::async_shutdown(callback);
157 virtual void clear() {
169 virtual std::string getSubject() {
170 const std::vector<Botan::X509_Certificate>& cert_chain =
171 Base::native_handle()->peer_cert_chain();
172 if (cert_chain.empty()) {
175 const Botan::X509_DN& subject = cert_chain[0].subject_dn();
176 return (subject.get_first_attribute(
"CommonName"));
188 virtual std::string getIssuer() {
189 const std::vector<Botan::X509_Certificate>& cert_chain =
190 Base::native_handle()->peer_cert_chain();
191 if (cert_chain.empty()) {
194 const Botan::X509_DN& issuer = cert_chain[0].issuer_dn();
195 return (issuer.get_first_attribute(
"CommonName"));
200 const int STREAM_TRUNCATED = Botan::TLS::StreamError::StreamTruncated;
205 #endif // WITH_BOTAN && WITH_BOTAN_BOOST
207 #endif // BOTAN_BOOST_TLS_H
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
Defines the logger used by the top-level component of kea-dhcp-ddns.
TlsStreamBase(IOService &service, TlsContextPtr context)
Constructor.
A wrapper interface for the ASIO library.
TlsRole
Client and server roles.
Botan boost ASIO wrapper.