Cryptography Reference
In-Depth Information
typeValuePair = typeValuePair->next;
}
return 0;
}
As you can see, after you've decided how to represent a distinguished name,
parsing it isn't complex, although it is a bit tedious.
Following the issuer name is the validity structure that tells the user between
which dates the certifi cate is valid. It is parsed in Listing 5-18.
Listing 5-18: “parse_validity”
static int parse_validity( validity_period *target, struct asn1struct *source )
{
struct asn1struct *not_before;
struct asn1struct *not_after;
struct tm not_before_tm;
struct tm not_after_tm;
not_before = source->children;
not_after = not_before->next;
// Convert time instances into time_t
if ( sscanf( ( char * ) not_before->data, “%2d%2d%2d%2d%2d%2d”,
&not_before_tm.tm_year, &not_before_tm.tm_mon, &not_before_tm.tm_mday,
&not_before_tm.tm_hour, &not_before_tm.tm_min, &not_before_tm.tm_sec ) < 6 )
{
fprintf( stderr, “Error parsing not before; malformed date.” );
return 6;
}
if ( sscanf( ( char * ) not_after->data, “%2d%2d%2d%2d%2d%2d”,
&not_after_tm.tm_year, &not_after_tm.tm_mon, &not_after_tm.tm_mday,
&not_after_tm.tm_hour, &not_after_tm.tm_min, &not_after_tm.tm_sec ) < 6 )
{
fprintf( stderr, “Error parsing not after; malformed date.” );
return 7;
}
not_before_tm.tm_year += 100;
not_after_tm.tm_year += 100;
not_before_tm.tm_mon -= 1;
not_after_tm.tm_mon -= 1;
// TODO account for TZ information on end
target->notBefore = mktime( &not_before_tm );
target->notAfter = mktime( &not_after_tm );
return 0;
}
 
Search WWH ::




Custom Search