xref: /minix3/crypto/external/bsd/openssl/dist/crypto/cms/cms_att.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1ebfedea0SLionel Sambuc /* crypto/cms/cms_att.c */
2*0a6a1f1dSLionel Sambuc /*
3*0a6a1f1dSLionel Sambuc  * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4ebfedea0SLionel Sambuc  * project.
5ebfedea0SLionel Sambuc  */
6ebfedea0SLionel Sambuc /* ====================================================================
7ebfedea0SLionel Sambuc  * Copyright (c) 2008 The OpenSSL Project.  All rights reserved.
8ebfedea0SLionel Sambuc  *
9ebfedea0SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
10ebfedea0SLionel Sambuc  * modification, are permitted provided that the following conditions
11ebfedea0SLionel Sambuc  * are met:
12ebfedea0SLionel Sambuc  *
13ebfedea0SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
14ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
15ebfedea0SLionel Sambuc  *
16ebfedea0SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
17ebfedea0SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in
18ebfedea0SLionel Sambuc  *    the documentation and/or other materials provided with the
19ebfedea0SLionel Sambuc  *    distribution.
20ebfedea0SLionel Sambuc  *
21ebfedea0SLionel Sambuc  * 3. All advertising materials mentioning features or use of this
22ebfedea0SLionel Sambuc  *    software must display the following acknowledgment:
23ebfedea0SLionel Sambuc  *    "This product includes software developed by the OpenSSL Project
24ebfedea0SLionel Sambuc  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25ebfedea0SLionel Sambuc  *
26ebfedea0SLionel Sambuc  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27ebfedea0SLionel Sambuc  *    endorse or promote products derived from this software without
28ebfedea0SLionel Sambuc  *    prior written permission. For written permission, please contact
29ebfedea0SLionel Sambuc  *    licensing@OpenSSL.org.
30ebfedea0SLionel Sambuc  *
31ebfedea0SLionel Sambuc  * 5. Products derived from this software may not be called "OpenSSL"
32ebfedea0SLionel Sambuc  *    nor may "OpenSSL" appear in their names without prior written
33ebfedea0SLionel Sambuc  *    permission of the OpenSSL Project.
34ebfedea0SLionel Sambuc  *
35ebfedea0SLionel Sambuc  * 6. Redistributions of any form whatsoever must retain the following
36ebfedea0SLionel Sambuc  *    acknowledgment:
37ebfedea0SLionel Sambuc  *    "This product includes software developed by the OpenSSL Project
38ebfedea0SLionel Sambuc  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39ebfedea0SLionel Sambuc  *
40ebfedea0SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41ebfedea0SLionel Sambuc  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42ebfedea0SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43ebfedea0SLionel Sambuc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
44ebfedea0SLionel Sambuc  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45ebfedea0SLionel Sambuc  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46ebfedea0SLionel Sambuc  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47ebfedea0SLionel Sambuc  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48ebfedea0SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49ebfedea0SLionel Sambuc  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50ebfedea0SLionel Sambuc  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51ebfedea0SLionel Sambuc  * OF THE POSSIBILITY OF SUCH DAMAGE.
52ebfedea0SLionel Sambuc  * ====================================================================
53ebfedea0SLionel Sambuc  */
54ebfedea0SLionel Sambuc 
55ebfedea0SLionel Sambuc #include <openssl/asn1t.h>
56ebfedea0SLionel Sambuc #include <openssl/pem.h>
57ebfedea0SLionel Sambuc #include <openssl/x509v3.h>
58ebfedea0SLionel Sambuc #include <openssl/err.h>
59ebfedea0SLionel Sambuc #include "cms.h"
60ebfedea0SLionel Sambuc #include "cms_lcl.h"
61ebfedea0SLionel Sambuc 
62ebfedea0SLionel Sambuc /* CMS SignedData Attribute utilities */
63ebfedea0SLionel Sambuc 
CMS_signed_get_attr_count(const CMS_SignerInfo * si)64ebfedea0SLionel Sambuc int CMS_signed_get_attr_count(const CMS_SignerInfo *si)
65ebfedea0SLionel Sambuc {
66ebfedea0SLionel Sambuc     return X509at_get_attr_count(si->signedAttrs);
67ebfedea0SLionel Sambuc }
68ebfedea0SLionel Sambuc 
CMS_signed_get_attr_by_NID(const CMS_SignerInfo * si,int nid,int lastpos)69*0a6a1f1dSLionel Sambuc int CMS_signed_get_attr_by_NID(const CMS_SignerInfo *si, int nid, int lastpos)
70ebfedea0SLionel Sambuc {
71ebfedea0SLionel Sambuc     return X509at_get_attr_by_NID(si->signedAttrs, nid, lastpos);
72ebfedea0SLionel Sambuc }
73ebfedea0SLionel Sambuc 
CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo * si,ASN1_OBJECT * obj,int lastpos)74ebfedea0SLionel Sambuc int CMS_signed_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
75ebfedea0SLionel Sambuc                                int lastpos)
76ebfedea0SLionel Sambuc {
77ebfedea0SLionel Sambuc     return X509at_get_attr_by_OBJ(si->signedAttrs, obj, lastpos);
78ebfedea0SLionel Sambuc }
79ebfedea0SLionel Sambuc 
CMS_signed_get_attr(const CMS_SignerInfo * si,int loc)80ebfedea0SLionel Sambuc X509_ATTRIBUTE *CMS_signed_get_attr(const CMS_SignerInfo *si, int loc)
81ebfedea0SLionel Sambuc {
82ebfedea0SLionel Sambuc     return X509at_get_attr(si->signedAttrs, loc);
83ebfedea0SLionel Sambuc }
84ebfedea0SLionel Sambuc 
CMS_signed_delete_attr(CMS_SignerInfo * si,int loc)85ebfedea0SLionel Sambuc X509_ATTRIBUTE *CMS_signed_delete_attr(CMS_SignerInfo *si, int loc)
86ebfedea0SLionel Sambuc {
87ebfedea0SLionel Sambuc     return X509at_delete_attr(si->signedAttrs, loc);
88ebfedea0SLionel Sambuc }
89ebfedea0SLionel Sambuc 
CMS_signed_add1_attr(CMS_SignerInfo * si,X509_ATTRIBUTE * attr)90ebfedea0SLionel Sambuc int CMS_signed_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
91ebfedea0SLionel Sambuc {
92*0a6a1f1dSLionel Sambuc     if (X509at_add1_attr(&si->signedAttrs, attr))
93*0a6a1f1dSLionel Sambuc         return 1;
94ebfedea0SLionel Sambuc     return 0;
95ebfedea0SLionel Sambuc }
96ebfedea0SLionel Sambuc 
CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo * si,const ASN1_OBJECT * obj,int type,const void * bytes,int len)97ebfedea0SLionel Sambuc int CMS_signed_add1_attr_by_OBJ(CMS_SignerInfo *si,
98ebfedea0SLionel Sambuc                                 const ASN1_OBJECT *obj, int type,
99ebfedea0SLionel Sambuc                                 const void *bytes, int len)
100ebfedea0SLionel Sambuc {
101*0a6a1f1dSLionel Sambuc     if (X509at_add1_attr_by_OBJ(&si->signedAttrs, obj, type, bytes, len))
102*0a6a1f1dSLionel Sambuc         return 1;
103ebfedea0SLionel Sambuc     return 0;
104ebfedea0SLionel Sambuc }
105ebfedea0SLionel Sambuc 
CMS_signed_add1_attr_by_NID(CMS_SignerInfo * si,int nid,int type,const void * bytes,int len)106ebfedea0SLionel Sambuc int CMS_signed_add1_attr_by_NID(CMS_SignerInfo *si,
107*0a6a1f1dSLionel Sambuc                                 int nid, int type, const void *bytes, int len)
108ebfedea0SLionel Sambuc {
109*0a6a1f1dSLionel Sambuc     if (X509at_add1_attr_by_NID(&si->signedAttrs, nid, type, bytes, len))
110*0a6a1f1dSLionel Sambuc         return 1;
111ebfedea0SLionel Sambuc     return 0;
112ebfedea0SLionel Sambuc }
113ebfedea0SLionel Sambuc 
CMS_signed_add1_attr_by_txt(CMS_SignerInfo * si,const char * attrname,int type,const void * bytes,int len)114ebfedea0SLionel Sambuc int CMS_signed_add1_attr_by_txt(CMS_SignerInfo *si,
115ebfedea0SLionel Sambuc                                 const char *attrname, int type,
116ebfedea0SLionel Sambuc                                 const void *bytes, int len)
117ebfedea0SLionel Sambuc {
118*0a6a1f1dSLionel Sambuc     if (X509at_add1_attr_by_txt(&si->signedAttrs, attrname, type, bytes, len))
119*0a6a1f1dSLionel Sambuc         return 1;
120ebfedea0SLionel Sambuc     return 0;
121ebfedea0SLionel Sambuc }
122ebfedea0SLionel Sambuc 
CMS_signed_get0_data_by_OBJ(CMS_SignerInfo * si,ASN1_OBJECT * oid,int lastpos,int type)123ebfedea0SLionel Sambuc void *CMS_signed_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
124ebfedea0SLionel Sambuc                                   int lastpos, int type)
125ebfedea0SLionel Sambuc {
126ebfedea0SLionel Sambuc     return X509at_get0_data_by_OBJ(si->signedAttrs, oid, lastpos, type);
127ebfedea0SLionel Sambuc }
128ebfedea0SLionel Sambuc 
CMS_unsigned_get_attr_count(const CMS_SignerInfo * si)129ebfedea0SLionel Sambuc int CMS_unsigned_get_attr_count(const CMS_SignerInfo *si)
130ebfedea0SLionel Sambuc {
131ebfedea0SLionel Sambuc     return X509at_get_attr_count(si->unsignedAttrs);
132ebfedea0SLionel Sambuc }
133ebfedea0SLionel Sambuc 
CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo * si,int nid,int lastpos)134ebfedea0SLionel Sambuc int CMS_unsigned_get_attr_by_NID(const CMS_SignerInfo *si, int nid,
135ebfedea0SLionel Sambuc                                  int lastpos)
136ebfedea0SLionel Sambuc {
137ebfedea0SLionel Sambuc     return X509at_get_attr_by_NID(si->unsignedAttrs, nid, lastpos);
138ebfedea0SLionel Sambuc }
139ebfedea0SLionel Sambuc 
CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo * si,ASN1_OBJECT * obj,int lastpos)140ebfedea0SLionel Sambuc int CMS_unsigned_get_attr_by_OBJ(const CMS_SignerInfo *si, ASN1_OBJECT *obj,
141ebfedea0SLionel Sambuc                                  int lastpos)
142ebfedea0SLionel Sambuc {
143ebfedea0SLionel Sambuc     return X509at_get_attr_by_OBJ(si->unsignedAttrs, obj, lastpos);
144ebfedea0SLionel Sambuc }
145ebfedea0SLionel Sambuc 
CMS_unsigned_get_attr(const CMS_SignerInfo * si,int loc)146ebfedea0SLionel Sambuc X509_ATTRIBUTE *CMS_unsigned_get_attr(const CMS_SignerInfo *si, int loc)
147ebfedea0SLionel Sambuc {
148ebfedea0SLionel Sambuc     return X509at_get_attr(si->unsignedAttrs, loc);
149ebfedea0SLionel Sambuc }
150ebfedea0SLionel Sambuc 
CMS_unsigned_delete_attr(CMS_SignerInfo * si,int loc)151ebfedea0SLionel Sambuc X509_ATTRIBUTE *CMS_unsigned_delete_attr(CMS_SignerInfo *si, int loc)
152ebfedea0SLionel Sambuc {
153ebfedea0SLionel Sambuc     return X509at_delete_attr(si->unsignedAttrs, loc);
154ebfedea0SLionel Sambuc }
155ebfedea0SLionel Sambuc 
CMS_unsigned_add1_attr(CMS_SignerInfo * si,X509_ATTRIBUTE * attr)156ebfedea0SLionel Sambuc int CMS_unsigned_add1_attr(CMS_SignerInfo *si, X509_ATTRIBUTE *attr)
157ebfedea0SLionel Sambuc {
158*0a6a1f1dSLionel Sambuc     if (X509at_add1_attr(&si->unsignedAttrs, attr))
159*0a6a1f1dSLionel Sambuc         return 1;
160ebfedea0SLionel Sambuc     return 0;
161ebfedea0SLionel Sambuc }
162ebfedea0SLionel Sambuc 
CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo * si,const ASN1_OBJECT * obj,int type,const void * bytes,int len)163ebfedea0SLionel Sambuc int CMS_unsigned_add1_attr_by_OBJ(CMS_SignerInfo *si,
164ebfedea0SLionel Sambuc                                   const ASN1_OBJECT *obj, int type,
165ebfedea0SLionel Sambuc                                   const void *bytes, int len)
166ebfedea0SLionel Sambuc {
167*0a6a1f1dSLionel Sambuc     if (X509at_add1_attr_by_OBJ(&si->unsignedAttrs, obj, type, bytes, len))
168*0a6a1f1dSLionel Sambuc         return 1;
169ebfedea0SLionel Sambuc     return 0;
170ebfedea0SLionel Sambuc }
171ebfedea0SLionel Sambuc 
CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo * si,int nid,int type,const void * bytes,int len)172ebfedea0SLionel Sambuc int CMS_unsigned_add1_attr_by_NID(CMS_SignerInfo *si,
173ebfedea0SLionel Sambuc                                   int nid, int type,
174ebfedea0SLionel Sambuc                                   const void *bytes, int len)
175ebfedea0SLionel Sambuc {
176*0a6a1f1dSLionel Sambuc     if (X509at_add1_attr_by_NID(&si->unsignedAttrs, nid, type, bytes, len))
177*0a6a1f1dSLionel Sambuc         return 1;
178ebfedea0SLionel Sambuc     return 0;
179ebfedea0SLionel Sambuc }
180ebfedea0SLionel Sambuc 
CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo * si,const char * attrname,int type,const void * bytes,int len)181ebfedea0SLionel Sambuc int CMS_unsigned_add1_attr_by_txt(CMS_SignerInfo *si,
182ebfedea0SLionel Sambuc                                   const char *attrname, int type,
183ebfedea0SLionel Sambuc                                   const void *bytes, int len)
184ebfedea0SLionel Sambuc {
185ebfedea0SLionel Sambuc     if (X509at_add1_attr_by_txt(&si->unsignedAttrs, attrname,
186*0a6a1f1dSLionel Sambuc                                 type, bytes, len))
187*0a6a1f1dSLionel Sambuc         return 1;
188ebfedea0SLionel Sambuc     return 0;
189ebfedea0SLionel Sambuc }
190ebfedea0SLionel Sambuc 
CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo * si,ASN1_OBJECT * oid,int lastpos,int type)191ebfedea0SLionel Sambuc void *CMS_unsigned_get0_data_by_OBJ(CMS_SignerInfo *si, ASN1_OBJECT *oid,
192ebfedea0SLionel Sambuc                                     int lastpos, int type)
193ebfedea0SLionel Sambuc {
194ebfedea0SLionel Sambuc     return X509at_get0_data_by_OBJ(si->unsignedAttrs, oid, lastpos, type);
195ebfedea0SLionel Sambuc }
196ebfedea0SLionel Sambuc 
197ebfedea0SLionel Sambuc /* Specific attribute cases */
198