RCFProto
 All Classes Functions Typedefs
Win32Certificate.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_WIN32CERTIFICATE_HPP
20 #define INCLUDE_RCF_WIN32CERTIFICATE_HPP
21 
22 #include <RCF/Certificate.hpp>
23 
24 #include <RCF/ByteBuffer.hpp>
25 #include <RCF/util/Tchar.hpp>
26 
27 #include <windows.h>
28 #include <schnlsp.h>
29 #include <wincrypt.h>
30 
31 namespace RCF {
32 
34  class RCF_EXPORT Win32Certificate : public Certificate
35  {
36  public:
37  Win32Certificate();
38  Win32Certificate(PCCERT_CONTEXT pContext);
39  ~Win32Certificate();
40 
41  // *** SWIG BEGIN ***
42 
43  virtual CertificateImplementationType _getType()
44  {
45  return Cit_Win32;
46  }
47 
49  tstring getCertificateName();
50 
52  tstring getIssuerName();
53 
55  void exportToPfx(const std::string & pfxFilePath);
56 
59  Win32CertificatePtr findRootCertificate(
60  Win32CertificateLocation certStoreLocation,
61  Win32CertificateStore certStore);
62 
63  // *** SWIG END ***
64 
65  PCCERT_CONTEXT getWin32Context();
66 
67 
68 
69  void setHasBeenDeleted()
70  {
71  mHasBeenDeleted = true;
72  }
73 
74  tstring getSubjectName();
75  tstring getOrganizationName();
76  tstring getCertAttribute(const char * whichAttr);
77 
78  RCF::ByteBuffer exportToPfx();
79 
80  protected:
81 
82  PCCERT_CONTEXT mpCert;
83  bool mHasBeenDeleted;
84  };
85 
86 
88  class RCF_EXPORT PfxCertificate : public Win32Certificate
89  {
90  public:
91 
92  // *** SWIG BEGIN ***
93 
95  PfxCertificate(
96  const std::string & pathToCert,
97  const tstring & password,
98  const tstring & certName);
99 
101  void addToStore(
102  Win32CertificateLocation certStoreLocation,
103  Win32CertificateStore certStore);
104 
105  // *** SWIG END ***
106 
107  PfxCertificate(
108  ByteBuffer certPfxBlob,
109  const tstring & password,
110  const tstring & certName);
111 
112  ~PfxCertificate();
113 
114  private:
115 
116  void init(
117  ByteBuffer pfxBlob,
118  const tstring & password,
119  const tstring & certName);
120 
121  void initFromFile(
122  const std::string & pathToCert,
123  const RCF::tstring & password,
124  const RCF::tstring & certName);
125 
126  HCERTSTORE mPfxStore;
127  };
128 
130  class RCF_EXPORT StoreCertificate : public Win32Certificate
131  {
132  public:
133 
134  // *** SWIG BEGIN ***
135 
137  StoreCertificate(
138  Win32CertificateLocation certStoreLocation,
139  Win32CertificateStore certStore,
140  const tstring & certName);
141 
143  void removeFromStore();
144 
145  // *** SWIG END ***
146 
147  ~StoreCertificate();
148 
149  private:
150  HCERTSTORE mStore;
151  };
152 
154  class RCF_EXPORT StoreCertificateIterator
155  {
156  public:
157 
158  // *** SWIG BEGIN ***
159 
161  StoreCertificateIterator(
162  Win32CertificateLocation certStoreLocation,
163  Win32CertificateStore certStore);
164 
166  bool moveNext();
167 
169  void reset();
170 
172  Win32CertificatePtr current();
173 
174  // *** SWIG END ***
175 
176  ~StoreCertificateIterator();
177 
178  private:
179 
180  HCERTSTORE mhCertStore;
181  PCCERT_CONTEXT mpCertIterator;
182  Win32CertificatePtr mCurrentCertPtr;
183  };
184 
185 } // namespace RCF
186 
187 #endif // ! INCLUDE_RCF_WIN32CERTIFICATE_HPP