diff options
author | beck <> | 2017-08-13 19:47:49 +0000 |
---|---|---|
committer | beck <> | 2017-08-13 19:47:49 +0000 |
commit | 9fc3669524ffd3d0ffaf2b50d35ed87ba2c123f7 (patch) | |
tree | 634fa74bb5ef06aea9f9743d7bd052703b25d395 | |
parent | cde37b72cb59adfc12216ed65e5ec3b132080ec2 (diff) | |
download | openbsd-9fc3669524ffd3d0ffaf2b50d35ed87ba2c123f7.tar.gz openbsd-9fc3669524ffd3d0ffaf2b50d35ed87ba2c123f7.tar.bz2 openbsd-9fc3669524ffd3d0ffaf2b50d35ed87ba2c123f7.zip |
Add ability to clamp a notafter to values representable in a 32 bit time_t
This will only be used in portable. As noted, necessary to
make us conformant to RFC 5280 4.1.2.5.
ok jsing@ bcook@
-rw-r--r-- | src/lib/libcrypto/asn1/a_time_tm.c | 18 | ||||
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_locl.h | 4 | ||||
-rw-r--r-- | src/lib/libcrypto/x509/x509_vfy.c | 26 |
3 files changed, 41 insertions, 7 deletions
diff --git a/src/lib/libcrypto/asn1/a_time_tm.c b/src/lib/libcrypto/asn1/a_time_tm.c index f0afc00be4..48f9f8b5e1 100644 --- a/src/lib/libcrypto/asn1/a_time_tm.c +++ b/src/lib/libcrypto/asn1/a_time_tm.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: a_time_tm.c,v 1.12 2017/05/06 17:12:59 beck Exp $ */ | 1 | /* $OpenBSD: a_time_tm.c,v 1.13 2017/08/13 19:47:49 beck Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2015 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2015 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -58,6 +58,22 @@ ASN1_time_tm_cmp(struct tm *tm1, struct tm *tm2) { | |||
58 | return 0; | 58 | return 0; |
59 | } | 59 | } |
60 | 60 | ||
61 | int | ||
62 | ASN1_time_tm_clamp_notafter(struct tm *tm) | ||
63 | { | ||
64 | #ifdef SMALL_TIME_T | ||
65 | struct tm broken_os_epoch_tm; | ||
66 | time_t broken_os_epoch_time = INT_MAX; | ||
67 | |||
68 | if (gmtime_r(&broken_os_epoch_time, &broken_os_epoch_tm) == NULL) | ||
69 | return 0; | ||
70 | |||
71 | if (ASN1_time_tm_cmp(tm, &broken_os_epoch_tm) == 1) | ||
72 | memcpy(tm, &broken_os_epoch_tm, sizeof(*tm)); | ||
73 | #endif | ||
74 | return 1; | ||
75 | } | ||
76 | |||
61 | /* Format a time as an RFC 5280 format Generalized time */ | 77 | /* Format a time as an RFC 5280 format Generalized time */ |
62 | char * | 78 | char * |
63 | gentime_string_from_tm(struct tm *tm) | 79 | gentime_string_from_tm(struct tm *tm) |
diff --git a/src/lib/libcrypto/asn1/asn1_locl.h b/src/lib/libcrypto/asn1/asn1_locl.h index 17bb4157a9..68f71dfc4a 100644 --- a/src/lib/libcrypto/asn1/asn1_locl.h +++ b/src/lib/libcrypto/asn1/asn1_locl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1_locl.h,v 1.8 2016/12/21 15:49:29 jsing Exp $ */ | 1 | /* $OpenBSD: asn1_locl.h,v 1.9 2017/08/13 19:47:49 beck Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -152,4 +152,6 @@ struct x509_crl_method_st { | |||
152 | int UTF8_getc(const unsigned char *str, int len, unsigned long *val); | 152 | int UTF8_getc(const unsigned char *str, int len, unsigned long *val); |
153 | int UTF8_putc(unsigned char *str, int len, unsigned long value); | 153 | int UTF8_putc(unsigned char *str, int len, unsigned long value); |
154 | 154 | ||
155 | int ASN1_time_tm_clamp_notafter(struct tm *tm); | ||
156 | |||
155 | __END_HIDDEN_DECLS | 157 | __END_HIDDEN_DECLS |
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c index 0d01301446..23ecf63d60 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.64 2017/04/28 23:03:58 beck Exp $ */ | 1 | /* $OpenBSD: x509_vfy.c,v 1.65 2017/08/13 19:47:49 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 | * |
@@ -73,8 +73,9 @@ | |||
73 | #include <openssl/objects.h> | 73 | #include <openssl/objects.h> |
74 | #include <openssl/x509.h> | 74 | #include <openssl/x509.h> |
75 | #include <openssl/x509v3.h> | 75 | #include <openssl/x509v3.h> |
76 | #include "x509_lcl.h" | 76 | #include "asn1_locl.h" |
77 | #include "vpm_int.h" | 77 | #include "vpm_int.h" |
78 | #include "x509_lcl.h" | ||
78 | 79 | ||
79 | /* CRL score values */ | 80 | /* CRL score values */ |
80 | 81 | ||
@@ -137,6 +138,8 @@ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score, | |||
137 | static int check_crl_path(X509_STORE_CTX *ctx, X509 *x); | 138 | static int check_crl_path(X509_STORE_CTX *ctx, X509 *x); |
138 | static int check_crl_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *cert_path, | 139 | static int check_crl_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *cert_path, |
139 | STACK_OF(X509) *crl_path); | 140 | STACK_OF(X509) *crl_path); |
141 | static int X509_cmp_time_internal(const ASN1_TIME *ctm, time_t *cmp_time, | ||
142 | int clamp_notafter); | ||
140 | 143 | ||
141 | static int internal_verify(X509_STORE_CTX *ctx); | 144 | static int internal_verify(X509_STORE_CTX *ctx); |
142 | 145 | ||
@@ -1745,7 +1748,7 @@ x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int depth) | |||
1745 | X509_V_ERR_CERT_NOT_YET_VALID)) | 1748 | X509_V_ERR_CERT_NOT_YET_VALID)) |
1746 | return 0; | 1749 | return 0; |
1747 | 1750 | ||
1748 | i = X509_cmp_time(X509_get_notAfter(x), ptime); | 1751 | i = X509_cmp_time_internal(X509_get_notAfter(x), ptime, 1); |
1749 | if (i <= 0 && depth < 0) | 1752 | if (i <= 0 && depth < 0) |
1750 | return 0; | 1753 | return 0; |
1751 | if (i == 0 && !verify_cb_cert(ctx, x, depth, | 1754 | if (i == 0 && !verify_cb_cert(ctx, x, depth, |
@@ -1852,8 +1855,8 @@ X509_cmp_current_time(const ASN1_TIME *ctm) | |||
1852 | * 1 if the ASN1_time is later than *cmp_time. | 1855 | * 1 if the ASN1_time is later than *cmp_time. |
1853 | * 0 on error. | 1856 | * 0 on error. |
1854 | */ | 1857 | */ |
1855 | int | 1858 | static int |
1856 | X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) | 1859 | X509_cmp_time_internal(const ASN1_TIME *ctm, time_t *cmp_time, int clamp_notafter) |
1857 | { | 1860 | { |
1858 | time_t time1, time2; | 1861 | time_t time1, time2; |
1859 | struct tm tm1, tm2; | 1862 | struct tm tm1, tm2; |
@@ -1877,6 +1880,12 @@ X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) | |||
1877 | if (tm1.tm_year >= 150 && type != V_ASN1_GENERALIZEDTIME) | 1880 | if (tm1.tm_year >= 150 && type != V_ASN1_GENERALIZEDTIME) |
1878 | goto out; | 1881 | goto out; |
1879 | 1882 | ||
1883 | if (clamp_notafter) { | ||
1884 | /* Allow for completely broken operating systems. */ | ||
1885 | if (!ASN1_time_tm_clamp_notafter(&tm1)) | ||
1886 | goto out; | ||
1887 | } | ||
1888 | |||
1880 | /* | 1889 | /* |
1881 | * Defensively fail if the time string is not representable as | 1890 | * Defensively fail if the time string is not representable as |
1882 | * a time_t. A time_t must be sane if you care about times after | 1891 | * a time_t. A time_t must be sane if you care about times after |
@@ -1895,6 +1904,13 @@ X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) | |||
1895 | return (ret); | 1904 | return (ret); |
1896 | } | 1905 | } |
1897 | 1906 | ||
1907 | int | ||
1908 | X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) | ||
1909 | { | ||
1910 | return X509_cmp_time_internal(ctm, cmp_time, 0); | ||
1911 | } | ||
1912 | |||
1913 | |||
1898 | ASN1_TIME * | 1914 | ASN1_TIME * |
1899 | X509_gmtime_adj(ASN1_TIME *s, long adj) | 1915 | X509_gmtime_adj(ASN1_TIME *s, long adj) |
1900 | { | 1916 | { |