28inline Botan::TLS::Connection_Side roleToImpl(
TlsRole role) {
30 return (Botan::TLS::Connection_Side::Server);
32 return (Botan::TLS::Connection_Side::Client);
47 virtual ~TlsContext();
52 explicit TlsContext(TlsRole role);
55 std::shared_ptr<Botan::TLS::Context> getContext();
61 virtual bool getCertRequired()
const;
68 virtual void setCertRequired(
bool cert_required);
73 virtual void loadCaFile(
const std::string& ca_file);
78 virtual void loadCaPath(
const std::string& ca_path);
83 virtual void loadCertFile(
const std::string& cert_file);
88 virtual void loadKeyFile(
const std::string& key_file);
91 std::unique_ptr<TlsContextImpl> impl_;
94 friend class TlsContextBase;
98typedef Botan::TLS::Stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
107template <
typename Callback,
typename TlsStreamImpl>
111 TlsStreamImpl(io_service->getInternalIOService(),
112 context->getContext()), role_(context->getRole()) {
118template <
typename Callback>
119class TlsStream :
public TlsStreamBase<Callback, TlsStreamImpl>
124 typedef TlsStreamBase<Callback, TlsStreamImpl> Base;
131 TlsStream(
const IOServicePtr& service, TlsContextPtr context)
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"));
200const int STREAM_TRUNCATED = Botan::TLS::StreamError::StreamTruncated;
TlsStreamBase(const IOServicePtr &service, TlsContextPtr context)
Constructor.
boost::shared_ptr< TlsContext > TlsContextPtr
The type of shared pointers to TlsContext objects.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
TlsRole
Client and server roles.
Defines the logger used by the top-level component of kea-lfc.