Added big boy Makefile and updated README accordingly.
[bcr-a2csamples.git] / printcert / printcert.c
blob8e66c88dc8128df0f4e9a8d5fe40c86821f9092a
1 #include "rfc3280.h"
3 #include "util.h"
5 static void print_attribute_value(A2C_OPEN_TYPE* value)
7 PBYTE string = NULL;
9 if (_A2C_PrintToMemory(value->objectPtr, value->functionPtr, &string) == A2C_ERROR_Success)
11 printf("%s\n", string);
13 free(string);
17 static void print_name_email_addresses(Cert_Name* name)
19 int counter = 0;
21 for (counter = 0;counter < name->rdnSequence.count;++counter)
23 int rdn_counter = 0;
25 for (rdn_counter = 0;rdn_counter < name->rdnSequence.array[counter].count;++rdn_counter)
27 Cert_AttributeTypeAndValue* attribute = &(name->rdnSequence.array[counter].array[rdn_counter]);
29 if (_A2C_OIDS_EQUAL(&(attribute->type), Cert_emailAddress.id))
31 print_attribute_value(&attribute->value);
37 static void print_subject_alt_name_email_addresses(Cert_Extensions* extensions)
39 int counter = 0;
41 for (counter = 0;counter < extensions->count;++counter)
43 if (_A2C_OIDS_EQUAL(&extensions->array[counter].extnID, &CertImpl_id_ce_subjectAltName))
45 CertImpl_GeneralNames* names = NULL;
46 A2C_ERROR err = A2C_ERROR_Success;
47 int names_counter = 0;
49 err = A2C_DecodeBer(
50 (PVOID*) &names,
51 &CertImpl_GeneralNames_descriptor,
53 NULL,
54 extensions->array[counter].extnValue.data,
55 extensions->array[counter].extnValue.length
57 if (err < A2C_ERROR_Success)
59 return;
62 for (names_counter = 0;names_counter < names->count;++names_counter)
64 if (names->array[names_counter].index == CertImpl_GeneralName_rfc822Name_index)
66 printf("%s\n", names->array[names_counter].rfc822Name.string);
70 (void) A2C_Free(names, &CertImpl_GeneralNames_descriptor);
75 int main(int argc, char** argv)
77 Cert_Certificate* certificate = NULL;
79 certificate = read_certificate_from_file(argv[1]);
80 if (certificate != NULL)
82 print_name_email_addresses(&certificate->toBeSigned.subject);
83 print_subject_alt_name_email_addresses(&certificate->toBeSigned.extensions);