155714Skris/* v3_bcons.c */ 2296465Sdelphij/* 3296465Sdelphij * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project 4296465Sdelphij * 1999. 555714Skris */ 655714Skris/* ==================================================================== 755714Skris * Copyright (c) 1999 The OpenSSL Project. All rights reserved. 855714Skris * 955714Skris * Redistribution and use in source and binary forms, with or without 1055714Skris * modification, are permitted provided that the following conditions 1155714Skris * are met: 1255714Skris * 1355714Skris * 1. Redistributions of source code must retain the above copyright 14296465Sdelphij * notice, this list of conditions and the following disclaimer. 1555714Skris * 1655714Skris * 2. Redistributions in binary form must reproduce the above copyright 1755714Skris * notice, this list of conditions and the following disclaimer in 1855714Skris * the documentation and/or other materials provided with the 1955714Skris * distribution. 2055714Skris * 2155714Skris * 3. All advertising materials mentioning features or use of this 2255714Skris * software must display the following acknowledgment: 2355714Skris * "This product includes software developed by the OpenSSL Project 2455714Skris * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 2555714Skris * 2655714Skris * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 2755714Skris * endorse or promote products derived from this software without 2855714Skris * prior written permission. For written permission, please contact 2955714Skris * licensing@OpenSSL.org. 3055714Skris * 3155714Skris * 5. Products derived from this software may not be called "OpenSSL" 3255714Skris * nor may "OpenSSL" appear in their names without prior written 3355714Skris * permission of the OpenSSL Project. 3455714Skris * 3555714Skris * 6. Redistributions of any form whatsoever must retain the following 3655714Skris * acknowledgment: 3755714Skris * "This product includes software developed by the OpenSSL Project 3855714Skris * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 3955714Skris * 4055714Skris * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 4155714Skris * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4255714Skris * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 4355714Skris * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 4455714Skris * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 4555714Skris * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 4655714Skris * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4755714Skris * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 4855714Skris * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 4955714Skris * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 5055714Skris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 5155714Skris * OF THE POSSIBILITY OF SUCH DAMAGE. 5255714Skris * ==================================================================== 5355714Skris * 5455714Skris * This product includes cryptographic software written by Eric Young 5555714Skris * (eay@cryptsoft.com). This product includes software written by Tim 5655714Skris * Hudson (tjh@cryptsoft.com). 5755714Skris * 5855714Skris */ 5955714Skris 6055714Skris#include <stdio.h> 6155714Skris#include "cryptlib.h" 6255714Skris#include <openssl/asn1.h> 63109998Smarkm#include <openssl/asn1t.h> 6455714Skris#include <openssl/conf.h> 6555714Skris#include <openssl/x509v3.h> 6655714Skris 67296465Sdelphijstatic STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, 68296465Sdelphij BASIC_CONSTRAINTS *bcons, 69296465Sdelphij STACK_OF(CONF_VALUE) 70296465Sdelphij *extlist); 71296465Sdelphijstatic BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, 72296465Sdelphij X509V3_CTX *ctx, 73296465Sdelphij STACK_OF(CONF_VALUE) *values); 7455714Skris 75167612Ssimonconst X509V3_EXT_METHOD v3_bcons = { 76296465Sdelphij NID_basic_constraints, 0, 77296465Sdelphij ASN1_ITEM_ref(BASIC_CONSTRAINTS), 78296465Sdelphij 0, 0, 0, 0, 79296465Sdelphij 0, 0, 80296465Sdelphij (X509V3_EXT_I2V) i2v_BASIC_CONSTRAINTS, 81296465Sdelphij (X509V3_EXT_V2I)v2i_BASIC_CONSTRAINTS, 82296465Sdelphij NULL, NULL, 83296465Sdelphij NULL 8455714Skris}; 8555714Skris 86109998SmarkmASN1_SEQUENCE(BASIC_CONSTRAINTS) = { 87296465Sdelphij ASN1_OPT(BASIC_CONSTRAINTS, ca, ASN1_FBOOLEAN), 88296465Sdelphij ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER) 89109998Smarkm} ASN1_SEQUENCE_END(BASIC_CONSTRAINTS) 9055714Skris 91109998SmarkmIMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) 9255714Skris 9355714Skrisstatic STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, 94296465Sdelphij BASIC_CONSTRAINTS *bcons, 95296465Sdelphij STACK_OF(CONF_VALUE) 96296465Sdelphij *extlist) 9755714Skris{ 98296465Sdelphij X509V3_add_value_bool("CA", bcons->ca, &extlist); 99296465Sdelphij X509V3_add_value_int("pathlen", bcons->pathlen, &extlist); 100296465Sdelphij return extlist; 10155714Skris} 10255714Skris 10355714Skrisstatic BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, 104296465Sdelphij X509V3_CTX *ctx, 105296465Sdelphij STACK_OF(CONF_VALUE) *values) 10655714Skris{ 107296465Sdelphij BASIC_CONSTRAINTS *bcons = NULL; 108296465Sdelphij CONF_VALUE *val; 109296465Sdelphij int i; 110296465Sdelphij if (!(bcons = BASIC_CONSTRAINTS_new())) { 111296465Sdelphij X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, ERR_R_MALLOC_FAILURE); 112296465Sdelphij return NULL; 113296465Sdelphij } 114296465Sdelphij for (i = 0; i < sk_CONF_VALUE_num(values); i++) { 115296465Sdelphij val = sk_CONF_VALUE_value(values, i); 116296465Sdelphij if (!strcmp(val->name, "CA")) { 117296465Sdelphij if (!X509V3_get_value_bool(val, &bcons->ca)) 118296465Sdelphij goto err; 119296465Sdelphij } else if (!strcmp(val->name, "pathlen")) { 120296465Sdelphij if (!X509V3_get_value_int(val, &bcons->pathlen)) 121296465Sdelphij goto err; 122296465Sdelphij } else { 123296465Sdelphij X509V3err(X509V3_F_V2I_BASIC_CONSTRAINTS, X509V3_R_INVALID_NAME); 124296465Sdelphij X509V3_conf_err(val); 125296465Sdelphij goto err; 126296465Sdelphij } 127296465Sdelphij } 128296465Sdelphij return bcons; 129296465Sdelphij err: 130296465Sdelphij BASIC_CONSTRAINTS_free(bcons); 131296465Sdelphij return NULL; 13255714Skris} 133