155714Skris/* v3_bitst.c */ 2194206Ssimon/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 355714Skris * project 1999. 455714Skris */ 555714Skris/* ==================================================================== 655714Skris * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 755714Skris * 855714Skris * Redistribution and use in source and binary forms, with or without 955714Skris * modification, are permitted provided that the following conditions 1055714Skris * are met: 1155714Skris * 1255714Skris * 1. Redistributions of source code must retain the above copyright 1355714Skris * notice, this list of conditions and the following disclaimer. 1455714Skris * 1555714Skris * 2. Redistributions in binary form must reproduce the above copyright 1655714Skris * notice, this list of conditions and the following disclaimer in 1755714Skris * the documentation and/or other materials provided with the 1855714Skris * distribution. 1955714Skris * 2055714Skris * 3. All advertising materials mentioning features or use of this 2155714Skris * software must display the following acknowledgment: 2255714Skris * "This product includes software developed by the OpenSSL Project 2355714Skris * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 2455714Skris * 2555714Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 2655714Skris * endorse or promote products derived from this software without 2755714Skris * prior written permission. For written permission, please contact 2855714Skris * licensing@OpenSSL.org. 2955714Skris * 3055714Skris * 5. Products derived from this software may not be called "OpenSSL" 3155714Skris * nor may "OpenSSL" appear in their names without prior written 3255714Skris * permission of the OpenSSL Project. 3355714Skris * 3455714Skris * 6. Redistributions of any form whatsoever must retain the following 3555714Skris * acknowledgment: 3655714Skris * "This product includes software developed by the OpenSSL Project 3755714Skris * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 3855714Skris * 3955714Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 4055714Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4155714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4255714Skris * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 4355714Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4455714Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 4555714Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4655714Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4755714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4855714Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 4955714Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 5055714Skris * OF THE POSSIBILITY OF SUCH DAMAGE. 5155714Skris * ==================================================================== 5255714Skris * 5355714Skris * This product includes cryptographic software written by Eric Young 5455714Skris * (eay@cryptsoft.com). This product includes software written by Tim 5555714Skris * Hudson (tjh@cryptsoft.com). 5655714Skris * 5755714Skris */ 5855714Skris 5955714Skris#include <stdio.h> 6055714Skris#include "cryptlib.h" 6155714Skris#include <openssl/conf.h> 6255714Skris#include <openssl/x509v3.h> 6355714Skris 6455714Skrisstatic BIT_STRING_BITNAME ns_cert_type_table[] = { 6555714Skris{0, "SSL Client", "client"}, 6655714Skris{1, "SSL Server", "server"}, 6755714Skris{2, "S/MIME", "email"}, 6855714Skris{3, "Object Signing", "objsign"}, 6955714Skris{4, "Unused", "reserved"}, 7055714Skris{5, "SSL CA", "sslCA"}, 7155714Skris{6, "S/MIME CA", "emailCA"}, 7255714Skris{7, "Object Signing CA", "objCA"}, 7355714Skris{-1, NULL, NULL} 7455714Skris}; 7555714Skris 7655714Skrisstatic BIT_STRING_BITNAME key_usage_type_table[] = { 7755714Skris{0, "Digital Signature", "digitalSignature"}, 7855714Skris{1, "Non Repudiation", "nonRepudiation"}, 7955714Skris{2, "Key Encipherment", "keyEncipherment"}, 8055714Skris{3, "Data Encipherment", "dataEncipherment"}, 8155714Skris{4, "Key Agreement", "keyAgreement"}, 8255714Skris{5, "Certificate Sign", "keyCertSign"}, 8355714Skris{6, "CRL Sign", "cRLSign"}, 8455714Skris{7, "Encipher Only", "encipherOnly"}, 8555714Skris{8, "Decipher Only", "decipherOnly"}, 8655714Skris{-1, NULL, NULL} 8755714Skris}; 8855714Skris 8955714Skris 9055714Skris 91167612Ssimonconst X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table); 92167612Ssimonconst X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table); 9355714Skris 94160814SsimonSTACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 9555714Skris ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret) 9655714Skris{ 9755714Skris BIT_STRING_BITNAME *bnam; 9855714Skris for(bnam =method->usr_data; bnam->lname; bnam++) { 9955714Skris if(ASN1_BIT_STRING_get_bit(bits, bnam->bitnum)) 10055714Skris X509V3_add_value(bnam->lname, NULL, &ret); 10155714Skris } 10255714Skris return ret; 10355714Skris} 10455714Skris 105160814SsimonASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 10655714Skris X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) 10755714Skris{ 10855714Skris CONF_VALUE *val; 10955714Skris ASN1_BIT_STRING *bs; 11055714Skris int i; 11155714Skris BIT_STRING_BITNAME *bnam; 11259191Skris if(!(bs = M_ASN1_BIT_STRING_new())) { 11355714Skris X509V3err(X509V3_F_V2I_ASN1_BIT_STRING,ERR_R_MALLOC_FAILURE); 11455714Skris return NULL; 11555714Skris } 11655714Skris for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { 11755714Skris val = sk_CONF_VALUE_value(nval, i); 11855714Skris for(bnam = method->usr_data; bnam->lname; bnam++) { 11955714Skris if(!strcmp(bnam->sname, val->name) || 12055714Skris !strcmp(bnam->lname, val->name) ) { 121160814Ssimon if(!ASN1_BIT_STRING_set_bit(bs, bnam->bitnum, 1)) { 122160814Ssimon X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, 123160814Ssimon ERR_R_MALLOC_FAILURE); 124160814Ssimon M_ASN1_BIT_STRING_free(bs); 125160814Ssimon return NULL; 126160814Ssimon } 12755714Skris break; 12855714Skris } 12955714Skris } 13055714Skris if(!bnam->lname) { 13155714Skris X509V3err(X509V3_F_V2I_ASN1_BIT_STRING, 13255714Skris X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT); 13355714Skris X509V3_conf_err(val); 13459191Skris M_ASN1_BIT_STRING_free(bs); 13555714Skris return NULL; 13655714Skris } 13755714Skris } 13855714Skris return bs; 13955714Skris} 14055714Skris 14155714Skris 142