Allow callers to force ASN.1 date encoding as GENERALIZEDTIME.
This commit is contained in:
@@ -426,9 +426,8 @@ time_t asn1_to_time(const chunk_t *utctime, asn1_t type)
|
||||
/**
|
||||
* Convert a date into ASN.1 UTCTIME or GENERALIZEDTIME format
|
||||
*/
|
||||
chunk_t asn1_from_time(const time_t *time)
|
||||
chunk_t asn1_from_time(const time_t *time, asn1_t type)
|
||||
{
|
||||
asn1_t type;
|
||||
int offset;
|
||||
const char *format;
|
||||
char buf[BUF_LEN];
|
||||
@@ -437,8 +436,10 @@ chunk_t asn1_from_time(const time_t *time)
|
||||
|
||||
gmtime_r(time, &t);
|
||||
/* RFC 5280 says that dates through the year 2049 MUST be encoded as UTCTIME
|
||||
* and dates in 2050 or later MUST be encoded as GENERALIZEDTIME */
|
||||
type = (t.tm_year < 150) ? ASN1_UTCTIME : ASN1_GENERALIZEDTIME;
|
||||
* and dates in 2050 or later MUST be encoded as GENERALIZEDTIME. We only
|
||||
* enforce the latter to avoid overflows but allow callers to force the
|
||||
* encoding to GENERALIZEDTIME */
|
||||
type = (t.tm_year >= 150) ? ASN1_GENERALIZEDTIME : type;
|
||||
if (type == ASN1_GENERALIZEDTIME)
|
||||
{
|
||||
format = "%04d%02d%02d%02d%02d%02dZ";
|
||||
|
||||
@@ -191,12 +191,13 @@ time_t asn1_to_time(const chunk_t *utctime, asn1_t type);
|
||||
/**
|
||||
* Converts time_t to an ASN.1 UTCTIME or GENERALIZEDTIME string
|
||||
*
|
||||
* The type is automatically chosen based on the encoded year.
|
||||
* @note The type is automatically changed to GENERALIZEDTIME if needed
|
||||
*
|
||||
* @param time time_t in UTC
|
||||
* @param type ASN1_UTCTIME or ASN1_GENERALIZEDTIME
|
||||
* @return body of an ASN.1 code time object
|
||||
*/
|
||||
chunk_t asn1_from_time(const time_t *time);
|
||||
chunk_t asn1_from_time(const time_t *time, asn1_t type);
|
||||
|
||||
/**
|
||||
* Parse an ASN.1 UTCTIME or GENERALIZEDTIME object
|
||||
|
||||
Reference in New Issue
Block a user