More code for X509_print_ex() support.
[openssl.git] / apps / x509.c
index b86352e2fbd8eaa923f35bbd1c7cfb7ddabbafb2..3bef1fc590a62342c72314ff65e824eb47e4b0c5 100644 (file)
@@ -129,6 +129,7 @@ static char *x509_usage[]={
 " -extensions     - section from config file with X509V3 extensions to add\n",
 " -clrext         - delete extensions before signing and input certificate\n",
 " -nameopt arg    - various certificate name options\n",
+" -certopt arg    - various certificate text options\n",
 NULL
 };
 
@@ -174,7 +175,7 @@ int MAIN(int argc, char **argv)
        char *extsect = NULL, *extfile = NULL, *passin = NULL, *passargin = NULL;
        int need_rand = 0;
        int checkend=0,checkoffset=0;
-       unsigned long nmflag = 0;
+       unsigned long nmflag = 0, certflag = 0;
 
        reqfile=0;
 
@@ -183,6 +184,12 @@ int MAIN(int argc, char **argv)
        if (bio_err == NULL)
                bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
        STDout=BIO_new_fp(stdout,BIO_NOCLOSE);
+#ifdef VMS
+       {
+       BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+       STDout = BIO_push(tmpbio, STDout);
+       }
+#endif
 
        informat=FORMAT_PEM;
        outformat=FORMAT_PEM;
@@ -320,6 +327,11 @@ int MAIN(int argc, char **argv)
                        alias= *(++argv);
                        trustout = 1;
                        }
+               else if (strcmp(*argv,"-certopt") == 0)
+                       {
+                       if (--argc < 1) goto bad;
+                       if (!set_cert_ex(&certflag, *(++argv))) goto bad;
+                       }
                else if (strcmp(*argv,"-nameopt") == 0)
                        {
                        if (--argc < 1) goto bad;
@@ -576,7 +588,15 @@ bad:
                        goto end;
                        }
                if (outfile == NULL)
+                       {
                        BIO_set_fp(out,stdout,BIO_NOCLOSE);
+#ifdef VMS
+                       {
+                       BIO *tmpbio = BIO_new(BIO_f_linebuffer());
+                       out = BIO_push(tmpbio, out);
+                       }
+#endif
+                       }
                else
                        {
                        if (BIO_write_filename(out,outfile) <= 0)
@@ -760,7 +780,7 @@ bad:
                                }
                        else if (text == i)
                                {
-                               X509_print(out,x);
+                               X509_print_ex(out,x,nmflag, certflag);
                                }
                        else if (startdate == i)
                                {
@@ -933,8 +953,8 @@ end:
                app_RAND_write_file(NULL, bio_err);
        OBJ_cleanup();
        CONF_free(extconf);
-       BIO_free(out);
-       BIO_free(STDout);
+       BIO_free_all(out);
+       BIO_free_all(STDout);
        X509_STORE_free(ctx);
        X509_REQ_free(req);
        X509_free(x);