c++ - How do you verify a public key was issued by your private CA? -


I created a CA certificate, and anyone on it is used to issue public key in the future, I Verify that the loaded certificate was issued by my CA.

How can I do this with the OpenSSL API (c ++)?

I verification required minimum functions. C is lowered (openssl / apps /). Concepts: Certificates and CA certificates are both PEM format files, no CRLS or reliable list checks are required.

Verify the call () with the path to your certificate and CA PEM files.

  Verify fixed int (const char * certfile, const four * cafile); Static X509 * LoadCart (const char * file); Fixed int check (X509_STORE * CTX, Const four * file); Int Verify (Const char * certfile, const char * CAfile) {int ret = 0; X509_STORE * cert_ctx = NULL; X509_LOOKUP * Lookup = Faucet; Cert_ctx = x509_STORE_new (); If (cert_ctx == faucet) goto end; OpenSSL_add_all_algorithms (); View = X509_STORE_add_lookup (cert_ctx, X509_LOOKUP_file ()); If (lookup == tap) goto end; If (! X509_LOOKUP_load_file (Lookup, CAfile, X509_FILETYPE_PEM)) goto end; View = X509_STORE_add_lookup (cert_ctx, X509_LOOKUP_hash_dir ()); If (lookup == tap) goto end; X509_LOOKUP_add_dir (see, zero, X509_FILETYPE_DEFAULT); Rate = check (strict_tactics, certfile); Inter: if (cert_ctx! = NULL) X509_STORE_free (cert_ctx); Return writ; } Fixed X509 * load_ cert (console four * file) {X50 9 * x = NULL; Bio * certificate; If the end ((cert = BIO_new (BIO_s_file ())) == NULL goto end; if (BIO_read_filename (cert, file) & lt; = 0) goto end; X = PEM_read_bio_X509_AUX (evidence, zero, zero, zero);: If (cert! = NULL) BIO_free (cert); return (x);} static Int Czech (X509_STORE * ctx, const char * file) {X509 * x = NULL; Int i = 0, ret = 0; X50 9_STORE_CTX * CSC; X = load_cert (file); if (x == null) goto end; CSC = X509_STORE_CTX_new (); if (CSC == null) goto end; x 50 9_STORE_set_flags (Sitiaks, 0); if (! X50 9_STORE_CTX_init ( CSC, Sitiaks, x, 0)) goto end; i = X509_verify_cert (CSC); X509_STORE_CTX_free (CSC), retired Appropriate = 0; end: Rate = (i & gt; 0); if (x! = NULL) X509_free (x); return (ret);}  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -