diff options
Diffstat (limited to 'src/lib/libcrypto/x509/x509_v3.c')
-rw-r--r-- | src/lib/libcrypto/x509/x509_v3.c | 225 |
1 files changed, 41 insertions, 184 deletions
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c index 1c03602f0b..dd2f9f1b17 100644 --- a/src/lib/libcrypto/x509/x509_v3.c +++ b/src/lib/libcrypto/x509/x509_v3.c | |||
@@ -57,34 +57,21 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "stack.h" | 60 | #include <openssl/stack.h> |
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include "asn1.h" | 62 | #include <openssl/asn1.h> |
63 | #include "objects.h" | 63 | #include <openssl/objects.h> |
64 | #include "evp.h" | 64 | #include <openssl/evp.h> |
65 | #include "x509.h" | 65 | #include <openssl/x509.h> |
66 | 66 | ||
67 | #ifndef NOPROTO | 67 | int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x) |
68 | static X509_EXTENSION_METHOD *find_by_nid(int nid); | ||
69 | static int xem_cmp(X509_EXTENSION_METHOD **a, X509_EXTENSION_METHOD **b); | ||
70 | #else | ||
71 | static X509_EXTENSION_METHOD *find_by_nid(); | ||
72 | static int xem_cmp(); | ||
73 | #endif | ||
74 | |||
75 | static STACK *extensions=NULL; | ||
76 | |||
77 | int X509v3_get_ext_count(x) | ||
78 | STACK *x; | ||
79 | { | 68 | { |
80 | if (x == NULL) return(0); | 69 | if (x == NULL) return(0); |
81 | return(sk_num(x)); | 70 | return(sk_X509_EXTENSION_num(x)); |
82 | } | 71 | } |
83 | 72 | ||
84 | int X509v3_get_ext_by_NID(x,nid,lastpos) | 73 | int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, int nid, |
85 | STACK *x; | 74 | int lastpos) |
86 | int nid; | ||
87 | int lastpos; | ||
88 | { | 75 | { |
89 | ASN1_OBJECT *obj; | 76 | ASN1_OBJECT *obj; |
90 | 77 | ||
@@ -93,10 +80,8 @@ int lastpos; | |||
93 | return(X509v3_get_ext_by_OBJ(x,obj,lastpos)); | 80 | return(X509v3_get_ext_by_OBJ(x,obj,lastpos)); |
94 | } | 81 | } |
95 | 82 | ||
96 | int X509v3_get_ext_by_OBJ(sk,obj,lastpos) | 83 | int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *sk, ASN1_OBJECT *obj, |
97 | STACK *sk; | 84 | int lastpos) |
98 | ASN1_OBJECT *obj; | ||
99 | int lastpos; | ||
100 | { | 85 | { |
101 | int n; | 86 | int n; |
102 | X509_EXTENSION *ex; | 87 | X509_EXTENSION *ex; |
@@ -105,20 +90,18 @@ int lastpos; | |||
105 | lastpos++; | 90 | lastpos++; |
106 | if (lastpos < 0) | 91 | if (lastpos < 0) |
107 | lastpos=0; | 92 | lastpos=0; |
108 | n=sk_num(sk); | 93 | n=sk_X509_EXTENSION_num(sk); |
109 | for ( ; lastpos < n; lastpos++) | 94 | for ( ; lastpos < n; lastpos++) |
110 | { | 95 | { |
111 | ex=(X509_EXTENSION *)sk_value(sk,lastpos); | 96 | ex=sk_X509_EXTENSION_value(sk,lastpos); |
112 | if (OBJ_cmp(ex->object,obj) == 0) | 97 | if (OBJ_cmp(ex->object,obj) == 0) |
113 | return(lastpos); | 98 | return(lastpos); |
114 | } | 99 | } |
115 | return(-1); | 100 | return(-1); |
116 | } | 101 | } |
117 | 102 | ||
118 | int X509v3_get_ext_by_critical(sk,crit,lastpos) | 103 | int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit, |
119 | STACK *sk; | 104 | int lastpos) |
120 | int crit; | ||
121 | int lastpos; | ||
122 | { | 105 | { |
123 | int n; | 106 | int n; |
124 | X509_EXTENSION *ex; | 107 | X509_EXTENSION *ex; |
@@ -127,10 +110,10 @@ int lastpos; | |||
127 | lastpos++; | 110 | lastpos++; |
128 | if (lastpos < 0) | 111 | if (lastpos < 0) |
129 | lastpos=0; | 112 | lastpos=0; |
130 | n=sk_num(sk); | 113 | n=sk_X509_EXTENSION_num(sk); |
131 | for ( ; lastpos < n; lastpos++) | 114 | for ( ; lastpos < n; lastpos++) |
132 | { | 115 | { |
133 | ex=(X509_EXTENSION *)sk_value(sk,lastpos); | 116 | ex=sk_X509_EXTENSION_value(sk,lastpos); |
134 | if ( (ex->critical && crit) || | 117 | if ( (ex->critical && crit) || |
135 | (!ex->critical && !crit)) | 118 | (!ex->critical && !crit)) |
136 | return(lastpos); | 119 | return(lastpos); |
@@ -138,52 +121,46 @@ int lastpos; | |||
138 | return(-1); | 121 | return(-1); |
139 | } | 122 | } |
140 | 123 | ||
141 | X509_EXTENSION *X509v3_get_ext(x,loc) | 124 | X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, int loc) |
142 | STACK *x; | ||
143 | int loc; | ||
144 | { | 125 | { |
145 | if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) | 126 | if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) |
146 | return(NULL); | 127 | return NULL; |
147 | else | 128 | else |
148 | return((X509_EXTENSION *)sk_value(x,loc)); | 129 | return sk_X509_EXTENSION_value(x,loc); |
149 | } | 130 | } |
150 | 131 | ||
151 | X509_EXTENSION *X509v3_delete_ext(x,loc) | 132 | X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc) |
152 | STACK *x; | ||
153 | int loc; | ||
154 | { | 133 | { |
155 | X509_EXTENSION *ret; | 134 | X509_EXTENSION *ret; |
156 | 135 | ||
157 | if ((x == NULL) || (sk_num(x) <= loc) || (loc < 0)) | 136 | if (x == NULL || sk_X509_EXTENSION_num(x) <= loc || loc < 0) |
158 | return(NULL); | 137 | return(NULL); |
159 | ret=(X509_EXTENSION *)sk_delete(x,loc); | 138 | ret=sk_X509_EXTENSION_delete(x,loc); |
160 | return(ret); | 139 | return(ret); |
161 | } | 140 | } |
162 | 141 | ||
163 | STACK *X509v3_add_ext(x,ex,loc) | 142 | STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, |
164 | STACK **x; | 143 | X509_EXTENSION *ex, int loc) |
165 | X509_EXTENSION *ex; | ||
166 | int loc; | ||
167 | { | 144 | { |
168 | X509_EXTENSION *new_ex=NULL; | 145 | X509_EXTENSION *new_ex=NULL; |
169 | int n; | 146 | int n; |
170 | STACK *sk=NULL; | 147 | STACK_OF(X509_EXTENSION) *sk=NULL; |
171 | 148 | ||
172 | if ((x != NULL) && (*x == NULL)) | 149 | if ((x != NULL) && (*x == NULL)) |
173 | { | 150 | { |
174 | if ((sk=sk_new_null()) == NULL) | 151 | if ((sk=sk_X509_EXTENSION_new_null()) == NULL) |
175 | goto err; | 152 | goto err; |
176 | } | 153 | } |
177 | else | 154 | else |
178 | sk= *x; | 155 | sk= *x; |
179 | 156 | ||
180 | n=sk_num(sk); | 157 | n=sk_X509_EXTENSION_num(sk); |
181 | if (loc > n) loc=n; | 158 | if (loc > n) loc=n; |
182 | else if (loc < 0) loc=n; | 159 | else if (loc < 0) loc=n; |
183 | 160 | ||
184 | if ((new_ex=X509_EXTENSION_dup(ex)) == NULL) | 161 | if ((new_ex=X509_EXTENSION_dup(ex)) == NULL) |
185 | goto err2; | 162 | goto err2; |
186 | if (!sk_insert(sk,(char *)new_ex,loc)) | 163 | if (!sk_X509_EXTENSION_insert(sk,new_ex,loc)) |
187 | goto err; | 164 | goto err; |
188 | if ((x != NULL) && (*x == NULL)) | 165 | if ((x != NULL) && (*x == NULL)) |
189 | *x=sk; | 166 | *x=sk; |
@@ -192,15 +169,12 @@ err: | |||
192 | X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE); | 169 | X509err(X509_F_X509V3_ADD_EXT,ERR_R_MALLOC_FAILURE); |
193 | err2: | 170 | err2: |
194 | if (new_ex != NULL) X509_EXTENSION_free(new_ex); | 171 | if (new_ex != NULL) X509_EXTENSION_free(new_ex); |
195 | if (sk != NULL) sk_free(sk); | 172 | if (sk != NULL) sk_X509_EXTENSION_free(sk); |
196 | return(NULL); | 173 | return(NULL); |
197 | } | 174 | } |
198 | 175 | ||
199 | X509_EXTENSION *X509_EXTENSION_create_by_NID(ex,nid,crit,data) | 176 | X509_EXTENSION *X509_EXTENSION_create_by_NID(X509_EXTENSION **ex, int nid, |
200 | X509_EXTENSION **ex; | 177 | int crit, ASN1_OCTET_STRING *data) |
201 | int nid; | ||
202 | int crit; | ||
203 | ASN1_OCTET_STRING *data; | ||
204 | { | 178 | { |
205 | ASN1_OBJECT *obj; | 179 | ASN1_OBJECT *obj; |
206 | X509_EXTENSION *ret; | 180 | X509_EXTENSION *ret; |
@@ -216,11 +190,8 @@ ASN1_OCTET_STRING *data; | |||
216 | return(ret); | 190 | return(ret); |
217 | } | 191 | } |
218 | 192 | ||
219 | X509_EXTENSION *X509_EXTENSION_create_by_OBJ(ex,obj,crit,data) | 193 | X509_EXTENSION *X509_EXTENSION_create_by_OBJ(X509_EXTENSION **ex, |
220 | X509_EXTENSION **ex; | 194 | ASN1_OBJECT *obj, int crit, ASN1_OCTET_STRING *data) |
221 | ASN1_OBJECT *obj; | ||
222 | int crit; | ||
223 | ASN1_OCTET_STRING *data; | ||
224 | { | 195 | { |
225 | X509_EXTENSION *ret; | 196 | X509_EXTENSION *ret; |
226 | 197 | ||
@@ -250,9 +221,7 @@ err: | |||
250 | return(NULL); | 221 | return(NULL); |
251 | } | 222 | } |
252 | 223 | ||
253 | int X509_EXTENSION_set_object(ex,obj) | 224 | int X509_EXTENSION_set_object(X509_EXTENSION *ex, ASN1_OBJECT *obj) |
254 | X509_EXTENSION *ex; | ||
255 | ASN1_OBJECT *obj; | ||
256 | { | 225 | { |
257 | if ((ex == NULL) || (obj == NULL)) | 226 | if ((ex == NULL) || (obj == NULL)) |
258 | return(0); | 227 | return(0); |
@@ -261,18 +230,14 @@ ASN1_OBJECT *obj; | |||
261 | return(1); | 230 | return(1); |
262 | } | 231 | } |
263 | 232 | ||
264 | int X509_EXTENSION_set_critical(ex,crit) | 233 | int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit) |
265 | X509_EXTENSION *ex; | ||
266 | int crit; | ||
267 | { | 234 | { |
268 | if (ex == NULL) return(0); | 235 | if (ex == NULL) return(0); |
269 | ex->critical=(crit)?0xFF:0; | 236 | ex->critical=(crit)?0xFF:0; |
270 | return(1); | 237 | return(1); |
271 | } | 238 | } |
272 | 239 | ||
273 | int X509_EXTENSION_set_data(ex,data) | 240 | int X509_EXTENSION_set_data(X509_EXTENSION *ex, ASN1_OCTET_STRING *data) |
274 | X509_EXTENSION *ex; | ||
275 | ASN1_OCTET_STRING *data; | ||
276 | { | 241 | { |
277 | int i; | 242 | int i; |
278 | 243 | ||
@@ -282,128 +247,20 @@ ASN1_OCTET_STRING *data; | |||
282 | return(1); | 247 | return(1); |
283 | } | 248 | } |
284 | 249 | ||
285 | ASN1_OBJECT *X509_EXTENSION_get_object(ex) | 250 | ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex) |
286 | X509_EXTENSION *ex; | ||
287 | { | 251 | { |
288 | if (ex == NULL) return(NULL); | 252 | if (ex == NULL) return(NULL); |
289 | return(ex->object); | 253 | return(ex->object); |
290 | } | 254 | } |
291 | 255 | ||
292 | ASN1_OCTET_STRING *X509_EXTENSION_get_data(ex) | 256 | ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex) |
293 | X509_EXTENSION *ex; | ||
294 | { | 257 | { |
295 | if (ex == NULL) return(NULL); | 258 | if (ex == NULL) return(NULL); |
296 | return(ex->value); | 259 | return(ex->value); |
297 | } | 260 | } |
298 | 261 | ||
299 | int X509_EXTENSION_get_critical(ex) | 262 | int X509_EXTENSION_get_critical(X509_EXTENSION *ex) |
300 | X509_EXTENSION *ex; | ||
301 | { | 263 | { |
302 | if (ex == NULL) return(0); | 264 | if (ex == NULL) return(0); |
303 | return(ex->critical); | 265 | return(ex->critical); |
304 | } | 266 | } |
305 | |||
306 | int X509v3_data_type_by_OBJ(obj) | ||
307 | ASN1_OBJECT *obj; | ||
308 | { | ||
309 | int nid; | ||
310 | |||
311 | nid=OBJ_obj2nid(obj); | ||
312 | if (nid == V_ASN1_UNDEF) return(V_ASN1_UNDEF); | ||
313 | return(X509v3_data_type_by_NID(nid)); | ||
314 | } | ||
315 | |||
316 | int X509v3_data_type_by_NID(nid) | ||
317 | int nid; | ||
318 | { | ||
319 | X509_EXTENSION_METHOD *x; | ||
320 | |||
321 | x=find_by_nid(nid); | ||
322 | if (x == NULL) | ||
323 | return(V_ASN1_UNDEF); | ||
324 | else | ||
325 | return(x->data_type); | ||
326 | } | ||
327 | |||
328 | int X509v3_pack_type_by_OBJ(obj) | ||
329 | ASN1_OBJECT *obj; | ||
330 | { | ||
331 | int nid; | ||
332 | |||
333 | nid=OBJ_obj2nid(obj); | ||
334 | if (nid == NID_undef) return(X509_EXT_PACK_UNKNOWN); | ||
335 | return(X509v3_pack_type_by_NID(nid)); | ||
336 | } | ||
337 | |||
338 | int X509v3_pack_type_by_NID(nid) | ||
339 | int nid; | ||
340 | { | ||
341 | X509_EXTENSION_METHOD *x; | ||
342 | |||
343 | x=find_by_nid(nid); | ||
344 | if (x == NULL) | ||
345 | return(X509_EXT_PACK_UNKNOWN); | ||
346 | else | ||
347 | return(x->pack_type); | ||
348 | } | ||
349 | |||
350 | static X509_EXTENSION_METHOD *find_by_nid(nid) | ||
351 | int nid; | ||
352 | { | ||
353 | X509_EXTENSION_METHOD x; | ||
354 | int i; | ||
355 | |||
356 | x.nid=nid; | ||
357 | if (extensions == NULL) return(NULL); | ||
358 | i=sk_find(extensions,(char *)&x); | ||
359 | if (i < 0) | ||
360 | return(NULL); | ||
361 | else | ||
362 | return((X509_EXTENSION_METHOD *)sk_value(extensions,i)); | ||
363 | } | ||
364 | |||
365 | static int xem_cmp(a,b) | ||
366 | X509_EXTENSION_METHOD **a,**b; | ||
367 | { | ||
368 | return((*a)->nid-(*b)->nid); | ||
369 | } | ||
370 | |||
371 | void X509v3_cleanup_extensions() | ||
372 | { | ||
373 | int i; | ||
374 | |||
375 | if (extensions != NULL) | ||
376 | { | ||
377 | for (i=0; i<sk_num(extensions); i++) | ||
378 | Free(sk_value(extensions,i)); | ||
379 | sk_free(extensions); | ||
380 | extensions=NULL; | ||
381 | } | ||
382 | } | ||
383 | |||
384 | int X509v3_add_extension(x) | ||
385 | X509_EXTENSION_METHOD *x; | ||
386 | { | ||
387 | X509_EXTENSION_METHOD *newx; | ||
388 | |||
389 | if (extensions == NULL) | ||
390 | { | ||
391 | extensions=sk_new(xem_cmp); | ||
392 | if (extensions == NULL) goto err; | ||
393 | } | ||
394 | newx=(X509_EXTENSION_METHOD *)Malloc(sizeof(X509_EXTENSION_METHOD)); | ||
395 | if (newx == NULL) goto err; | ||
396 | newx->nid=x->nid; | ||
397 | newx->data_type=x->data_type; | ||
398 | newx->pack_type=x->pack_type; | ||
399 | if (!sk_push(extensions,(char *)newx)) | ||
400 | { | ||
401 | Free(newx); | ||
402 | goto err; | ||
403 | } | ||
404 | return(1); | ||
405 | err: | ||
406 | X509err(X509_F_X509V3_ADD_EXTENSION,ERR_R_MALLOC_FAILURE); | ||
407 | return(0); | ||
408 | } | ||
409 | |||