OLD | NEW |
1 /* crypto/x509/x509_req.c */ | 1 /* crypto/x509/x509_req.c */ |
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
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 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
56 * [including the GNU Public Licence.] | 56 * [including the GNU Public Licence.] |
57 */ | 57 */ |
58 | 58 |
59 #include <stdio.h> | 59 #include <stdio.h> |
60 #include "cryptlib.h" | 60 #include "cryptlib.h" |
61 #include <openssl/bn.h> | 61 #include <openssl/bn.h> |
62 #include <openssl/evp.h> | 62 #include <openssl/evp.h> |
63 #include <openssl/asn1.h> | 63 #include <openssl/asn1.h> |
| 64 #include <openssl/asn1t.h> |
64 #include <openssl/x509.h> | 65 #include <openssl/x509.h> |
65 #include <openssl/objects.h> | 66 #include <openssl/objects.h> |
66 #include <openssl/buffer.h> | 67 #include <openssl/buffer.h> |
67 #include <openssl/pem.h> | 68 #include <openssl/pem.h> |
68 | 69 |
69 X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) | 70 X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md) |
70 { | 71 { |
71 X509_REQ *ret; | 72 X509_REQ *ret; |
72 X509_REQ_INFO *ri; | 73 X509_REQ_INFO *ri; |
73 int i; | 74 int i; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 continue; | 199 continue; |
199 attr = X509_REQ_get_attr(req, idx); | 200 attr = X509_REQ_get_attr(req, idx); |
200 if(attr->single) ext = attr->value.single; | 201 if(attr->single) ext = attr->value.single; |
201 else if(sk_ASN1_TYPE_num(attr->value.set)) | 202 else if(sk_ASN1_TYPE_num(attr->value.set)) |
202 ext = sk_ASN1_TYPE_value(attr->value.set, 0); | 203 ext = sk_ASN1_TYPE_value(attr->value.set, 0); |
203 break; | 204 break; |
204 } | 205 } |
205 if(!ext || (ext->type != V_ASN1_SEQUENCE)) | 206 if(!ext || (ext->type != V_ASN1_SEQUENCE)) |
206 return NULL; | 207 return NULL; |
207 p = ext->value.sequence->data; | 208 p = ext->value.sequence->data; |
208 » return d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p, | 209 » return (STACK_OF(X509_EXTENSION) *) |
209 » » » ext->value.sequence->length, | 210 » » ASN1_item_d2i(NULL, &p, ext->value.sequence->length, |
210 » » » d2i_X509_EXTENSION, X509_EXTENSION_free, | 211 » » » » ASN1_ITEM_rptr(X509_EXTENSIONS)); |
211 » » » V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | |
212 } | 212 } |
213 | 213 |
214 /* Add a STACK_OF extensions to a certificate request: allow alternative OIDs | 214 /* Add a STACK_OF extensions to a certificate request: allow alternative OIDs |
215 * in case we want to create a non standard one. | 215 * in case we want to create a non standard one. |
216 */ | 216 */ |
217 | 217 |
218 int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, | 218 int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, |
219 int nid) | 219 int nid) |
220 { | 220 { |
221 unsigned char *p = NULL, *q; | |
222 long len; | |
223 ASN1_TYPE *at = NULL; | 221 ASN1_TYPE *at = NULL; |
224 X509_ATTRIBUTE *attr = NULL; | 222 X509_ATTRIBUTE *attr = NULL; |
225 if(!(at = ASN1_TYPE_new()) || | 223 if(!(at = ASN1_TYPE_new()) || |
226 !(at->value.sequence = ASN1_STRING_new())) goto err; | 224 !(at->value.sequence = ASN1_STRING_new())) goto err; |
227 | 225 |
228 at->type = V_ASN1_SEQUENCE; | 226 at->type = V_ASN1_SEQUENCE; |
229 /* Generate encoding of extensions */ | 227 /* Generate encoding of extensions */ |
230 » len = i2d_ASN1_SET_OF_X509_EXTENSION(exts, NULL, i2d_X509_EXTENSION, | 228 » at->value.sequence->length = |
231 » » » V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE); | 229 » » » ASN1_item_i2d((ASN1_VALUE *)exts, |
232 » if(!(p = OPENSSL_malloc(len))) goto err; | 230 » » » » &at->value.sequence->data, |
233 » q = p; | 231 » » » » ASN1_ITEM_rptr(X509_EXTENSIONS)); |
234 » i2d_ASN1_SET_OF_X509_EXTENSION(exts, &q, i2d_X509_EXTENSION, | |
235 » » » V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE); | |
236 » at->value.sequence->data = p; | |
237 » p = NULL; | |
238 » at->value.sequence->length = len; | |
239 if(!(attr = X509_ATTRIBUTE_new())) goto err; | 232 if(!(attr = X509_ATTRIBUTE_new())) goto err; |
240 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err; | 233 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err; |
241 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err; | 234 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err; |
242 at = NULL; | 235 at = NULL; |
243 attr->single = 0; | 236 attr->single = 0; |
244 attr->object = OBJ_nid2obj(nid); | 237 attr->object = OBJ_nid2obj(nid); |
245 if (!req->req_info->attributes) | 238 if (!req->req_info->attributes) |
246 { | 239 { |
247 if (!(req->req_info->attributes = sk_X509_ATTRIBUTE_new_null())) | 240 if (!(req->req_info->attributes = sk_X509_ATTRIBUTE_new_null())) |
248 goto err; | 241 goto err; |
249 } | 242 } |
250 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err; | 243 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err; |
251 return 1; | 244 return 1; |
252 err: | 245 err: |
253 if(p) OPENSSL_free(p); | |
254 X509_ATTRIBUTE_free(attr); | 246 X509_ATTRIBUTE_free(attr); |
255 ASN1_TYPE_free(at); | 247 ASN1_TYPE_free(at); |
256 return 0; | 248 return 0; |
257 } | 249 } |
258 /* This is the normal usage: use the "official" OID */ | 250 /* This is the normal usage: use the "official" OID */ |
259 int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts) | 251 int X509_REQ_add_extensions(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts) |
260 { | 252 { |
261 return X509_REQ_add_extensions_nid(req, exts, NID_ext_req); | 253 return X509_REQ_add_extensions_nid(req, exts, NID_ext_req); |
262 } | 254 } |
263 | 255 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 307 } |
316 | 308 |
317 int X509_REQ_add1_attr_by_txt(X509_REQ *req, | 309 int X509_REQ_add1_attr_by_txt(X509_REQ *req, |
318 const char *attrname, int type, | 310 const char *attrname, int type, |
319 const unsigned char *bytes, int len) | 311 const unsigned char *bytes, int len) |
320 { | 312 { |
321 if(X509at_add1_attr_by_txt(&req->req_info->attributes, attrname, | 313 if(X509at_add1_attr_by_txt(&req->req_info->attributes, attrname, |
322 type, bytes, len)) return 1; | 314 type, bytes, len)) return 1; |
323 return 0; | 315 return 0; |
324 } | 316 } |
OLD | NEW |