RCFProto

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
OpenSslEncryptionFilter.hpp
1
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, 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: 2.0
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
25 #include <boost/function.hpp>
26 #include <boost/noncopyable.hpp>
27 #include <boost/shared_ptr.hpp>
28
29 #include <RCF/Filter.hpp>
30 #include <RCF/Export.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
48 typedef boost::function1<bool, Certificate *> CertificateValidationCb;
49
51 class RCF_EXPORT PemCertificate : public Certificate
52 {
53 public:
54
55 // *** SWIG BEGIN ***
56
58 PemCertificate(const std::string & pathToCert, const std::string & password = "");
59
60 // *** SWIG END ***
61
62 private:
63
64 friend class OpenSslEncryptionFilter;
65 friend class OpenSslEncryptionFilterFactory;
66
67 std::string mPathToCert;
68 std::string mPassword;
69 };
70
71 class OpenSslDll;
72 class OpenSslCryptoDll;
73
75 class RCF_EXPORT X509Certificate : public Certificate
76 {
77 public:
78
79 // *** SWIG BEGIN ***
80
81 virtual CertificateImplementationType _getType()
82 {
83 return Cit_X509;
84 }
85
87 std::string getCertificateName();
88
90 std::string getIssuerName();
91
92 // *** SWIG END ***
93
94 X509Certificate(X509 * pX509);
95
96 X509 * getX509();
97
98 private:
99 OpenSslDll & mSslDll;
100 OpenSslCryptoDll & mCryptoDll;
101 X509 * mpX509;
102 };
103
104 typedef boost::shared_ptr<X509Certificate> X509CertificatePtr;
105
106 class ClientStub;
107
108 class RCF_EXPORT OpenSslEncryptionFilter : public Filter, boost::noncopyable
109 {
110 public:
111 int getFilterId() const;
112
113 public:
114
115 OpenSslEncryptionFilter(
116 ClientStub * pClientStub,
117 SslRole sslRole = SslClient,
118 unsigned int bioBufferSize = 2048);
119
120 OpenSslEncryptionFilter(
121 const std::string & certificateFile,
122 const std::string & certificateFilePassword,
123 const std::string & caCertificate,
124 const std::string & ciphers,
125 CertificateValidationCb verifyFunctor,
126 SslRole sslRole = SslClient,
127 unsigned int bioBufferSize = 2048);
128
129 void resetState();
130 void read(const ByteBuffer &byteBuffer, std::size_t bytesRequested);
131 void write(const std::vector<ByteBuffer> &byteBuffers);
132 void onReadCompleted(const ByteBuffer &byteBuffer);
133 void onWriteCompleted(std::size_t bytesTransferred);
134
135 SSL * getSSL();
136 SSL_CTX * getCTX();
137
138 CertificatePtr getPeerCertificate();
139
140 private:
141 friend class OpenSslEncryptionFilterImpl;
142 boost::shared_ptr<OpenSslEncryptionFilterImpl> mImplPtr;
143 };
144
145 class OpenSslEncryptionFilterFactory : public FilterFactory
146 {
147 public:
148 OpenSslEncryptionFilterFactory();
149
150 FilterPtr createFilter(RcfServer & server);
151 int getFilterId();
152
153 private:
154 SslRole mRole;
155 };
156
157
158 } // namespace RCF
159
160 #endif // ! INCLUDE_RCF_OPENSSLENCRYPTIONFILTER_HPP