1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/x509v3/v3_extku.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,173 @@
1.4 +/* v3_extku.c */
1.5 +/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
1.6 + * project 1999.
1.7 + */
1.8 +/* ====================================================================
1.9 + * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
1.10 + *
1.11 + * Redistribution and use in source and binary forms, with or without
1.12 + * modification, are permitted provided that the following conditions
1.13 + * are met:
1.14 + *
1.15 + * 1. Redistributions of source code must retain the above copyright
1.16 + * notice, this list of conditions and the following disclaimer.
1.17 + *
1.18 + * 2. Redistributions in binary form must reproduce the above copyright
1.19 + * notice, this list of conditions and the following disclaimer in
1.20 + * the documentation and/or other materials provided with the
1.21 + * distribution.
1.22 + *
1.23 + * 3. All advertising materials mentioning features or use of this
1.24 + * software must display the following acknowledgment:
1.25 + * "This product includes software developed by the OpenSSL Project
1.26 + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
1.27 + *
1.28 + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
1.29 + * endorse or promote products derived from this software without
1.30 + * prior written permission. For written permission, please contact
1.31 + * licensing@OpenSSL.org.
1.32 + *
1.33 + * 5. Products derived from this software may not be called "OpenSSL"
1.34 + * nor may "OpenSSL" appear in their names without prior written
1.35 + * permission of the OpenSSL Project.
1.36 + *
1.37 + * 6. Redistributions of any form whatsoever must retain the following
1.38 + * acknowledgment:
1.39 + * "This product includes software developed by the OpenSSL Project
1.40 + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
1.41 + *
1.42 + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
1.43 + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.44 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1.45 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
1.46 + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1.47 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
1.48 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
1.49 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.50 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1.51 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1.52 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1.53 + * OF THE POSSIBILITY OF SUCH DAMAGE.
1.54 + * ====================================================================
1.55 + *
1.56 + * This product includes cryptographic software written by Eric Young
1.57 + * (eay@cryptsoft.com). This product includes software written by Tim
1.58 + * Hudson (tjh@cryptsoft.com).
1.59 + *
1.60 + */
1.61 +/*
1.62 + © Portions copyright (c) 2006, 2010 Nokia Corporation. All rights reserved.
1.63 + */
1.64 +
1.65 +#include <stdio.h>
1.66 +#include "cryptlib.h"
1.67 +#include <openssl/asn1t.h>
1.68 +#include <openssl/conf.h>
1.69 +#include <openssl/x509v3.h>
1.70 +#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
1.71 +#include "libcrypto_wsd_macros.h"
1.72 +#include "libcrypto_wsd.h"
1.73 +#endif
1.74 +static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
1.75 + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
1.76 +static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
1.77 + void *eku, STACK_OF(CONF_VALUE) *extlist);
1.78 +
1.79 +#ifndef EMULATOR
1.80 +EXPORT_C X509V3_EXT_METHOD v3_ext_ku = {
1.81 + NID_ext_key_usage, 0,
1.82 + ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
1.83 + 0,0,0,0,
1.84 + 0,0,
1.85 + i2v_EXTENDED_KEY_USAGE,
1.86 + v2i_EXTENDED_KEY_USAGE,
1.87 + 0,0,
1.88 + NULL
1.89 +};
1.90 +#else
1.91 +EXPORT_C const X509V3_EXT_METHOD v3_ext_ku = {
1.92 + NID_ext_key_usage, 0,
1.93 + ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
1.94 + 0,0,0,0,
1.95 + 0,0,
1.96 + i2v_EXTENDED_KEY_USAGE,
1.97 + v2i_EXTENDED_KEY_USAGE,
1.98 + 0,0,
1.99 + NULL
1.100 +};
1.101 +#endif
1.102 +
1.103 +#ifndef EMULATOR
1.104 +/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
1.105 +EXPORT_C X509V3_EXT_METHOD v3_ocsp_accresp = {
1.106 + NID_id_pkix_OCSP_acceptableResponses, 0,
1.107 + ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
1.108 + 0,0,0,0,
1.109 + 0,0,
1.110 + i2v_EXTENDED_KEY_USAGE,
1.111 + v2i_EXTENDED_KEY_USAGE,
1.112 + 0,0,
1.113 + NULL
1.114 +};
1.115 +#else
1.116 +EXPORT_C const X509V3_EXT_METHOD v3_ocsp_accresp = {
1.117 + NID_id_pkix_OCSP_acceptableResponses, 0,
1.118 + ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
1.119 + 0,0,0,0,
1.120 + 0,0,
1.121 + i2v_EXTENDED_KEY_USAGE,
1.122 + v2i_EXTENDED_KEY_USAGE,
1.123 + 0,0,
1.124 + NULL
1.125 +};
1.126 +#endif
1.127 +
1.128 +ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) =
1.129 + ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT)
1.130 +ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE)
1.131 +
1.132 +IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE)
1.133 +
1.134 +static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
1.135 + void *a, STACK_OF(CONF_VALUE) *ext_list)
1.136 +{
1.137 + EXTENDED_KEY_USAGE *eku = a;
1.138 + int i;
1.139 + ASN1_OBJECT *obj;
1.140 + char obj_tmp[80];
1.141 + for(i = 0; i < sk_ASN1_OBJECT_num(eku); i++) {
1.142 + obj = sk_ASN1_OBJECT_value(eku, i);
1.143 + i2t_ASN1_OBJECT(obj_tmp, 80, obj);
1.144 + X509V3_add_value(NULL, obj_tmp, &ext_list);
1.145 + }
1.146 + return ext_list;
1.147 +}
1.148 +
1.149 +static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
1.150 + X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
1.151 +{
1.152 + EXTENDED_KEY_USAGE *extku;
1.153 + char *extval;
1.154 + ASN1_OBJECT *objtmp;
1.155 + CONF_VALUE *val;
1.156 + int i;
1.157 +
1.158 + if(!(extku = sk_ASN1_OBJECT_new_null())) {
1.159 + X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,ERR_R_MALLOC_FAILURE);
1.160 + return NULL;
1.161 + }
1.162 +
1.163 + for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
1.164 + val = sk_CONF_VALUE_value(nval, i);
1.165 + if(val->value) extval = val->value;
1.166 + else extval = val->name;
1.167 + if(!(objtmp = OBJ_txt2obj(extval, 0))) {
1.168 + sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
1.169 + X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,X509V3_R_INVALID_OBJECT_IDENTIFIER);
1.170 + X509V3_conf_err(val);
1.171 + return NULL;
1.172 + }
1.173 + sk_ASN1_OBJECT_push(extku, objtmp);
1.174 + }
1.175 + return extku;
1.176 +}