summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509/x509_req.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/x509/x509_req.c')
-rw-r--r--src/lib/libcrypto/x509/x509_req.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index 48183dc00c..3872e1fb64 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -61,7 +61,6 @@
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>
65#include <openssl/x509.h> 64#include <openssl/x509.h>
66#include <openssl/objects.h> 65#include <openssl/objects.h>
67#include <openssl/buffer.h> 66#include <openssl/buffer.h>
@@ -206,9 +205,10 @@ STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
206 if(!ext || (ext->type != V_ASN1_SEQUENCE)) 205 if(!ext || (ext->type != V_ASN1_SEQUENCE))
207 return NULL; 206 return NULL;
208 p = ext->value.sequence->data; 207 p = ext->value.sequence->data;
209 return (STACK_OF(X509_EXTENSION) *) 208 return d2i_ASN1_SET_OF_X509_EXTENSION(NULL, &p,
210 ASN1_item_d2i(NULL, &p, ext->value.sequence->length, 209 ext->value.sequence->length,
211 ASN1_ITEM_rptr(X509_EXTENSIONS)); 210 d2i_X509_EXTENSION, X509_EXTENSION_free,
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
@@ -218,6 +218,8 @@ STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
218int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts, 218int 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;
221 ASN1_TYPE *at = NULL; 223 ASN1_TYPE *at = NULL;
222 X509_ATTRIBUTE *attr = NULL; 224 X509_ATTRIBUTE *attr = NULL;
223 if(!(at = ASN1_TYPE_new()) || 225 if(!(at = ASN1_TYPE_new()) ||
@@ -225,10 +227,15 @@ int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
225 227
226 at->type = V_ASN1_SEQUENCE; 228 at->type = V_ASN1_SEQUENCE;
227 /* Generate encoding of extensions */ 229 /* Generate encoding of extensions */
228 at->value.sequence->length = 230 len = i2d_ASN1_SET_OF_X509_EXTENSION(exts, NULL, i2d_X509_EXTENSION,
229 ASN1_item_i2d((ASN1_VALUE *)exts, 231 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, IS_SEQUENCE);
230 &at->value.sequence->data, 232 if(!(p = OPENSSL_malloc(len))) goto err;
231 ASN1_ITEM_rptr(X509_EXTENSIONS)); 233 q = p;
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;
232 if(!(attr = X509_ATTRIBUTE_new())) goto err; 239 if(!(attr = X509_ATTRIBUTE_new())) goto err;
233 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err; 240 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
234 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err; 241 if(!sk_ASN1_TYPE_push(attr->value.set, at)) goto err;
@@ -243,6 +250,7 @@ int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
243 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err; 250 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err;
244 return 1; 251 return 1;
245 err: 252 err:
253 if(p) OPENSSL_free(p);
246 X509_ATTRIBUTE_free(attr); 254 X509_ATTRIBUTE_free(attr);
247 ASN1_TYPE_free(at); 255 ASN1_TYPE_free(at);
248 return 0; 256 return 0;