diff options
author | beck <> | 2020-09-15 11:55:14 +0000 |
---|---|---|
committer | beck <> | 2020-09-15 11:55:14 +0000 |
commit | 4abed603e66e229dd22adefec8520b9a472ed533 (patch) | |
tree | 8192c077f2ef8442fec646b97bcbedf8d15e04aa /src/lib/libcrypto/x509/x509_vfy.c | |
parent | ae829e60e2e59d44b8414fe32e951de15367a3f8 (diff) | |
download | openbsd-4abed603e66e229dd22adefec8520b9a472ed533.tar.gz openbsd-4abed603e66e229dd22adefec8520b9a472ed533.tar.bz2 openbsd-4abed603e66e229dd22adefec8520b9a472ed533.zip |
Deduplicate the time validation code between the legacy and new
verification code.
ok jsing@
Diffstat (limited to 'src/lib/libcrypto/x509/x509_vfy.c')
-rw-r--r-- | src/lib/libcrypto/x509/x509_vfy.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c index 8a616b6bc2..99a699f99e 100644 --- a/src/lib/libcrypto/x509/x509_vfy.c +++ b/src/lib/libcrypto/x509/x509_vfy.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: x509_vfy.c,v 1.78 2020/09/14 09:09:08 beck Exp $ */ | 1 | /* $OpenBSD: x509_vfy.c,v 1.79 2020/09/15 11:55:14 beck Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -2004,7 +2004,6 @@ X509_cmp_time_internal(const ASN1_TIME *ctm, time_t *cmp_time, int clamp_notafte | |||
2004 | time_t compare; | 2004 | time_t compare; |
2005 | struct tm tm1, tm2; | 2005 | struct tm tm1, tm2; |
2006 | int ret = 0; | 2006 | int ret = 0; |
2007 | int type; | ||
2008 | 2007 | ||
2009 | if (cmp_time == NULL) | 2008 | if (cmp_time == NULL) |
2010 | compare = time(NULL); | 2009 | compare = time(NULL); |
@@ -2013,30 +2012,9 @@ X509_cmp_time_internal(const ASN1_TIME *ctm, time_t *cmp_time, int clamp_notafte | |||
2013 | 2012 | ||
2014 | memset(&tm1, 0, sizeof(tm1)); | 2013 | memset(&tm1, 0, sizeof(tm1)); |
2015 | 2014 | ||
2016 | type = ASN1_time_parse(ctm->data, ctm->length, &tm1, ctm->type); | 2015 | if (!x509_verify_asn1_time_to_tm(ctm, &tm1, clamp_notafter)) |
2017 | if (type == -1) | ||
2018 | goto out; /* invalid time */ | 2016 | goto out; /* invalid time */ |
2019 | 2017 | ||
2020 | /* RFC 5280 section 4.1.2.5 */ | ||
2021 | if (tm1.tm_year < 150 && type != V_ASN1_UTCTIME) | ||
2022 | goto out; | ||
2023 | if (tm1.tm_year >= 150 && type != V_ASN1_GENERALIZEDTIME) | ||
2024 | goto out; | ||
2025 | |||
2026 | if (clamp_notafter) { | ||
2027 | /* Allow for completely broken operating systems. */ | ||
2028 | if (!ASN1_time_tm_clamp_notafter(&tm1)) | ||
2029 | goto out; | ||
2030 | } | ||
2031 | |||
2032 | /* | ||
2033 | * Defensively fail if the time string is not representable as | ||
2034 | * a time_t. A time_t must be sane if you care about times after | ||
2035 | * Jan 19 2038. | ||
2036 | */ | ||
2037 | if (timegm(&tm1) == -1) | ||
2038 | goto out; | ||
2039 | |||
2040 | if (gmtime_r(&compare, &tm2) == NULL) | 2018 | if (gmtime_r(&compare, &tm2) == NULL) |
2041 | goto out; | 2019 | goto out; |
2042 | 2020 | ||