23#include <botan/asio_stream.h> 
   29inline Botan::TLS::Connection_Side roleToImpl(
TlsRole role) {
 
   31        return (Botan::TLS::Connection_Side::Server);
 
   33        return (Botan::TLS::Connection_Side::Client);
 
   48    virtual ~TlsContext();
 
   53    explicit TlsContext(TlsRole role);
 
   56    std::shared_ptr<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;
 
   99typedef Botan::TLS::Stream<boost::asio::ip::tcp::socket> TlsStreamImpl;
 
  108template <
typename Callback, 
typename TlsStreamImpl>
 
  112      TlsStreamImpl(io_service->getInternalIOService(),
 
  113      context->getContext()), role_(context->getRole()) {
 
  119template <
typename Callback>
 
  120class TlsStream : 
public TlsStreamBase<Callback, TlsStreamImpl>
 
  125    typedef TlsStreamBase<Callback, TlsStreamImpl> Base;
 
  132    TlsStream(
const IOServicePtr& service, TlsContextPtr context)
 
  133        : Base(service, context) {
 
  137    virtual ~TlsStream() { }
 
  142    virtual void handshake(Callback& callback) {
 
  143        Base::async_handshake(roleToImpl(Base::getRole()), callback);
 
  149    virtual void shutdown(Callback& callback) {
 
  150        Base::async_shutdown(callback);
 
  158    virtual void clear() {
 
  170    virtual std::string getSubject() {
 
  171        const std::vector<Botan::X509_Certificate>& cert_chain =
 
  172            Base::native_handle()->peer_cert_chain();
 
  173        if (cert_chain.empty()) {
 
  176        const Botan::X509_DN& subject = cert_chain[0].subject_dn();
 
  177        return (subject.get_first_attribute(
"CommonName"));
 
  189    virtual std::string getIssuer() {
 
  190        const std::vector<Botan::X509_Certificate>& cert_chain =
 
  191            Base::native_handle()->peer_cert_chain();
 
  192        if (cert_chain.empty()) {
 
  195        const Botan::X509_DN& issuer = cert_chain[0].issuer_dn();
 
  196        return (issuer.get_first_attribute(
"CommonName"));
 
  201const 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.