diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/a_gentm.c')
-rw-r--r-- | src/lib/libcrypto/asn1/a_gentm.c | 191 |
1 files changed, 104 insertions, 87 deletions
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c index 2ef6e6bc22..56f8992424 100644 --- a/src/lib/libcrypto/asn1/a_gentm.c +++ b/src/lib/libcrypto/asn1/a_gentm.c | |||
@@ -5,21 +5,21 @@ | |||
5 | * This package is an SSL implementation written | 5 | * This package is an SSL implementation written |
6 | * by Eric Young (eay@cryptsoft.com). | 6 | * by Eric Young (eay@cryptsoft.com). |
7 | * The implementation was written so as to conform with Netscapes SSL. | 7 | * The implementation was written so as to conform with Netscapes SSL. |
8 | * | 8 | * |
9 | * This library is free for commercial and non-commercial use as long as | 9 | * This library is free for commercial and non-commercial use as long as |
10 | * the following conditions are aheared to. The following conditions | 10 | * the following conditions are aheared to. The following conditions |
11 | * apply to all code found in this distribution, be it the RC4, RSA, | 11 | * apply to all code found in this distribution, be it the RC4, RSA, |
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation |
13 | * included with this distribution is covered by the same copyright terms | 13 | * included with this distribution is covered by the same copyright terms |
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). |
15 | * | 15 | * |
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | 16 | * Copyright remains Eric Young's, and as such any Copyright notices in |
17 | * the code are not to be removed. | 17 | * the code are not to be removed. |
18 | * If this package is used in a product, Eric Young should be given attribution | 18 | * If this package is used in a product, Eric Young should be given attribution |
19 | * as the author of the parts of the library used. | 19 | * as the author of the parts of the library used. |
20 | * This can be in the form of a textual message at program startup or | 20 | * This can be in the form of a textual message at program startup or |
21 | * in documentation (online or textual) provided with the package. | 21 | * in documentation (online or textual) provided with the package. |
22 | * | 22 | * |
23 | * Redistribution and use in source and binary forms, with or without | 23 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 24 | * modification, are permitted provided that the following conditions |
25 | * are met: | 25 | * are met: |
@@ -34,10 +34,10 @@ | |||
34 | * Eric Young (eay@cryptsoft.com)" | 34 | * Eric Young (eay@cryptsoft.com)" |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 35 | * The word 'cryptographic' can be left out if the rouines from the library |
36 | * being used are not cryptographic related :-). | 36 | * being used are not cryptographic related :-). |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 37 | * 4. If you include any Windows specific code (or a derivative thereof) from |
38 | * the apps directory (application code) you must include an acknowledgement: | 38 | * the apps directory (application code) you must include an acknowledgement: |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" |
40 | * | 40 | * |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
@@ -48,8 +48,8 @@ | |||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
51 | * SUCH DAMAGE. | 51 | * SUCH DAMAGE. |
52 | * | 52 | * |
53 | * The licence and distribution terms for any publically available version or | 53 | * The licence and distribution terms for any publically available version or |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be |
55 | * copied and put under another distribution licence | 55 | * copied and put under another distribution licence |
@@ -66,170 +66,187 @@ | |||
66 | 66 | ||
67 | #if 0 | 67 | #if 0 |
68 | 68 | ||
69 | int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) | 69 | int |
70 | i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) | ||
70 | { | 71 | { |
71 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | 72 | return(i2d_ASN1_bytes((ASN1_STRING *)a, pp, |
72 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL)); | 73 | V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL)); |
73 | } | 74 | } |
74 | 75 | ||
75 | 76 | ||
76 | ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, | 77 | ASN1_GENERALIZEDTIME * |
77 | unsigned char **pp, long length) | 78 | d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a, unsigned char **pp, |
79 | long length) | ||
78 | { | 80 | { |
79 | ASN1_GENERALIZEDTIME *ret=NULL; | 81 | ASN1_GENERALIZEDTIME *ret = NULL; |
80 | 82 | ||
81 | ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length, | 83 | ret = (ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a, pp, length, |
82 | V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL); | 84 | V_ASN1_GENERALIZEDTIME, V_ASN1_UNIVERSAL); |
83 | if (ret == NULL) | 85 | if (ret == NULL) { |
84 | { | 86 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ERR_R_NESTED_ASN1_ERROR); |
85 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR); | 87 | return (NULL); |
86 | return(NULL); | ||
87 | } | 88 | } |
88 | if (!ASN1_GENERALIZEDTIME_check(ret)) | 89 | if (!ASN1_GENERALIZEDTIME_check(ret)) { |
89 | { | 90 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME, ASN1_R_INVALID_TIME_FORMAT); |
90 | ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT); | ||
91 | goto err; | 91 | goto err; |
92 | } | 92 | } |
93 | 93 | ||
94 | return(ret); | 94 | return (ret); |
95 | |||
95 | err: | 96 | err: |
96 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | 97 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) |
97 | M_ASN1_GENERALIZEDTIME_free(ret); | 98 | M_ASN1_GENERALIZEDTIME_free(ret); |
98 | return(NULL); | 99 | return (NULL); |
99 | } | 100 | } |
100 | 101 | ||
101 | #endif | 102 | #endif |
102 | 103 | ||
103 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | 104 | int |
105 | ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) | ||
104 | { | 106 | { |
105 | static const int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; | 107 | static const int min[9] = {0, 0, 1, 1, 0, 0, 0, 0, 0}; |
106 | static const int max[9]={99, 99,12,31,23,59,59,12,59}; | 108 | static const int max[9] = {99, 99, 12, 31, 23, 59, 59, 12, 59}; |
107 | char *a; | 109 | char *a; |
108 | int n,i,l,o; | 110 | int n, i, l, o; |
109 | 111 | ||
110 | if (d->type != V_ASN1_GENERALIZEDTIME) return(0); | 112 | if (d->type != V_ASN1_GENERALIZEDTIME) |
111 | l=d->length; | 113 | return (0); |
112 | a=(char *)d->data; | 114 | l = d->length; |
113 | o=0; | 115 | a = (char *)d->data; |
116 | o = 0; | ||
114 | /* GENERALIZEDTIME is similar to UTCTIME except the year is | 117 | /* GENERALIZEDTIME is similar to UTCTIME except the year is |
115 | * represented as YYYY. This stuff treats everything as a two digit | 118 | * represented as YYYY. This stuff treats everything as a two digit |
116 | * field so make first two fields 00 to 99 | 119 | * field so make first two fields 00 to 99 |
117 | */ | 120 | */ |
118 | if (l < 13) goto err; | 121 | if (l < 13) |
119 | for (i=0; i<7; i++) { | 122 | goto err; |
123 | for (i = 0; i < 7; i++) { | ||
120 | if ((i == 6) && ((a[o] == 'Z') || | 124 | if ((i == 6) && ((a[o] == 'Z') || |
121 | (a[o] == '+') || (a[o] == '-'))) | 125 | (a[o] == '+') || (a[o] == '-'))) { |
122 | { i++; break; } | 126 | i++; |
123 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 127 | break; |
128 | } | ||
129 | if ((a[o] < '0') || (a[o] > '9')) | ||
130 | goto err; | ||
124 | n= a[o]-'0'; | 131 | n= a[o]-'0'; |
125 | if (++o > l) goto err; | 132 | if (++o > l) |
133 | goto err; | ||
126 | 134 | ||
127 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 135 | if ((a[o] < '0') || (a[o] > '9')) |
128 | n=(n*10)+ a[o]-'0'; | 136 | goto err; |
129 | if (++o > l) goto err; | 137 | n = (n * 10)+ a[o] - '0'; |
138 | if (++o > l) | ||
139 | goto err; | ||
130 | 140 | ||
131 | if ((n < min[i]) || (n > max[i])) goto err; | 141 | if ((n < min[i]) || (n > max[i])) |
142 | goto err; | ||
132 | } | 143 | } |
133 | /* Optional fractional seconds: decimal point followed by one | 144 | /* Optional fractional seconds: decimal point followed by one |
134 | * or more digits. | 145 | * or more digits. |
135 | */ | 146 | */ |
136 | if (a[o] == '.') | 147 | if (a[o] == '.') { |
137 | { | 148 | if (++o > l) |
138 | if (++o > l) goto err; | 149 | goto err; |
139 | i = o; | 150 | i = o; |
140 | while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) | 151 | while ((a[o] >= '0') && (a[o] <= '9') && (o <= l)) |
141 | o++; | 152 | o++; |
142 | /* Must have at least one digit after decimal point */ | 153 | /* Must have at least one digit after decimal point */ |
143 | if (i == o) goto err; | 154 | if (i == o) |
155 | goto err; | ||
144 | } | 156 | } |
145 | 157 | ||
146 | if (a[o] == 'Z') | 158 | if (a[o] == 'Z') |
147 | o++; | 159 | o++; |
148 | else if ((a[o] == '+') || (a[o] == '-')) { | 160 | else if ((a[o] == '+') || (a[o] == '-')) { |
149 | o++; | 161 | o++; |
150 | if (o+4 > l) goto err; | 162 | if (o + 4 > l) |
151 | for (i=7; i<9; i++) { | 163 | goto err; |
152 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 164 | for (i = 7; i < 9; i++) { |
153 | n= a[o]-'0'; | 165 | if ((a[o] < '0') || (a[o] > '9')) |
166 | goto err; | ||
167 | n = a[o] - '0'; | ||
154 | o++; | 168 | o++; |
155 | if ((a[o] < '0') || (a[o] > '9')) goto err; | 169 | if ((a[o] < '0') || (a[o] > '9')) |
156 | n=(n*10)+ a[o]-'0'; | 170 | goto err; |
157 | if ((n < min[i]) || (n > max[i])) goto err; | 171 | n = (n * 10) + a[o] - '0'; |
172 | if ((n < min[i]) || (n > max[i])) | ||
173 | goto err; | ||
158 | o++; | 174 | o++; |
159 | } | 175 | } |
160 | } else { | 176 | } else { |
161 | /* Missing time zone information. */ | 177 | /* Missing time zone information. */ |
162 | goto err; | 178 | goto err; |
163 | } | 179 | } |
164 | return(o == l); | 180 | return (o == l); |
165 | err: | 181 | err: |
166 | return(0); | 182 | return (0); |
167 | } | 183 | } |
168 | 184 | ||
169 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) | 185 | int |
186 | ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str) | ||
170 | { | 187 | { |
171 | ASN1_GENERALIZEDTIME t; | 188 | ASN1_GENERALIZEDTIME t; |
172 | 189 | ||
173 | t.type=V_ASN1_GENERALIZEDTIME; | 190 | t.type = V_ASN1_GENERALIZEDTIME; |
174 | t.length=strlen(str); | 191 | t.length = strlen(str); |
175 | t.data=(unsigned char *)str; | 192 | t.data = (unsigned char *)str; |
176 | if (ASN1_GENERALIZEDTIME_check(&t)) { | 193 | if (ASN1_GENERALIZEDTIME_check(&t)) { |
177 | if (s != NULL) { | 194 | if (s != NULL) { |
178 | if (!ASN1_STRING_set((ASN1_STRING *)s, | 195 | if (!ASN1_STRING_set((ASN1_STRING *)s, |
179 | (unsigned char *)str,t.length)) | 196 | (unsigned char *)str, t.length)) |
180 | return 0; | 197 | return 0; |
181 | s->type=V_ASN1_GENERALIZEDTIME; | 198 | s->type = V_ASN1_GENERALIZEDTIME; |
182 | } | 199 | } |
183 | return(1); | 200 | return (1); |
184 | } | 201 | } else |
185 | else | 202 | return (0); |
186 | return(0); | ||
187 | } | 203 | } |
188 | 204 | ||
189 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, | 205 | ASN1_GENERALIZEDTIME * |
190 | time_t t) | 206 | ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, time_t t) |
191 | { | 207 | { |
192 | return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); | 208 | return ASN1_GENERALIZEDTIME_adj(s, t, 0, 0); |
193 | } | 209 | } |
194 | 210 | ||
195 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, | 211 | ASN1_GENERALIZEDTIME * |
196 | time_t t, int offset_day, long offset_sec) | 212 | ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day, |
213 | long offset_sec) | ||
197 | { | 214 | { |
198 | char *p; | 215 | char *p; |
199 | struct tm *ts; | 216 | struct tm *ts; |
200 | struct tm data; | 217 | struct tm data; |
201 | size_t len = 20; | 218 | size_t len = 20; |
202 | 219 | ||
203 | if (s == NULL) | 220 | if (s == NULL) |
204 | s=M_ASN1_GENERALIZEDTIME_new(); | 221 | s = M_ASN1_GENERALIZEDTIME_new(); |
205 | if (s == NULL) | 222 | if (s == NULL) |
206 | return(NULL); | 223 | return (NULL); |
207 | 224 | ||
208 | ts=OPENSSL_gmtime(&t, &data); | 225 | ts = OPENSSL_gmtime(&t, &data); |
209 | if (ts == NULL) | 226 | if (ts == NULL) |
210 | return(NULL); | 227 | return (NULL); |
211 | 228 | ||
212 | if (offset_day || offset_sec) { | 229 | if (offset_day || offset_sec) { |
213 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) | 230 | if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) |
214 | return NULL; | 231 | return NULL; |
215 | } | 232 | } |
216 | 233 | ||
217 | p=(char *)s->data; | 234 | p = (char *)s->data; |
218 | if ((p == NULL) || ((size_t)s->length < len)) { | 235 | if ((p == NULL) || ((size_t)s->length < len)) { |
219 | p=malloc(len); | 236 | p = malloc(len); |
220 | if (p == NULL) { | 237 | if (p == NULL) { |
221 | ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, | 238 | ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_ADJ, |
222 | ERR_R_MALLOC_FAILURE); | 239 | ERR_R_MALLOC_FAILURE); |
223 | return(NULL); | 240 | return (NULL); |
224 | } | 241 | } |
225 | if (s->data != NULL) | 242 | if (s->data != NULL) |
226 | free(s->data); | 243 | free(s->data); |
227 | s->data=(unsigned char *)p; | 244 | s->data = (unsigned char *)p; |
228 | } | 245 | } |
229 | 246 | ||
230 | (void) snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900, | 247 | (void) snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, |
231 | ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); | 248 | ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, ts->tm_sec); |
232 | s->length=strlen(p); | 249 | s->length = strlen(p); |
233 | s->type=V_ASN1_GENERALIZEDTIME; | 250 | s->type = V_ASN1_GENERALIZEDTIME; |
234 | return(s); | 251 | return (s); |
235 | } | 252 | } |