RCFProto
 All Classes Functions Typedefs
Schannel.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_SCHANNEL_HPP
20 #define INCLUDE_RCF_SCHANNEL_HPP
21 
22 #include <RCF/Filter.hpp>
23 #include <RCF/SspiFilter.hpp>
24 #include <RCF/util/Tchar.hpp>
25 
26 #include <schnlsp.h>
27 
28 // missing stuff in mingw headers
29 #ifdef __MINGW32__
30 #ifndef SP_PROT_NONE
31 #define SP_PROT_NONE 0
32 #endif
33 #endif // __MINGW32__
34 
35 namespace RCF {
36 
37  static const ULONG DefaultSchannelContextRequirements =
38  ASC_REQ_SEQUENCE_DETECT |
39  ASC_REQ_REPLAY_DETECT |
40  ASC_REQ_CONFIDENTIALITY |
41  ASC_REQ_EXTENDED_ERROR |
42  ASC_REQ_ALLOCATE_MEMORY |
43  ASC_REQ_STREAM;
44 
45  class SchannelServerFilter : public SspiServerFilter
46  {
47  public:
48  SchannelServerFilter(
49  RcfServer & server,
50  DWORD enabledProtocols,
51  ULONG contextRequirements);
52 
53  int getFilterId() const;
54  };
55 
56  class SchannelFilterFactory : public FilterFactory
57  {
58  public:
59 
60  SchannelFilterFactory(
61  DWORD enabledProtocols = SP_PROT_TLS1_SERVER,
62  ULONG contextRequirements = DefaultSchannelContextRequirements);
63 
64  FilterPtr createFilter(RcfServer & server);
65  int getFilterId();
66 
67  private:
68 
69  ULONG mContextRequirements;
70  DWORD mEnabledProtocols;
71  };
72 
73  class SchannelClientFilter : public SspiClientFilter
74  {
75  public:
76  SchannelClientFilter(
77  ClientStub * pClientStub,
78  DWORD enabledProtocols = SP_PROT_NONE,
79  ULONG contextRequirements = DefaultSchannelContextRequirements);
80 
81  int getFilterId() const;
82  };
83 
84  typedef SchannelClientFilter SchannelFilter;
85 
86  // Certificate utility classes.
87 
88  class Win32Certificate;
89  typedef boost::shared_ptr<Win32Certificate> Win32CertificatePtr;
90 
92  class RCF_EXPORT Win32Certificate : public Certificate
93  {
94  public:
95  Win32Certificate();
96  Win32Certificate(PCCERT_CONTEXT pContext);
97  ~Win32Certificate();
98 
99  // *** SWIG BEGIN ***
100 
101  virtual CertificateImplementationType _getType()
102  {
103  return Cit_Win32;
104  }
105 
107  tstring getCertificateName();
108 
110  tstring getIssuerName();
111 
113  void exportToPfx(const std::string & pfxFilePath);
114 
117  Win32CertificatePtr findRootCertificate(
118  Win32CertificateLocation certStoreLocation,
119  Win32CertificateStore certStore);
120 
121  // *** SWIG END ***
122 
123  PCCERT_CONTEXT getWin32Context();
124 
125 
126 
127  void setHasBeenDeleted()
128  {
129  mHasBeenDeleted = true;
130  }
131 
132  tstring getSubjectName();
133  tstring getOrganizationName();
134  tstring getCertAttribute(const char * whichAttr);
135 
136  RCF::ByteBuffer exportToPfx();
137 
138  protected:
139 
140  PCCERT_CONTEXT mpCert;
141  bool mHasBeenDeleted;
142  };
143 
144 
146  class RCF_EXPORT PfxCertificate : public Win32Certificate
147  {
148  public:
149 
150  // *** SWIG BEGIN ***
151 
153  PfxCertificate(
154  const std::string & pathToCert,
155  const tstring & password,
156  const tstring & certName);
157 
159  void addToStore(
160  Win32CertificateLocation certStoreLocation,
161  Win32CertificateStore certStore);
162 
163  // *** SWIG END ***
164 
165  PfxCertificate(
166  ByteBuffer certPfxBlob,
167  const tstring & password,
168  const tstring & certName);
169 
170  ~PfxCertificate();
171 
172  private:
173 
174  void init(
175  ByteBuffer pfxBlob,
176  const tstring & password,
177  const tstring & certName);
178 
179  void initFromFile(
180  const std::string & pathToCert,
181  const RCF::tstring & password,
182  const RCF::tstring & certName);
183 
184  HCERTSTORE mPfxStore;
185  };
186 
188  class RCF_EXPORT StoreCertificate : public Win32Certificate
189  {
190  public:
191 
192  // *** SWIG BEGIN ***
193 
195  StoreCertificate(
196  Win32CertificateLocation certStoreLocation,
197  Win32CertificateStore certStore,
198  const tstring & certName);
199 
201  void removeFromStore();
202 
203  // *** SWIG END ***
204 
205  ~StoreCertificate();
206 
207  private:
208  HCERTSTORE mStore;
209  };
210 
212  class RCF_EXPORT StoreCertificateIterator
213  {
214  public:
215 
216  // *** SWIG BEGIN ***
217 
219  StoreCertificateIterator(
220  Win32CertificateLocation certStoreLocation,
221  Win32CertificateStore certStore);
222 
224  bool moveNext();
225 
227  void reset();
228 
230  Win32CertificatePtr current();
231 
232  // *** SWIG END ***
233 
234  ~StoreCertificateIterator();
235 
236  private:
237 
238  HCERTSTORE mhCertStore;
239  PCCERT_CONTEXT mpCertIterator;
240  Win32CertificatePtr mCurrentCertPtr;
241  };
242 
243 } // namespace RCF
244 
245 #endif // ! INCLUDE_RCF_SCHANNEL_HPP