apps/x509.c:645: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `x509_certify`.
Showing all 13 steps of the trace


apps/x509.c:170:6: Call
168.   	CAkeyformat=FORMAT_PEM;
169.   
170.   	ctx=X509_STORE_new();
            ^
171.   	if (ctx == NULL) goto end;
172.   	X509_STORE_set_verify_cb_func(ctx,callb);

crypto/x509/x509_lu.c:202:13: Call
  200.   	if ((ret=(X509_STORE *)Malloc(sizeof(X509_STORE))) == NULL)
  201.   		return(NULL);
  202.   	ret->certs=lh_new(x509_object_hash,x509_object_cmp);
                     ^
  203.   	ret->cache=1;
  204.   	ret->get_cert_methods=sk_X509_LOOKUP_new_null();

crypto/lhash/lhash.c:136:2: Assignment
    134.   	ret->up_load=UP_LOAD;
    135.   	ret->down_load=DOWN_LOAD;
    136.   	ret->num_items=0;
            ^
    137.   
    138.   	ret->num_expands=0;

apps/x509.c:645:10: Call
643.   #endif
644.   				
645.   				if (!x509_certify(ctx,CAfile,digest,x,xca,
                ^
646.   					CApkey, CAserial,CA_createserial,days,
647.   					extconf, extsect))

apps/x509.c:735:1: Parameter `ctx->certs->num_items`
  733.   	}
  734.   
  735. > static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,
  736.   	     X509 *x, X509 *xca, EVP_PKEY *pkey, char *serialfile, int create,
  737.   	     int days, LHASH *conf, char *section)

apps/x509.c:834:7: Call
  832.   	io=NULL;
  833.   	
  834.   	if (!X509_STORE_add_cert(ctx,x)) goto end;
               ^
  835.   
  836.   	/* NOTE: this certificate can/should be self signed, unless it was

crypto/x509/x509_vfy.c:509:1: Parameter `ctx->certs->num_items`
    507.   	}
    508.   
    509. > int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
    510.   	{
    511.   	X509_OBJECT *obj,*r;

crypto/x509/x509_vfy.c:528:19: Call
    526.   	X509_OBJECT_up_ref_count(obj);
    527.   
    528.   	r=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj);
                             ^
    529.   	if (r != NULL)
    530.   		{ /* oops, put it back */

crypto/lhash/lhash.c:182:1: Parameter `lh->num_items`
      180.   	}
      181.   
      182. > char *lh_insert(LHASH *lh, char *data)
      183.   	{
      184.   	unsigned long hash;

crypto/x509/x509_vfy.c:531:3: Call
    529.   	if (r != NULL)
    530.   		{ /* oops, put it back */
    531.   		lh_delete(ctx->certs,(char *)obj);
             ^
    532.   		X509_OBJECT_free_contents(obj);
    533.   		Free(obj);

crypto/lhash/lhash.c:220:1: <LHS trace>
218.   	}
219.   
220. > char *lh_delete(LHASH *lh, char *data)
221.   	{
222.   	unsigned long hash;

crypto/lhash/lhash.c:220:1: Parameter `lh->num_items`
      218.   	}
      219.   
      220. > char *lh_delete(LHASH *lh, char *data)
      221.   	{
      222.   	unsigned long hash;

crypto/lhash/lhash.c:243:2: Binary operation: ([0, +oo] - 1):unsigned64 by call to `x509_certify` 
      241.   		}
      242.   
      243.   	lh->num_items--;
              ^
      244.   	if ((lh->num_nodes > MIN_NODES) &&
      245.   		(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))

char *lh_delete(LHASH *lh, char *data)
	{
	unsigned long hash;
	LHASH_NODE *nn,**rn;
	char *ret;
	lh->error=0;
	rn=getrn(lh,data,&hash);
	if (*rn == NULL)
		{
		lh->num_no_delete++;
		return(NULL);
		}
	else
		{
		nn= *rn;
		*rn=nn->next;
		ret=nn->data;
		Free((char *)nn);
		lh->num_delete++;
		}
	lh->num_items--;
	if ((lh->num_nodes > MIN_NODES) &&
		(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
		contract(lh);
	return(ret);
	}
['int MAIN(int argc, char **argv)\n\t{\n\tint ret=1;\n\tX509_REQ *req=NULL;\n\tX509 *x=NULL,*xca=NULL;\n\tEVP_PKEY *Upkey=NULL,*CApkey=NULL;\n\tint i,num,badops=0;\n\tBIO *out=NULL;\n\tBIO *STDout=NULL;\n\tint informat,outformat,keyformat,CAformat,CAkeyformat;\n\tchar *infile=NULL,*outfile=NULL,*keyfile=NULL,*CAfile=NULL;\n\tchar *CAkeyfile=NULL,*CAserial=NULL;\n\tint text=0,serial=0,hash=0,subject=0,issuer=0,startdate=0,enddate=0;\n\tint noout=0,sign_flag=0,CA_flag=0,CA_createserial=0;\n\tint C=0;\n\tint x509req=0,days=DEF_DAYS,modulus=0;\n\tchar **pp;\n\tX509_STORE *ctx=NULL;\n\tX509_REQ *rq=NULL;\n\tint fingerprint=0;\n\tchar buf[256];\n\tconst EVP_MD *md_alg,*digest=EVP_md5();\n\tLHASH *extconf = NULL;\n\tchar *extsect = NULL, *extfile = NULL;\n\treqfile=0;\n\tapps_startup();\n\tif (bio_err == NULL)\n\t\tbio_err=BIO_new_fp(stderr,BIO_NOCLOSE);\n\tSTDout=BIO_new_fp(stdout,BIO_NOCLOSE);\n\tinformat=FORMAT_PEM;\n\toutformat=FORMAT_PEM;\n\tkeyformat=FORMAT_PEM;\n\tCAformat=FORMAT_PEM;\n\tCAkeyformat=FORMAT_PEM;\n\tctx=X509_STORE_new();\n\tif (ctx == NULL) goto end;\n\tX509_STORE_set_verify_cb_func(ctx,callb);\n\targc--;\n\targv++;\n\tnum=0;\n\twhile (argc >= 1)\n\t\t{\n\t\tif \t(strcmp(*argv,"-inform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-outform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-req") == 0)\n\t\t\treqfile=1;\n\t\telse if (strcmp(*argv,"-CAform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAkeyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAformat=str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (strcmp(*argv,"-days") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tdays=atoi(*(++argv));\n\t\t\tif (days == 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"bad number of days\\n");\n\t\t\t\tgoto bad;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (strcmp(*argv,"-extfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\textfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\toutfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-signkey") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeyfile= *(++argv);\n\t\t\tsign_flag= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CA") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAfile= *(++argv);\n\t\t\tCA_flag= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAkey") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAkeyfile= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-CAserial") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAserial= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-C") == 0)\n\t\t\tC= ++num;\n\t\telse if (strcmp(*argv,"-serial") == 0)\n\t\t\tserial= ++num;\n\t\telse if (strcmp(*argv,"-modulus") == 0)\n\t\t\tmodulus= ++num;\n\t\telse if (strcmp(*argv,"-x509toreq") == 0)\n\t\t\tx509req= ++num;\n\t\telse if (strcmp(*argv,"-text") == 0)\n\t\t\ttext= ++num;\n\t\telse if (strcmp(*argv,"-hash") == 0)\n\t\t\thash= ++num;\n\t\telse if (strcmp(*argv,"-subject") == 0)\n\t\t\tsubject= ++num;\n\t\telse if (strcmp(*argv,"-issuer") == 0)\n\t\t\tissuer= ++num;\n\t\telse if (strcmp(*argv,"-fingerprint") == 0)\n\t\t\tfingerprint= ++num;\n\t\telse if (strcmp(*argv,"-dates") == 0)\n\t\t\t{\n\t\t\tstartdate= ++num;\n\t\t\tenddate= ++num;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-startdate") == 0)\n\t\t\tstartdate= ++num;\n\t\telse if (strcmp(*argv,"-enddate") == 0)\n\t\t\tenddate= ++num;\n\t\telse if (strcmp(*argv,"-noout") == 0)\n\t\t\tnoout= ++num;\n\t\telse if (strcmp(*argv,"-CAcreateserial") == 0)\n\t\t\tCA_createserial= ++num;\n\t\telse if ((md_alg=EVP_get_digestbyname(&((*argv)[1]))) != NULL)\n\t\t\t{\n\t\t\tdigest=md_alg;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadops=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badops)\n\t\t{\nbad:\n\t\tfor (pp=x509_usage; (*pp != NULL); pp++)\n\t\t\tBIO_printf(bio_err,*pp);\n\t\tgoto end;\n\t\t}\n\tERR_load_crypto_strings();\n\tX509V3_add_standard_extensions();\n\tif (!X509_STORE_set_default_paths(ctx))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif ((CAkeyfile == NULL) && (CA_flag) && (CAformat == FORMAT_PEM))\n\t\t{ CAkeyfile=CAfile; }\n\telse if ((CA_flag) && (CAkeyfile == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"need to specify a CAkey if using the CA command\\n");\n\t\tgoto end;\n\t\t}\n\tif (extfile) {\n\t\tlong errorline;\n\t\tX509V3_CTX ctx2;\n\t\tif (!(extconf=CONF_load(NULL,extfile,&errorline))) {\n\t\t\tif (errorline <= 0)\n\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t"error loading the config file \'%s\'\\n",\n\t\t\t\t\t\t\t\textfile);\n                \telse\n                        \tBIO_printf(bio_err,\n\t\t\t\t       "error on line %ld of config file \'%s\'\\n"\n\t\t\t\t\t\t\t,errorline,extfile);\n\t\t\tgoto end;\n\t\t}\n\t\tif(!(extsect = CONF_get_string(extconf, "default",\n\t\t\t\t\t "extensions"))) extsect = "default";\n\t\tX509V3_set_ctx_test(&ctx2);\n\t\tX509V3_set_conf_lhash(&ctx2, extconf);\n\t\tif(!X509V3_EXT_add_conf(extconf, &ctx2, extsect, NULL)) {\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t"Error Loading extension section %s\\n",\n\t\t\t\t\t\t\t\t extsect);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n                }\n\t}\n\tif (reqfile)\n\t\t{\n\t\tEVP_PKEY *pkey;\n\t\tX509_CINF *ci;\n\t\tBIO *in;\n\t\tif (!sign_flag && !CA_flag)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"We need a private key to sign with\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tin=BIO_new(BIO_s_file());\n\t\tif (in == NULL)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (infile == NULL)\n\t\t\tBIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_read_filename(in,infile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(infile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\treq=PEM_read_bio_X509_REQ(in,NULL,NULL);\n\t\tBIO_free(in);\n\t\tif (req == NULL) { perror(infile); goto end; }\n\t\tif (\t(req->req_info == NULL) ||\n\t\t\t(req->req_info->pubkey == NULL) ||\n\t\t\t(req->req_info->pubkey->public_key == NULL) ||\n\t\t\t(req->req_info->pubkey->public_key->data == NULL))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"The certificate request appears to corrupted\\n");\n\t\t\tBIO_printf(bio_err,"It does not contain a public key\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tif ((pkey=X509_REQ_get_pubkey(req)) == NULL)\n\t                {\n\t                BIO_printf(bio_err,"error unpacking public key\\n");\n\t                goto end;\n\t                }\n\t\ti=X509_REQ_verify(req,pkey);\n\t\tEVP_PKEY_free(pkey);\n\t\tif (i < 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Signature verification error\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t        if (i == 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Signature did not match the certificate request\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\tBIO_printf(bio_err,"Signature ok\\n");\n\t\tX509_NAME_oneline(req->req_info->subject,buf,256);\n\t\tBIO_printf(bio_err,"subject=%s\\n",buf);\n\t\tif ((x=X509_new()) == NULL) goto end;\n\t\tci=x->cert_info;\n\t\tif (!ASN1_INTEGER_set(X509_get_serialNumber(x),0)) goto end;\n\t\tif (!X509_set_issuer_name(x,req->req_info->subject)) goto end;\n\t\tif (!X509_set_subject_name(x,req->req_info->subject)) goto end;\n\t\tX509_gmtime_adj(X509_get_notBefore(x),0);\n\t        X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days);\n#if 0\n\t\tX509_PUBKEY_free(ci->key);\n\t\tci->key=req->req_info->pubkey;\n\t        req->req_info->pubkey=NULL;\n#else\n\t\tpkey = X509_REQ_get_pubkey(req);\n\t\tX509_set_pubkey(x,pkey);\n\t\tEVP_PKEY_free(pkey);\n#endif\n\t\t}\n\telse\n\t\tx=load_cert(infile,informat);\n\tif (x == NULL) goto end;\n\tif (CA_flag)\n\t\t{\n\t\txca=load_cert(CAfile,CAformat);\n\t\tif (xca == NULL) goto end;\n\t\t}\n\tif (!noout || text)\n\t\t{\n\t\tOBJ_create("2.99999.3",\n\t\t\t"SET.ex3","SET x509v3 extension 3");\n\t\tout=BIO_new(BIO_s_file());\n\t\tif (out == NULL)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tif (outfile == NULL)\n\t\t\tBIO_set_fp(out,stdout,BIO_NOCLOSE);\n\t\telse\n\t\t\t{\n\t\t\tif (BIO_write_filename(out,outfile) <= 0)\n\t\t\t\t{\n\t\t\t\tperror(outfile);\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (num)\n\t\t{\n\t\tfor (i=1; i<=num; i++)\n\t\t\t{\n\t\t\tif (issuer == i)\n\t\t\t\t{\n\t\t\t\tX509_NAME_oneline(X509_get_issuer_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"issuer= %s\\n",buf);\n\t\t\t\t}\n\t\t\telse if (subject == i)\n\t\t\t\t{\n\t\t\t\tX509_NAME_oneline(X509_get_subject_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"subject=%s\\n",buf);\n\t\t\t\t}\n\t\t\telse if (serial == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"serial=");\n\t\t\t\ti2a_ASN1_INTEGER(STDout,x->cert_info->serialNumber);\n\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (hash == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(STDout,"%08lx\\n",X509_subject_name_hash(x));\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tif (modulus == i)\n\t\t\t\t{\n\t\t\t\tEVP_PKEY *pkey;\n\t\t\t\tpkey=X509_get_pubkey(x);\n\t\t\t\tif (pkey == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"Modulus=unavailable\\n");\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(STDout,"Modulus=");\n#ifndef NO_RSA\n\t\t\t\tif (pkey->type == EVP_PKEY_RSA)\n\t\t\t\t\tBN_print(STDout,pkey->pkey.rsa->n);\n\t\t\t\telse\n#endif\n#ifndef NO_DSA\n\t\t\t\tif (pkey->type == EVP_PKEY_DSA)\n\t\t\t\t\tBN_print(STDout,pkey->pkey.dsa->pub_key);\n\t\t\t\telse\n#endif\n\t\t\t\t\tBIO_printf(STDout,"Wrong Algorithm type");\n\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\tEVP_PKEY_free(pkey);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\tif (C == i)\n\t\t\t\t{\n\t\t\t\tunsigned char *d;\n\t\t\t\tchar *m;\n\t\t\t\tint y,z;\n\t\t\t\tX509_NAME_oneline(X509_get_subject_name(x),\n\t\t\t\t\tbuf,256);\n\t\t\t\tBIO_printf(STDout,"/* subject:%s */\\n",buf);\n\t\t\t\tm=X509_NAME_oneline(\n\t\t\t\t\tX509_get_issuer_name(x),buf,256);\n\t\t\t\tBIO_printf(STDout,"/* issuer :%s */\\n",buf);\n\t\t\t\tz=i2d_X509(x,NULL);\n\t\t\t\tm=Malloc(z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tz=i2d_X509_NAME(X509_get_subject_name(x),&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_subject_name[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f) BIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tz=i2d_X509_PUBKEY(X509_get_X509_PUBKEY(x),&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_public_key[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f)\n\t\t\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tz=i2d_X509(x,&d);\n\t\t\t\tBIO_printf(STDout,"unsigned char XXX_certificate[%d]={\\n",z);\n\t\t\t\td=(unsigned char *)m;\n\t\t\t\tfor (y=0; y<z; y++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"0x%02X,",d[y]);\n\t\t\t\t\tif ((y & 0x0f) == 0x0f)\n\t\t\t\t\t\tBIO_printf(STDout,"\\n");\n\t\t\t\t\t}\n\t\t\t\tif (y%16 != 0) BIO_printf(STDout,"\\n");\n\t\t\t\tBIO_printf(STDout,"};\\n");\n\t\t\t\tFree(m);\n\t\t\t\t}\n\t\t\telse if (text == i)\n\t\t\t\t{\n\t\t\t\tX509_print(out,x);\n\t\t\t\t}\n\t\t\telse if (startdate == i)\n\t\t\t\t{\n\t\t\t\tBIO_puts(STDout,"notBefore=");\n\t\t\t\tASN1_TIME_print(STDout,X509_get_notBefore(x));\n\t\t\t\tBIO_puts(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (enddate == i)\n\t\t\t\t{\n\t\t\t\tBIO_puts(STDout,"notAfter=");\n\t\t\t\tASN1_TIME_print(STDout,X509_get_notAfter(x));\n\t\t\t\tBIO_puts(STDout,"\\n");\n\t\t\t\t}\n\t\t\telse if (fingerprint == i)\n\t\t\t\t{\n\t\t\t\tint j;\n\t\t\t\tunsigned int n;\n\t\t\t\tunsigned char md[EVP_MAX_MD_SIZE];\n\t\t\t\tif (!X509_digest(x,EVP_md5(),md,&n))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(STDout,"MD5 Fingerprint=");\n\t\t\t\tfor (j=0; j<(int)n; j++)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(STDout,"%02X%c",md[j],\n\t\t\t\t\t\t(j+1 == (int)n)\n\t\t\t\t\t\t?\'\\n\':\':\');\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\telse if ((sign_flag == i) && (x509req == 0))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"Getting Private key\\n");\n\t\t\t\tif (Upkey == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tUpkey=load_key(keyfile,keyformat);\n\t\t\t\t\tif (Upkey == NULL) goto end;\n\t\t\t\t\t}\n#ifndef NO_DSA\n\t\t                if (Upkey->type == EVP_PKEY_DSA)\n\t\t                        digest=EVP_dss1();\n#endif\n\t\t\t\tif (!sign(x,Upkey,days,digest,\n\t\t\t\t\t\t extconf, extsect)) goto end;\n\t\t\t\t}\n\t\t\telse if (CA_flag == i)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"Getting CA Private Key\\n");\n\t\t\t\tif (CAkeyfile != NULL)\n\t\t\t\t\t{\n\t\t\t\t\tCApkey=load_key(CAkeyfile,CAkeyformat);\n\t\t\t\t\tif (CApkey == NULL) goto end;\n\t\t\t\t\t}\n#ifndef NO_DSA\n\t\t                if (CApkey->type == EVP_PKEY_DSA)\n\t\t                        digest=EVP_dss1();\n#endif\n\t\t\t\tif (!x509_certify(ctx,CAfile,digest,x,xca,\n\t\t\t\t\tCApkey, CAserial,CA_createserial,days,\n\t\t\t\t\textconf, extsect))\n\t\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\telse if (x509req == i)\n\t\t\t\t{\n\t\t\t\tEVP_PKEY *pk;\n\t\t\t\tBIO_printf(bio_err,"Getting request Private Key\\n");\n\t\t\t\tif (keyfile == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"no request key file specified\\n");\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tpk=load_key(keyfile,FORMAT_PEM);\n\t\t\t\t\tif (pk == NULL) goto end;\n\t\t\t\t\t}\n\t\t\t\tBIO_printf(bio_err,"Generating certificate request\\n");\n\t\t\t\trq=X509_to_X509_REQ(x,pk,EVP_md5());\n\t\t\t\tEVP_PKEY_free(pk);\n\t\t\t\tif (rq == NULL)\n\t\t\t\t\t{\n\t\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\t\tgoto end;\n\t\t\t\t\t}\n\t\t\t\tif (!noout)\n\t\t\t\t\t{\n\t\t\t\t\tX509_REQ_print(out,rq);\n\t\t\t\t\tPEM_write_bio_X509_REQ(out,rq);\n\t\t\t\t\t}\n\t\t\t\tnoout=1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (noout)\n\t\t{\n\t\tret=0;\n\t\tgoto end;\n\t\t}\n\tif \t(outformat == FORMAT_ASN1)\n\t\ti=i2d_X509_bio(out,x);\n\telse if (outformat == FORMAT_PEM)\n\t\ti=PEM_write_bio_X509(out,x);\n\telse if (outformat == FORMAT_NETSCAPE)\n\t\t{\n\t\tASN1_HEADER ah;\n\t\tASN1_OCTET_STRING os;\n\t\tos.data=(unsigned char *)CERT_HDR;\n\t\tos.length=strlen(CERT_HDR);\n\t\tah.header= &os;\n\t\tah.data=(char *)x;\n\t\tah.meth=X509_asn1_meth();\n\t\ti=ASN1_i2d_bio(i2d_ASN1_HEADER,out,(unsigned char *)&ah);\n\t\t}\n\telse\t{\n\t\tBIO_printf(bio_err,"bad output format specified for outfile\\n");\n\t\tgoto end;\n\t\t}\n\tif (!i) {\n\t\tBIO_printf(bio_err,"unable to write certificate\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tret=0;\nend:\n\tOBJ_cleanup();\n\tCONF_free(extconf);\n\tBIO_free(out);\n\tBIO_free(STDout);\n\tX509_STORE_free(ctx);\n\tX509_REQ_free(req);\n\tX509_free(x);\n\tX509_free(xca);\n\tEVP_PKEY_free(Upkey);\n\tEVP_PKEY_free(CApkey);\n\tX509_REQ_free(rq);\n\tX509V3_EXT_cleanup();\n\tEXIT(ret);\n\t}', 'X509_STORE *X509_STORE_new(void)\n\t{\n\tX509_STORE *ret;\n\tif ((ret=(X509_STORE *)Malloc(sizeof(X509_STORE))) == NULL)\n\t\treturn(NULL);\n\tret->certs=lh_new(x509_object_hash,x509_object_cmp);\n\tret->cache=1;\n\tret->get_cert_methods=sk_X509_LOOKUP_new_null();\n\tret->verify=NULL;\n\tret->verify_cb=NULL;\n\tmemset(&ret->ex_data,0,sizeof(CRYPTO_EX_DATA));\n\tret->references=1;\n\tret->depth=0;\n\treturn(ret);\n\t}', 'LHASH *lh_new(unsigned long (*h)(), int (*c)())\n\t{\n\tLHASH *ret;\n\tint i;\n\tif ((ret=(LHASH *)Malloc(sizeof(LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=(LHASH_NODE **)Malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->b[i]=NULL;\n\tret->comp=((c == NULL)?(int (*)())strcmp:c);\n\tret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);\n\tret->num_nodes=MIN_NODES/2;\n\tret->num_alloc_nodes=MIN_NODES;\n\tret->p=0;\n\tret->pmax=MIN_NODES/2;\n\tret->up_load=UP_LOAD;\n\tret->down_load=DOWN_LOAD;\n\tret->num_items=0;\n\tret->num_expands=0;\n\tret->num_expand_reallocs=0;\n\tret->num_contracts=0;\n\tret->num_contract_reallocs=0;\n\tret->num_hash_calls=0;\n\tret->num_comp_calls=0;\n\tret->num_insert=0;\n\tret->num_replace=0;\n\tret->num_delete=0;\n\tret->num_no_delete=0;\n\tret->num_retrieve=0;\n\tret->num_retrieve_miss=0;\n\tret->num_hash_comps=0;\n\tret->error=0;\n\treturn(ret);\nerr1:\n\tFree((char *)ret);\nerr0:\n\treturn(NULL);\n\t}', 'static int x509_certify(X509_STORE *ctx, char *CAfile, const EVP_MD *digest,\n\t     X509 *x, X509 *xca, EVP_PKEY *pkey, char *serialfile, int create,\n\t     int days, LHASH *conf, char *section)\n\t{\n\tint ret=0;\n\tBIO *io=NULL;\n\tMS_STATIC char buf2[1024];\n\tchar *buf=NULL,*p;\n\tBIGNUM *serial=NULL;\n\tASN1_INTEGER *bs=NULL,bs2;\n\tX509_STORE_CTX xsc;\n\tEVP_PKEY *upkey;\n\tupkey = X509_get_pubkey(xca);\n\tEVP_PKEY_copy_parameters(upkey,pkey);\n\tEVP_PKEY_free(upkey);\n\tX509_STORE_CTX_init(&xsc,ctx,x,NULL);\n\tbuf=(char *)Malloc(EVP_PKEY_size(pkey)*2+\n\t\t((serialfile == NULL)\n\t\t\t?(strlen(CAfile)+strlen(POSTFIX)+1)\n\t\t\t:(strlen(serialfile)))+1);\n\tif (buf == NULL) { BIO_printf(bio_err,"out of mem\\n"); goto end; }\n\tif (serialfile == NULL)\n\t\t{\n\t\tstrcpy(buf,CAfile);\n\t\tfor (p=buf; *p; p++)\n\t\t\tif (*p == \'.\')\n\t\t\t\t{\n\t\t\t\t*p=\'\\0\';\n\t\t\t\tbreak;\n\t\t\t\t}\n\t\tstrcat(buf,POSTFIX);\n\t\t}\n\telse\n\t\tstrcpy(buf,serialfile);\n\tserial=BN_new();\n\tbs=ASN1_INTEGER_new();\n\tif ((serial == NULL) || (bs == NULL))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tio=BIO_new(BIO_s_file());\n\tif (io == NULL)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (BIO_read_filename(io,buf) <= 0)\n\t\t{\n\t\tif (!create)\n\t\t\t{\n\t\t\tperror(buf);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tASN1_INTEGER_set(bs,0);\n\t\t\tBN_zero(serial);\n\t\t\t}\n\t\t}\n\telse\n\t\t{\n\t\tif (!a2i_ASN1_INTEGER(io,bs,buf2,1024))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unable to load serial number from %s\\n",buf);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tserial=BN_bin2bn(bs->data,bs->length,serial);\n\t\t\tif (serial == NULL)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"error converting bin 2 bn");\n\t\t\t\tgoto end;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (!BN_add_word(serial,1))\n\t\t{ BIO_printf(bio_err,"add_word failure\\n"); goto end; }\n\tbs2.data=(unsigned char *)buf2;\n\tbs2.length=BN_bn2bin(serial,bs2.data);\n\tif (BIO_write_filename(io,buf) <= 0)\n\t\t{\n\t\tBIO_printf(bio_err,"error attempting to write serial number file\\n");\n\t\tperror(buf);\n\t\tgoto end;\n\t\t}\n\ti2a_ASN1_INTEGER(io,&bs2);\n\tBIO_puts(io,"\\n");\n\tBIO_free(io);\n\tio=NULL;\n\tif (!X509_STORE_add_cert(ctx,x)) goto end;\n\tX509_STORE_CTX_set_cert(&xsc,x);\n\tif (!reqfile && !X509_verify_cert(&xsc))\n\t\tgoto end;\n\tif (!X509_check_private_key(xca,pkey))\n\t\t{\n\t\tBIO_printf(bio_err,"CA certificate and CA private key do not match\\n");\n\t\tgoto end;\n\t\t}\n\tif (!X509_set_issuer_name(x,X509_get_subject_name(xca))) goto end;\n\tif (!X509_set_serialNumber(x,bs)) goto end;\n\tif (X509_gmtime_adj(X509_get_notBefore(x),0L) == NULL)\n\t\tgoto end;\n\tif (X509_gmtime_adj(X509_get_notAfter(x),(long)60*60*24*days) == NULL)\n\t\tgoto end;\n\tupkey=X509_get_pubkey(x);\n\tif (!EVP_PKEY_missing_parameters(pkey) &&\n\t\t(EVP_PKEY_cmp_parameters(pkey,upkey) == 0))\n\t\t{\n\t\tEVP_PKEY_save_parameters(upkey,0);\n\t\tX509_set_pubkey(x,upkey);\n\t\t}\n\tEVP_PKEY_free(upkey);\n\tif(conf) {\n\t\tX509V3_CTX ctx2;\n\t\tX509_set_version(x,2);\n                X509V3_set_ctx(&ctx2, xca, x, NULL, NULL, 0);\n                X509V3_set_conf_lhash(&ctx2, conf);\n                if(!X509V3_EXT_add_conf(conf, &ctx2, section, x)) goto end;\n\t}\n\tif (!X509_sign(x,pkey,digest)) goto end;\n\tret=1;\nend:\n\tX509_STORE_CTX_cleanup(&xsc);\n\tif (!ret)\n\t\tERR_print_errors(bio_err);\n\tif (buf != NULL) Free(buf);\n\tif (bs != NULL) ASN1_INTEGER_free(bs);\n\tif (io != NULL)\tBIO_free(io);\n\tif (serial != NULL) BN_free(serial);\n\treturn(ret);\n\t}', 'int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)\n\t{\n\tX509_OBJECT *obj,*r;\n\tint ret=1;\n\tif (x == NULL) return(0);\n\tobj=(X509_OBJECT *)Malloc(sizeof(X509_OBJECT));\n\tif (obj == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,ERR_R_MALLOC_FAILURE);\n\t\treturn(0);\n\t\t}\n\tobj->type=X509_LU_X509;\n\tobj->data.x509=x;\n\tCRYPTO_w_lock(CRYPTO_LOCK_X509_STORE);\n\tX509_OBJECT_up_ref_count(obj);\n\tr=(X509_OBJECT *)lh_insert(ctx->certs,(char *)obj);\n\tif (r != NULL)\n\t\t{\n\t\tlh_delete(ctx->certs,(char *)obj);\n\t\tX509_OBJECT_free_contents(obj);\n\t\tFree(obj);\n\t\tlh_insert(ctx->certs,(char *)r);\n\t\tX509err(X509_F_X509_STORE_ADD_CERT,X509_R_CERT_ALREADY_IN_HASH_TABLE);\n\t\tret=0;\n\t\t}\n\tCRYPTO_w_unlock(CRYPTO_LOCK_X509_STORE);\n\treturn(ret);\n\t}', 'char *lh_insert(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\tif (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))\n\t\texpand(lh);\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tif ((nn=(LHASH_NODE *)Malloc(sizeof(LHASH_NODE))) == NULL)\n\t\t\t{\n\t\t\tlh->error++;\n\t\t\treturn(NULL);\n\t\t\t}\n\t\tnn->data=data;\n\t\tnn->next=NULL;\n#ifndef NO_HASH_COMP\n\t\tnn->hash=hash;\n#endif\n\t\t*rn=nn;\n\t\tret=NULL;\n\t\tlh->num_insert++;\n\t\tlh->num_items++;\n\t\t}\n\telse\n\t\t{\n\t\tret= (*rn)->data;\n\t\t(*rn)->data=data;\n\t\tlh->num_replace++;\n\t\t}\n\treturn(ret);\n\t}', 'char *lh_delete(LHASH *lh, char *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tchar *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tFree((char *)nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']