v3_utl.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/* v3_utl.c */
/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
* project 1999.
*/
/* ====================================================================
* Copyright (c) 1999 The OpenSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
*
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please contact
* licensing@OpenSSL.org.
*
* 5. Products derived from this software may not be called "OpenSSL"
* nor may "OpenSSL" appear in their names without prior written
* permission of the OpenSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the OpenSSL Project
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*
* This product includes cryptographic software written by Eric Young
* (eay@cryptsoft.com). This product includes software written by Tim
* Hudson (tjh@cryptsoft.com).
*
*/
/* X509 v3 extension utilities */
#include <stdio.h>
#include <ctype.h>
#include "cryptlib.h"
static char *strip_spaces(char *name);
static int sk_strcmp(const char * const *a, const char * const *b);
/* Add a CONF_VALUE name value pair to stack */
{
return 1;
err:
return 0;
}
{
}
/* Free function for STACK_OF(CONF_VALUE) */
{
if(!conf) return;
}
{
}
{
return 1;
}
{
if(!a) return NULL;
return strtmp;
}
{
if(!a) return NULL;
return strtmp;
}
{
int ret;
if (!value) {
return 0;
}
if (value[0] == '-') {
value++;
isneg = 1;
} else isneg = 0;
value += 2;
ishex = 1;
} else ishex = 0;
if (!ret) {
return 0;
}
if (!aint) {
return 0;
}
return aint;
}
{
char *strtmp;
int ret;
if(!aint) return 1;
return ret;
}
{
char *btmp;
*asn1_bool = 0xff;
return 1;
*asn1_bool = 0;
return 1;
}
err:
return 0;
}
{
return 0;
}
return 1;
}
#define HDR_NAME 1
#define HDR_VALUE 2
/*#define DEBUG*/
{
char *p, *q, c;
char *linebuf;
int state;
/* We are going to modify the line so copy it first */
/* Go through all characters */
switch(state) {
case HDR_NAME:
if(c == ':') {
*p = 0;
ntmp = strip_spaces(q);
if(!ntmp) {
goto err;
}
q = p + 1;
} else if(c == ',') {
*p = 0;
ntmp = strip_spaces(q);
q = p + 1;
#if 0
#endif
if(!ntmp) {
goto err;
}
}
break ;
case HDR_VALUE:
if(c == ',') {
*p = 0;
vtmp = strip_spaces(q);
#if 0
#endif
if(!vtmp) {
goto err;
}
q = p + 1;
}
}
}
vtmp = strip_spaces(q);
#if 0
#endif
if(!vtmp) {
goto err;
}
} else {
ntmp = strip_spaces(q);
#if 0
#endif
if(!ntmp) {
goto err;
}
}
return values;
err:
return NULL;
}
/* Delete leading and trailing spaces from a string */
static char *strip_spaces(char *name)
{
char *p, *q;
/* Skip over leading spaces */
p = name;
while(*p && isspace((unsigned char)*p)) p++;
if(!*p) return NULL;
q = p + strlen(p) - 1;
while((q != p) && isspace((unsigned char)*q)) q--;
if(p != q) q[1] = 0;
if(!*p) return NULL;
return p;
}
/* hex string utilities */
/* Given a buffer of length 'len' return a OPENSSL_malloc'ed string with its
* hex representation
* @@@ (Contents of buffer are always kept in ASCII, also on EBCDIC machines)
*/
{
char *tmp, *q;
unsigned char *p;
int i;
static char hexdig[] = "0123456789ABCDEF";
return NULL;
}
q = tmp;
*q++ = hexdig[*p & 0xf];
*q++ = ':';
}
q[-1] = 0;
#ifdef CHARSET_EBCDIC
#endif
return tmp;
}
/* Give a string of hex digits convert to
* a buffer
*/
{
unsigned char *hexbuf, *q;
if(!str) {
return NULL;
}
ch = *p++;
#ifdef CHARSET_EBCDIC
#endif
if(ch == ':') continue;
cl = *p++;
#ifdef CHARSET_EBCDIC
#endif
if(!cl) {
return NULL;
}
else goto badhex;
else goto badhex;
}
return hexbuf;
err:
return NULL;
return NULL;
}
/* V2I name comparison function: returns zero if 'name' matches
* cmp or cmp.*
*/
{
char c;
if(!c || (c=='.')) return 0;
return 1;
}
static int sk_strcmp(const char * const *a, const char * const *b)
{
return strcmp(*a, *b);
}
{
return ret;
}
{
exts = X509_REQ_get_extensions(x);
return ret;
}
{
int i;
/* Now add any email address(es) to STACK */
i = -1;
/* First supplied X509_NAME */
while((i = X509_NAME_get_index_by_NID(name,
NID_pkcs9_emailAddress, i)) >= 0) {
}
for(i = 0; i < sk_GENERAL_NAME_num(gens); i++)
{
}
return ret;
}
{
}
{
char *emtmp;
/* First some sanity checks */
if(!*sk) return 0;
/* Don't add duplicates */
return 0;
}
return 1;
}
{
}