Missing space in VC-32.pl.
[openssl.git] / apps / x509.c
index d00511c78a7b1f2e04de96747eff37293abe51db..8d20681ec3b476e3ad0c698d2209c4f859f4a24e 100644 (file)
 #include <openssl/x509v3.h>
 #include <openssl/objects.h>
 #include <openssl/pem.h>
+#ifndef OPENSSL_NO_RSA
 #include <openssl/rsa.h>
+#endif
+#ifndef OPENSSL_NO_DSA
 #include <openssl/dsa.h>
+#endif
 
 #undef PROG
 #define PROG x509_main
@@ -83,7 +87,7 @@
 #define        POSTFIX ".srl"
 #define DEF_DAYS       30
 
-static char *x509_usage[]={
+static const char *x509_usage[]={
 "usage: x509 args\n",
 " -inform arg     - input format - default PEM (one of DER, NET or PEM)\n",
 " -outform arg    - output format - default PEM (one of DER, NET or PEM)\n",
@@ -179,12 +183,12 @@ int MAIN(int argc, char **argv)
        int C=0;
        int x509req=0,days=DEF_DAYS,modulus=0,pubkey=0;
        int pprint = 0;
-       char **pp;
+       const char **pp;
        X509_STORE *ctx=NULL;
        X509_REQ *rq=NULL;
        int fingerprint=0;
        char buf[256];
-       const EVP_MD *md_alg,*digest=EVP_md5();
+       const EVP_MD *md_alg,*digest=EVP_sha1();
        CONF *extconf = NULL;
        char *extsect = NULL, *extfile = NULL, *passin = NULL, *passargin = NULL;
        int need_rand = 0;
@@ -606,9 +610,12 @@ bad:
                        sno = ASN1_INTEGER_new();
                        if (!sno || !rand_serial(NULL, sno))
                                goto end;
+                       if (!X509_set_serialNumber(x, sno)) 
+                               goto end;
+                       ASN1_INTEGER_free(sno);
+                       sno = NULL;
                        }
-
-               if (!X509_set_serialNumber(x, sno)) 
+               else if (!X509_set_serialNumber(x, sno)) 
                        goto end;
 
                if (!X509_set_issuer_name(x,req->req_info->subject)) goto end;
@@ -996,9 +1003,9 @@ bad:
 
        if (checkend)
                {
-               time_t tnow=time(NULL);
+               time_t tcheck=time(NULL) + checkoffset;
 
-               if (ASN1_UTCTIME_cmp_time_t(X509_get_notAfter(x), tnow+checkoffset) == -1)
+               if (X509_cmp_time(X509_get_notAfter(x), &tcheck) < 0)
                        {
                        BIO_printf(out,"Certificate will expire\n");
                        ret=1;
@@ -1026,17 +1033,15 @@ bad:
                }
        else if (outformat == FORMAT_NETSCAPE)
                {
-               ASN1_HEADER ah;
-               ASN1_OCTET_STRING os;
+               NETSCAPE_X509 nx;
+               ASN1_OCTET_STRING hdr;
 
-               os.data=(unsigned char *)NETSCAPE_CERT_HDR;
-               os.length=strlen(NETSCAPE_CERT_HDR);
-               ah.header= &os;
-               ah.data=(char *)x;
-               ah.meth=X509_asn1_meth();
+               hdr.data=(unsigned char *)NETSCAPE_CERT_HDR;
+               hdr.length=strlen(NETSCAPE_CERT_HDR);
+               nx.header= &hdr;
+               nx.cert=x;
 
-               /* no macro for this one yet */
-               i=ASN1_i2d_bio(i2d_ASN1_HEADER,out,(unsigned char *)&ah);
+               i=ASN1_item_i2d_bio(ASN1_ITEM_rptr(NETSCAPE_X509),out,&nx);
                }
        else    {
                BIO_printf(bio_err,"bad output format specified for outfile\n");