diff options
author | cvs2svn <admin@example.com> | 2015-03-08 16:48:49 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 2015-03-08 16:48:49 +0000 |
commit | decf84ba5550c1656a7fdb51b5b81969590c3f03 (patch) | |
tree | 44872802e872bdfd60730fa9cf01d9d5751251c1 /src/lib/libcrypto/asn1/a_time.c | |
parent | 7a8f138352aa4eb7b65ac4b1a5fe7630fbee1427 (diff) | |
download | openbsd-libressl-v2.1.5.tar.gz openbsd-libressl-v2.1.5.tar.bz2 openbsd-libressl-v2.1.5.zip |
This commit was manufactured by cvs2git to create branch 'OPENBSD_5_7'.libressl-v2.1.5
Diffstat (limited to 'src/lib/libcrypto/asn1/a_time.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_time.c | 216 |
1 files changed, 0 insertions, 216 deletions
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c deleted file mode 100644 index 95481fc4c6..0000000000 --- a/src/lib/libcrypto/asn1/a_time.c +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
1 | /* $OpenBSD: a_time.c,v 1.23 2015/02/09 15:05:59 jsing Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* This is an implementation of the ASN1 Time structure which is: | ||
57 | * Time ::= CHOICE { | ||
58 | * utcTime UTCTime, | ||
59 | * generalTime GeneralizedTime } | ||
60 | * written by Steve Henson. | ||
61 | */ | ||
62 | |||
63 | #include <stdio.h> | ||
64 | #include <string.h> | ||
65 | #include <time.h> | ||
66 | |||
67 | #include <openssl/asn1t.h> | ||
68 | #include <openssl/err.h> | ||
69 | |||
70 | #include "o_time.h" | ||
71 | |||
72 | IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) | ||
73 | |||
74 | |||
75 | ASN1_TIME * | ||
76 | d2i_ASN1_TIME(ASN1_TIME **a, const unsigned char **in, long len) | ||
77 | { | ||
78 | return (ASN1_TIME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
79 | &ASN1_TIME_it); | ||
80 | } | ||
81 | |||
82 | int | ||
83 | i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **out) | ||
84 | { | ||
85 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &ASN1_TIME_it); | ||
86 | } | ||
87 | |||
88 | ASN1_TIME * | ||
89 | ASN1_TIME_new(void) | ||
90 | { | ||
91 | return (ASN1_TIME *)ASN1_item_new(&ASN1_TIME_it); | ||
92 | } | ||
93 | |||
94 | void | ||
95 | ASN1_TIME_free(ASN1_TIME *a) | ||
96 | { | ||
97 | ASN1_item_free((ASN1_VALUE *)a, &ASN1_TIME_it); | ||
98 | } | ||
99 | |||
100 | ASN1_TIME * | ||
101 | ASN1_TIME_set(ASN1_TIME *s, time_t t) | ||
102 | { | ||
103 | return ASN1_TIME_adj(s, t, 0, 0); | ||
104 | } | ||
105 | |||
106 | ASN1_TIME * | ||
107 | ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, long offset_sec) | ||
108 | { | ||
109 | struct tm *ts; | ||
110 | struct tm data; | ||
111 | |||
112 | ts = gmtime_r(&t, &data); | ||
113 | if (ts == NULL) { | ||
114 | ASN1err(ASN1_F_ASN1_TIME_ADJ, ASN1_R_ERROR_GETTING_TIME); | ||
115 | return NULL; | ||
116 | } | ||
117 | if (offset_day || offset_sec) { | ||
118 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | ||
119 | return NULL; | ||
120 | } | ||
121 | if ((ts->tm_year >= 50) && (ts->tm_year < 150)) | ||
122 | return ASN1_UTCTIME_adj(s, t, offset_day, offset_sec); | ||
123 | return ASN1_GENERALIZEDTIME_adj(s, t, offset_day, offset_sec); | ||
124 | } | ||
125 | |||
126 | int | ||
127 | ASN1_TIME_check(ASN1_TIME *t) | ||
128 | { | ||
129 | if (t->type == V_ASN1_GENERALIZEDTIME) | ||
130 | return ASN1_GENERALIZEDTIME_check(t); | ||
131 | else if (t->type == V_ASN1_UTCTIME) | ||
132 | return ASN1_UTCTIME_check(t); | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | ||
137 | static ASN1_GENERALIZEDTIME * | ||
138 | ASN1_TIME_to_generalizedtime_internal(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
139 | { | ||
140 | ASN1_GENERALIZEDTIME *ret; | ||
141 | char *str; | ||
142 | int newlen; | ||
143 | int i; | ||
144 | |||
145 | if (!ASN1_TIME_check(t)) | ||
146 | return NULL; | ||
147 | |||
148 | ret = *out; | ||
149 | |||
150 | /* If already GeneralizedTime just copy across */ | ||
151 | if (t->type == V_ASN1_GENERALIZEDTIME) { | ||
152 | if (!ASN1_STRING_set(ret, t->data, t->length)) | ||
153 | return NULL; | ||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | /* grow the string */ | ||
158 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | ||
159 | return NULL; | ||
160 | /* ASN1_STRING_set() allocated 'len + 1' bytes. */ | ||
161 | newlen = t->length + 2 + 1; | ||
162 | str = (char *)ret->data; | ||
163 | /* XXX ASN1_TIME is not Y2050 compatible */ | ||
164 | i = snprintf(str, newlen, "%s%s", (t->data[0] >= '5') ? "19" : "20", | ||
165 | (char *) t->data); | ||
166 | if (i == -1 || i >= newlen) { | ||
167 | M_ASN1_GENERALIZEDTIME_free(ret); | ||
168 | *out = NULL; | ||
169 | return NULL; | ||
170 | } | ||
171 | return ret; | ||
172 | } | ||
173 | |||
174 | ASN1_GENERALIZEDTIME * | ||
175 | ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
176 | { | ||
177 | ASN1_GENERALIZEDTIME *tmp = NULL, *ret; | ||
178 | |||
179 | if (!out || !*out) { | ||
180 | if (!(tmp = ASN1_GENERALIZEDTIME_new())) | ||
181 | return NULL; | ||
182 | if (out != NULL) | ||
183 | *out = tmp; | ||
184 | else | ||
185 | out = &tmp; | ||
186 | } | ||
187 | |||
188 | ret = ASN1_TIME_to_generalizedtime_internal(t, out); | ||
189 | if (ret == NULL && tmp != NULL) | ||
190 | ASN1_GENERALIZEDTIME_free(tmp); | ||
191 | |||
192 | return ret; | ||
193 | } | ||
194 | |||
195 | int | ||
196 | ASN1_TIME_set_string(ASN1_TIME *s, const char *str) | ||
197 | { | ||
198 | ASN1_TIME t; | ||
199 | |||
200 | t.length = strlen(str); | ||
201 | t.data = (unsigned char *)str; | ||
202 | t.flags = 0; | ||
203 | |||
204 | t.type = V_ASN1_UTCTIME; | ||
205 | |||
206 | if (!ASN1_TIME_check(&t)) { | ||
207 | t.type = V_ASN1_GENERALIZEDTIME; | ||
208 | if (!ASN1_TIME_check(&t)) | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | if (s && !ASN1_STRING_copy((ASN1_STRING *)s, (ASN1_STRING *)&t)) | ||
213 | return 0; | ||
214 | |||
215 | return 1; | ||
216 | } | ||