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 8768567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:06:08+00:00 2026-06-13T17:06:08+00:00

I am trying to parse an x509v3 certificate. I’ve pieced together how to get

  • 0

I am trying to parse an x509v3 certificate. I’ve pieced together how to get all of the parts I need except the URI field in the subject alternative name. I have the following code. When I change my subject alt name fields around in the config file I use to create my test certs, I see the appropriate changes to the count, SA, and Type output, so it appears to be reading in the right area for SA URIs. However, my SA output always comes out as “1”, so it does not appear to be the right struct member, as I have a name in my URI field.

From the cert text output (via the openssl command):

X509v3 Subject Alternative Name: 
URI:ThisIsTheUri, email:foo@bar.com

The Code:

GENERAL_NAMES* subjectAltNames =
               (GENERAL_NAMES*)X509_get_ext_d2i(&certificate, NID_subject_alt_name, NULL, NULL);

boost::int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames);
std::cout << "Alt Name Count: " << altNameCount << "." << std::endl;
for (boost::int32_t i = 0; i < altNameCount; ++i)
{
  GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i);
  if (generalName->type == GEN_URI)
  {
    subjectAltName = std::string(reinterpret_cast<char*>(generalName->d.ia5->data));
    // subjectAltName should be "ThisIsTheUri", but is "1".
    std::cout << "SA: '" << subjectAltName << "'." << std::endl;
  }
  else
  {
    std::cout << "Type: '" << generalName->type << "'." << std::endl;
  }
}
  • 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-06-13T17:06:09+00:00Added an answer on June 13, 2026 at 5:06 pm

    The trick is to use ASN1_STRING_data() and ASN1_STRING_length() to extract the ia5 string:

    std::string(reinterpret_cast<char*>(ASN1_STRING_data(generalName->d.uniformResourceIdentifier)),
                ASN1_STRING_length(generalName->d.uniformResourceIdentifier));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to parse the RSS feed from www.ted.com/talks/rss, I can access all normal
Trying to parse out this xml file to get a list of Elements but
I'm trying to parse a web page, but when I want to get a
I am trying to parse an html page but I need to filter the
Trying to parse a csv file that has all the data wrapped in double
Trying to parse time from string, but get this error. Tried few formatting string.
Am trying to parse this HTML document to get the contents of flight, time,
trying ot parse the push I geting with my app. but i get some
When trying to parse the following file, I get the error [10,4]: [ERR 101]
im trying to parse the following string; data[Product][0][fieldname] i need to be able to

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.