Continued patches so certificates and CRLs now can support and use
[openssl.git] / crypto / asn1 / t_x509.c
index b10fbbb9922e8edc6b4d0b1523820dba1509591e..060f99d5a88f00c602d92e2b34cf63bcde207ee9 100644 (file)
@@ -146,9 +146,9 @@ X509 *x;
        if (!X509_NAME_print(bp,X509_get_issuer_name(x),16)) goto err;
        if (BIO_write(bp,"\n        Validity\n",18) <= 0) goto err;
        if (BIO_write(bp,"            Not Before: ",24) <= 0) goto err;
-       if (!ASN1_UTCTIME_print(bp,X509_get_notBefore(x))) goto err;
+       if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err;
        if (BIO_write(bp,"\n            Not After : ",25) <= 0) goto err;
-       if (!ASN1_UTCTIME_print(bp,X509_get_notAfter(x))) goto err;
+       if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err;
        if (BIO_write(bp,"\n        Subject: ",18) <= 0) goto err;
        if (!X509_NAME_print(bp,X509_get_subject_name(x),16)) goto err;
        if (BIO_write(bp,"\n        Subject Public Key Info:\n",34) <= 0)
@@ -158,6 +158,11 @@ X509 *x;
                (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)) <= 0) goto err;
 
        pkey=X509_get_pubkey(x);
+       if (pkey == NULL)
+               {
+               BIO_printf(bp,"%12sUnable to load Public Key\n","");
+               }
+       else
 #ifndef NO_RSA
        if (pkey->type == EVP_PKEY_RSA)
                {
@@ -175,7 +180,9 @@ X509 *x;
                }
        else
 #endif
-               BIO_printf(bp,"%12sDSA Public Key:\n","");
+               BIO_printf(bp,"%12sUnknown Public Key:\n","");
+
+       EVP_PKEY_free(pkey);
 
        n=X509_get_ext_count(x);
        if (n > 0)
@@ -284,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;