Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7673227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:27:48+00:00 2026-05-31T16:27:48+00:00

Working with the OpenSSL library in c, what is the best way to load

  • 0

Working with the OpenSSL library in c, what is the best way to load a complete certificate chain from a PEM file into memory? The input is a single PEM file with 1..n certificates concatenated, the output should be a STACK_OF(X509)*.

For single certificates, the easiest way to load them is as follows:

SSL_CTX *sslctx = SSL_CTX_new(SSLv23_server_method());
SSL_CTX_use_certificate_file(sslctx, "certificate.pem", SSL_FILETYPE_PEM);
SSL *ssl = SSL_new(sslctx);
X509 *crt = SSL_get_certificate(ssl);

(error handling, resource freeing and reference counting omitted for clarity; using C99 syntax; “easy” meaning “avoiding lower level BIO and ASN.1 APIs”)

However, for complete certificate chains, SSL_CTX_use_certificate_chain_file() can be used to load them into the SSL_CTX and the first certificate can then be retrieved using SSL_get_certificate(), but there seems to be no API function to retrieve the rest of the certificate chain from an SSL context.

So what is the best way to load a certificate chain from a file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:27:49+00:00Added an answer on May 31, 2026 at 4:27 pm

    The function SSL_CTX_use_certificate_chain_file puts the certificate into SSL_CTX::cert and all additional certificates in the chain (additional CA cetrificates) into SSL_CTX::extra_certs which type is STACK_OF(X509)*, so to get your additional chain:

    STACK_OF(X509)* ca_stack = sslctx->extra_certs;
    

    I could not find any macro or function that can give you the extra_cets field without accessing it directly in SSL_CTX structure, but looking at the OpenSSL code they do access it directly everywhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following working code to decrypt a file: #include <openssl/aes.h> #include <stdio.h>
i'm working with OpenSSL lib and get very strange effect with AES encrypt/decrypt: if
Working on a simple poker script in PHP and need a way to determine
My .htaccess file isn't working. I have checked that it is in the root
Does anybody have any working example of RSA encryption with OpenSSL.NET ? I want
The project that I'm working on could benefit from having the possibility to easily
I am trying to use openssl to get a certificate, and it seems to
I have been working on a Ruby Script that enters in data into a
I'm working through a tutorial on using OpenSSL and when I try something rather
my situation: I am working on a application that is using openssl and rsa-certificates

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.