|
@@ -20,6 +20,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
20
|
20
|
|
21
|
21
|
#include <string.h>
|
22
|
22
|
#include <ctype.h>
|
|
23
|
+#include <time.h>
|
23
|
24
|
#include <errno.h>
|
24
|
25
|
#include <assert.h>
|
25
|
26
|
#include <ipxe/asn1.h>
|
|
@@ -331,6 +332,7 @@ static int x509_parse_time ( struct x509_certificate *cert,
|
331
|
332
|
} __attribute__ (( packed )) named;
|
332
|
333
|
uint8_t raw[7];
|
333
|
334
|
} pairs;
|
|
335
|
+ struct tm tm;
|
334
|
336
|
const uint8_t *data;
|
335
|
337
|
size_t remaining;
|
336
|
338
|
unsigned int tens;
|
|
@@ -395,12 +397,16 @@ static int x509_parse_time ( struct x509_certificate *cert,
|
395
|
397
|
}
|
396
|
398
|
|
397
|
399
|
/* Fill in time */
|
398
|
|
- time->year = ( ( pairs.named.century * 100 ) + pairs.named.year );
|
399
|
|
- time->month = pairs.named.month;
|
400
|
|
- time->day = pairs.named.day;
|
401
|
|
- time->hour = pairs.named.hour;
|
402
|
|
- time->minute = pairs.named.minute;
|
403
|
|
- time->second = pairs.named.second;
|
|
400
|
+ tm.tm_year = ( ( ( pairs.named.century - 19 ) * 100 ) +
|
|
401
|
+ pairs.named.year );
|
|
402
|
+ tm.tm_mon = ( pairs.named.month - 1 );
|
|
403
|
+ tm.tm_mday = pairs.named.day;
|
|
404
|
+ tm.tm_hour = pairs.named.hour;
|
|
405
|
+ tm.tm_min = pairs.named.minute;
|
|
406
|
+ tm.tm_sec = pairs.named.second;
|
|
407
|
+
|
|
408
|
+ /* Convert to seconds since the Epoch */
|
|
409
|
+ time->time = mktime ( &tm );
|
404
|
410
|
|
405
|
411
|
return 0;
|
406
|
412
|
}
|
|
@@ -492,17 +498,13 @@ static int x509_parse_validity ( struct x509_certificate *cert,
|
492
|
498
|
/* Parse notBefore */
|
493
|
499
|
if ( ( rc = x509_parse_time ( cert, not_before, &cursor ) ) != 0 )
|
494
|
500
|
return rc;
|
495
|
|
- DBGC ( cert, "X509 %p valid from %04d-%02d-%02d %02d:%02d:%02d\n",
|
496
|
|
- cert, not_before->year, not_before->month, not_before->day,
|
497
|
|
- not_before->hour, not_before->minute, not_before->second );
|
|
501
|
+ DBGC ( cert, "X509 %p valid from time %lld\n", cert, not_before->time );
|
498
|
502
|
asn1_skip_any ( &cursor );
|
499
|
503
|
|
500
|
504
|
/* Parse notAfter */
|
501
|
505
|
if ( ( rc = x509_parse_time ( cert, not_after, &cursor ) ) != 0 )
|
502
|
506
|
return rc;
|
503
|
|
- DBGC ( cert, "X509 %p valid until %04d-%02d-%02d %02d:%02d:%02d\n",
|
504
|
|
- cert, not_after->year, not_after->month, not_after->day,
|
505
|
|
- not_after->hour, not_after->minute, not_after->second );
|
|
507
|
+ DBGC ( cert, "X509 %p valid until time %lld\n", cert, not_after->time );
|
506
|
508
|
|
507
|
509
|
return 0;
|
508
|
510
|
}
|