Add support for VISIBLESTRING and UTF8String

This commit is contained in:
Dr. Stephen Henson 1999-04-17 15:53:32 +00:00
parent cfdcfede9c
commit d77b3054cd
10 changed files with 253 additions and 5 deletions

View File

@ -5,6 +5,9 @@
Changes between 0.9.2b and 0.9.3
*) Add support for ASN1 types UTF8String and VISIBLESTRING.
[Steve Henson]
*) Add code to allow r2i extensions to access the configuration database,
add an LHASH database driver and add several ctx helper functions.
[Steve Henson]

View File

@ -24,7 +24,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_enum.c a_sign.c a_digest.c a_verify.c \
a_enum.c a_vis.c a_utf8.c a_sign.c a_digest.c a_verify.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_crl.c x_info.c x_spki.c nsseq.c \
d2i_r_pr.c i2d_r_pr.c d2i_r_pu.c i2d_r_pu.c \
@ -39,7 +39,7 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.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_enum.o a_sign.o a_digest.o a_verify.o \
a_enum.o a_vis.o a_utf8.o a_sign.o a_digest.o a_verify.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_crl.o x_info.o x_spki.o nsseq.o \
d2i_r_pr.o i2d_r_pr.o d2i_r_pu.o i2d_r_pu.o \

View File

@ -60,7 +60,7 @@
#include "cryptlib.h"
#include "asn1.h"
/* ASN1err(ASN1_F_D2I_ASN1_INTEGER,ASN1_R_EXPECTING_AN_INTEGER);
/* ASN1err(ASN1_F_D2I_ASN1_BMPSTRING,ASN1_R_EXPECTING_AN_INTEGER);
*/
int i2d_ASN1_BMPSTRING(a, pp)

View File

@ -68,7 +68,7 @@ static unsigned long tag2bit[32]={
0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 12-15 */
B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
0, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING,
B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING,0,
0,B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING,
@ -81,7 +81,7 @@ static int asn1_collate_primative(ASN1_STRING *a, ASN1_CTX *c);
static int asn1_collate_primative();
#endif
/* type is a 'bitmap' of acceptable string types to be accepted.
/* type is a 'bitmap' of acceptable string types.
*/
ASN1_STRING *d2i_ASN1_type_bytes(a, pp, length, type)
ASN1_STRING **a;

View File

@ -117,6 +117,12 @@ unsigned char **pp;
case V_ASN1_UNIVERSALSTRING:
r=M_i2d_ASN1_UNIVERSALSTRING(a->value.universalstring,pp);
break;
case V_ASN1_UTF8STRING:
r=M_i2d_ASN1_UTF8STRING(a->value.utf8string,pp);
break;
case V_ASN1_VISIBLESTRING:
r=M_i2d_ASN1_VISIBLESTRING(a->value.visiblestring,pp);
break;
case V_ASN1_BMPSTRING:
r=M_i2d_ASN1_BMPSTRING(a->value.bmpstring,pp);
break;
@ -196,6 +202,16 @@ long length;
d2i_ASN1_OCTET_STRING(NULL,&p,max-p)) == NULL)
goto err;
break;
case V_ASN1_VISIBLESTRING:
if ((ret->value.visiblestring=
d2i_ASN1_VISIBLESTRING(NULL,&p,max-p)) == NULL)
goto err;
break;
case V_ASN1_UTF8STRING:
if ((ret->value.utf8string=
d2i_ASN1_UTF8STRING(NULL,&p,max-p)) == NULL)
goto err;
break;
case V_ASN1_OBJECT:
if ((ret->value.object=
d2i_ASN1_OBJECT(NULL,&p,max-p)) == NULL)
@ -336,6 +352,7 @@ ASN1_TYPE *a;
case V_ASN1_GENERALSTRING:
case V_ASN1_UNIVERSALSTRING:
case V_ASN1_BMPSTRING:
case V_ASN1_UTF8STRING:
ASN1_STRING_free((ASN1_STRING *)a->value.ptr);
break;
default:

90
crypto/asn1/a_utf8.c Normal file
View File

@ -0,0 +1,90 @@
/* crypto/asn1/a_utf8.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* 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 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 acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS 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 AUTHOR OR 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.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include "asn1.h"
/* ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_MALLOC_FAILURE);
*/
int i2d_ASN1_UTF8STRING(a, pp)
ASN1_UTF8STRING *a;
unsigned char **pp;
{
return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL));
}
ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(a, pp, length)
ASN1_UTF8STRING **a;
unsigned char **pp;
long length;
{
ASN1_UTF8STRING *ret=NULL;
ret=(ASN1_UTF8STRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
pp,length,V_ASN1_UTF8STRING,V_ASN1_UNIVERSAL);
if (ret == NULL)
{
ASN1err(ASN1_F_D2I_ASN1_UTF8STRING,ERR_R_NESTED_ASN1_ERROR);
return(NULL);
}
return(ret);
}

90
crypto/asn1/a_vis.c Normal file
View File

@ -0,0 +1,90 @@
/* crypto/asn1/a_vis.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* 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 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 acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS 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 AUTHOR OR 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.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include "asn1.h"
/* ASN1err(ASN1_F_D2I_ASN1_VISIBLESTRING,ERR_R_MALLOC_FAILURE);
*/
int i2d_ASN1_VISIBLESTRING(a, pp)
ASN1_VISIBLESTRING *a;
unsigned char **pp;
{
return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
V_ASN1_VISIBLESTRING,V_ASN1_UNIVERSAL));
}
ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(a, pp, length)
ASN1_VISIBLESTRING **a;
unsigned char **pp;
long length;
{
ASN1_VISIBLESTRING *ret=NULL;
ret=(ASN1_VISIBLESTRING *)d2i_ASN1_bytes((ASN1_STRING **)a,
pp,length,V_ASN1_VISIBLESTRING,V_ASN1_UNIVERSAL);
if (ret == NULL)
{
ASN1err(ASN1_F_D2I_ASN1_VISIBLESTRING,ERR_R_NESTED_ASN1_ERROR);
return(NULL);
}
return(ret);
}

View File

@ -52,6 +52,8 @@
#define ASN1_F_D2I_ASN1_TYPE 133
#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
#define ASN1_F_D2I_ASN1_UTCTIME 135
#define ASN1_F_D2I_ASN1_UTF8STRING 266
#define ASN1_F_D2I_ASN1_VISIBLESTRING 267
#define ASN1_F_D2I_AUTHORITY_KEYID 238
#define ASN1_F_D2I_BASIC_CONSTRAINTS 227
#define ASN1_F_D2I_DHPARAMS 136

View File

@ -91,6 +91,7 @@ extern "C" {
#define V_ASN1_REAL 9
#define V_ASN1_ENUMERATED 10
#define V_ASN1_NEG_ENUMERATED (10+0x100)
#define V_ASN1_UTF8STRING 12
#define V_ASN1_SEQUENCE 16
#define V_ASN1_SET 17
#define V_ASN1_NUMERICSTRING 18 /**/
@ -112,16 +113,19 @@ extern "C" {
#define B_ASN1_NUMERICSTRING 0x0001
#define B_ASN1_PRINTABLESTRING 0x0002
#define B_ASN1_T61STRING 0x0004
#define B_ASN1_TELETEXSTRING 0x0008
#define B_ASN1_VIDEOTEXSTRING 0x0008
#define B_ASN1_IA5STRING 0x0010
#define B_ASN1_GRAPHICSTRING 0x0020
#define B_ASN1_ISO64STRING 0x0040
#define B_ASN1_VISIBLESTRING 0x0040
#define B_ASN1_GENERALSTRING 0x0080
#define B_ASN1_UNIVERSALSTRING 0x0100
#define B_ASN1_OCTET_STRING 0x0200
#define B_ASN1_BIT_STRING 0x0400
#define B_ASN1_BMPSTRING 0x0800
#define B_ASN1_UNKNOWN 0x1000
#define B_ASN1_UTF8STRING 0x2000
typedef struct asn1_ctx_st
{
@ -181,6 +185,8 @@ typedef struct asn1_string_st
#define ASN1_GENERALSTRING ASN1_STRING
#define ASN1_UNIVERSALSTRING ASN1_STRING
#define ASN1_BMPSTRING ASN1_STRING
#define ASN1_VISIBLESTRING ASN1_STRING
#define ASN1_UTF8STRING ASN1_STRING
#else
typedef struct asn1_string_st ASN1_INTEGER;
typedef struct asn1_string_st ASN1_ENUMERATED;
@ -195,6 +201,8 @@ typedef struct asn1_string_st ASN1_BMPSTRING;
typedef struct asn1_string_st ASN1_UTCTIME;
typedef struct asn1_string_st ASN1_TIME;
typedef struct asn1_string_st ASN1_GENERALIZEDTIME;
typedef struct asn1_string_st ASN1_VISIBLESTRING;
typedef struct asn1_string_st ASN1_UTF8STRING;
#endif
typedef struct asn1_type_st
@ -216,6 +224,8 @@ typedef struct asn1_type_st
ASN1_UNIVERSALSTRING * universalstring;
ASN1_UTCTIME * utctime;
ASN1_GENERALIZEDTIME * generalizedtime;
ASN1_VISIBLESTRING * visiblestring;
ASN1_UTF8STRING * utf8string;
/* set and sequence are left complete and still
* contain the set or sequence bytes */
ASN1_STRING * set;
@ -396,6 +406,26 @@ typedef struct asn1_header_st
(ASN1_BMPSTRING *)d2i_ASN1_type_bytes\
((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING)
#define ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
#define ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_i2d_ASN1_VISIBLESTRING(a,pp) \
i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\
V_ASN1_UNIVERSAL)
#define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \
(ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\
((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING)
#define ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
ASN1_STRING_type_new(V_ASN1_UTF8STRING)
#define ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
#define M_i2d_ASN1_UTF8STRING(a,pp) \
i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\
V_ASN1_UNIVERSAL)
#define M_d2i_ASN1_UTF8STRING(a,pp,l) \
(ASN1_UTF8STRING *)d2i_ASN1_type_bytes\
((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING)
/* for the is_set parameter to i2d_ASN1_SET */
#define IS_SEQUENCE 0
#define IS_SET 1
@ -451,6 +481,14 @@ int i2d_ASN1_OCTET_STRING(ASN1_OCTET_STRING *a,unsigned char **pp);
ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **a,
unsigned char **pp,long length);
int i2d_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING *a,unsigned char **pp);
ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING(ASN1_VISIBLESTRING **a,
unsigned char **pp,long length);
int i2d_ASN1_UTF8STRING(ASN1_UTF8STRING *a,unsigned char **pp);
ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **a,
unsigned char **pp,long length);
int i2d_ASN1_BMPSTRING(ASN1_BMPSTRING *a, unsigned char **pp);
ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **a, unsigned char **pp,
long length);
@ -646,6 +684,10 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set();
int ASN1_GENERALIZEDTIME_set_string();
int i2d_ASN1_OCTET_STRING();
ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING();
int i2d_ASN1_VISIBLESTRING();
ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING();
int i2d_ASN1_UTF8STRING();
ASN1_UTF8STRING *d2i_ASN1_UTF8STRING();
int i2d_ASN1_PRINTABLE();
ASN1_STRING *d2i_ASN1_PRINTABLE();
ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING();
@ -784,6 +826,8 @@ ASN1_STRING *ASN1_pack_string();
#define ASN1_F_D2I_ASN1_TYPE 133
#define ASN1_F_D2I_ASN1_TYPE_BYTES 134
#define ASN1_F_D2I_ASN1_UTCTIME 135
#define ASN1_F_D2I_ASN1_UTF8STRING 266
#define ASN1_F_D2I_ASN1_VISIBLESTRING 267
#define ASN1_F_D2I_AUTHORITY_KEYID 238
#define ASN1_F_D2I_BASIC_CONSTRAINTS 227
#define ASN1_F_D2I_DHPARAMS 136

View File

@ -114,6 +114,8 @@ static ERR_STRING_DATA ASN1_str_functs[]=
{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE,0), "d2i_ASN1_TYPE"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "d2i_ASN1_UTCTIME"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_UTF8STRING,0), "d2i_ASN1_UTF8STRING"},
{ERR_PACK(0,ASN1_F_D2I_ASN1_VISIBLESTRING,0), "d2i_ASN1_VISIBLESTRING"},
{ERR_PACK(0,ASN1_F_D2I_AUTHORITY_KEYID,0), "D2I_AUTHORITY_KEYID"},
{ERR_PACK(0,ASN1_F_D2I_BASIC_CONSTRAINTS,0), "D2I_BASIC_CONSTRAINTS"},
{ERR_PACK(0,ASN1_F_D2I_DHPARAMS,0), "D2I_DHPARAMS"},