Remote Call Framework 3.2
OpenSslEncryptionFilter.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2020, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.2
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_OPENSSLENCRYPTIONFILTER_HPP
20 #define INCLUDE_RCF_OPENSSLENCRYPTIONFILTER_HPP
21 
22 #include <memory>
23 #include <string>
24 #include <functional>
25 
26 #include <RCF/Certificate.hpp>
27 #include <RCF/Enums.hpp>
28 #include <RCF/Filter.hpp>
29 #include <RCF/Export.hpp>
30 #include <RCF/Tools.hpp>
31 
32 typedef struct ssl_st SSL;
33 typedef struct ssl_ctx_st SSL_CTX;
34 typedef struct x509_st X509;
35 
36 namespace RCF {
37 
38  // Enumeration describing the role in a SSL conversation that an endpoint is playing.
39  enum SslRole
40  {
41  SslServer,
42  SslClient
43  };
44 
45  class OpenSslEncryptionFilter;
46  class OpenSslEncryptionFilterImpl;
47 
49  class RCF_EXPORT PemCertificate : public Certificate
50  {
51  public:
52 
53  // *** SWIG BEGIN ***
54 
56  PemCertificate(const std::string & pathToCert, const std::string & password = "");
57 
58  // *** SWIG END ***
59 
60  private:
61 
62  friend class OpenSslEncryptionFilter;
63  friend class OpenSslEncryptionFilterFactory;
64 
65  std::string mPathToCert;
66  std::string mPassword;
67  };
68 
69  class OpenSslDll;
70  class OpenSslCryptoDll;
71 
73  class RCF_EXPORT X509Certificate : public Certificate
74  {
75  public:
76 
77  // *** SWIG BEGIN ***
78 
79  virtual CertificateImplementationType _getType()
80  {
81  return Cit_X509;
82  }
83 
85  std::string getCertificateName();
86 
88  std::string getIssuerName();
89 
90  // *** SWIG END ***
91 
92  X509Certificate(X509 * pX509);
93 
94  X509 * getX509();
95 
96  private:
97  OpenSslDll & mSslDll;
98  OpenSslCryptoDll & mCryptoDll;
99  X509 * mpX509;
100  };
101 
102  typedef std::shared_ptr<X509Certificate> X509CertificatePtr;
103 
104  class ClientStub;
105 
106  class RCF_EXPORT OpenSslEncryptionFilter : public Filter, Noncopyable
107  {
108  public:
109  int getFilterId() const;
110 
111  public:
112 
113  OpenSslEncryptionFilter(
114  ClientStub * pClientStub,
115  SslRole sslRole = SslClient,
116  unsigned int bioBufferSize = 2048);
117 
118  OpenSslEncryptionFilter(
119  const std::string & certificateFile,
120  const std::string & certificateFilePassword,
121  const std::string & caCertificate,
122  const std::string & ciphers,
123  CertificateValidationCallback verifyFunctor,
124  SslRole sslRole = SslClient,
125  unsigned int bioBufferSize = 2048);
126 
127  void resetState();
128  void read(const ByteBuffer &byteBuffer, std::size_t bytesRequested);
129  void write(const std::vector<ByteBuffer> &byteBuffers);
130  void onReadCompleted(const ByteBuffer &byteBuffer);
131  void onWriteCompleted(std::size_t bytesTransferred);
132 
133  SSL * getSSL();
134  SSL_CTX * getCTX();
135 
136  CertificatePtr getPeerCertificate();
137 
138  private:
139  friend class OpenSslEncryptionFilterImpl;
140  std::shared_ptr<OpenSslEncryptionFilterImpl> mImplPtr;
141  };
142 
143  class OpenSslEncryptionFilterFactory : public FilterFactory
144  {
145  public:
146  OpenSslEncryptionFilterFactory();
147 
148  FilterPtr createFilter(RcfServer & server);
149  int getFilterId();
150 
151  private:
152  SslRole mRole;
153  };
154 
155 
156 } // namespace RCF
157 
158 #endif // ! INCLUDE_RCF_OPENSSLENCRYPTIONFILTER_HPP
Controls the client side of a RCF connection.
Definition: ClientStub.hpp:83
std::shared_ptr< Certificate > CertificatePtr
Reference counted wrapper for RCF::Certificate.
Definition: RcfFwd.hpp:109
std::function< bool(Certificate *)> CertificateValidationCallback
Describes user-provided callback functions for validating a certificate.
Definition: RcfFwd.hpp:115
Provides RCF server-side functionality.
Definition: RcfServer.hpp:54
Represents an in-memory certificate, usually from a remote peer. Only applicable to OpenSSL...
Definition: OpenSslEncryptionFilter.hpp:73
Definition: ByteBuffer.hpp:40
Definition: AmiIoHandler.hpp:24
Base class for all RCF certificate classes.
Definition: Certificate.hpp:30
Use this class to load a certificate from .pem format. Only applicable to OpenSSL.
Definition: OpenSslEncryptionFilter.hpp:49