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