On Sat, Jun 13, 2009 at 11:14:30AM +1000, Tim Hudson wrote:

> Martin Kaiser wrote:
>> Hi Jerry,
>> Thus wrote Jerry Wang (jerry...@gmail.com):
>>> Does OpenSSL have a function for getting the common name from a X509
>>> certificate?
>> how about something like
>> X509 *cert;
>> X509_NAME *subjectName;
>> char  subjectCn[256];
>>    subjectName = X509_get_subject_name(cert);
>> X509_NAME_get_text_by_NID(
>>     subjectName, NID_commonName, subjectCn, sizeof(subjectCn));
>
> Also look at X509_NAME_oneline() and X509_NAME_print_ex() which may be 
> closer to what you are looking for depending on your context.

Not also, rather, from the manpage for X509_NAME_get_text_by_NID(3):

       X509_NAME_get_text_by_NID() and X509_NAME_get_text_by_OBJ() are legacy
       functions which have various limitations which make them of minimal use
       in practice. They can only find the first matching entry and will copy
       the contents of the field verbatim: this can be highly confusing if the
       target is a muticharacter string type like a BMPString or a UTF8String.

       For a more general solution X509_NAME_get_index_by_NID() or
       X509_NAME_get_index_by_OBJ() should be used followed by
       X509_NAME_get_entry() on any matching indices and then the various
       X509_NAME_ENTRY utility functions on the result.

-- 
        Viktor.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to