Answer the question
In order to leave comments, you need to log in
How to add CA certificate to Trusted Publisher using WinAPI?
I'm trying to add the CA certificate in the store (current user) to trusted.
#include <QCoreApplication>
#include <QFile>
#include <QDebug>
#include <windows.h>
#include <Wincrypt.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if ( argc == 1 ) {
qDebug() << "Enter path to certificate";
return 1;
} else if ( argc > 2 ) {
qDebug() << "Too much parameters";
return 1;
}
QString fileName = argv[1];
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) return 1;
QByteArray blob = file.readAll();
HCERTSTORE systemStore = CertOpenStore(
CERT_STORE_PROV_SYSTEM,
0,
0,
CERT_SYSTEM_STORE_CURRENT_USER,
L"Trusted Publisher");
qDebug() << "Store pointer";
qDebug() << systemStore;
unsigned char* blob2 = reinterpret_cast<unsigned char*>( blob.data( ) );
PCCERT_CONTEXT context = CertCreateCertificateContext( ( X509_ASN_ENCODING | PKCS_7_ASN_ENCODING ), blob2, blob.size() );
qDebug() << "New context";
qDebug() << &context;
PCCERT_CONTEXT newContext;
bool ok = CertAddCertificateContextToStore( systemStore, context, CERT_STORE_ADD_REPLACE_EXISTING, NULL );
if (!ok)
{
qDebug() << "Could not add certificate to system store!";
qDebug() << GetLastError();
}
CertFreeCertificateContext(context);
return a.exec();
}
Program received signal SIGSEGV, Segmentation fault.
0x75154c84 in CertAddCertificateContextToStore ()
from C:\Windows\SysWOW64\crypt32.dll
(gdb) bt
#0 0x75154c84 in CertAddCertificateContextToStore ()
from C:\Windows\SysWOW64\crypt32.dll
#1 0x00401859 in main (argc=2, argv=0x6a1278) at main.cpp:56
(gdb)
Answer the question
In order to leave comments, you need to log in
qDebug() << &context;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question