diff options
Diffstat (limited to 'src/lib/libcrypto/ocsp/ocsp_ext.c')
-rw-r--r-- | src/lib/libcrypto/ocsp/ocsp_ext.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c index d6c8899f58..57399433fc 100644 --- a/src/lib/libcrypto/ocsp/ocsp_ext.c +++ b/src/lib/libcrypto/ocsp/ocsp_ext.c | |||
@@ -305,6 +305,8 @@ err: | |||
305 | 305 | ||
306 | /* Add a nonce to an extension stack. A nonce can be specificed or if NULL | 306 | /* Add a nonce to an extension stack. A nonce can be specificed or if NULL |
307 | * a random nonce will be generated. | 307 | * a random nonce will be generated. |
308 | * Note: OpenSSL 0.9.7d and later create an OCTET STRING containing the | ||
309 | * nonce, previous versions used the raw nonce. | ||
308 | */ | 310 | */ |
309 | 311 | ||
310 | static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len) | 312 | static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, int len) |
@@ -313,20 +315,28 @@ static int ocsp_add1_nonce(STACK_OF(X509_EXTENSION) **exts, unsigned char *val, | |||
313 | ASN1_OCTET_STRING os; | 315 | ASN1_OCTET_STRING os; |
314 | int ret = 0; | 316 | int ret = 0; |
315 | if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH; | 317 | if (len <= 0) len = OCSP_DEFAULT_NONCE_LENGTH; |
316 | if (val) tmpval = val; | 318 | /* Create the OCTET STRING manually by writing out the header and |
319 | * appending the content octets. This avoids an extra memory allocation | ||
320 | * operation in some cases. Applications should *NOT* do this because | ||
321 | * it relies on library internals. | ||
322 | */ | ||
323 | os.length = ASN1_object_size(0, len, V_ASN1_OCTET_STRING); | ||
324 | os.data = OPENSSL_malloc(os.length); | ||
325 | if (os.data == NULL) | ||
326 | goto err; | ||
327 | tmpval = os.data; | ||
328 | ASN1_put_object(&tmpval, 0, len, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL); | ||
329 | if (val) | ||
330 | memcpy(tmpval, val, len); | ||
317 | else | 331 | else |
318 | { | ||
319 | if (!(tmpval = OPENSSL_malloc(len))) goto err; | ||
320 | RAND_pseudo_bytes(tmpval, len); | 332 | RAND_pseudo_bytes(tmpval, len); |
321 | } | ||
322 | os.data = tmpval; | ||
323 | os.length = len; | ||
324 | if(!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, | 333 | if(!X509V3_add1_i2d(exts, NID_id_pkix_OCSP_Nonce, |
325 | &os, 0, X509V3_ADD_REPLACE)) | 334 | &os, 0, X509V3_ADD_REPLACE)) |
326 | goto err; | 335 | goto err; |
327 | ret = 1; | 336 | ret = 1; |
328 | err: | 337 | err: |
329 | if(!val) OPENSSL_free(tmpval); | 338 | if (os.data) |
339 | OPENSSL_free(os.data); | ||
330 | return ret; | 340 | return ret; |
331 | } | 341 | } |
332 | 342 | ||