v3_bitst.c revision 160814
155682Smarkm/* v3_bitst.c */ 2233294Sstas/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 3233294Sstas * project 1999. 4233294Sstas */ 555682Smarkm/* ==================================================================== 6233294Sstas * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 7233294Sstas * 8233294Sstas * Redistribution and use in source and binary forms, with or without 955682Smarkm * modification, are permitted provided that the following conditions 10233294Sstas * are met: 11233294Sstas * 1255682Smarkm * 1. Redistributions of source code must retain the above copyright 13233294Sstas * notice, this list of conditions and the following disclaimer. 14233294Sstas * 15233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 1655682Smarkm * notice, this list of conditions and the following disclaimer in 17233294Sstas * the documentation and/or other materials provided with the 18233294Sstas * distribution. 19233294Sstas * 2055682Smarkm * 3. All advertising materials mentioning features or use of this 21233294Sstas * software must display the following acknowledgment: 22233294Sstas * "This product includes software developed by the OpenSSL Project 23233294Sstas * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24233294Sstas * 25233294Sstas * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26233294Sstas * endorse or promote products derived from this software without 27233294Sstas * prior written permission. For written permission, please contact 28233294Sstas * licensing@OpenSSL.org. 29233294Sstas * 30233294Sstas * 5. Products derived from this software may not be called "OpenSSL" 31233294Sstas * nor may "OpenSSL" appear in their names without prior written 3255682Smarkm * permission of the OpenSSL Project. 3355682Smarkm * 3455682Smarkm * 6. Redistributions of any form whatsoever must retain the following 35233294Sstas * acknowledgment: 3655682Smarkm * "This product includes software developed by the OpenSSL Project 3755682Smarkm * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 3855682Smarkm * 3955682Smarkm * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 4055682Smarkm * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4155682Smarkm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4255682Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 4372445Sassar * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4455682Smarkm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 4555682Smarkm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4655682Smarkm * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4755682Smarkm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4855682Smarkm * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 4955682Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 5055682Smarkm * OF THE POSSIBILITY OF SUCH DAMAGE. 5155682Smarkm * ==================================================================== 5255682Smarkm * 53178825Sdfr * This product includes cryptographic software written by Eric Young 5455682Smarkm * (eay@cryptsoft.com). This product includes software written by Tim 5555682Smarkm * Hudson (tjh@cryptsoft.com). 5655682Smarkm * 5755682Smarkm */ 5855682Smarkm 5955682Smarkm#include <stdio.h> 6055682Smarkm#include "cryptlib.h" 6155682Smarkm#include <openssl/conf.h> 6255682Smarkm#include <openssl/x509v3.h> 6355682Smarkm 6455682Smarkmstatic BIT_STRING_BITNAME ns_cert_type_table[] = { 6555682Smarkm{0, "SSL Client", "client"}, 6655682Smarkm{1, "SSL Server", "server"}, 6772445Sassar{2, "S/MIME", "email"}, 6855682Smarkm{3, "Object Signing", "objsign"}, 6955682Smarkm{4, "Unused", "reserved"}, 7055682Smarkm{5, "SSL CA", "sslCA"}, 7155682Smarkm{6, "S/MIME CA", "emailCA"}, 7255682Smarkm{7, "Object Signing CA", "objCA"}, 7355682Smarkm{-1, NULL, NULL} 7455682Smarkm}; 7555682Smarkm 7655682Smarkmstatic BIT_STRING_BITNAME key_usage_type_table[] = { 7755682Smarkm{0, "Digital Signature", "digitalSignature"}, 7855682Smarkm{1, "Non Repudiation", "nonRepudiation"}, 7955682Smarkm{2, "Key Encipherment", "keyEncipherment"}, 8055682Smarkm{3, "Data Encipherment", "dataEncipherment"}, 8155682Smarkm{4, "Key Agreement", "keyAgreement"}, 8255682Smarkm{5, "Certificate Sign", "keyCertSign"}, 8355682Smarkm{6, "CRL Sign", "cRLSign"}, 8455682Smarkm{7, "Encipher Only", "encipherOnly"}, 8555682Smarkm{8, "Decipher Only", "decipherOnly"}, 8655682Smarkm{-1, NULL, NULL} 8755682Smarkm}; 8855682Smarkm 8955682Smarkm 9055682Smarkm 9155682SmarkmX509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table); 92178825SdfrX509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table); 93178825Sdfr 9455682SmarkmSTACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 9555682Smarkm ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret) 9655682Smarkm{ 9755682Smarkm BIT_STRING_BITNAME *bnam; 98233294Sstas for(bnam =method->usr_data; bnam->lname; bnam++) { 99233294Sstas if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum)) 100233294Sstas X509V3_add_value(bnam->lname, NULL, &ret); 10155682Smarkm } 10255682Smarkm return ret; 10355682Smarkm} 104178825Sdfr 105233294SstasASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 10655682Smarkm X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) 10755682Smarkm{ 10855682Smarkm CONF_VALUE *val; 10955682Smarkm ASN1_BIT_STRING *bs; 11055682Smarkm int i; 11155682Smarkm BIT_STRING_BITNAME *bnam; 11255682Smarkm if(!(bs = M_ASN1_BIT_STRING_new())) { 11355682Smarkm X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE); 11455682Smarkm return NULL; 11555682Smarkm } 11655682Smarkm for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { 11755682Smarkm val = sk_CONF_VALUE_value(nval, i); 11855682Smarkm for(bnam = method->usr_data; bnam->lname; bnam++) { 11955682Smarkm if(!strcmp(bnam->sname, val->name) || 12055682Smarkm !strcmp(bnam->lname, val->name) ) { 12155682Smarkm if(!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) { 12255682Smarkm X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, 12355682Smarkm ERR_R_MALLOC_FAILURE); 12455682Smarkm M_ASN1_BIT_STRING_free(bs); 12555682Smarkm return NULL; 12655682Smarkm } 12755682Smarkm break; 12855682Smarkm } 12955682Smarkm } 13055682Smarkm if(!bnam->lname) { 131233294Sstas X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, 132233294Sstas X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT); 133178825Sdfr X509V3_conf_err(val); 13455682Smarkm M_ASN1_BIT_STRING_free(bs); 13555682Smarkm return NULL; 13655682Smarkm } 137233294Sstas } 138178825Sdfr return bs; 139178825Sdfr} 140178825Sdfr 141178825Sdfr 142178825Sdfr