1160814Ssimon/* v3_pcons.c */ 2194206Ssimon/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3160814Ssimon * project. 4160814Ssimon */ 5160814Ssimon/* ==================================================================== 6160814Ssimon * Copyright (c) 2003 The OpenSSL Project. All rights reserved. 7160814Ssimon * 8160814Ssimon * Redistribution and use in source and binary forms, with or without 9160814Ssimon * modification, are permitted provided that the following conditions 10160814Ssimon * are met: 11160814Ssimon * 12160814Ssimon * 1. Redistributions of source code must retain the above copyright 13160814Ssimon * notice, this list of conditions and the following disclaimer. 14160814Ssimon * 15160814Ssimon * 2. Redistributions in binary form must reproduce the above copyright 16160814Ssimon * notice, this list of conditions and the following disclaimer in 17160814Ssimon * the documentation and/or other materials provided with the 18160814Ssimon * distribution. 19160814Ssimon * 20160814Ssimon * 3. All advertising materials mentioning features or use of this 21160814Ssimon * software must display the following acknowledgment: 22160814Ssimon * "This product includes software developed by the OpenSSL Project 23160814Ssimon * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 24160814Ssimon * 25160814Ssimon * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 26160814Ssimon * endorse or promote products derived from this software without 27160814Ssimon * prior written permission. For written permission, please contact 28160814Ssimon * licensing@OpenSSL.org. 29160814Ssimon * 30160814Ssimon * 5. Products derived from this software may not be called "OpenSSL" 31160814Ssimon * nor may "OpenSSL" appear in their names without prior written 32160814Ssimon * permission of the OpenSSL Project. 33160814Ssimon * 34160814Ssimon * 6. Redistributions of any form whatsoever must retain the following 35160814Ssimon * acknowledgment: 36160814Ssimon * "This product includes software developed by the OpenSSL Project 37160814Ssimon * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 38160814Ssimon * 39160814Ssimon * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 40160814Ssimon * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 41160814Ssimon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 42160814Ssimon * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 43160814Ssimon * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 44160814Ssimon * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 45160814Ssimon * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 46160814Ssimon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47160814Ssimon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 48160814Ssimon * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 49160814Ssimon * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 50160814Ssimon * OF THE POSSIBILITY OF SUCH DAMAGE. 51160814Ssimon * ==================================================================== 52160814Ssimon * 53160814Ssimon * This product includes cryptographic software written by Eric Young 54160814Ssimon * (eay@cryptsoft.com). This product includes software written by Tim 55160814Ssimon * Hudson (tjh@cryptsoft.com). 56160814Ssimon * 57160814Ssimon */ 58160814Ssimon 59160814Ssimon 60160814Ssimon#include <stdio.h> 61160814Ssimon#include "cryptlib.h" 62160814Ssimon#include <openssl/asn1.h> 63160814Ssimon#include <openssl/asn1t.h> 64160814Ssimon#include <openssl/conf.h> 65160814Ssimon#include <openssl/x509v3.h> 66160814Ssimon 67238405Sjkimstatic STACK_OF(CONF_VALUE) * 68238405Sjkimi2v_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *bcons, 69238405Sjkim STACK_OF(CONF_VALUE) *extlist); 70238405Sjkimstatic void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, 71238405Sjkim X509V3_CTX *ctx, 72238405Sjkim STACK_OF(CONF_VALUE) *values); 73160814Ssimon 74167612Ssimonconst X509V3_EXT_METHOD v3_policy_constraints = { 75160814SsimonNID_policy_constraints, 0, 76160814SsimonASN1_ITEM_ref(POLICY_CONSTRAINTS), 77160814Ssimon0,0,0,0, 78160814Ssimon0,0, 79160814Ssimoni2v_POLICY_CONSTRAINTS, 80160814Ssimonv2i_POLICY_CONSTRAINTS, 81160814SsimonNULL,NULL, 82160814SsimonNULL 83160814Ssimon}; 84160814Ssimon 85160814SsimonASN1_SEQUENCE(POLICY_CONSTRAINTS) = { 86160814Ssimon ASN1_IMP_OPT(POLICY_CONSTRAINTS, requireExplicitPolicy, ASN1_INTEGER,0), 87160814Ssimon ASN1_IMP_OPT(POLICY_CONSTRAINTS, inhibitPolicyMapping, ASN1_INTEGER,1) 88160814Ssimon} ASN1_SEQUENCE_END(POLICY_CONSTRAINTS) 89160814Ssimon 90160814SsimonIMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) 91160814Ssimon 92160814Ssimon 93238405Sjkimstatic STACK_OF(CONF_VALUE) * 94238405Sjkimi2v_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *a, 95238405Sjkim STACK_OF(CONF_VALUE) *extlist) 96160814Ssimon{ 97160814Ssimon POLICY_CONSTRAINTS *pcons = a; 98160814Ssimon X509V3_add_value_int("Require Explicit Policy", 99160814Ssimon pcons->requireExplicitPolicy, &extlist); 100160814Ssimon X509V3_add_value_int("Inhibit Policy Mapping", 101160814Ssimon pcons->inhibitPolicyMapping, &extlist); 102160814Ssimon return extlist; 103160814Ssimon} 104160814Ssimon 105238405Sjkimstatic void *v2i_POLICY_CONSTRAINTS(const X509V3_EXT_METHOD *method, 106238405Sjkim X509V3_CTX *ctx, 107238405Sjkim STACK_OF(CONF_VALUE) *values) 108160814Ssimon{ 109160814Ssimon POLICY_CONSTRAINTS *pcons=NULL; 110160814Ssimon CONF_VALUE *val; 111160814Ssimon int i; 112160814Ssimon if(!(pcons = POLICY_CONSTRAINTS_new())) { 113160814Ssimon X509V3err(X509V3_F_V2I_POLICY_CONSTRAINTS, ERR_R_MALLOC_FAILURE); 114160814Ssimon return NULL; 115160814Ssimon } 116160814Ssimon for(i = 0; i < sk_CONF_VALUE_num(values); i++) { 117160814Ssimon val = sk_CONF_VALUE_value(values, i); 118160814Ssimon if(!strcmp(val->name, "requireExplicitPolicy")) { 119160814Ssimon if(!X509V3_get_value_int(val, 120160814Ssimon &pcons->requireExplicitPolicy)) goto err; 121160814Ssimon } else if(!strcmp(val->name, "inhibitPolicyMapping")) { 122160814Ssimon if(!X509V3_get_value_int(val, 123160814Ssimon &pcons->inhibitPolicyMapping)) goto err; 124160814Ssimon } else { 125160814Ssimon X509V3err(X509V3_F_V2I_POLICY_CONSTRAINTS, X509V3_R_INVALID_NAME); 126160814Ssimon X509V3_conf_err(val); 127160814Ssimon goto err; 128160814Ssimon } 129160814Ssimon } 130160814Ssimon if (!pcons->inhibitPolicyMapping && !pcons->requireExplicitPolicy) { 131160814Ssimon X509V3err(X509V3_F_V2I_POLICY_CONSTRAINTS, X509V3_R_ILLEGAL_EMPTY_EXTENSION); 132160814Ssimon goto err; 133160814Ssimon } 134160814Ssimon 135160814Ssimon return pcons; 136160814Ssimon err: 137160814Ssimon POLICY_CONSTRAINTS_free(pcons); 138160814Ssimon return NULL; 139160814Ssimon} 140160814Ssimon 141