diff options
Diffstat (limited to 'src/lib/libcrypto/pkcs7/pk7_attr.c')
-rw-r--r-- | src/lib/libcrypto/pkcs7/pk7_attr.c | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c index d549717169..a97db51210 100644 --- a/src/lib/libcrypto/pkcs7/pk7_attr.c +++ b/src/lib/libcrypto/pkcs7/pk7_attr.c | |||
@@ -60,6 +60,7 @@ | |||
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <openssl/bio.h> | 61 | #include <openssl/bio.h> |
62 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
63 | #include <openssl/asn1t.h> | ||
63 | #include <openssl/pem.h> | 64 | #include <openssl/pem.h> |
64 | #include <openssl/pkcs7.h> | 65 | #include <openssl/pkcs7.h> |
65 | #include <openssl/x509.h> | 66 | #include <openssl/x509.h> |
@@ -68,27 +69,12 @@ | |||
68 | int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap) | 69 | int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap) |
69 | { | 70 | { |
70 | ASN1_STRING *seq; | 71 | ASN1_STRING *seq; |
71 | unsigned char *p, *pp; | ||
72 | int len; | ||
73 | len=i2d_ASN1_SET_OF_X509_ALGOR(cap,NULL,i2d_X509_ALGOR, | ||
74 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, | ||
75 | IS_SEQUENCE); | ||
76 | if(!(pp=(unsigned char *)OPENSSL_malloc(len))) { | ||
77 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); | ||
78 | return 0; | ||
79 | } | ||
80 | p=pp; | ||
81 | i2d_ASN1_SET_OF_X509_ALGOR(cap,&p,i2d_X509_ALGOR, V_ASN1_SEQUENCE, | ||
82 | V_ASN1_UNIVERSAL, IS_SEQUENCE); | ||
83 | if(!(seq = ASN1_STRING_new())) { | 72 | if(!(seq = ASN1_STRING_new())) { |
84 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); | 73 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); |
85 | return 0; | 74 | return 0; |
86 | } | 75 | } |
87 | if(!ASN1_STRING_set (seq, pp, len)) { | 76 | seq->length = ASN1_item_i2d((ASN1_VALUE *)cap,&seq->data, |
88 | PKCS7err(PKCS7_F_PKCS7_ADD_ATTRIB_SMIMECAP,ERR_R_MALLOC_FAILURE); | 77 | ASN1_ITEM_rptr(X509_ALGORS)); |
89 | return 0; | ||
90 | } | ||
91 | OPENSSL_free (pp); | ||
92 | return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities, | 78 | return PKCS7_add_signed_attribute(si, NID_SMIMECapabilities, |
93 | V_ASN1_SEQUENCE, seq); | 79 | V_ASN1_SEQUENCE, seq); |
94 | } | 80 | } |
@@ -102,10 +88,9 @@ STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) | |||
102 | if (!cap || (cap->type != V_ASN1_SEQUENCE)) | 88 | if (!cap || (cap->type != V_ASN1_SEQUENCE)) |
103 | return NULL; | 89 | return NULL; |
104 | p = cap->value.sequence->data; | 90 | p = cap->value.sequence->data; |
105 | return d2i_ASN1_SET_OF_X509_ALGOR(NULL, &p, | 91 | return (STACK_OF(X509_ALGOR) *) |
106 | cap->value.sequence->length, | 92 | ASN1_item_d2i(NULL, &p, cap->value.sequence->length, |
107 | d2i_X509_ALGOR, X509_ALGOR_free, | 93 | ASN1_ITEM_rptr(X509_ALGORS)); |
108 | V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | ||
109 | } | 94 | } |
110 | 95 | ||
111 | /* Basic smime-capabilities OID and optional integer arg */ | 96 | /* Basic smime-capabilities OID and optional integer arg */ |
@@ -139,3 +124,42 @@ int PKCS7_simple_smimecap(STACK_OF(X509_ALGOR) *sk, int nid, int arg) | |||
139 | sk_X509_ALGOR_push (sk, alg); | 124 | sk_X509_ALGOR_push (sk, alg); |
140 | return 1; | 125 | return 1; |
141 | } | 126 | } |
127 | |||
128 | int PKCS7_add_attrib_content_type(PKCS7_SIGNER_INFO *si, ASN1_OBJECT *coid) | ||
129 | { | ||
130 | if (PKCS7_get_signed_attribute(si, NID_pkcs9_contentType)) | ||
131 | return 0; | ||
132 | if (!coid) | ||
133 | coid = OBJ_nid2obj(NID_pkcs7_data); | ||
134 | return PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, | ||
135 | V_ASN1_OBJECT, coid); | ||
136 | } | ||
137 | |||
138 | int PKCS7_add0_attrib_signing_time(PKCS7_SIGNER_INFO *si, ASN1_TIME *t) | ||
139 | { | ||
140 | if (!t && !(t=X509_gmtime_adj(NULL,0))) | ||
141 | { | ||
142 | PKCS7err(PKCS7_F_PKCS7_ADD0_ATTRIB_SIGNING_TIME, | ||
143 | ERR_R_MALLOC_FAILURE); | ||
144 | return 0; | ||
145 | } | ||
146 | return PKCS7_add_signed_attribute(si, NID_pkcs9_signingTime, | ||
147 | V_ASN1_UTCTIME, t); | ||
148 | } | ||
149 | |||
150 | int PKCS7_add1_attrib_digest(PKCS7_SIGNER_INFO *si, | ||
151 | const unsigned char *md, int mdlen) | ||
152 | { | ||
153 | ASN1_OCTET_STRING *os; | ||
154 | os = ASN1_OCTET_STRING_new(); | ||
155 | if (!os) | ||
156 | return 0; | ||
157 | if (!ASN1_STRING_set(os, md, mdlen) | ||
158 | || !PKCS7_add_signed_attribute(si, NID_pkcs9_messageDigest, | ||
159 | V_ASN1_OCTET_STRING, os)) | ||
160 | { | ||
161 | ASN1_OCTET_STRING_free(os); | ||
162 | return 0; | ||
163 | } | ||
164 | return 1; | ||
165 | } | ||