summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1
diff options
context:
space:
mode:
authormarkus <>2002-09-05 12:51:52 +0000
committermarkus <>2002-09-05 12:51:52 +0000
commit5514995a9d5ed91db089875adb509c7781357c0e (patch)
tree2484410a46ba6c05ef94c253da36fbceef990b64 /src/lib/libcrypto/asn1
parentfd9566423b542798f5c8b06e68101a9ea5bb9885 (diff)
downloadopenbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.gz
openbsd-5514995a9d5ed91db089875adb509c7781357c0e.tar.bz2
openbsd-5514995a9d5ed91db089875adb509c7781357c0e.zip
import openssl-0.9.7-beta1
Diffstat (limited to 'src/lib/libcrypto/asn1')
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c39
-rw-r--r--src/lib/libcrypto/asn1/a_hdr.c33
-rw-r--r--src/lib/libcrypto/asn1/a_meth.c8
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c148
-rw-r--r--src/lib/libcrypto/asn1/p8_key.c4
5 files changed, 160 insertions, 72 deletions
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c
index 226474f057..cd09f68b38 100644
--- a/src/lib/libcrypto/asn1/a_gentm.c
+++ b/src/lib/libcrypto/asn1/a_gentm.c
@@ -61,8 +61,11 @@
61#include <stdio.h> 61#include <stdio.h>
62#include <time.h> 62#include <time.h>
63#include "cryptlib.h" 63#include "cryptlib.h"
64#include "o_time.h"
64#include <openssl/asn1.h> 65#include <openssl/asn1.h>
65 66
67#if 0
68
66int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp) 69int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
67 { 70 {
68#ifdef CHARSET_EBCDIC 71#ifdef CHARSET_EBCDIC
@@ -106,10 +109,12 @@ ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
106 return(ret); 109 return(ret);
107err: 110err:
108 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 111 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
109 ASN1_GENERALIZEDTIME_free(ret); 112 M_ASN1_GENERALIZEDTIME_free(ret);
110 return(NULL); 113 return(NULL);
111 } 114 }
112 115
116#endif
117
113int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d) 118int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
114 { 119 {
115 static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0}; 120 static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
@@ -141,6 +146,19 @@ int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
141 146
142 if ((n < min[i]) || (n > max[i])) goto err; 147 if ((n < min[i]) || (n > max[i])) goto err;
143 } 148 }
149 /* Optional fractional seconds: decimal point followed by one
150 * or more digits.
151 */
152 if (a[o] == '.')
153 {
154 if (++o > l) goto err;
155 i = o;
156 while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
157 o++;
158 /* Must have at least one digit after decimal point */
159 if (i == o) goto err;
160 }
161
144 if (a[o] == 'Z') 162 if (a[o] == 'Z')
145 o++; 163 o++;
146 else if ((a[o] == '+') || (a[o] == '-')) 164 else if ((a[o] == '+') || (a[o] == '-'))
@@ -176,6 +194,7 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)
176 { 194 {
177 ASN1_STRING_set((ASN1_STRING *)s, 195 ASN1_STRING_set((ASN1_STRING *)s,
178 (unsigned char *)str,t.length); 196 (unsigned char *)str,t.length);
197 s->type=V_ASN1_GENERALIZEDTIME;
179 } 198 }
180 return(1); 199 return(1);
181 } 200 }
@@ -188,28 +207,24 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
188 { 207 {
189 char *p; 208 char *p;
190 struct tm *ts; 209 struct tm *ts;
191#if defined(THREADS) && !defined(WIN32)
192 struct tm data; 210 struct tm data;
193#endif
194 211
195 if (s == NULL) 212 if (s == NULL)
196 s=ASN1_GENERALIZEDTIME_new(); 213 s=M_ASN1_GENERALIZEDTIME_new();
197 if (s == NULL) 214 if (s == NULL)
198 return(NULL); 215 return(NULL);
199 216
200#if defined(THREADS) && !defined(WIN32) 217 ts=OPENSSL_gmtime(&t, &data);
201 gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */ 218 if (ts == NULL)
202 ts=&data; 219 return(NULL);
203#else 220
204 ts=gmtime(&t);
205#endif
206 p=(char *)s->data; 221 p=(char *)s->data;
207 if ((p == NULL) || (s->length < 16)) 222 if ((p == NULL) || (s->length < 16))
208 { 223 {
209 p=Malloc(20); 224 p=OPENSSL_malloc(20);
210 if (p == NULL) return(NULL); 225 if (p == NULL) return(NULL);
211 if (s->data != NULL) 226 if (s->data != NULL)
212 Free(s->data); 227 OPENSSL_free(s->data);
213 s->data=(unsigned char *)p; 228 s->data=(unsigned char *)p;
214 } 229 }
215 230
diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c
index 4fb7a5fa75..b1aad81f77 100644
--- a/src/lib/libcrypto/asn1/a_hdr.c
+++ b/src/lib/libcrypto/asn1/a_hdr.c
@@ -58,19 +58,10 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "asn1_mac.h" 61#include <openssl/asn1_mac.h>
62#include "asn1.h" 62#include <openssl/asn1.h>
63 63
64/* 64int i2d_ASN1_HEADER(ASN1_HEADER *a, unsigned char **pp)
65 * ASN1err(ASN1_F_D2I_ASN1_HEADER,ASN1_R_LENGTH_MISMATCH);
66 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
67 * ASN1err(ASN1_F_I2D_ASN1_HEADER,ASN1_R_BAD_GET_OBJECT);
68 * ASN1err(ASN1_F_ASN1_HEADER_NEW,ASN1_R_BAD_GET_OBJECT);
69 */
70
71int i2d_ASN1_HEADER(a,pp)
72ASN1_HEADER *a;
73unsigned char **pp;
74 { 65 {
75 M_ASN1_I2D_vars(a); 66 M_ASN1_I2D_vars(a);
76 67
@@ -85,10 +76,8 @@ unsigned char **pp;
85 M_ASN1_I2D_finish(); 76 M_ASN1_I2D_finish();
86 } 77 }
87 78
88ASN1_HEADER *d2i_ASN1_HEADER(a,pp,length) 79ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, unsigned char **pp,
89ASN1_HEADER **a; 80 long length)
90unsigned char **pp;
91long length;
92 { 81 {
93 M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new); 82 M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new);
94 83
@@ -107,24 +96,24 @@ long length;
107 M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER); 96 M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER);
108 } 97 }
109 98
110ASN1_HEADER *ASN1_HEADER_new() 99ASN1_HEADER *ASN1_HEADER_new(void)
111 { 100 {
112 ASN1_HEADER *ret=NULL; 101 ASN1_HEADER *ret=NULL;
102 ASN1_CTX c;
113 103
114 M_ASN1_New_Malloc(ret,ASN1_HEADER); 104 M_ASN1_New_Malloc(ret,ASN1_HEADER);
115 M_ASN1_New(ret->header,ASN1_OCTET_STRING_new); 105 M_ASN1_New(ret->header,M_ASN1_OCTET_STRING_new);
116 ret->meth=NULL; 106 ret->meth=NULL;
117 ret->data=NULL; 107 ret->data=NULL;
118 return(ret); 108 return(ret);
119 M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW); 109 M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW);
120 } 110 }
121 111
122void ASN1_HEADER_free(a) 112void ASN1_HEADER_free(ASN1_HEADER *a)
123ASN1_HEADER *a;
124 { 113 {
125 if (a == NULL) return; 114 if (a == NULL) return;
126 ASN1_OCTET_STRING_free(a->header); 115 M_ASN1_OCTET_STRING_free(a->header);
127 if (a->meth != NULL) 116 if (a->meth != NULL)
128 a->meth->destroy(a->data); 117 a->meth->destroy(a->data);
129 Free((char *)a); 118 OPENSSL_free(a);
130 } 119 }
diff --git a/src/lib/libcrypto/asn1/a_meth.c b/src/lib/libcrypto/asn1/a_meth.c
index 513625c305..63158e9cab 100644
--- a/src/lib/libcrypto/asn1/a_meth.c
+++ b/src/lib/libcrypto/asn1/a_meth.c
@@ -58,8 +58,8 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include "buffer.h" 61#include <openssl/buffer.h>
62#include "x509.h" 62#include <openssl/asn1.h>
63 63
64static ASN1_METHOD ia5string_meth={ 64static ASN1_METHOD ia5string_meth={
65 (int (*)()) i2d_ASN1_IA5STRING, 65 (int (*)()) i2d_ASN1_IA5STRING,
@@ -73,12 +73,12 @@ static ASN1_METHOD bit_string_meth={
73 (char *(*)()) ASN1_STRING_new, 73 (char *(*)()) ASN1_STRING_new,
74 (void (*)()) ASN1_STRING_free}; 74 (void (*)()) ASN1_STRING_free};
75 75
76ASN1_METHOD *ASN1_IA5STRING_asn1_meth() 76ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void)
77 { 77 {
78 return(&ia5string_meth); 78 return(&ia5string_meth);
79 } 79 }
80 80
81ASN1_METHOD *ASN1_BIT_STRING_asn1_meth() 81ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void)
82 { 82 {
83 return(&bit_string_meth); 83 return(&bit_string_meth);
84 } 84 }
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c
index 17a7abbb67..ed2d827db2 100644
--- a/src/lib/libcrypto/asn1/a_utctm.c
+++ b/src/lib/libcrypto/asn1/a_utctm.c
@@ -59,25 +59,31 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <time.h> 60#include <time.h>
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include "asn1.h" 62#include "o_time.h"
63#include <openssl/asn1.h>
63 64
64/* ASN1err(ASN1_F_ASN1_UTCTIME_NEW,ASN1_R_UTCTIME_TOO_LONG); 65#if 0
65 * ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_EXPECTING_A_UTCTIME); 66int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
66 */
67
68int i2d_ASN1_UTCTIME(a,pp)
69ASN1_UTCTIME *a;
70unsigned char **pp;
71 { 67 {
68#ifndef CHARSET_EBCDIC
72 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, 69 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
73 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL)); 70 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
71#else
72 /* KLUDGE! We convert to ascii before writing DER */
73 int len;
74 char tmp[24];
75 ASN1_STRING x = *(ASN1_STRING *)a;
76
77 len = x.length;
78 ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len);
79 x.data = tmp;
80 return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
81#endif
74 } 82 }
75 83
76 84
77ASN1_UTCTIME *d2i_ASN1_UTCTIME(a, pp, length) 85ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
78ASN1_UTCTIME **a; 86 long length)
79unsigned char **pp;
80long length;
81 { 87 {
82 ASN1_UTCTIME *ret=NULL; 88 ASN1_UTCTIME *ret=NULL;
83 89
@@ -85,9 +91,12 @@ long length;
85 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL); 91 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
86 if (ret == NULL) 92 if (ret == NULL)
87 { 93 {
88 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_ERROR_STACK); 94 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ERR_R_NESTED_ASN1_ERROR);
89 return(NULL); 95 return(NULL);
90 } 96 }
97#ifdef CHARSET_EBCDIC
98 ascii2ebcdic(ret->data, ret->data, ret->length);
99#endif
91 if (!ASN1_UTCTIME_check(ret)) 100 if (!ASN1_UTCTIME_check(ret))
92 { 101 {
93 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT); 102 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
@@ -97,12 +106,13 @@ long length;
97 return(ret); 106 return(ret);
98err: 107err:
99 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 108 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
100 ASN1_UTCTIME_free(ret); 109 M_ASN1_UTCTIME_free(ret);
101 return(NULL); 110 return(NULL);
102 } 111 }
103 112
104int ASN1_UTCTIME_check(d) 113#endif
105ASN1_UTCTIME *d; 114
115int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
106 { 116 {
107 static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0}; 117 static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
108 static int max[8]={99,12,31,23,59,59,12,59}; 118 static int max[8]={99,12,31,23,59,59,12,59};
@@ -152,9 +162,7 @@ err:
152 return(0); 162 return(0);
153 } 163 }
154 164
155int ASN1_UTCTIME_set_string(s,str) 165int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str)
156ASN1_UTCTIME *s;
157char *str;
158 { 166 {
159 ASN1_UTCTIME t; 167 ASN1_UTCTIME t;
160 168
@@ -167,6 +175,7 @@ char *str;
167 { 175 {
168 ASN1_STRING_set((ASN1_STRING *)s, 176 ASN1_STRING_set((ASN1_STRING *)s,
169 (unsigned char *)str,t.length); 177 (unsigned char *)str,t.length);
178 s->type = V_ASN1_UTCTIME;
170 } 179 }
171 return(1); 180 return(1);
172 } 181 }
@@ -174,33 +183,28 @@ char *str;
174 return(0); 183 return(0);
175 } 184 }
176 185
177ASN1_UTCTIME *ASN1_UTCTIME_set(s, t) 186ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
178ASN1_UTCTIME *s;
179time_t t;
180 { 187 {
181 char *p; 188 char *p;
182 struct tm *ts; 189 struct tm *ts;
183#if defined(THREADS)
184 struct tm data; 190 struct tm data;
185#endif
186 191
187 if (s == NULL) 192 if (s == NULL)
188 s=ASN1_UTCTIME_new(); 193 s=M_ASN1_UTCTIME_new();
189 if (s == NULL) 194 if (s == NULL)
190 return(NULL); 195 return(NULL);
191 196
192#if defined(THREADS) 197 ts=OPENSSL_gmtime(&t, &data);
193 ts=(struct tm *)gmtime_r(&t,&data); 198 if (ts == NULL)
194#else 199 return(NULL);
195 ts=(struct tm *)gmtime(&t); 200
196#endif
197 p=(char *)s->data; 201 p=(char *)s->data;
198 if ((p == NULL) || (s->length < 14)) 202 if ((p == NULL) || (s->length < 14))
199 { 203 {
200 p=Malloc(20); 204 p=OPENSSL_malloc(20);
201 if (p == NULL) return(NULL); 205 if (p == NULL) return(NULL);
202 if (s->data != NULL) 206 if (s->data != NULL)
203 Free(s->data); 207 OPENSSL_free(s->data);
204 s->data=(unsigned char *)p; 208 s->data=(unsigned char *)p;
205 } 209 }
206 210
@@ -208,5 +212,85 @@ time_t t;
208 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec); 212 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
209 s->length=strlen(p); 213 s->length=strlen(p);
210 s->type=V_ASN1_UTCTIME; 214 s->type=V_ASN1_UTCTIME;
215#ifdef CHARSET_EBCDIC_not
216 ebcdic2ascii(s->data, s->data, s->length);
217#endif
211 return(s); 218 return(s);
212 } 219 }
220
221
222int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
223 {
224 struct tm *tm;
225 int offset;
226 int year;
227
228#define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')
229
230 if (s->data[12] == 'Z')
231 offset=0;
232 else
233 {
234 offset = g2(s->data+13)*60+g2(s->data+15);
235 if (s->data[12] == '-')
236 offset = -offset;
237 }
238
239 t -= offset*60; /* FIXME: may overflow in extreme cases */
240
241 { struct tm data; tm = OPENSSL_gmtime(&t, &data); }
242
243#define return_cmp(a,b) if ((a)<(b)) return -1; else if ((a)>(b)) return 1
244 year = g2(s->data);
245 if (year < 50)
246 year += 100;
247 return_cmp(year, tm->tm_year);
248 return_cmp(g2(s->data+2) - 1, tm->tm_mon);
249 return_cmp(g2(s->data+4), tm->tm_mday);
250 return_cmp(g2(s->data+6), tm->tm_hour);
251 return_cmp(g2(s->data+8), tm->tm_min);
252 return_cmp(g2(s->data+10), tm->tm_sec);
253#undef g2
254#undef return_cmp
255
256 return 0;
257 }
258
259
260#if 0
261time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
262 {
263 struct tm tm;
264 int offset;
265
266 memset(&tm,'\0',sizeof tm);
267
268#define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')
269 tm.tm_year=g2(s->data);
270 if(tm.tm_year < 50)
271 tm.tm_year+=100;
272 tm.tm_mon=g2(s->data+2)-1;
273 tm.tm_mday=g2(s->data+4);
274 tm.tm_hour=g2(s->data+6);
275 tm.tm_min=g2(s->data+8);
276 tm.tm_sec=g2(s->data+10);
277 if(s->data[12] == 'Z')
278 offset=0;
279 else
280 {
281 offset=g2(s->data+13)*60+g2(s->data+15);
282 if(s->data[12] == '-')
283 offset= -offset;
284 }
285#undef g2
286
287 return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone
288 * instead of UTC, and unless we rewrite OpenSSL
289 * in Lisp we cannot locally change the timezone
290 * without possibly interfering with other parts
291 * of the program. timegm, which uses UTC, is
292 * non-standard.
293 * Also time_t is inappropriate for general
294 * UTC times because it may a 32 bit type. */
295 }
296#endif
diff --git a/src/lib/libcrypto/asn1/p8_key.c b/src/lib/libcrypto/asn1/p8_key.c
index 0b24374627..3a31248e14 100644
--- a/src/lib/libcrypto/asn1/p8_key.c
+++ b/src/lib/libcrypto/asn1/p8_key.c
@@ -94,7 +94,7 @@ X509 *X509_KEY_new(void)
94 { 94 {
95 X509_KEY *ret=NULL; 95 X509_KEY *ret=NULL;
96 96
97 M_ASN1_New_Malloc(ret,X509_KEY); 97 M_ASN1_New_OPENSSL_malloc(ret,X509_KEY);
98 ret->references=1; 98 ret->references=1;
99 ret->type=NID 99 ret->type=NID
100 M_ASN1_New(ret->cert_info,X509_CINF_new); 100 M_ASN1_New(ret->cert_info,X509_CINF_new);
@@ -126,6 +126,6 @@ void X509_KEY_free(X509 *a)
126 X509_CINF_free(a->cert_info); 126 X509_CINF_free(a->cert_info);
127 X509_ALGOR_free(a->sig_alg); 127 X509_ALGOR_free(a->sig_alg);
128 ASN1_BIT_STRING_free(a->signature); 128 ASN1_BIT_STRING_free(a->signature);
129 Free(a); 129 OPENSSL_free(a);
130 } 130 }
131 131