2

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?

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
2vision2
  • 4,933
  • 16
  • 83
  • 164
  • I found the code in this link http://stackoverflow.com/questions/566570/how-can-i-install-a-certificate-into-the-local-machine-store-programmatically-us?answertab=active#tab-top , I intend to do the same but with C programming. – 2vision2 May 24 '12 at 06:15

2 Answers2

4

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.

Dmitry Zagorulkin
  • 8,370
  • 4
  • 37
  • 60
  • I need to use it in my code and it looks like its developed by sunmicrosyste... Is it an opensource?? – 2vision2 May 24 '12 at 07:37
2

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;

}
elhadi dp ıpɐɥןǝ
  • 4,763
  • 2
  • 30
  • 34