Remote Call Framework 3.4
Win32Certificate.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_WIN32CERTIFICATE_HPP
19 #define INCLUDE_RCF_WIN32CERTIFICATE_HPP
20 
21 #include <RCF/Certificate.hpp>
22 
23 #include <RCF/Tchar.hpp>
24 
25 #include <windows.h>
26 #include <schnlsp.h>
27 #include <wincrypt.h>
28 
29 namespace RCF {
30 
31  class ByteBuffer;
32 
35 
37  class RCF_EXPORT Win32Certificate : public Certificate
38  {
39  public:
41  Win32Certificate(PCCERT_CONTEXT pContext);
43 
44  // *** SWIG BEGIN ***
45 
46  virtual CertificateImplementationType _getType();
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 
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 
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 
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 
162  Win32CertificateLocation certStoreLocation,
163  Win32CertificateStore certStore);
164 
166  bool moveNext();
167 
169  void reset();
170 
172  Win32CertificatePtr current();
173 
174  // *** SWIG END ***
175 
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
Win32CertificateStore
Win32 certificate stores.
Definition: Enums.hpp:104
std::shared_ptr< Win32Certificate > Win32CertificatePtr
Reference counted wrapper for RCF::Win32Certificate.
Definition: RcfFwd.hpp:257
Win32CertificateLocation
Win32 certificate store locations.
Definition: Enums.hpp:94
Use this class to load a certificate from .pfx format. Only applicable to Schannel.
Definition: Win32Certificate.hpp:88
Represents a certificate in a Windows certificate store.
Definition: Win32Certificate.hpp:130
Represents an in-memory certificate, either from a remote peer or loaded from a local certificate sto...
Definition: Win32Certificate.hpp:37
Iterates over the certificates in a Windows certificate store.
Definition: Win32Certificate.hpp:154
Definition: ByteBuffer.hpp:39
Definition: AmiIoHandler.hpp:23
Base class for all RCF certificate classes.
Definition: Certificate.hpp:29
RCF_EXPORT bool init(RcfConfigT *=nullptr)
Reference-counted initialization of RCF library. May be called multiple times (see deinit())...