//*****************************************************************************
// RCF - Remote Call Framework
// Copyright (c) 2005. All rights reserved.
// Developed by Jarl Lindrud.
// Contact: jlindrud@hotmail.com .
//*****************************************************************************
#ifndef INCLUDE_RCF_OPENSSLENCRYPTIONFILTER_HPP
#define INCLUDE_RCF_OPENSSLENCRYPTIONFILTER_HPP
#include <memory>
#include <string>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <RCF/AsyncFilter.hpp>
namespace RCF {
static const int RCF_FILTER_OPENSSL_ENCRYPTION = 2;
/// Enumeration describing the role in a SSL conversation that an endpoint is playing.
enum SslRole
{
SslServer,
SslClient
};
/// Filter implementing the SSL encryption protocol, through the OpenSSL library.
class OpenSslEncryptionFilter : public IdentityFilter, boost::noncopyable
{
public:
static FilterDescription sGetFilterDescription();
FilterDescription getFilterDescription() const;
OpenSslEncryptionFilter(SslRole sslRole, const std::string &certificateFile, const std::string &certificateFilePassword, unsigned int bioBufferSize = 2048);
void read(char *buffer, std::size_t bufferLen);
void write(const char *buffer, std::size_t bufferLen);
void onReadWriteCompleted(std::size_t bytesTransferred, int error);
private:
friend class OpenSslEncryptionFilterImpl;
boost::shared_ptr<OpenSslEncryptionFilterImpl> implPtr;
};
/// Filter factory for OpenSslEncryptionFilter.
class OpenSslEncryptionFilterFactory : public FilterFactory
{
public:
OpenSslEncryptionFilterFactory(const std::string &certificateFile, const std::string &certificateFilePassword, bool serverRole = true);
FilterPtr createFilter();
FilterDescription getFilterDescription();
private:
std::string mCertificateFile;
std::string mCertificateFilePassword;
SslRole mRole;
};
} // namespace RCF
#endif // ! INCLUDE_RCF_OPENSSLENCRYPTIONFILTER_HPP