version 1.313, 2018/02/23 15:58:38 |
version 1.314, 2018/03/12 00:52:01 |
|
|
return now + (u_int64_t)(secs * mul); |
return now + (u_int64_t)(secs * mul); |
} |
} |
|
|
static u_int64_t |
|
parse_absolute_time(const char *s) |
|
{ |
|
struct tm tm; |
|
time_t tt; |
|
char buf[32], *fmt; |
|
|
|
/* |
|
* POSIX strptime says "The application shall ensure that there |
|
* is white-space or other non-alphanumeric characters between |
|
* any two conversion specifications" so arrange things this way. |
|
*/ |
|
switch (strlen(s)) { |
|
case 8: |
|
fmt = "%Y-%m-%d"; |
|
snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2s", s, s + 4, s + 6); |
|
break; |
|
case 14: |
|
fmt = "%Y-%m-%dT%H:%M:%S"; |
|
snprintf(buf, sizeof(buf), "%.4s-%.2s-%.2sT%.2s:%.2s:%.2s", |
|
s, s + 4, s + 6, s + 8, s + 10, s + 12); |
|
break; |
|
default: |
|
fatal("Invalid certificate time format \"%s\"", s); |
|
} |
|
|
|
memset(&tm, 0, sizeof(tm)); |
|
if (strptime(buf, fmt, &tm) == NULL) |
|
fatal("Invalid certificate time %s", s); |
|
if ((tt = mktime(&tm)) < 0) |
|
fatal("Certificate time %s cannot be represented", s); |
|
return (u_int64_t)tt; |
|
} |
|
|
|
static void |
static void |
parse_cert_times(char *timespec) |
parse_cert_times(char *timespec) |
{ |
{ |
|
|
cert_valid_from = parse_relative_time(from, now); |
cert_valid_from = parse_relative_time(from, now); |
else if (strcmp(from, "always") == 0) |
else if (strcmp(from, "always") == 0) |
cert_valid_from = 0; |
cert_valid_from = 0; |
else |
else if (parse_absolute_time(from, &cert_valid_from) != 0) |
cert_valid_from = parse_absolute_time(from); |
fatal("Invalid from time \"%s\"", from); |
|
|
if (*to == '-' || *to == '+') |
if (*to == '-' || *to == '+') |
cert_valid_to = parse_relative_time(to, now); |
cert_valid_to = parse_relative_time(to, now); |
else if (strcmp(to, "forever") == 0) |
else if (strcmp(to, "forever") == 0) |
cert_valid_to = ~(u_int64_t)0; |
cert_valid_to = ~(u_int64_t)0; |
else |
else if (parse_absolute_time(to, &cert_valid_to) != 0) |
cert_valid_to = parse_absolute_time(to); |
fatal("Invalid to time \"%s\"", to); |
|
|
if (cert_valid_to <= cert_valid_from) |
if (cert_valid_to <= cert_valid_from) |
fatal("Empty certificate validity interval"); |
fatal("Empty certificate validity interval"); |