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