Remote Call Framework 3.1
Win32Certificate.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2019, 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.1
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/Tchar.hpp>
25 
26 #include <windows.h>
27 #include <schnlsp.h>
28 #include <wincrypt.h>
29 
30 namespace RCF {
31 
32  class ByteBuffer;
33 
36 
38  class RCF_EXPORT Win32Certificate : public Certificate
39  {
40  public:
42  Win32Certificate(PCCERT_CONTEXT pContext);
44 
45  // *** SWIG BEGIN ***
46 
47  virtual CertificateImplementationType _getType();
48 
50  tstring getCertificateName();
51 
53  tstring getIssuerName();
54 
56  void exportToPfx(const std::string & pfxFilePath);
57 
60  Win32CertificatePtr findRootCertificate(
61  Win32CertificateLocation certStoreLocation,
62  Win32CertificateStore certStore);
63 
64  // *** SWIG END ***
65 
66  PCCERT_CONTEXT getWin32Context();
67 
68 
69 
70  void setHasBeenDeleted()
71  {
72  mHasBeenDeleted = true;
73  }
74 
75  tstring getSubjectName();
76  tstring getOrganizationName();
77  tstring getCertAttribute(const char * whichAttr);
78 
79  RCF::ByteBuffer exportToPfx();
80 
81  protected:
82 
83  PCCERT_CONTEXT mpCert;
84  bool mHasBeenDeleted;
85  };
86 
87 
89  class RCF_EXPORT PfxCertificate : public Win32Certificate
90  {
91  public:
92 
93  // *** SWIG BEGIN ***
94 
97  const std::string & pathToCert,
98  const tstring & password,
99  const tstring & certName);
100 
102  void addToStore(
103  Win32CertificateLocation certStoreLocation,
104  Win32CertificateStore certStore);
105 
106  // *** SWIG END ***
107 
109  ByteBuffer certPfxBlob,
110  const tstring & password,
111  const tstring & certName);
112 
113  ~PfxCertificate();
114 
115  private:
116 
117  void init(
118  ByteBuffer pfxBlob,
119  const tstring & password,
120  const tstring & certName);
121 
122  void initFromFile(
123  const std::string & pathToCert,
124  const RCF::tstring & password,
125  const RCF::tstring & certName);
126 
127  HCERTSTORE mPfxStore;
128  };
129 
131  class RCF_EXPORT StoreCertificate : public Win32Certificate
132  {
133  public:
134 
135  // *** SWIG BEGIN ***
136 
139  Win32CertificateLocation certStoreLocation,
140  Win32CertificateStore certStore,
141  const tstring & certName);
142 
144  void removeFromStore();
145 
146  // *** SWIG END ***
147 
148  ~StoreCertificate();
149 
150  private:
151  HCERTSTORE mStore;
152  };
153 
155  class RCF_EXPORT StoreCertificateIterator
156  {
157  public:
158 
159  // *** SWIG BEGIN ***
160 
163  Win32CertificateLocation certStoreLocation,
164  Win32CertificateStore certStore);
165 
167  bool moveNext();
168 
170  void reset();
171 
173  Win32CertificatePtr current();
174 
175  // *** SWIG END ***
176 
178 
179  private:
180 
181  HCERTSTORE mhCertStore;
182  PCCERT_CONTEXT mpCertIterator;
183  Win32CertificatePtr mCurrentCertPtr;
184  };
185 
186 } // namespace RCF
187 
188 #endif // ! INCLUDE_RCF_WIN32CERTIFICATE_HPP
Win32CertificateStore
Win32 certificate stores.
Definition: Enums.hpp:105
std::shared_ptr< Win32Certificate > Win32CertificatePtr
Reference counted wrapper for RCF::Win32Certificate.
Definition: RcfFwd.hpp:257
Win32CertificateLocation
Win32 certificate store locations.
Definition: Enums.hpp:95
Use this class to load a certificate from .pfx format. Only applicable to Schannel.
Definition: Win32Certificate.hpp:89
Represents a certificate in a Windows certificate store.
Definition: Win32Certificate.hpp:131
Represents an in-memory certificate, either from a remote peer or loaded from a local certificate sto...
Definition: Win32Certificate.hpp:38
Iterates over the certificates in a Windows certificate store.
Definition: Win32Certificate.hpp:155
Definition: ByteBuffer.hpp:40
Definition: AmiIoHandler.hpp:24
Base class for all RCF certificate classes.
Definition: Certificate.hpp:30
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...