summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pkcs7/pk7_attr.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pkcs7/pk7_attr.c')
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c90
1 files changed, 72 insertions, 18 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
index 3b9c0fe3f2..5ff5a88b5c 100644
--- a/src/lib/libcrypto/pkcs7/pk7_attr.c
+++ b/src/lib/libcrypto/pkcs7/pk7_attr.c
@@ -1,9 +1,59 @@
1/* pk7_attr.c */ 1/* pk7_attr.c */
2/* S/MIME code. 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * Copyright (C) 1997-8 Dr S N Henson (shenson@bigfoot.com) 3 * project 2001.
4 * All Rights Reserved. 4 */
5 * Redistribution of this code without the authors permission is expressly 5/* ====================================================================
6 * prohibited. 6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
7 */ 57 */
8 58
9#include <stdio.h> 59#include <stdio.h>
@@ -12,22 +62,24 @@
12#include <openssl/asn1.h> 62#include <openssl/asn1.h>
13#include <openssl/pem.h> 63#include <openssl/pem.h>
14#include <openssl/pkcs7.h> 64#include <openssl/pkcs7.h>
65#include <openssl/x509.h>
15#include <openssl/err.h> 66#include <openssl/err.h>
16 67
17int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK *cap) 68int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap)
18{ 69{
19 ASN1_STRING *seq; 70 ASN1_STRING *seq;
20 unsigned char *p, *pp; 71 unsigned char *p, *pp;
21 int len; 72 int len;
22 len=i2d_ASN1_SET(cap,NULL,i2d_X509_ALGOR, V_ASN1_SEQUENCE, 73 len=i2d_ASN1_SET_OF_X509_ALGOR(cap,NULL,i2d_X509_ALGOR,
23 V_ASN1_UNIVERSAL, IS_SEQUENCE); 74 V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL,
24 if(!(pp=(unsigned char *)Malloc(len))) { 75 IS_SEQUENCE);
76 if(!(pp=(unsigned char *)OPENSSL_malloc(len))) {
25 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); 77 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
26 return 0; 78 return 0;
27 } 79 }
28 p=pp; 80 p=pp;
29 i2d_ASN1_SET(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE, 81 i2d_ASN1_SET_OF_X509_ALGOR(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE,
30 V_ASN1_UNIVERSAL, IS_SEQUENCE); 82 V_ASN1_UNIVERSAL, IS_SEQUENCE);
31 if(!(seq = ASN1_STRING_new())) { 83 if(!(seq = ASN1_STRING_new())) {
32 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); 84 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
33 return 0; 85 return 0;
@@ -36,27 +88,29 @@ int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK *cap)
36 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); 88 PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE);
37 return 0; 89 return 0;
38 } 90 }
39 Free (pp); 91 OPENSSL_free (pp);
40 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities, 92 return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities,
41 V_ASN1_SEQUENCE, seq); 93 V_ASN1_SEQUENCE, seq);
42} 94}
43 95
44STACK *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) 96STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
45{ 97{
46 ASN1_TYPE *cap; 98 ASN1_TYPE *cap;
47 unsigned char *p; 99 unsigned char *p;
48 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities); 100 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
49 if (!cap) return NULL; 101 if (!cap) return NULL;
50 p = cap->value.sequence->data; 102 p = cap->value.sequence->data;
51 return d2i_ASN1_SET (NULL, &p, cap->value.sequence->length, 103 return d2i_ASN1_SET_OF_X509_ALGOR(NULL, &p,
52 (char *(*)())d2i_X509_ALGOR, X509_ALGOR_free, V_ASN1_SEQUENCE, 104 cap->value.sequence->length,
53 V_ASN1_UNIVERSAL); 105 d2i_X509_ALGOR, X509_ALGOR_free,
106 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
54} 107}
55 108
56/* Basic smime-capabilities OID and optional integer arg */ 109/* Basic smime-capabilities OID and optional integer arg */
57int PKCS7_simple_smimecap(STACK *sk, int nid, int arg) 110int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg)
58{ 111{
59 X509_ALGOR *alg; 112 X509_ALGOR *alg;
113
60 if(!(alg = X509_ALGOR_new())) { 114 if(!(alg = X509_ALGOR_new())) {
61 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE); 115 PKCS7err(PKCS7_F_PKCS7_SIMPLE_SMIMECAP,ERR_R_MALLOC_FAILURE);
62 return 0; 116 return 0;
@@ -80,6 +134,6 @@ int PKCS7_simple_smimecap(STACK *sk, int nid, int arg)
80 alg->parameter->value.integer = nbit; 134 alg->parameter->value.integer = nbit;
81 alg->parameter->type = V_ASN1_INTEGER; 135 alg->parameter->type = V_ASN1_INTEGER;
82 } 136 }
83 sk_push (sk, (char *)alg); 137 sk_X509_ALGOR_push (sk, alg);
84 return 1; 138 return 1;
85} 139}