2vision2
2vision2

Reputation: 5023

C code equivalent of C# to install certificate

I found the below code to install a certificate into local machines trusted publisher. But the code is in C# I want the same to be done in C. How to convert this to C?

private static void InstallCertificate(string cerFileName)
{
  X509Certificate2 certificate = new X509Certificate2(cerFileName);
  X509Store store = new X509Store(StoreName.TrustedPublisher,StoreLocation.LocalMachine);
  store.Open(OpenFlags.ReadWrite);
  store.Add(certificate);
  store.Close();
 }

Any Windows APIS available?

Upvotes: 2

Views: 915

Answers (2)

elhadi dp ıpɐɥןǝ
elhadi dp ıpɐɥןǝ

Reputation: 5201

try this example:

#include <openssl/ssl.h>
static int store_cert(SSL_CTX * ctx, X509 * cert)
{
    X509_STORE * x509_store;

    x509_store=SSL_CTX_get_cert_store(ctx);

    if (X509_STORE_add_cert(x509_store, cert)==0)
    {
        printf("ERROR: add certificate\n");
        return 0;
    }
    return 1;

}

Upvotes: 2

Dmitry Zagorulkin
Dmitry Zagorulkin

Reputation: 8548

Try to look at libpkix lib

The purpose of the libpkix library is to provide a widely useful C library for building and validating chains of X.509 certificates, compliant with the latest IETF PKIX standards (namely, RFC 3280). This project aims to provide complete support for all the mandatory features of RFC 3280, as well as a number of optional features.

Upvotes: 4

Related Questions