diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_time.c')
| -rw-r--r-- | src/lib/libcrypto/asn1/a_time.c | 117 |
1 files changed, 1 insertions, 116 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index a6c7c8e736..7a3742fd70 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: a_time.c,v 1.26 2015/10/02 15:04:45 beck Exp $ */ | 1 | /* $OpenBSD: a_time.c,v 1.27 2015/10/19 16:32:37 beck Exp $ */ |
| 2 | /* ==================================================================== | 2 | /* ==================================================================== |
| 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
| 4 | * | 4 | * |
| @@ -105,118 +105,3 @@ ASN1_TIME_free(ASN1_TIME *a) | |||
| 105 | { | 105 | { |
| 106 | ASN1_item_free((ASN1_VALUE *)a, &ASN1_TIME_it); | 106 | ASN1_item_free((ASN1_VALUE *)a, &ASN1_TIME_it); |
| 107 | } | 107 | } |
| 108 | |||
| 109 | ASN1_TIME * | ||
| 110 | ASN1_TIME_set(ASN1_TIME *s, time_t t) | ||
| 111 | { | ||
| 112 | return ASN1_TIME_adj(s, t, 0, 0); | ||
| 113 | } | ||
| 114 | |||
| 115 | ASN1_TIME * | ||
| 116 | ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec) | ||
| 117 | { | ||
| 118 | struct tm *ts; | ||
| 119 | struct tm data; | ||
| 120 | |||
| 121 | ts = gmtime_r(&t, &data); | ||
| 122 | if (ts == NULL) { | ||
| 123 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); | ||
| 124 | return NULL; | ||
| 125 | } | ||
| 126 | if (offset_day || offset_sec) { | ||
| 127 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | ||
| 128 | return NULL; | ||
| 129 | } | ||
| 130 | if ((ts->tm_year >= 50) && (ts->tm_year < 150)) | ||
| 131 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); | ||
| 132 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); | ||
| 133 | } | ||
| 134 | |||
| 135 | int | ||
| 136 | ASN1_TIME_check(ASN1_TIME *t) | ||
| 137 | { | ||
| 138 | if (t->type != V_ASN1_GENERALIZEDTIME && t->type != V_ASN1_UTCTIME) | ||
| 139 | return 0; | ||
| 140 | return (t->type == asn1_time_parse(t->data, t->length, NULL, t->type)); | ||
| 141 | } | ||
| 142 | |||
| 143 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | ||
| 144 | static ASN1_GENERALIZEDTIME * | ||
| 145 | ASN1_TIME_to_generalizedtime_internal(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
| 146 | { | ||
| 147 | ASN1_GENERALIZEDTIME *ret; | ||
| 148 | char *str; | ||
| 149 | int newlen; | ||
| 150 | int i; | ||
| 151 | |||
| 152 | if (!ASN1_TIME_check(t)) | ||
| 153 | return NULL; | ||
| 154 | |||
| 155 | ret = *out; | ||
| 156 | |||
| 157 | /* If already GeneralizedTime just copy across */ | ||
| 158 | if (t->type == V_ASN1_GENERALIZEDTIME) { | ||
| 159 | if (!ASN1_STRING_set(ret, t->data, t->length)) | ||
| 160 | return NULL; | ||
| 161 | return ret; | ||
| 162 | } | ||
| 163 | |||
| 164 | /* grow the string */ | ||
| 165 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | ||
| 166 | return NULL; | ||
| 167 | /* ASN1_STRING_set() allocated 'len + 1' bytes. */ | ||
| 168 | newlen = t->length + 2 + 1; | ||
| 169 | str = (char *)ret->data; | ||
| 170 | /* XXX ASN1_TIME is not Y2050 compatible */ | ||
| 171 | i = snprintf(str, newlen, "%s%s", (t->data[0] >= '5') ? "19" : "20", | ||
| 172 | (char *) t->data); | ||
| 173 | if (i == -1 || i >= newlen) { | ||
| 174 | ASN1_GENERALIZEDTIME_free(ret); | ||
| 175 | *out = NULL; | ||
| 176 | return NULL; | ||
| 177 | } | ||
| 178 | return ret; | ||
| 179 | } | ||
| 180 | |||
| 181 | ASN1_GENERALIZEDTIME * | ||
| 182 | ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
| 183 | { | ||
| 184 | ASN1_GENERALIZEDTIME *tmp = NULL, *ret; | ||
| 185 | |||
| 186 | if (!out || !*out) { | ||
| 187 | if (!(tmp = ASN1_GENERALIZEDTIME_new())) | ||
| 188 | return NULL; | ||
| 189 | if (out != NULL) | ||
| 190 | *out = tmp; | ||
| 191 | else | ||
| 192 | out = &tmp; | ||
| 193 | } | ||
| 194 | |||
| 195 | ret = ASN1_TIME_to_generalizedtime_internal(t, out); | ||
| 196 | if (ret == NULL && tmp != NULL) | ||
| 197 | ASN1_GENERALIZEDTIME_free(tmp); | ||
| 198 | |||
| 199 | return ret; | ||
| 200 | } | ||
| 201 | |||
| 202 | int | ||
| 203 | ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | ||
| 204 | { | ||
| 205 | ASN1_TIME t; | ||
| 206 | |||
| 207 | t.length = strlen(str); | ||
| 208 | t.data = (unsigned char *)str; | ||
| 209 | t.flags = 0; | ||
| 210 | |||
| 211 | t.type = asn1_time_parse(t.data, t.length, NULL, V_ASN1_UTCTIME); | ||
| 212 | if (t.type == -1) | ||
| 213 | t.type = asn1_time_parse(t.data, t.length, NULL, | ||
| 214 | V_ASN1_GENERALIZEDTIME); | ||
| 215 | if (t.type == -1) | ||
| 216 | return 0; | ||
| 217 | |||
| 218 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) | ||
| 219 | return 0; | ||
| 220 | |||
| 221 | return 1; | ||
| 222 | } | ||
