Support for ASN1 NULL type.

This commit is contained in:
Dr. Stephen Henson 1999-12-22 01:39:23 +00:00
parent 15df5802fd
commit e76f935ead
6 changed files with 142 additions and 3 deletions

View File

@ -4,6 +4,13 @@
Changes between 0.9.4 and 0.9.5 [xx XXX 1999]
*) Support for ASN1 "NULL" type. This could be handled before by using
ASN1_TYPE but there wasn't any function that would try to read a NULL
and produce an error if it couldn't. For compatability we also have
ASN1_NULL_new() and ASN1_NULL_free() functions but these are faked and
don't allocate anything because they don't need to.
[Steve Henson]
*) Initial support for MacOS is now provided. Examine INSTALL.MacOS
for details.
[Andy Polyakov, Roy Woods <roy@centicsystems.ca>]

View File

@ -23,7 +23,7 @@ APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \
a_null.c a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c a_bmp.c \
a_enum.c a_vis.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c \
x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c \
x_name.c x_cinf.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c \
@ -38,7 +38,7 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \
evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c
LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \
a_null.o a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o a_bmp.o \
a_enum.o a_vis.o a_utf8.o a_sign.o a_digest.o a_verify.o a_mbstr.o \
x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o \
x_name.o x_cinf.o x_x509.o x_x509a.o x_crl.o x_info.o x_spki.o nsseq.o \

119
crypto/asn1/a_null.c Normal file
View File

@ -0,0 +1,119 @@
/* a_null.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
* the documentation and/or other materials provided with the
* 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).
*
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/asn1.h>
/* ASN1 functions for NULL type. For compatability with other ASN1 code
* it returns a pointer to an "ASN1_NULL" structure. The new/free functions
* don't need to do any allocating because nothing is stored in a NULL.
*/
int i2d_ASN1_NULL(ASN1_NULL *a, unsigned char **pp)
{
if(!a) return 0;
if (pp) ASN1_put_object(pp,0,0,V_ASN1_NULL,V_ASN1_UNIVERSAL);
return 2;
}
ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp, long length)
{
ASN1_NULL *ret = NULL;
unsigned char *p;
long len;
int inf,tag,xclass;
int i=0;
p= *pp;
inf=ASN1_get_object(&p,&len,&tag,&xclass,length);
if (inf & 0x80)
{
i=ASN1_R_BAD_OBJECT_HEADER;
goto err;
}
if (tag != V_ASN1_NULL)
{
i=ASN1_R_EXPECTING_A_NULL;
goto err;
}
if (len != 0)
{
i=ASN1_R_NULL_IS_WRONG_LENGTH;
goto err;
}
ret=(ASN1_NULL *)1;
if (a != NULL) (*a)=ret;
*pp=p;
return(ret);
err:
ASN1err(ASN1_F_D2I_ASN1_NULL,i);
return(ret);
}
ASN1_NULL *ASN1_NULL_new(void)
{
return (ASN1_NULL *)1;
}
void ASN1_NULL_free(ASN1_NULL *a)
{
return;
}

View File

@ -268,6 +268,8 @@ typedef struct asn1_string_st ASN1_VISIBLESTRING;
typedef struct asn1_string_st ASN1_UTF8STRING;
#endif
typedef int ASN1_NULL;
typedef struct asn1_type_st
{
int type;
@ -599,6 +601,11 @@ int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
unsigned char **pp,long length);
ASN1_NULL * ASN1_NULL_new(void);
void ASN1_NULL_free(ASN1_NULL *a);
int i2d_ASN1_NULL(ASN1_NULL *a,unsigned char **pp);
ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **a, unsigned char **pp,long length);
ASN1_BMPSTRING * ASN1_BMPSTRING_new(void);
void ASN1_BMPSTRING_free(ASN1_BMPSTRING *a);
int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
@ -832,6 +839,7 @@ void ASN1_STRING_TABLE_cleanup(void);
#define ASN1_F_D2I_ASN1_GENERALIZEDTIME 223
#define ASN1_F_D2I_ASN1_HEADER 127
#define ASN1_F_D2I_ASN1_INTEGER 128
#define ASN1_F_D2I_ASN1_NULL 292
#define ASN1_F_D2I_ASN1_OBJECT 129
#define ASN1_F_D2I_ASN1_OCTET_STRING 130
#define ASN1_F_D2I_ASN1_PRINT_TYPE 131
@ -1002,6 +1010,7 @@ void ASN1_STRING_TABLE_cleanup(void);
#define ASN1_R_EXPECTING_A_BIT_STRING 116
#define ASN1_R_EXPECTING_A_BOOLEAN 117
#define ASN1_R_EXPECTING_A_GENERALIZEDTIME 151
#define ASN1_R_EXPECTING_A_NULL 164
#define ASN1_R_EXPECTING_A_TIME 152
#define ASN1_R_EXPECTING_A_UTCTIME 118
#define ASN1_R_FIRST_NUM_TOO_LARGE 119
@ -1019,6 +1028,7 @@ void ASN1_STRING_TABLE_cleanup(void);
#define ASN1_R_MISSING_SECOND_NUMBER 126
#define ASN1_R_NON_HEX_CHARACTERS 127
#define ASN1_R_NOT_ENOUGH_DATA 128
#define ASN1_R_NULL_IS_WRONG_LENGTH 165
#define ASN1_R_ODD_NUMBER_OF_CHARS 129
#define ASN1_R_PARSING 130
#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 131

View File

@ -112,6 +112,7 @@ static ERR_STRING_DATA ASN1_str_functs[]=
{ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "d2i_ASN1_GENERALIZEDTIME"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "d2i_ASN1_INTEGER"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_NULL,0), "d2i_ASN1_NULL"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_OCTET_STRING,0), "d2i_ASN1_OCTET_STRING"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_PRINT_TYPE,0), "D2I_ASN1_PRINT_TYPE"},
@ -285,6 +286,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
{ASN1_R_EXPECTING_A_BIT_STRING ,"expecting a bit string"},
{ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"},
{ASN1_R_EXPECTING_A_GENERALIZEDTIME ,"expecting a generalizedtime"},
{ASN1_R_EXPECTING_A_NULL ,"expecting a null"},
{ASN1_R_EXPECTING_A_TIME ,"expecting a time"},
{ASN1_R_EXPECTING_A_UTCTIME ,"expecting a utctime"},
{ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"},
@ -302,6 +304,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
{ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"},
{ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"},
{ASN1_R_NOT_ENOUGH_DATA ,"not enough data"},
{ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"},
{ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"},
{ASN1_R_PARSING ,"parsing"},
{ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"},

View File

@ -111,7 +111,7 @@ err:\
c.slen = length;
/* End reading ASN1 with no check on length */
#define M_ASN1_D2I_Finish_nolen() \
#define M_ASN1_D2I_Finish_nolen(a, func, e) \
*pp=c.p; \
if (a != NULL) (*a)=ret; \
return(ret); \