473,395 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

x509 certificates

Hi PHP folks,

Does anybody know a way to read the extension fields from a x509
certificate?
Maybe there is a better PHP module than openssl.
Until a better sollution came up, I did some changes to the openssl
PHP module,
I added the following lines, but here is still more to work (I hope
some developer from PHP hear me and give me a help):

Thanks in advance.
Sergiu.

/* {{{ proto array openssl_x509_parse(mixed x509 [, bool
shortnames=true])
Returns an array of the fields/values of the CERT */
PHP_FUNCTION(openssl_x509_parse)
{
zval * zcert;
X509 * cert = NULL;
long certresource = -1;
int i;
zend_bool useshortnames = 1;
char * tmpstr;
zval * subitem;
X509_EXTENSION *extension;
ASN1_OCTET_STRING *extdata;
char extstr[20];

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &zcert,
&useshortnames) == FAILURE)
return;

cert = php_openssl_x509_from_zval(&zcert, 0, &certresource
TSRMLS_CC);
if (cert == NULL)
RETURN_FALSE;

array_init(return_value);

if (cert->name)
add_assoc_string(return_value, "name", cert->name, 1);
/* add_assoc_bool(return_value, "valid", cert->valid); */

add_assoc_name_entry(return_value, "subject",
X509_get_subject_name(cert), useshortnames TSRMLS_CC);
/* hash as used in CA directories to lookup cert by subject name */
{
char buf[32];
snprintf(buf, sizeof(buf), "%08lx", X509_subject_name_hash(cert));
add_assoc_string(return_value, "hash", buf, 1);
}

add_assoc_name_entry(return_value, "issuer",
X509_get_issuer_name(cert), useshortnames TSRMLS_CC);
add_assoc_long(return_value, "version", X509_get_version(cert));
add_assoc_long(return_value, "serialNumber",
ASN1_INTEGER_get(X509_get_serialNumber(cert)));

add_assoc_asn1_string(return_value, "validFrom",
X509_get_notBefore(cert));
add_assoc_asn1_string(return_value, "validTo",
X509_get_notAfter(cert));

add_assoc_long(return_value, "validFrom_time_t",
asn1_time_to_time_t(X509_get_notBefore(cert) TSRMLS_CC));
add_assoc_long(return_value, "validTo_time_t",
asn1_time_to_time_t(X509_get_notAfter(cert) TSRMLS_CC));

tmpstr = X509_alias_get0(cert, NULL);
if (tmpstr)
add_assoc_string(return_value, "alias", tmpstr, 1);

/*
add_assoc_long(return_value, "signaturetypeLONG",
X509_get_signature_type(cert));
add_assoc_string(return_value, "signaturetype",
OBJ_nid2sn(X509_get_signature_type(cert)), 1);
add_assoc_string(return_value, "signaturetypeLN",
OBJ_nid2ln(X509_get_signature_type(cert)), 1);
*/
MAKE_STD_ZVAL(subitem);
array_init(subitem);

/* NOTE: the purposes are added as integer keys - the keys match up
to the X509_PURPOSE_SSL_XXX defines
in x509v3.h */
for (i = 0; i < X509_PURPOSE_get_count(); i++) {
int id, purpset;
char * pname;
X509_PURPOSE * purp;
zval * subsub;

MAKE_STD_ZVAL(subsub);
array_init(subsub);

purp = X509_PURPOSE_get0(i);
id = X509_PURPOSE_get_id(purp);

purpset = X509_check_purpose(cert, id, 0);
add_index_bool(subsub, 0, purpset);

purpset = X509_check_purpose(cert, id, 1);
add_index_bool(subsub, 1, purpset);

pname = useshortnames ? X509_PURPOSE_get0_sname(purp) :
X509_PURPOSE_get0_name(purp);
add_index_string(subsub, 2, pname, 1);

/* NOTE: if purpset > 1 then it's a warning - we should mention it ?
*/

add_index_zval(subitem, id, subsub);
}
add_assoc_zval(return_value, "purposes", subitem);

/* Adding extension support by Sergiu */
add_assoc_string(return_value, "extensions added", "true", 1);
for (i = 0; i < X509_get_ext_count(cert); i++) {
extension = X509_get_ext(cert, i);
extdata = X509_EXTENSION_get_data(extension);
sprintf(extstr, "ext%i", i);
add_assoc_asn1_string(return_value, extstr, extdata);
}

if (certresource == -1 && cert)
X509_free(cert);

}
/* }}} */
Jul 16 '05 #1
0 3563

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gustavo Quinteros | last post by:
I'm trying to sign a XML with a X509 Certificate (Like an email), and store it in a database. I want to include the certificate in the XML in order to display the certificate properties (like...
0
by: Carlos Guzmán Álvarez | last post by:
Hello: I want to know if there are any class on the .NET Framework for allow validation of X509 certificates. Thanks in advance.
6
by: Mattia Saccotelli | last post by:
Hi I would like to encrypt data using AES (Rijndael) algorithm, providing as the key the key from a given certificate. Just for testing I'm using the public key.. Shouldn't I use the private...
1
by: KlassifiedBBS | last post by:
Does anyone know if there is any sample code to create a x509 certificate out there - I'll buy a book if it has the code in it. I have spent a couple of days digging around in the...
1
by: rds | last post by:
We are developing a smart client application which consumes web services. The web services are being secured with X509 certificates. During the development/testing phase we have been using the X509...
0
by: WhyOhWhy | last post by:
Hi There, I need to be able to pull a certificate out of an Active Directory Certificate store, rather than a local file-based store (such as Local Machine or Current User), With .NET 2.0 and...
2
by: David G | last post by:
My company has a Webservice that is currently running in production. It is secured using SSL and clients are authenticated using X509 certificates. I am able to consume the Webservice methods in...
0
by: Chaz Ginger | last post by:
I have been looking for a server application as an example of how to use TLSLite or PyOpenSSL X509 certificates for authentication. Does any one have a pointer or two? Peace, Chaz
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.