1
#include "MSX509CertStore.h"
2
#include "X509CertStore_p.h"
8
#include <openssl/err.h>
10
using namespace digidoc;
13
* Loads all certificates from system store and adds these to the certificate store.
15
* @throws IOException exception is throws if failed to open certstore
17
MSX509CertStore::MSX509CertStore() throw(IOException)
21
INFO("Loaded %d certificates into certificate store.", sk_X509_num(d->stack));
25
* Load all certificates found in CertStore and adds these to the cert store.
27
* @param provider name.
28
* @throws IOException exception is throws if failed open CertStore.
30
void MSX509CertStore::loadCerts(const std::string &provider) throw(IOException)
32
HCERTSTORE s = CertOpenStore(CERT_STORE_PROV_SYSTEM_A,
33
X509_ASN_ENCODING, 0, CERT_SYSTEM_STORE_CURRENT_USER, provider.c_str() );
35
THROW_IOEXCEPTION("Failed to ope CertStore with provider %s, can not load cert store.", provider.c_str());
37
PCCERT_CONTEXT pc = 0;
38
while((pc = CertEnumCertificatesInStore(s, pc)))
40
const unsigned char *pBytes = pc->pbCertEncoded;
41
X509 *c = d2i_X509(0, &pBytes, pc->cbCertEncoded);
43
WARN("Cant add cert %ld to X509_STORE, %s", ASN1_INTEGER_get(X509_get_serialNumber(c)), ERR_reason_error_string(ERR_get_error()));
44
sk_X509_push(d->stack, c);
45
if(!X509_STORE_add_cert(d->store, c))
46
WARN("Cant add cert %ld to X509_STORE, %s", ASN1_INTEGER_get(X509_get_serialNumber(c)), ERR_reason_error_string(ERR_get_error()));