diff options
author | Matt Caswell <matt@openssl.org> | 2015-01-22 03:40:55 +0000 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2015-01-22 09:20:09 +0000 |
commit | 0f113f3ee4d629ef9a4a30911b22b224772085e5 (patch) | |
tree | e014603da5aed1d0751f587a66d6e270b6bda3de /apps/x509.c | |
parent | 22b52164aaed31d6e93dbd2d397ace041360e6aa (diff) |
Run util/openssl-format-source -v -c .
Reviewed-by: Tim Hudson <tjh@openssl.org>
Diffstat (limited to 'apps/x509.c')
-rw-r--r-- | apps/x509.c | 2359 |
1 files changed, 1130 insertions, 1229 deletions
diff --git a/apps/x509.c b/apps/x509.c index b3c23907bf..4248bdb8fa 100644 --- a/apps/x509.c +++ b/apps/x509.c @@ -5,21 +5,21 @@ * 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: @@ -34,10 +34,10 @@ * 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 + * 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 @@ -49,7 +49,7 @@ * 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 @@ -71,1301 +71,1202 @@ #include <openssl/objects.h> #include <openssl/pem.h> #ifndef OPENSSL_NO_RSA -#include <openssl/rsa.h> +# include <openssl/rsa.h> #endif #ifndef OPENSSL_NO_DSA -#include <openssl/dsa.h> +# include <openssl/dsa.h> #endif #undef PROG #define PROG x509_main #undef POSTFIX -#define POSTFIX ".srl" -#define DEF_DAYS 30 - -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", -" -keyform arg - private key format - default PEM\n", -" -CAform arg - CA format - default PEM\n", -" -CAkeyform arg - CA key format - default PEM\n", -" -in arg - input file - default stdin\n", -" -out arg - output file - default stdout\n", -" -passin arg - private key password source\n", -" -serial - print serial number value\n", -" -subject_hash - print subject hash value\n", +#define POSTFIX ".srl" +#define DEF_DAYS 30 + +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", + " -keyform arg - private key format - default PEM\n", + " -CAform arg - CA format - default PEM\n", + " -CAkeyform arg - CA key format - default PEM\n", + " -in arg - input file - default stdin\n", + " -out arg - output file - default stdout\n", + " -passin arg - private key password source\n", + " -serial - print serial number value\n", + " -subject_hash - print subject hash value\n", #ifndef OPENSSL_NO_MD5 -" -subject_hash_old - print old-style (MD5) subject hash value\n", + " -subject_hash_old - print old-style (MD5) subject hash value\n", #endif -" -issuer_hash - print issuer hash value\n", + " -issuer_hash - print issuer hash value\n", #ifndef OPENSSL_NO_MD5 -" -issuer_hash_old - print old-style (MD5) issuer hash value\n", + " -issuer_hash_old - print old-style (MD5) issuer hash value\n", #endif -" -hash - synonym for -subject_hash\n", -" -subject - print subject DN\n", -" -issuer - print issuer DN\n", -" -email - print email address(es)\n", -" -startdate - notBefore field\n", -" -enddate - notAfter field\n", -" -purpose - print out certificate purposes\n", -" -dates - both Before and After dates\n", -" -modulus - print the RSA key modulus\n", -" -pubkey - output the public key\n", -" -fingerprint - print the certificate fingerprint\n", -" -alias - output certificate alias\n", -" -noout - no certificate output\n", -" -ocspid - print OCSP hash values for the subject name and public key\n", -" -ocsp_uri - print OCSP Responder URL(s)\n", -" -trustout - output a \"trusted\" certificate\n", -" -clrtrust - clear all trusted purposes\n", -" -clrreject - clear all rejected purposes\n", -" -addtrust arg - trust certificate for a given purpose\n", -" -addreject arg - reject certificate for a given purpose\n", -" -setalias arg - set certificate alias\n", -" -days arg - How long till expiry of a signed certificate - def 30 days\n", -" -checkend arg - check whether the cert expires in the next arg seconds\n", -" exit 1 if so, 0 if not\n", -" -signkey arg - self sign cert with arg\n", -" -x509toreq - output a certification request object\n", -" -req - input is a certificate request, sign and output.\n", -" -CA arg - set the CA certificate, must be PEM format.\n", -" -CAkey arg - set the CA key, must be PEM format\n", -" missing, it is assumed to be in the CA file.\n", -" -CAcreateserial - create serial number file if it does not exist\n", -" -CAserial arg - serial file\n", -" -set_serial - serial number to use\n", -" -text - print the certificate in text form\n", -" -C - print out C code forms\n", -" -md2/-md5/-sha1/-mdc2 - digest to use\n", -" -extfile - configuration file with X509V3 extensions to add\n", -" -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", + " -hash - synonym for -subject_hash\n", + " -subject - print subject DN\n", + " -issuer - print issuer DN\n", + " -email - print email address(es)\n", + " -startdate - notBefore field\n", + " -enddate - notAfter field\n", + " -purpose - print out certificate purposes\n", + " -dates - both Before and After dates\n", + " -modulus - print the RSA key modulus\n", + " -pubkey - output the public key\n", + " -fingerprint - print the certificate fingerprint\n", + " -alias - output certificate alias\n", + " -noout - no certificate output\n", + " -ocspid - print OCSP hash values for the subject name and public key\n", + " -ocsp_uri - print OCSP Responder URL(s)\n", + " -trustout - output a \"trusted\" certificate\n", + " -clrtrust - clear all trusted purposes\n", + " -clrreject - clear all rejected purposes\n", + " -addtrust arg - trust certificate for a given purpose\n", + " -addreject arg - reject certificate for a given purpose\n", + " -setalias arg - set certificate alias\n", + " -days arg - How long till expiry of a signed certificate - def 30 days\n", + " -checkend arg - check whether the cert expires in the next arg seconds\n", + " exit 1 if so, 0 if not\n", + " -signkey arg - self sign cert with arg\n", + " -x509toreq - output a certification request object\n", + " -req - input is a certificate request, sign and output.\n", + " -CA arg - set the CA certificate, must be PEM format.\n", + " -CAkey arg - set the CA key, must be PEM format\n", + " missing, it is assumed to be in the CA file.\n", + " -CAcreateserial - create serial number file if it does not exist\n", + " -CAserial arg - serial file\n", + " -set_serial - serial number to use\n", + " -text - print the certificate in text form\n", + " -C - print out C code forms\n", + " -md2/-md5/-sha1/-mdc2 - digest to use\n", + " -extfile - configuration file with X509V3 extensions to add\n", + " -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", #ifndef OPENSSL_NO_ENGINE -" -engine e - use engine e, possibly a hardware device.\n", + " -engine e - use engine e, possibly a hardware device.\n", #endif -" -certopt arg - various certificate text options\n", -" -checkhost host - check certificate matches \"host\"\n", -" -checkemail email - check certificate matches \"email\"\n", -" -checkip ipaddr - check certificate matches \"ipaddr\"\n", -NULL + " -certopt arg - various certificate text options\n", + " -checkhost host - check certificate matches \"host\"\n", + " -checkemail email - check certificate matches \"email\"\n", + " -checkip ipaddr - check certificate matches \"ipaddr\"\n", + NULL }; static int callb(int ok, X509_STORE_CTX *ctx); -static int sign (X509 *x, EVP_PKEY *pkey,int days,int clrext, const EVP_MD *digest, - CONF *conf, char *section); -static int x509_certify (X509_STORE *ctx,char *CAfile,const EVP_MD *digest, - X509 *x,X509 *xca,EVP_PKEY *pkey, - STACK_OF(OPENSSL_STRING) *sigopts, - char *serial, int create ,int days, int clrext, - CONF *conf, char *section, ASN1_INTEGER *sno); +static int sign(X509 *x, EVP_PKEY *pkey, int days, int clrext, + const EVP_MD *digest, CONF *conf, char *section); +static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest, + X509 *x, X509 *xca, EVP_PKEY *pkey, + STACK_OF(OPENSSL_STRING) *sigopts, char *serial, + int create, int days, int clrext, CONF *conf, + char *section, ASN1_INTEGER *sno); static int purpose_print(BIO *bio, X509 *cert, X509_PURPOSE *pt); -static int reqfile=0; +static int reqfile = 0; #ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL -static int force_version=2; +static int force_version = 2; #endif int MAIN(int, char **); int MAIN(int argc, char **argv) - { - ENGINE *e = NULL; - int ret=1; - X509_REQ *req=NULL; - X509 *x=NULL,*xca=NULL; - ASN1_OBJECT *objtmp; - STACK_OF(OPENSSL_STRING) *sigopts = NULL; - EVP_PKEY *Upkey=NULL,*CApkey=NULL, *fkey = NULL; - ASN1_INTEGER *sno = NULL; - int i,num,badops=0, badsig=0; - BIO *out=NULL; - BIO *STDout=NULL; - STACK_OF(ASN1_OBJECT) *trust = NULL, *reject = NULL; - int informat,outformat,keyformat,CAformat,CAkeyformat; - char *infile=NULL,*outfile=NULL,*keyfile=NULL,*CAfile=NULL; - char *CAkeyfile=NULL,*CAserial=NULL; - char *fkeyfile=NULL; - char *alias=NULL; - int text=0,serial=0,subject=0,issuer=0,startdate=0,enddate=0; - int next_serial=0; - int subject_hash=0,issuer_hash=0,ocspid=0; +{ + ENGINE *e = NULL; + int ret = 1; + X509_REQ *req = NULL; + X509 *x = NULL, *xca = NULL; + ASN1_OBJECT *objtmp; + STACK_OF(OPENSSL_STRING) *sigopts = NULL; + EVP_PKEY *Upkey = NULL, *CApkey = NULL, *fkey = NULL; + ASN1_INTEGER *sno = NULL; + int i, num, badops = 0, badsig = 0; + BIO *out = NULL; + BIO *STDout = NULL; + STACK_OF(ASN1_OBJECT) *trust = NULL, *reject = NULL; + int informat, outformat, keyformat, CAformat, CAkeyformat; + char *infile = NULL, *outfile = NULL, *keyfile = NULL, *CAfile = NULL; + char *CAkeyfile = NULL, *CAserial = NULL; + char *fkeyfile = NULL; + char *alias = NULL; + int text = 0, serial = 0, subject = 0, issuer = 0, startdate = + 0, enddate = 0; + int next_serial = 0; + int subject_hash = 0, issuer_hash = 0, ocspid = 0; #ifndef OPENSSL_NO_MD5 - int subject_hash_old=0,issuer_hash_old=0; + int subject_hash_old = 0, issuer_hash_old = 0; #endif - int noout=0,sign_flag=0,CA_flag=0,CA_createserial=0,email=0; - int ocsp_uri=0; - int trustout=0,clrtrust=0,clrreject=0,aliasout=0,clrext=0; - int C=0; - int x509req=0,days=DEF_DAYS,modulus=0,pubkey=0; - int pprint = 0; - const char **pp; - X509_STORE *ctx=NULL; - X509_REQ *rq=NULL; - int fingerprint=0; - char buf[256]; - const EVP_MD *md_alg,*digest=NULL; - CONF *extconf = NULL; - char *extsect = NULL, *extfile = NULL, *passin = NULL, *passargin = NULL; - int need_rand = 0; - int checkend=0,checkoffset=0; - unsigned long nmflag = 0, certflag = 0; - char *checkhost = NULL; - char *checkemail = NULL; - char *checkip = NULL; + int noout = 0, sign_flag = 0, CA_flag = 0, CA_createserial = 0, email = 0; + int ocsp_uri = 0; + int trustout = 0, clrtrust = 0, clrreject = 0, aliasout = 0, clrext = 0; + int C = 0; + int x509req = 0, days = DEF_DAYS, modulus = 0, pubkey = 0; + int pprint = 0; + const char **pp; + X509_STORE *ctx = NULL; + X509_REQ *rq = NULL; + int fingerprint = 0; + char buf[256]; + const EVP_MD *md_alg, *digest = NULL; + CONF *extconf = NULL; + char *extsect = NULL, *extfile = NULL, *passin = NULL, *passargin = NULL; + int need_rand = 0; + int checkend = 0, checkoffset = 0; + unsigned long nmflag = 0, certflag = 0; + char *checkhost = NULL; + char *checkemail = NULL; + char *checkip = NULL; #ifndef OPENSSL_NO_ENGINE - char *engine=NULL; + char *engine = NULL; #endif - reqfile=0; + reqfile = 0; - apps_startup(); + apps_startup(); - if (bio_err == NULL) - bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); + if (bio_err == NULL) + bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); - if (!load_config(bio_err, NULL)) - goto end; - STDout=BIO_new_fp(stdout,BIO_NOCLOSE); + if (!load_config(bio_err, NULL)) + goto end; + STDout = BIO_new_fp(stdout, BIO_NOCLOSE); #ifdef OPENSSL_SYS_VMS - { - BIO *tmpbio = BIO_new(BIO_f_linebuffer()); - STDout = BIO_push(tmpbio, STDout); - } + { + BIO *tmpbio = BIO_new(BIO_f_linebuffer()); + STDout = BIO_push(tmpbio, STDout); + } #endif - informat=FORMAT_PEM; - outformat=FORMAT_PEM; - keyformat=FORMAT_PEM; - CAformat=FORMAT_PEM; - CAkeyformat=FORMAT_PEM; - - ctx=X509_STORE_new(); - if (ctx == NULL) goto end; - X509_STORE_set_verify_cb(ctx,callb); - - argc--; - argv++; - num=0; - while (argc >= 1) - { - if (strcmp(*argv,"-inform") == 0) - { - if (--argc < 1) goto bad; - informat=str2fmt(*(++argv)); - } - else if (strcmp(*argv,"-outform") == 0) - { - if (--argc < 1) goto bad; - outformat=str2fmt(*(++argv)); - } - else if (strcmp(*argv,"-keyform") == 0) - { - if (--argc < 1) goto bad; - keyformat=str2fmt(*(++argv)); - } - else if (strcmp(*argv,"-req") == 0) - { - reqfile=1; - need_rand = 1; - } - else if (strcmp(*argv,"-CAform") == 0) - { - if (--argc < 1) goto bad; - CAformat=str2fmt(*(++argv)); - } - else if (strcmp(*argv,"-CAkeyform") == 0) - { - if (--argc < 1) goto bad; - CAkeyformat=str2fmt(*(++argv)); - } - else if (strcmp(*argv,"-sigopt") == 0) - { - if (--argc < 1) - goto bad; - if (!sigopts) - sigopts = sk_OPENSSL_STRING_new_null(); - if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, *(++argv))) - goto bad; - } + informat = FORMAT_PEM; + outformat = FORMAT_PEM; + keyformat = FORMAT_PEM; + CAformat = FORMAT_PEM; + CAkeyformat = FORMAT_PEM; + + ctx = X509_STORE_new(); + if (ctx == NULL) + goto end; + X509_STORE_set_verify_cb(ctx, callb); + + argc--; + argv++; + num = 0; + while (argc >= 1) { + if (strcmp(*argv, "-inform") == 0) { + if (--argc < 1) + goto bad; + informat = str2fmt(*(++argv)); + } else if (strcmp(*argv, "-outform") == 0) { + if (--argc < 1) + goto bad; + outformat = str2fmt(*(++argv)); + } else if (strcmp(*argv, "-keyform") == 0) { + if (--argc < 1) + goto bad; + keyformat = str2fmt(*(++argv)); + } else if (strcmp(*argv, "-req") == 0) { + reqfile = 1; + need_rand = 1; + } else if (strcmp(*argv, "-CAform") == 0) { + if (--argc < 1) + goto bad; + CAformat = str2fmt(*(++argv)); + } else if (strcmp(*argv, "-CAkeyform") == 0) { + if (--argc < 1) + goto bad; + CAkeyformat = str2fmt(*(++argv)); + } else if (strcmp(*argv, "-sigopt") == 0) { + if (--argc < 1) + goto bad; + if (!sigopts) + sigopts = sk_OPENSSL_STRING_new_null(); + if (!sigopts || !sk_OPENSSL_STRING_push(sigopts, *(++argv))) + goto bad; + } #ifdef OPENSSL_SSL_DEBUG_BROKEN_PROTOCOL - else if (strcmp(*argv,"-force_version") == 0) - { - if (--argc < 1) goto bad; - force_version=atoi(*(++argv)) - 1; - } + else if (strcmp(*argv, "-force_version") == 0) { + if (--argc < 1) + goto bad; + force_version = atoi(*(++argv)) - 1; + } #endif - else if (strcmp(*argv,"-days") == 0) - { - if (--argc < 1) goto bad; - days=atoi(*(++argv)); - if (days == 0) - { - BIO_printf(bio_err,"bad number of days\n"); - goto bad; - } - } - else if (strcmp(*argv,"-passin") == 0) - { - if (--argc < 1) goto bad; - passargin= *(++argv); - } - else if (strcmp(*argv,"-extfile") == 0) - { - if (--argc < 1) goto bad; - extfile= *(++argv); - } - else if (strcmp(*argv,"-extensions") == 0) - { - if (--argc < 1) goto bad; - extsect= *(++argv); - } - else if (strcmp(*argv,"-in") == 0) - { - if (--argc < 1) goto bad; - infile= *(++argv); - } - else if (strcmp(*argv,"-out") == 0) - { - if (--argc < 1) goto bad; - outfile= *(++argv); - } - else if (strcmp(*argv,"-signkey") == 0) - { - if (--argc < 1) goto bad; - keyfile= *(++argv); - sign_flag= ++num; - need_rand = 1; - } - else if (strcmp(*argv,"-CA") == 0) - { - if (--argc < 1) goto bad; - CAfile= *(++argv); - CA_flag= ++num; - need_rand = 1; - } - else if (strcmp(*argv,"-CAkey") == 0) - { - if (--argc < 1) goto bad; - CAkeyfile= *(++argv); - } - else if (strcmp(*argv,"-CAserial") == 0) - { - if (--argc < 1) goto bad; - CAserial= *(++argv); - } - else if (strcmp(*argv,"-set_serial") == 0) - { - if (--argc < 1) goto bad; - if (!(sno = s2i_ASN1_INTEGER(NULL, *(++argv)))) - goto bad; - } - else if (strcmp(*argv,"-force_pubkey") == 0) - { - if (--argc < 1) goto bad; - fkeyfile= *(++argv); - } - else if (strcmp(*argv,"-addtrust") == 0) - { - if (--argc < 1) goto bad; - if (!(objtmp = OBJ_txt2obj(*(++argv), 0))) - { - BIO_printf(bio_err, - "Invalid trust object value %s\n", *argv); - goto bad; - } - if (!trust) trust = sk_ASN1_OBJECT_new_null(); - sk_ASN1_OBJECT_push(trust, objtmp); - trustout = 1; - } - else if (strcmp(*argv,"-addreject") == 0) - { - if (--argc < 1) goto bad; - if (!(objtmp = OBJ_txt2obj(*(++argv), 0))) - { - BIO_printf(bio_err, - "Invalid reject object value %s\n", *argv); - goto bad; - } - if (!reject) reject = sk_ASN1_OBJECT_new_null(); - sk_ASN1_OBJECT_push(reject, objtmp); - trustout = 1; - } - else if (strcmp(*argv,"-setalias") == 0) - { - if (--argc < 1) goto bad; - 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; - if (!set_name_ex(&nmflag, *(++argv))) goto bad; - } + else if (strcmp(*argv, "-days") == 0) { + if (--argc < 1) + goto bad; + days = atoi(*(++argv)); + if (days == 0) { + BIO_printf(bio_err, "bad number of days\n"); + goto bad; + } + } else if (strcmp(*argv, "-passin") == 0) { + if (--argc < 1) + goto bad; + passargin = *(++argv); + } else if (strcmp(*argv, "-extfile") == 0) { + if (--argc < 1) + goto bad; + extfile = *(++argv); + } else if (strcmp(*argv, "-extensions") == 0) { + if (--argc < 1) + goto bad; + extsect = *(++argv); + } else if (strcmp(*argv, "-in") == 0) { + if (--argc < 1) + goto bad; + infile = *(++argv); + } else if (strcmp(*argv, "-out") == 0) { + if (--argc < 1) + goto bad; + outfile = *(++argv); + } else if (strcmp(*argv, "-signkey") == 0) { + if (--argc < 1) + goto bad; + keyfile = *(++argv); + sign_flag = ++num; + need_rand = 1; + } else if (strcmp(*argv, "-CA") == 0) { + if (--argc < 1) + goto bad; + CAfile = *(++argv); + CA_flag = ++num; + need_rand = 1; + } else if (strcmp(*argv, "-CAkey") == 0) { + if (--argc < 1) + goto bad; + CAkeyfile = *(++argv); + } else if (strcmp(*argv, "-CAserial") == 0) { + if (--argc < 1) + goto bad; + CAserial = *(++argv); + } else if (strcmp(*argv, "-set_serial") == 0) { + if (--argc < 1) + goto bad; + if (!(sno = s2i_ASN1_INTEGER(NULL, *(++argv)))) + goto bad; + } else if (strcmp(*argv, "-force_pubkey") == 0) { + if (--argc < 1) + goto bad; + fkeyfile = *(++argv); + } else if (strcmp(*argv, "-addtrust") == 0) { + if (--argc < 1) + goto bad; + if (!(objtmp = OBJ_txt2obj(*(++argv), 0))) { + BIO_printf(bio_err, "Invalid trust object value %s\n", *argv); + goto bad; + } + if (!trust) + trust = sk_ASN1_OBJECT_new_null(); + sk_ASN1_OBJECT_push(trust, objtmp); + trustout = 1; + } else if (strcmp(*argv, "-addreject") == 0) { + if (--argc < 1) + goto bad; + if (!(objtmp = OBJ_txt2obj(*(++argv), 0))) { + BIO_printf(bio_err, + "Invalid reject object value %s\n", *argv); + goto bad; + } + if (!reject) + reject = sk_ASN1_OBJECT_new_null(); + sk_ASN1_OBJECT_push(reject, objtmp); + trustout = 1; + } else if (strcmp(*argv, "-setalias") == 0) { + if (--argc < 1) + goto bad; + 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; + if (!set_name_ex(&nmflag, *(++argv))) + goto bad; + } #ifndef OPENSSL_NO_ENGINE - else if (strcmp(*argv,"-engine") == 0) - { - if (--argc < 1) goto bad; - engine= *(++argv); - } + else if (strcmp(*argv, "-engine") == 0) { + if (--argc < 1) + goto bad; + engine = *(++argv); + } #endif - else if (strcmp(*argv,"-C") == 0) - C= ++num; - else if (strcmp(*argv,"-email") == 0) - email= ++num; - else if (strcmp(*argv,"-ocsp_uri") == 0) - ocsp_uri= ++num; - else if (strcmp(*argv,"-serial") == 0) - serial= ++num; - else if (strcmp(*argv,"-next_serial") == 0) - next_serial= ++num; - else if (strcmp(*argv,"-modulus") == 0) - modulus= ++num; - else if (strcmp(*argv,"-pubkey") == 0) - pubkey= ++num; - else if (strcmp(*argv,"-x509toreq") == 0) - x509req= ++num; - else if (strcmp(*argv,"-text") == 0) - text= ++num; - else if (strcmp(*argv,"-hash") == 0 - || strcmp(*argv,"-subject_hash") == 0) - subject_hash= ++num; + else if (strcmp(*argv, "-C") == 0) + C = ++num; + else if (strcmp(*argv, "-email") == 0) + email = ++num; + else if (strcmp(*argv, "-ocsp_uri") == 0) + ocsp_uri = ++num; + else if (strcmp(*argv, "-serial") == 0) + serial = ++num; + else if (strcmp(*argv, "-next_serial") == 0) + next_serial = ++num; + else if (strcmp(*argv, "-modulus") == 0) + modulus = ++num; + else if (strcmp(*argv, "-pubkey") == 0) + pubkey = ++num; + else if (strcmp(*argv, "-x509toreq") == 0) + x509req = ++num; + else if (strcmp(*argv, "-text") == 0) + text = ++num; + else if (strcmp(*argv, "-hash") == 0 + || strcmp(*argv, "-subject_hash") == 0) + subject_hash = ++num; #ifndef OPENSSL_NO_MD5 - else if (strcmp(*argv,"-subject_hash_old") == 0) - subject_hash_old= ++num; + else if (strcmp(*argv, "-subject_hash_old") == 0) + subject_hash_old = ++num; #endif - else if (strcmp(*argv,"-issuer_hash") == 0) - issuer_hash= ++num; + else if (strcmp(*argv, "-issuer_hash") == 0) + issuer_hash = ++num; #ifndef OPENSSL_NO_MD5 - else if (strcmp(*argv,"-issuer_hash_old") == 0) - issuer_hash_old= ++num; + else if (strcmp(*argv, "-issuer_hash_old") == 0) + issuer_hash_old = ++num; #endif - else if (strcmp(*argv,"-subject") == 0) - subject= ++num; - else if (strcmp(*argv,"-issuer") == 0) - issuer= ++num; - else if (strcmp(*argv,"-fingerprint") == 0) - fingerprint= ++num; - else if (strcmp(*argv,"-dates") == 0) - { - startdate= ++num; - enddate= ++num; - } - else if (strcmp(*argv,"-purpose") == 0) - pprint= ++num; - else if (strcmp(*argv,"-startdate") == 0) - startdate= ++num; - else if (strcmp(*argv,"-enddate") == 0) - enddate= ++num; - else if (strcmp(*argv,"-checkend") == 0) - { - if (--argc < 1) goto bad; - checkoffset=atoi(*(++argv)); - checkend=1; - } - else if (strcmp(*argv,"-checkhost") == 0) - { - if (--argc < 1) goto bad; - checkhost=*(++argv); - } - else if (strcmp(*argv,"-checkemail") == 0) - { - if (--argc < 1) goto bad; - checkemail=*(++argv); - } - else if (strcmp(*argv,"-checkip") == 0) - { - if (--argc < 1) goto bad; - checkip=*(++argv); - } - else if (strcmp(*argv,"-noout") == 0) - noout= ++num; - else if (strcmp(*argv,"-trustout") == 0) - trustout= 1; - else if (strcmp(*argv,"-clrtrust") == 0) - clrtrust= ++num; - else if (strcmp(*argv,"-clrreject") == 0) - clrreject= ++num; - else if (strcmp(*argv,"-alias") == 0) - aliasout= ++num; - else if (strcmp(*argv,"-CAcreateserial") == 0) - CA_createserial= ++num; - else if (strcmp(*argv,"-clrext") == 0) - clrext = 1; -#if 1 /* stay backwards-compatible with 0.9.5; this should go away soon */ - else if (strcmp(*argv,"-crlext") == 0) - { - BIO_printf(bio_err,"use -clrext instead of -crlext\n"); - clrext = 1; - } + else if (strcmp(*argv, "-subject") == 0) + subject = ++num; + else if (strcmp(*argv, "-issuer") == 0) + issuer = ++num; + else if (strcmp(*argv, "-fingerprint") == 0) + fingerprint = ++num; + else if (strcmp(*argv, "-dates") == 0) { + startdate = ++num; + enddate = ++num; + } else if (strcmp(*argv, "-purpose") == 0) + pprint = ++num; + else if (strcmp(*argv, "-startdate") == 0) + startdate = ++num; + else if (strcmp(*argv, "-enddate") == 0) + enddate = ++num; + else if (strcmp(*argv, "-checkend") == 0) { + if (--argc < 1) + goto bad; + checkoffset = atoi(*(++argv)); + checkend = 1; + } else if (strcmp(*argv, "-checkhost") == 0) { + if (--argc < 1) + goto bad; + checkhost = *(++argv); + } else if (strcmp(*argv, "-checkemail") == 0) { + if (--argc < 1) + goto bad; + checkemail = *(++argv); + } else if (strcmp(*argv, "-checkip") == 0) { + if (--argc < 1) + goto bad; + checkip = *(++argv); + } else if (strcmp(*argv, "-noout") == 0) + noout = ++num; + else if (strcmp(*argv, "-trustout") == 0) + trustout = 1; + else if (strcmp(*argv, "-clrtrust") == 0) + clrtrust = ++num; + else if (strcmp(*argv, "-clrreject") == 0) + clrreject = ++num; + else if (strcmp(*argv, "-alias") == 0) + aliasout = ++num; + else if (strcmp(*argv, "-CAcreateserial") == 0) + CA_createserial = ++num; + else if (strcmp(*argv, "-clrext") == 0) + clrext = 1; +#if 1 /* stay backwards-compatible with 0.9.5; this + * should go away soon */ + else if (strcmp(*argv, "-crlext") == 0) { + BIO_printf(bio_err, "use -clrext instead of -crlext\n"); + clrext = 1; + } #endif - else if (strcmp(*argv,"-ocspid") == 0) - ocspid= ++num; - else if (strcmp(*argv,"-badsig") == 0) - badsig = 1; - else if ((md_alg=EVP_get_digestbyname(*argv + 1))) - { - /* ok */ - digest=md_alg; - } - else - { - BIO_printf(bio_err,"unknown option %s\n",*argv); - badops=1; - break; - } - argc--; - argv++; - } - - if (badops) - { -bad: - for (pp=x509_usage; (*pp != NULL); pp++) - BIO_printf(bio_err,"%s",*pp); - goto end; - } - + else if (strcmp(*argv, "-ocspid") == 0) + ocspid = ++num; + else if (strcmp(*argv, "-badsig") == 0) + badsig = 1; + else if ((md_alg = EVP_get_digestbyname(*argv + 1))) { + /* ok */ + digest = md_alg; + } else { + BIO_printf(bio_err, "unknown option %s\n", *argv); + badops = 1; + break; + } + argc--; + argv++; + } + + if (badops) { + bad: + for (pp = x509_usage; (*pp != NULL); pp++) + BIO_printf(bio_err, "%s", *pp); + goto end; + } #ifndef OPENSSL_NO_ENGINE - e = setup_engine(bio_err, engine, 0); + e = setup_engine(bio_err, engine, 0); #endif - if (need_rand) - app_RAND_load_file(NULL, bio_err, 0); - - ERR_load_crypto_strings(); - - if (!app_passwd(bio_err, passargin, NULL, &passin, NULL)) - { - BIO_printf(bio_err, "Error getting password\n"); - goto end; - } - - if (!X509_STORE_set_default_paths(ctx)) - { - ERR_print_errors(bio_err); - goto end; - } - - if (fkeyfile) - { - fkey = load_pubkey(bio_err, fkeyfile, keyformat, 0, - NULL, e, "Forced key"); - if (fkey == NULL) goto end; - } - - if ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM)) - { CAkeyfile=CAfile; } - else if ((CA_flag) && (CAkeyfile == NULL)) - { - BIO_printf(bio_err,"need to specify a CAkey if using the CA command\n"); - goto end; - } - - if (extfile) - { - long errorline = -1; - X509V3_CTX ctx2; - extconf = NCONF_new(NULL); - if (!NCONF_load(extconf, extfile,&errorline)) - { - if (errorline <= 0) - BIO_printf(bio_err, - "error loading the config file '%s'\n", - extfile); - else - BIO_printf(bio_err, - "error on line %ld of config file '%s'\n" - ,errorline,extfile); - goto end; - } - if (!extsect) - { - extsect = NCONF_get_string(extconf, "default", "extensions"); - if (!extsect) - { - ERR_clear_error(); - extsect = "default"; - } - } - X509V3_set_ctx_test(&ctx2); - X509V3_set_nconf(&ctx2, extconf); - if (!X509V3_EXT_add_nconf(extconf, &ctx2, extsect, NULL)) - { - BIO_printf(bio_err, - "Error Loading extension section %s\n", - extsect); - ERR_print_errors(bio_err); - goto end; - } - } - - - if (reqfile) - { - EVP_PKEY *pkey; - BIO *in; - - if (!sign_flag && !CA_flag) - { - BIO_printf(bio_err,"We need a private key to sign with\n"); - goto end; - } - in=BIO_new(BIO_s_file()); - if (in == NULL) - { - ERR_print_errors(bio_err); - goto end; - } - - if (infile == NULL) - BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); - else - { - if (BIO_read_filename(in,infile) <= 0) - { - perror(infile); - BIO_free(in); - goto end; - } - } - req=PEM_read_bio_X509_REQ(in,NULL,NULL,NULL); - BIO_free(in); - - if (req == NULL) - { - ERR_print_errors(bio_err); - goto end; - } - - if ( (req->req_info == NULL) || - (req->req_info->pubkey == NULL) || - (req->req_info->pubkey->public_key == NULL) || - (req->req_info->pubkey->public_key->data == NULL)) - { - BIO_printf(bio_err,"The certificate request appears to corrupted\n"); - BIO_printf(bio_err,"It does not contain a public key\n"); - goto end; - } - if ((pkey |