os/ossrv/ssl/libcrypto/src/crypto/asn1/asn_moid.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/asn1/asn_moid.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,160 @@
     1.4 +/* asn_moid.c */
     1.5 +/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
     1.6 + * project 2001.
     1.7 + */
     1.8 +/* ====================================================================
     1.9 + * Copyright (c) 2001-2004 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 +#include <stdio.h>
    1.63 +#include <ctype.h>
    1.64 +#include <openssl/crypto.h>
    1.65 +#include "cryptlib.h"
    1.66 +#include <openssl/conf.h>
    1.67 +#include <openssl/dso.h>
    1.68 +#include <openssl/x509.h>
    1.69 +
    1.70 +/* Simple ASN1 OID module: add all objects in a given section */
    1.71 +
    1.72 +static int do_create(char *value, char *name);
    1.73 +
    1.74 +static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
    1.75 +	{
    1.76 +	int i;
    1.77 +	const char *oid_section;
    1.78 +	STACK_OF(CONF_VALUE) *sktmp;
    1.79 +	CONF_VALUE *oval;
    1.80 +	oid_section = CONF_imodule_get_value(md);
    1.81 +	if(!(sktmp = NCONF_get_section(cnf, oid_section)))
    1.82 +		{
    1.83 +		ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION);
    1.84 +		return 0;
    1.85 +		}
    1.86 +	for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
    1.87 +		{
    1.88 +		oval = sk_CONF_VALUE_value(sktmp, i);
    1.89 +		if(!do_create(oval->value, oval->name))
    1.90 +			{
    1.91 +			ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
    1.92 +			return 0;
    1.93 +			}
    1.94 +		}
    1.95 +	return 1;
    1.96 +	}
    1.97 +
    1.98 +static void oid_module_finish(CONF_IMODULE *md)
    1.99 +	{
   1.100 +	OBJ_cleanup();
   1.101 +	}
   1.102 +
   1.103 +EXPORT_C void ASN1_add_oid_module(void)
   1.104 +	{
   1.105 +	CONF_module_add("oid_section", oid_module_init, oid_module_finish);
   1.106 +	}
   1.107 +
   1.108 +/* Create an OID based on a name value pair. Accept two formats.
   1.109 + * shortname = 1.2.3.4
   1.110 + * shortname = some long name, 1.2.3.4
   1.111 + */
   1.112 +
   1.113 +
   1.114 +static int do_create(char *value, char *name)
   1.115 +	{
   1.116 +	int nid;
   1.117 +	ASN1_OBJECT *oid;
   1.118 +	char *ln, *ostr, *p, *lntmp;
   1.119 +	p = strrchr(value, ',');
   1.120 +	if (!p)
   1.121 +		{
   1.122 +		ln = name;
   1.123 +		ostr = value;
   1.124 +		}
   1.125 +	else
   1.126 +		{
   1.127 +		ln = NULL;
   1.128 +		ostr = p + 1;
   1.129 +		if (!*ostr)
   1.130 +			return 0;
   1.131 +		while(isspace((unsigned char)*ostr)) ostr++;
   1.132 +		}
   1.133 +
   1.134 +	nid = OBJ_create(ostr, name, ln);
   1.135 +
   1.136 +	if (nid == NID_undef)
   1.137 +		return 0;
   1.138 +
   1.139 +	if (p)
   1.140 +		{
   1.141 +		ln = value;
   1.142 +		while(isspace((unsigned char)*ln)) ln++;
   1.143 +		p--;
   1.144 +		while(isspace((unsigned char)*p))
   1.145 +			{
   1.146 +			if (p == ln)
   1.147 +				return 0;
   1.148 +			p--;
   1.149 +			}
   1.150 +		p++;
   1.151 +		lntmp = OPENSSL_malloc((p - ln) + 1);
   1.152 +		if (lntmp == NULL)
   1.153 +			return 0;
   1.154 +		memcpy(lntmp, ln, p - ln);
   1.155 +		lntmp[p - ln] = 0;
   1.156 +		oid = OBJ_nid2obj(nid);
   1.157 +		oid->ln = lntmp;
   1.158 +		}
   1.159 +
   1.160 +	return 1;
   1.161 +	}
   1.162 +		
   1.163 +