summaryrefslogtreecommitdiffstats
path: root/crypto/asn1
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>1999-01-17 00:13:14 +0000
committerDr. Stephen Henson <steve@openssl.org>1999-01-17 00:13:14 +0000
commitf6aed2cda608d6291225030fc259f207aac33732 (patch)
tree871e34a38284841b02131a1ad2725485a99a1ecc /crypto/asn1
parentc3ae9a4851463e083e1b5dd803a286a61f2b784b (diff)
Time to blow up the source tree :-) This is the beginning of support for
GeneralizedTime. At several points PKIX specifies that GeneralizedTime can be used but OpenSSL doesn't currently support it. This patch adds several files and a bunch of functions. Of interest is the ASN1_TIME structure and its related functions. At several points certificates, CRLs et al specify that a time can be expressed as a choice of UTCTime and GeneralizedTime. Currently OpenSSL interprets this (wrongly) as UTCTime because GeneralizedTime isn't supported. The ASN1_TIME stuff provides this functionality. Still todo is to trace which cert and CRL points need an ASN1_TIME and modify the utilities appropriately and of course fix all the bugs. Note new OpenSSL copyright in the new file a_time.c. I didn't put it in a_gentm.c because it is a minimally modified form a_utctm.c . Since this adds new files and error codes you will need to do a 'make errors' at the top level to add the new codes.
Diffstat (limited to 'crypto/asn1')
-rw-r--r--crypto/asn1/Makefile.ssl8
-rw-r--r--crypto/asn1/a_gentm.c217
-rw-r--r--crypto/asn1/a_time.c114
-rw-r--r--crypto/asn1/a_type.c8
-rw-r--r--crypto/asn1/asn1.h44
-rw-r--r--crypto/asn1/t_x509.c51
6 files changed, 433 insertions, 9 deletions
diff --git a/crypto/asn1/Makefile.ssl b/crypto/asn1/Makefile.ssl
index 1e9951fc56..fb2c7f36bc 100644
--- a/crypto/asn1/Makefile.ssl
+++ b/crypto/asn1/Makefile.ssl
@@ -22,8 +22,8 @@ TEST=
APPS=
LIB=$(TOP)/libcrypto.a
-LIBSRC= a_object.c a_bitstr.c a_utctm.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 \
+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_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 \
@@ -37,8 +37,8 @@ LIBSRC= a_object.c a_bitstr.c a_utctm.c a_int.c a_octet.c a_print.c \
a_hdr.c x_pkey.c a_bool.c x_exten.c \
asn1_par.c asn1_lib.c $(ERRC).c a_meth.c a_bytes.c \
evp_asn1.c
-LIBOBJ= a_object.o a_bitstr.o a_utctm.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 \
+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_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 \
diff --git a/crypto/asn1/a_gentm.c b/crypto/asn1/a_gentm.c
new file mode 100644
index 0000000000..3d37e9de71
--- /dev/null
+++ b/crypto/asn1/a_gentm.c
@@ -0,0 +1,217 @@
+/* crypto/asn1/a_gentm.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.]
+ */
+
+/* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME */
+
+#include <stdio.h>
+#include <time.h>
+#include "cryptlib.h"
+#include "asn1.h"
+
+/* ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_NEW,ASN1_R_GENERALIZEDTIME_TOO_LONG);
+ * ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_EXPECTING_A_GENERALIZEDTIME);
+ */
+
+int i2d_ASN1_GENERALIZEDTIME(a,pp)
+ASN1_GENERALIZEDTIME *a;
+unsigned char **pp;
+ {
+ return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
+ V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL));
+ }
+
+
+ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(a, pp, length)
+ASN1_GENERALIZEDTIME **a;
+unsigned char **pp;
+long length;
+ {
+ ASN1_GENERALIZEDTIME *ret=NULL;
+
+ ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
+ V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL);
+ if (ret == NULL)
+ {
+ ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR);
+ return(NULL);
+ }
+ if (!ASN1_GENERALIZEDTIME_check(ret))
+ {
+ ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
+ goto err;
+ }
+
+ return(ret);
+err:
+ if ((ret != NULL) && ((a == NULL) || (*a != ret)))
+ ASN1_GENERALIZEDTIME_free(ret);
+ return(NULL);
+ }
+
+int ASN1_GENERALIZEDTIME_check(d)
+ASN1_GENERALIZEDTIME *d;
+ {
+ static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
+ static int max[9]={99, 99,12,31,23,59,59,12,59};
+ char *a;
+ int n,i,l,o;
+
+ if (d->type != V_ASN1_GENERALIZEDTIME) return(0);
+ l=d->length;
+ a=(char *)d->data;
+ o=0;
+ /* GENERALIZEDTIME is similar to UTCTIME except the year is
+ * represented as YYYY. This stuff treats everything as a two digit
+ * field so make first two fields 00 to 99
+ */
+ if (l < 13) goto err;
+ for (i=0; i<7; i++)
+ {
+ if ((i == 6) && ((a[o] == 'Z') ||
+ (a[o] == '+') || (a[o] == '-')))
+ { i++; break; }
+ if ((a[o] < '0') || (a[o] > '9')) goto err;
+ n= a[o]-'0';
+ if (++o > l) goto err;
+
+ if ((a[o] < '0') || (a[o] > '9')) goto err;
+ n=(n*10)+ a[o]-'0';
+ if (++o > l) goto err;
+
+ if ((n < min[i]) || (n > max[i])) goto err;
+ }
+ if (a[o] == 'Z')
+ o++;
+ else if ((a[o] == '+') || (a[o] == '-'))
+ {
+ o++;
+ if (o+4 > l) goto err;
+ for (i=7; i<9; i++)
+ {
+ if ((a[o] < '0') || (a[o] > '9')) goto err;
+ n= a[o]-'0';
+ o++;
+ if ((a[o] < '0') || (a[o] > '9')) goto err;
+ n=(n*10)+ a[o]-'0';
+ if ((n < min[i]) || (n > max[i])) goto err;
+ o++;
+ }
+ }
+ return(o == l);
+err:
+ return(0);
+ }
+
+int ASN1_GENERALIZEDTIME_set_string(s,str)
+ASN1_GENERALIZEDTIME *s;
+char *str;
+ {
+ ASN1_GENERALIZEDTIME t;
+
+ t.type=V_ASN1_GENERALIZEDTIME;
+ t.length=strlen(str);
+ t.data=(unsigned char *)str;
+ if (ASN1_GENERALIZEDTIME_check(&t))
+ {
+ if (s != NULL)
+ {
+ ASN1_STRING_set((ASN1_STRING *)s,
+ (unsigned char *)str,t.length);
+ }
+ return(1);
+ }
+ else
+ return(0);
+ }
+
+ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(s, t)
+ASN1_GENERALIZEDTIME *s;
+time_t t;
+ {
+ char *p;
+ struct tm *ts;
+#if defined(THREADS) && !defined(WIN32)
+ struct tm data;
+#endif
+
+ if (s == NULL)
+ s=ASN1_GENERALIZEDTIME_new();
+ if (s == NULL)
+ return(NULL);
+
+#if defined(THREADS) && !defined(WIN32)
+ ts=(struct tm *)gmtime_r(&t,&data);
+#else
+ ts=(struct tm *)gmtime(&t);
+#endif
+ p=(char *)s->data;
+ if ((p == NULL) || (s->length < 16))
+ {
+ p=Malloc(20);
+ if (p == NULL) return(NULL);
+ if (s->data != NULL)
+ Free(s->data);
+ s->data=(unsigned char *)p;
+ }
+
+ sprintf(p,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year,
+ ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
+ s->length=strlen(p);
+ s->type=V_ASN1_GENERALIZEDTIME;
+ return(s);
+ }
diff --git a/crypto/asn1/a_time.c b/crypto/asn1/a_time.c
new file mode 100644
index 0000000000..953ed6088d
--- /dev/null
+++ b/crypto/asn1/a_time.c
@@ -0,0 +1,114 @@
+/* crypto/asn1/a_time.c */
+/* ====================================================================
+ * 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).
+ *
+ */
+
+
+/* This is an implementation of the ASN1 Time structure which is:
+ * Time ::= CHOICE {
+ * utcTime UTCTime,
+ * generalTime GeneralizedTime }
+ * written by Steve Henson.
+ */
+
+#include <stdio.h>
+#include <time.h>
+#include "cryptlib.h"
+#include "asn1.h"
+
+int i2d_ASN1_TIME(a,pp)
+ASN1_TIME *a;
+unsigned char **pp;
+ {
+ if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME)
+ return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
+ a->type ,V_ASN1_UNIVERSAL));
+ ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
+ return -1;
+ }
+
+
+ASN1_TIME *d2i_ASN1_TIME(a, pp, length)
+ASN1_TIME **a;
+unsigned char **pp;
+long length;
+ {
+ unsigned char tag;
+ tag = **pp & ~V_ASN1_CONSTRUCTED;
+ if(tag == (V_ASN1_UTCTIME|V_ASN1_UNIVERSAL))
+ return d2i_ASN1_UTCTIME(a, pp, length);
+ if(tag == (V_ASN1_GENERALIZEDTIME|V_ASN1_UNIVERSAL))
+ return d2i_ASN1_GENERALIZEDTIME(a, pp, length);
+ ASN1err(ASN1_F_D2I_ASN1_TIME,ASN1_R_EXPECTING_A_TIME);
+ return(NULL);
+ }
+
+
+ASN1_TIME *ASN1_TIME_set(s, t)
+ASN1_TIME *s;
+time_t t;
+ {
+ struct tm *ts;
+#if defined(THREADS) && !defined(WIN32)
+ struct tm data;
+#endif
+
+#if defined(THREADS) && !defined(WIN32)
+ ts=(struct tm *)gmtime_r(&t,&data);
+#else
+ ts=(struct tm *)gmtime(&t);
+#endif
+ if((ts->tm_year >= 1950) && (ts->tm_year < 2050))
+ return ASN1_UTCTIME_set(s, t);
+ return ASN1_GENERALIZEDTIME_set(s,t);
+ }
diff --git a/crypto/asn1/a_type.c b/crypto/asn1/a_type.c
index 7ddf5f9917..63b458358a 100644
--- a/crypto/asn1/a_type.c
+++ b/crypto/asn1/a_type.c
@@ -119,6 +119,9 @@ unsigned char **pp;
case V_ASN1_UTCTIME:
r=i2d_ASN1_UTCTIME(a->value.utctime,pp);
break;
+ case V_ASN1_GENERALIZEDTIME:
+ r=i2d_ASN1_GENERALIZEDTIME(a->value.generalizedtime,pp);
+ break;
case V_ASN1_SET:
case V_ASN1_SEQUENCE:
if (a->value.set == NULL)
@@ -224,6 +227,11 @@ long length;
d2i_ASN1_UTCTIME(NULL,&p,max-p)) == NULL)
goto err;
break;
+ case V_ASN1_GENERALIZEDTIME:
+ if ((ret->value.generalizedtime=
+ d2i_ASN1_GENERALIZEDTIME(NULL,&p,max-p)) == NULL)
+ goto err;
+ break;
case V_ASN1_SET:
case V_ASN1_SEQUENCE:
/* Sets and sequences are left complete */
diff --git a/crypto/asn1/asn1.h b/crypto/asn1/asn1.h
index 6cfbb6b07d..a8fa68c4ca 100644
--- a/crypto/asn1/asn1.h
+++ b/crypto/asn1/asn1.h
@@ -175,6 +175,7 @@ typedef struct asn1_string_st
#define ASN1_IA5STRING ASN1_STRING
#define ASN1_UTCTIME ASN1_STRING
#define ASN1_GENERALIZEDTIME ASN1_STRING
+#define ASN1_TIME ASN1_STRING
#define ASN1_GENERALSTRING ASN1_STRING
#define ASN1_UNIVERSALSTRING ASN1_STRING
#define ASN1_BMPSTRING ASN1_STRING
@@ -189,6 +190,7 @@ typedef struct asn1_string_st ASN1_GENERALSTRING;
typedef struct asn1_string_st ASN1_UNIVERSALSTRING;
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;
#endif
@@ -330,12 +332,22 @@ typedef struct asn1_header_st
#define ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
#define ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
-#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup(\
+#define ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
(ASN1_STRING *)a)
-/* DOES NOT EXIST YET i2d_ASN1_GENERALIZEDTIME() is a function */
-/* DOES NOT EXIST YET d2i_ASN1_GENERALIZEDTIME() is a function */
-/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_set() is a function */
-/* DOES NOT EXIST YET ASN1_GENERALIZEDTIME_check() is a function */
+/* i2d_ASN1_GENERALIZEDTIME() is a function */
+/* d2i_ASN1_GENERALIZEDTIME() is a function */
+/* ASN1_GENERALIZEDTIME_set() is a function */
+/* ASN1_GENERALIZEDTIME_check() is a function */
+
+#define ASN1_TIME_new() (ASN1_TIME *)\
+ ASN1_STRING_type_new(V_ASN1_UTCTIME)
+#define ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
+#define ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a)
+
+/* i2d_ASN1_TIME() is a function */
+/* d2i_ASN1_TIME() is a function */
+/* ASN1_TIME_set() is a function */
+/* ASN1_TIME_check() is a function */
#define ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
@@ -406,6 +418,10 @@ int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
+int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
+ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
+int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
+
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);
@@ -430,6 +446,13 @@ int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a,unsigned char **pp);
ASN1_UTCTIME * d2i_ASN1_UTCTIME(ASN1_UTCTIME **a,unsigned char **pp,
long length);
+int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a,unsigned char **pp);
+ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,unsigned char **pp,
+ long length);
+
+int i2d_ASN1_TIME(ASN1_TIME *a,unsigned char **pp);
+ASN1_TIME * d2i_ASN1_TIME(ASN1_TIME **a,unsigned char **pp, long length);
+
/* for the is_set parameter to i2d_ASN1_SET */
#define IS_SEQUENCE 0
#define IS_SET 1
@@ -491,6 +514,8 @@ int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
+int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
+int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
#endif
@@ -550,6 +575,9 @@ ASN1_INTEGER *d2i_ASN1_INTEGER();
int ASN1_UTCTIME_check();
ASN1_UTCTIME *ASN1_UTCTIME_set();
int ASN1_UTCTIME_set_string();
+int ASN1_GENERALIZEDTIME_check();
+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_PRINTABLE();
@@ -560,6 +588,10 @@ int i2d_ASN1_IA5STRING();
ASN1_IA5STRING *d2i_ASN1_IA5STRING();
int i2d_ASN1_UTCTIME();
ASN1_UTCTIME * d2i_ASN1_UTCTIME();
+int i2d_ASN1_GENERALIZEDTIME();
+ASN1_GENERALIZEDTIME * d2i_ASN1_GENERALIZEDTIME();
+int i2d_ASN1_TIME();
+ASN1_TIME * d2i_ASN1_TIME();
int i2d_ASN1_SET();
STACK * d2i_ASN1_SET();
int a2d_ASN1_OBJECT();
@@ -586,6 +618,8 @@ int ASN1_i2d_fp();
char *ASN1_d2i_bio();
int ASN1_i2d_bio();
int ASN1_UTCTIME_print();
+int ASN1_GENERALIZEDTIME_print();
+int ASN1_TIME_print();
int ASN1_STRING_print();
int ASN1_parse();
int i2a_ASN1_INTEGER();
diff --git a/crypto/asn1/t_x509.c b/crypto/asn1/t_x509.c
index 4bf1bd4536..bfee6f66a7 100644
--- a/crypto/asn1/t_x509.c
+++ b/crypto/asn1/t_x509.c
@@ -291,6 +291,57 @@ ASN1_STRING *v;
return(1);
}
+int ASN1_TIME_print(bp, tm)
+BIO *bp;
+ASN1_TIME *tm;
+{
+ if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm);
+ if(tm->type == V_ASN1_GENERALIZEDTIME)
+ return ASN1_GENERALIZEDTIME_print(bp, tm);
+ BIO_write(bp,"Bad time value",14);
+ return(0);
+}
+
+
+int ASN1_GENERALIZEDTIME_print(bp,tm)
+BIO *bp;
+ASN1_GENERALIZEDTIME *tm;
+ {
+ char *v;
+ int gmt=0;
+ static char *mon[12]={
+ "Jan","Feb","Mar","Apr","May","Jun",
+ "Jul","Aug","Sep","Oct","Nov","Dec"};
+ int i;
+ int y=0,M=0,d=0,h=0,m=0,s=0;
+
+ i=tm->length;
+ v=(char *)tm->data;
+
+ if (i < 12) goto err;
+ if (v[i-1] == 'Z') gmt=1;
+ for (i=0; i<12; i++)
+ if ((v[i] > '9') || (v[i] < '0')) goto err;
+ y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0');
+ M= (v[4]-'0')*10+(v[5]-'0');
+ if ((M > 12) || (M < 1)) goto err;
+ d= (v[6]-'0')*10+(v[7]-'0');
+ h= (v[8]-'0')*10+(v[9]-'0');
+ m= (v[10]-'0')*10+(v[11]-'0');
+ if ( (v[12] >= '0') && (v[12] <= '9') &&
+ (v[13] >= '0') && (v[13] <= '9'))
+ s= (v[12]-'0')*10+(v[13]-'0');
+
+ if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s",
+ mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0)
+ return(0);
+ else
+ return(1);
+err:
+ BIO_write(bp,"Bad time value",14);
+ return(0);
+ }
+
int ASN1_UTCTIME_print(bp,tm)
BIO *bp;
ASN1_UTCTIME *tm;