Cryptography Reference
In-Depth Information
free_x500_name( &certificate->tbsCertificate.subject );
free_huge(
certificate->tbsCertificate.subjectPublicKeyInfo.rsa_public_key.modulus );
free_huge(
certificate->tbsCertificate.subjectPublicKeyInfo.rsa_public_key.exponent );
free(
certificate->tbsCertificate.subjectPublicKeyInfo.rsa_public_key.modulus );
free(
certificate->tbsCertificate.subjectPublicKeyInfo.rsa_public_key.exponent );
free_huge( &certificate->signature_value );
}
After the signed_x509_certificate structure has been properly initialized,
parsing it involves invoking the parse_asn1_certificate function shown previ-
ously and then selectively copying data values from the asn1struct nodes into
the appropriate locations in the signed_x509_certificate target. The top-level
function that controls this whole process is in Listing 5-13.
Listing 5-13: “x509.c” parse_x509_certifi cate
int parse_x509_certificate( const unsigned char *buffer,
const unsigned int certificate_length,
signed_x509_certificate *parsed_certificate )
{
struct asn1struct certificate;
struct asn1struct *tbsCertificate;
struct asn1struct *algorithmIdentifier;
struct asn1struct *signatureValue;
// First, read the whole thing into a traversable ASN.1 structure
asn1parse( buffer, certificate_length, &certificate );
tbsCertificate = ( struct asn1struct * ) certificate.children;
algorithmIdentifier = ( struct asn1struct * ) tbsCertificate->next;
signatureValue = ( struct asn1struct * ) algorithmIdentifier->next;
if ( parse_tbs_certificate( &parsed_certificate->tbsCertificate,
tbsCertificate ) )
{
fprintf( stderr, “Error trying to parse TBS certificate\n” );
return 42;
}
if ( parse_algorithm_identifier( &parsed_certificate->algorithm,
algorithmIdentifier ) )
{
return 42;
}
if ( parse_signature_value( parsed_certificate, signatureValue ) )
{
return 42;
 
Search WWH ::




Custom Search