Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Botan::Certificate_Store_Windows Class Referencefinal

`#include <certstor_windows.h>`

Inheritance diagram for Botan::Certificate_Store_Windows:

## Public Member Functions
std::vector< X509_DN > | all_subjects () const override
bool | certificate_known (const X509_Certificate &cert) const
| Certificate_Store_Windows ()
| Certificate_Store_Windows (const Certificate_Store_Windows &)=default
| Certificate_Store_Windows (Certificate_Store_Windows &&)=default
std::vector< std::shared_ptr< const X509_Certificate > > | find_all_certs (const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const override
std::shared_ptr< const X509_Certificate > | find_cert (const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const override
std::shared_ptr< const X509_Certificate > | find_cert_by_pubkey_sha1 (const std::vector< uint8_t > &key_hash) const override
std::shared_ptr< const X509_Certificate > | find_cert_by_raw_subject_dn_sha256 (const std::vector< uint8_t > &subject_hash) const override
std::shared_ptr< const X509_CRL > | find_crl_for (const X509_Certificate &subject) const override
Certificate_Store_Windows & | operator= (const Certificate_Store_Windows &)=default
Certificate_Store_Windows & | operator= (Certificate_Store_Windows &&)=default

## Detailed Description

Certificate Store that is backed by the system trust store on Windows.

Definition at line 18 of file certstor_windows.h.

## Constructor & Destructor Documentation

Botan::Certificate_Store_Windows::Certificate_Store_Windows | ( |  | ) |

Definition at line 189 of file certstor_windows.cpp.

189 {}

Botan::Certificate_Store_Windows::Certificate_Store_Windows | ( | const Certificate_Store_Windows & |  | ) |
| default

Botan::Certificate_Store_Windows::Certificate_Store_Windows | ( | Certificate_Store_Windows && |  | ) |
| default

## Member Function Documentation

std::vector< X509_DN > Botan::Certificate_Store_Windows::all_subjects | ( |  | ) | const
| override virtual

Returns
  DNs for all certificates managed by the store

Implements Botan::Certificate_Store.

Definition at line 191 of file certstor_windows.cpp.

References Botan::X509_Certificate::subject_dn().

192 {
193 std::vector<X509_DN> subject_dns;
194 for(const auto store_name : cert_store_names)
195 {
196 Handle_Guard<HCERTSTORE> windows_cert_store = open_cert_store(store_name);
197 Handle_Guard<PCCERT_CONTEXT> cert_context = nullptr;
198
199 // Handle_Guard::assign exchanges the underlying pointer. No RAII is needed here, because the Windows API takes care of
200 // freeing the previous context.
201 while(cert_context.assign(CertEnumCertificatesInStore(windows_cert_store.get(), cert_context.get())))
202 {
203 X509_Certificate cert(cert_context->pbCertEncoded, cert_context->cbCertEncoded);
204 subject_dns.push_back(cert.subject_dn());
205 }
206 }
207
208 return subject_dns;
209 }

bool Botan::Certificate_Store::certificate_known | ( | const X509_Certificate & | cert | ) | const
| inline inherited

Returns
  whether the certificate is known

Parameters

  cert | certififcate to be searched

Definition at line 70 of file certstor.h.

References Botan::X509_Certificate::subject_dn(), and Botan::X509_Certificate::subject_key_id().

71 {
72 return find_cert(cert.subject_dn(), cert.subject_key_id()) != nullptr;
73 }
Botan::Certificate_Store::find_cert
virtual std::shared_ptr< const X509_Certificate > find_cert(const X509_DN &subject_dn, const std::vector< uint8_t > &key_id) const =0

Cert_Vector Botan::Certificate_Store_Windows::find_all_certs | ( | const X509_DN & | subject_dn,
|  | const std::vector< uint8_t > & | key_id
| ) |  | const
| override virtual

Find all certificates with a given Subject DN. Subject DN and even the key identifier might not be unique.

Implements Botan::Certificate_Store.

Definition at line 218 of file certstor_windows.cpp.

221 {
222 return find_cert_by_dn_and_key_id(subject_dn, key_id, false);
223 }

Cert_Pointer Botan::Certificate_Store_Windows::find_cert | ( | const X509_DN & | subject_dn,
|  | const std::vector< uint8_t > & | key_id
| ) |  | const
| override virtual

Find a certificate by Subject DN and (optionally) key identifier

Returns
  the first certificate that matches

Implements Botan::Certificate_Store.

Definition at line 211 of file certstor_windows.cpp.

213 {
214 const auto certs = find_cert_by_dn_and_key_id(subject_dn, key_id, true);
215 return certs.empty() ? nullptr : certs.front();
216 }

Cert_Pointer Botan::Certificate_Store_Windows::find_cert_by_pubkey_sha1 | ( | const std::vector< uint8_t > & | key_hash | ) | const
| override virtual

Find a certificate by searching for one with a matching SHA-1 hash of public key.

Returns
  a matching certificate or nullptr otherwise

Implements Botan::Certificate_Store.

Definition at line 225 of file certstor_windows.cpp.

226 {
227 if(key_hash.size() != 20)
228 {
229 throw Invalid_Argument("Certificate_Store_Windows::find_cert_by_pubkey_sha1 invalid hash");
230 }
231
232 CRYPT_HASH_BLOB blob;
233 blob.cbData = static_cast<DWORD>(key_hash.size());
234 blob.pbData = const_cast<BYTE*>(key_hash.data());
235
236 auto filter = [](const Cert_Vector&, Cert_Pointer) { return true; };
237
238 const auto certs = search_cert_stores(blob, CERT_FIND_KEY_IDENTIFIER, filter, true);
239 return certs.empty() ? nullptr : certs.front();
240 }

Cert_Pointer Botan::Certificate_Store_Windows::find_cert_by_raw_subject_dn_sha256 | ( | const std::vector< uint8_t > & | subject_hash | ) | const
| override virtual

Exceptions

  Botan::Not_Implemented |

Implements Botan::Certificate_Store.

Definition at line 242 of file certstor_windows.cpp.

References BOTAN_UNUSED.

244 {
245 BOTAN_UNUSED(subject_hash);
246 throw Not_Implemented("Certificate_Store_Windows::find_cert_by_raw_subject_dn_sha256");
247 }
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142

std::shared_ptr< const X509_CRL > Botan::Certificate_Store_Windows::find_crl_for | ( | const X509_Certificate & | subject | ) | const
| override virtual

Not Yet Implemented

Returns
  nullptr;

Reimplemented from Botan::Certificate_Store.

Definition at line 249 of file certstor_windows.cpp.

References BOTAN_UNUSED.

250 {
251 // TODO: this could be implemented by using the CertFindCRLInStore function
252 BOTAN_UNUSED(subject);
253 return {};
254 }
BOTAN_UNUSED
#define BOTAN_UNUSED(...)
Definition: assert.h:142

Certificate_Store_Windows& Botan::Certificate_Store_Windows::operator= | ( | const Certificate_Store_Windows & |  | ) |
| default

Certificate_Store_Windows& Botan::Certificate_Store_Windows::operator= | ( | Certificate_Store_Windows && |  | ) |
| default

The documentation for this class was generated from the following files:

- src/lib/x509/certstor_system_windows/certstor_windows.h
- src/lib/x509/certstor_system_windows/certstor_windows.cpp