void main(void)
{ X509 *cert = NULL; BIO *certBio = NULL; X509_EXTENSION *keyUsage = NULL; STACK_OF (X509_EXTENSION) *exts = NULL; ASN1_STRING *strUsage = NULL; void *Usage = NULL; X509V3_EXT_METHOD *method; STACK_OF(CONF_VALUE) *nval = NULL; CONF_VALUE *uval = NULL; int cnt = 0; /* Total extension in certificate */ int pos = 0; /* Position of the extension */ int critical = 0; /* Critical value */ OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); certBio = BIO_new(BIO_s_mem()); if (!(certBio = BIO_new_mem_buf (certBuf, -1))) { printf("Error reading certificate\n"); exit(0); } cert = PEM_read_bio_X509(certBio,NULL,NULL,NULL); cnt = X509_get_ext_count(cert); pos = X509_get_ext_by_NID(cert, NID_key_usage, -1); keyUsage = X509_get_ext(cert,pos); /* This is just a generic print key usage function */ /* See the OpenSSL source for more details */ /* See v3_prn.c openssl/crypto/x509v3/v3_prn.c */ method = X509V3_EXT_get(keyUsage); if(method->it) Usage = ASN1_item_d2i(NULL,&keyUsage->value->data,keyUsage->value->length, ASN1_ITEM_ptr(method->it)); else Usage = method->d2i(NULL, &keyUsage->value->data, keyUsage->value->length); if(method->i2v) { int cnt = 0; nval = method->i2v(method, Usage, NULL); cnt = sk_CONF_VALUE_num(nval); // The number of key usage extensions uval = sk_CONF_VALUE_value(nval, 0); // First ext printf("%s\n",uval->name); /* You can save uval->name to a buffer or use a pointer value */ uval = sk_CONF_VALUE_value(nval, 1); // Second ext printf("%s\n",uval->name); } } ----- Original Message ----- From: "Shivaram Mysore" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, July 05, 2004 12:42 PM Subject: question regarding getting keyusage info into a char * > Hi, > > I am interested in getting only the key usage info > from a X509 cert in C. > > I can print this by: > X509V3_EXT_print_fp(stdout, X509_get_ext(my_x509cert, > (X509_get_ext_by_NID(my_x509cert, > OBJ_sn2nid(SN_key_usage), -1))), 0, 0); > > If my cert has the following info: > > key usage: Digital Signature, Non Repudiation, Key > Encipherment, Data Encipherment, Key Agreement > > and I want to get the values into a say a char * how > can I do it. > > Any help is greatly appreciated. > > Thanks > > /Shivaram > > > > > __________________________________ > Do you Yahoo!? > Yahoo! Mail - 50x more storage than other providers! > http://promotions.yahoo.com/new_mail > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List [EMAIL PROTECTED] > Automated List Manager [EMAIL PROTECTED] ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]