apps/pkcs12.c:315: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, +oo] by call to `X509_check_private_key`.
Showing all 23 steps of the trace


apps/pkcs12.c:307:6: Call
305.   
306.   	/* Load in all certs in input file */
307.   	if(!cert_load(in, certs)) {
            ^
308.   		BIO_printf(bio_err, "Error loading certificates from input\n");
309.   		ERR_print_errors(bio_err);

apps/pkcs12.c:632:16: Call
  630.   	X509 *cert;
  631.   	ret = 0;
  632.   	while((cert = PEM_read_bio_X509(in, NULL, NULL, NULL))) {
                        ^
  633.   		ret = 1;
  634.   		sk_X509_push(sk, cert);

crypto/pem/pem_all.c:68:1: Call
    66.   #include <openssl/pem.h>
    67.   
    68. > IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
    69.   
    70.   IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)

crypto/pem/pem_lib.c:221:9: Call
      219.   			int klen;
      220.   			char psbuf[PEM_BUFSIZE];
      221.   			p8 = d2i_X509_SIG((X509_SIG **)x, &p, len);
                     ^
      222.   			if(!p8) goto p8err;
      223.   			if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);

crypto/asn1/x_sig.c:79:1: Parameter `(*a)->algor->parameter->value.ptr->data`
        77.   	}
        78.   
        79. > X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length)
        80.   	{
        81.   	M_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new);

apps/pkcs12.c:315:6: Call
313.   	for(i = 0; i < sk_X509_num(certs); i++) {
314.   		ucert = sk_X509_value(certs, i);
315.   		if(X509_check_private_key(ucert, key)) {
            ^
316.   			X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
317.   			break;

crypto/x509/x509_cmp.c:246:1: Parameter `*x->cert_info->key->algor->parameter->value.sequence->data`
  244.   	}
  245.   
  246. > int X509_check_private_key(X509 *x, EVP_PKEY *k)
  247.   	{
  248.   	EVP_PKEY *xk=NULL;

crypto/x509/x509_cmp.c:251:5: Call
  249.   	int ok=0;
  250.   
  251.   	xk=X509_get_pubkey(x);
             ^
  252.   	if (xk->type != k->type)
  253.   	    {

crypto/x509/x509_cmp.c:239:1: Parameter `*x->cert_info->key->algor->parameter->value.sequence->data`
    237.   	}
    238.   
    239. > EVP_PKEY *X509_get_pubkey(X509 *x)
    240.   	{
    241.   	if ((x == NULL) || (x->cert_info == NULL))

crypto/x509/x509_cmp.c:243:9: Call
    241.   	if ((x == NULL) || (x->cert_info == NULL))
    242.   		return(NULL);
    243.   	return(X509_PUBKEY_get(x->cert_info->key));
                   ^
    244.   	}
    245.   

crypto/asn1/x_pubkey.c:201:1: Parameter `*key->algor->parameter->value.sequence->data`
      199.   	}
      200.   
      201. > EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
      202.   	{
      203.   	EVP_PKEY *ret=NULL;

crypto/asn1/x_pubkey.c:238:4: Assignment
      236.   			{
      237.   			ret->pkey.dsa->write_params=0;
      238.   			p=a->parameter->value.sequence->data;
                ^
      239.   			j=a->parameter->value.sequence->length;
      240.   			if (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))

crypto/asn1/x_pubkey.c:240:9: Call
      238.   			p=a->parameter->value.sequence->data;
      239.   			j=a->parameter->value.sequence->length;
      240.   			if (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))
                     ^
      241.   				goto err;
      242.   			}

crypto/asn1/d2i_dsap.c:71:1: Parameter `**pp`
        69.   #endif
        70.   
        71. > DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)
        72.   	{
        73.   	int i=ERR_R_NESTED_ASN1_ERROR;

crypto/asn1/d2i_dsap.c:77:2: Assignment
        75.   	M_ASN1_D2I_vars(a,DSA *,DSA_new);
        76.   
        77.   	M_ASN1_D2I_Init();
               ^
        78.   	M_ASN1_D2I_start_sequence();
        79.   	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);

crypto/asn1/d2i_dsap.c:78:2: Call
        76.   
        77.   	M_ASN1_D2I_Init();
        78.   	M_ASN1_D2I_start_sequence();
               ^
        79.   	M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);
        80.   	if ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;

crypto/asn1/asn1_lib.c:277:1: Parameter `*c->p`
          275.   	}
          276.   
          277. > int asn1_GetSequence(ASN1_CTX *c, long *length)
          278.   	{
          279.   	unsigned char *q;

crypto/asn1/asn1_lib.c:282:9: Call
          280.   
          281.   	q=c->p;
          282.   	c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
                         ^
          283.   		*length);
          284.   	if (c->inf & 0x80)

crypto/asn1/asn1_lib.c:83:1: <Length trace>
81.   
82.   
83. > int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
84.   	     long omax)
85.   	{

crypto/asn1/asn1_lib.c:83:1: Parameter `**pp`
            81.   
            82.   
            83. > int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
            84.   	     long omax)
            85.   	{

crypto/asn1/asn1_lib.c:88:2: Assignment
            86.   	int i,ret;
            87.   	long l;
            88.   	unsigned char *p= *pp;
                   ^
            89.   	int tag,xclass,inf;
            90.   	long max=omax;

crypto/asn1/asn1_lib.c:98:3: Assignment
            96.   	if (i == V_ASN1_PRIMITIVE_TAG)
            97.   		{		/* high-tag */
            98.   		p++;
                     ^
            99.   		if (--max == 0) goto err;
            100.   		l=0;

crypto/asn1/asn1_lib.c:101:10: Array access: Offset: [1, +oo] Size: [0, +oo] by call to `X509_check_private_key` 
            99.   		if (--max == 0) goto err;
            100.   		l=0;
            101.   		while (*p&0x80)
                            ^
            102.   			{
            103.   			l<<=7L;

int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
	     long omax)
	{
	int i,ret;
	long l;
	unsigned char *p= *pp;
	int tag,xclass,inf;
	long max=omax;
	if (!max) goto err;
	ret=(*p&V_ASN1_CONSTRUCTED);
	xclass=(*p&V_ASN1_PRIVATE);
	i= *p&V_ASN1_PRIMITIVE_TAG;
	if (i == V_ASN1_PRIMITIVE_TAG)
		{
		p++;
		if (--max == 0) goto err;
		l=0;
		while (*p&0x80)
			{
			l<<=7L;
			l|= *(p++)&0x7f;
			if (--max == 0) goto err;
			}
		l<<=7L;
		l|= *(p++)&0x7f;
		tag=(int)l;
		}
	else
		{
		tag=i;
		p++;
		if (--max == 0) goto err;
		}
	*ptag=tag;
	*pclass=xclass;
	if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;
#if 0
	fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d  (%d > %d)\n",
		(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),
		(int)(omax+ *pp));
#endif
#if 0
	if ((p+ *plength) > (omax+ *pp))
		{
		ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);
		ret|=0x80;
		}
#endif
	*pp=p;
	return(ret|inf);
err:
	ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);
	return(0x80);
	}
['int MAIN(int argc, char **argv)\n{\n    char *infile=NULL, *outfile=NULL, *keyname = NULL;\n    char *certfile=NULL;\n    BIO *in=NULL, *out = NULL, *inkey = NULL, *certsin = NULL;\n    char **args;\n    char *name = NULL;\n    PKCS12 *p12 = NULL;\n    char pass[50], macpass[50];\n    int export_cert = 0;\n    int options = 0;\n    int chain = 0;\n    int badarg = 0;\n    int iter = PKCS12_DEFAULT_ITER;\n    int maciter = 1;\n    int twopass = 0;\n    int keytype = 0;\n    int cert_pbe = NID_pbe_WithSHA1And40BitRC2_CBC;\n    int ret = 1;\n    int macver = 1;\n    int noprompt = 0;\n    STACK *canames = NULL;\n    char *cpass = NULL, *mpass = NULL;\n    apps_startup();\n    enc = EVP_des_ede3_cbc();\n    if (bio_err == NULL ) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);\n    args = argv + 1;\n    while (*args) {\n\tif (*args[0] == \'-\') {\n\t\tif (!strcmp (*args, "-nokeys")) options |= NOKEYS;\n\t\telse if (!strcmp (*args, "-keyex")) keytype = KEY_EX;\n\t\telse if (!strcmp (*args, "-keysig")) keytype = KEY_SIG;\n\t\telse if (!strcmp (*args, "-nocerts")) options |= NOCERTS;\n\t\telse if (!strcmp (*args, "-clcerts")) options |= CLCERTS;\n\t\telse if (!strcmp (*args, "-cacerts")) options |= CACERTS;\n\t\telse if (!strcmp (*args, "-noout")) options |= (NOKEYS|NOCERTS);\n\t\telse if (!strcmp (*args, "-info")) options |= INFO;\n\t\telse if (!strcmp (*args, "-chain")) chain = 1;\n\t\telse if (!strcmp (*args, "-twopass")) twopass = 1;\n\t\telse if (!strcmp (*args, "-nomacver")) macver = 0;\n\t\telse if (!strcmp (*args, "-descert"))\n    \t\t\tcert_pbe = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;\n\t\telse if (!strcmp (*args, "-export")) export_cert = 1;\n\t\telse if (!strcmp (*args, "-des")) enc=EVP_des_cbc();\n#ifndef NO_IDEA\n\t\telse if (!strcmp (*args, "-idea")) enc=EVP_idea_cbc();\n#endif\n\t\telse if (!strcmp (*args, "-des3")) enc = EVP_des_ede3_cbc();\n\t\telse if (!strcmp (*args, "-noiter")) iter = 1;\n\t\telse if (!strcmp (*args, "-maciter"))\n\t\t\t\t\t maciter = PKCS12_DEFAULT_ITER;\n\t\telse if (!strcmp (*args, "-nodes")) enc=NULL;\n\t\telse if (!strcmp (*args, "-inkey")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tkeyname = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-certfile")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tcertfile = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-name")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tname = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-caname")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tif (!canames) canames = sk_new(NULL);\n\t\t\tsk_push(canames, *args);\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-in")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tinfile = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-out")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\toutfile = *args;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-envpass")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tif(!(cpass = getenv(*args))) {\n\t\t\t\tBIO_printf(bio_err,\n\t\t\t\t "Can\'t read environment variable %s\\n", *args);\n\t\t\t\tgoto end;\n\t\t\t}\n\t\t\tnoprompt = 1;\n\t\t    } else badarg = 1;\n\t\t} else if (!strcmp (*args, "-password")) {\n\t\t    if (args[1]) {\n\t\t\targs++;\n\t\t\tcpass = *args;\n\t\t    \tnoprompt = 1;\n\t\t    } else badarg = 1;\n\t\t} else badarg = 1;\n\t} else badarg = 1;\n\targs++;\n    }\n    if (badarg) {\n\tBIO_printf (bio_err, "Usage: pkcs12 [options]\\n");\n\tBIO_printf (bio_err, "where options are\\n");\n\tBIO_printf (bio_err, "-export       output PKCS12 file\\n");\n\tBIO_printf (bio_err, "-chain        add certificate chain\\n");\n\tBIO_printf (bio_err, "-inkey file   private key if not infile\\n");\n\tBIO_printf (bio_err, "-certfile f   add all certs in f\\n");\n\tBIO_printf (bio_err, "-name \\"name\\"  use name as friendly name\\n");\n\tBIO_printf (bio_err, "-caname \\"nm\\"  use nm as CA friendly name (can be used more than once).\\n");\n\tBIO_printf (bio_err, "-in  infile   input filename\\n");\n\tBIO_printf (bio_err, "-out outfile  output filename\\n");\n\tBIO_printf (bio_err, "-noout        don\'t output anything, just verify.\\n");\n\tBIO_printf (bio_err, "-nomacver     don\'t verify MAC.\\n");\n\tBIO_printf (bio_err, "-nocerts      don\'t output certificates.\\n");\n\tBIO_printf (bio_err, "-clcerts      only output client certificates.\\n");\n\tBIO_printf (bio_err, "-cacerts      only output CA certificates.\\n");\n\tBIO_printf (bio_err, "-nokeys       don\'t output private keys.\\n");\n\tBIO_printf (bio_err, "-info         give info about PKCS#12 structure.\\n");\n\tBIO_printf (bio_err, "-des          encrypt private keys with DES\\n");\n\tBIO_printf (bio_err, "-des3         encrypt private keys with triple DES (default)\\n");\n#ifndef NO_IDEA\n\tBIO_printf (bio_err, "-idea         encrypt private keys with idea\\n");\n#endif\n\tBIO_printf (bio_err, "-nodes        don\'t encrypt private keys\\n");\n\tBIO_printf (bio_err, "-noiter       don\'t use encryption iteration\\n");\n\tBIO_printf (bio_err, "-maciter      use MAC iteration\\n");\n\tBIO_printf (bio_err, "-twopass      separate MAC, encryption passwords\\n");\n\tBIO_printf (bio_err, "-descert      encrypt PKCS#12 certificates with triple DES (default RC2-40)\\n");\n\tBIO_printf (bio_err, "-keyex        set MS key exchange type\\n");\n\tBIO_printf (bio_err, "-keysig       set MS key signature type\\n");\n\tBIO_printf (bio_err, "-password p   set import/export password (NOT RECOMMENDED)\\n");\n\tBIO_printf (bio_err, "-envpass p    set import/export password from environment\\n");\n    \tgoto end;\n    }\n    if(cpass) mpass = cpass;\n    else {\n\tcpass = pass;\n\tmpass = macpass;\n    }\n    ERR_load_crypto_strings();\n    if (!infile) in = BIO_new_fp(stdin, BIO_NOCLOSE);\n    else in = BIO_new_file(infile, "rb");\n    if (!in) {\n\t    BIO_printf(bio_err, "Error opening input file %s\\n",\n\t\t\t\t\t\tinfile ? infile : "<stdin>");\n\t    perror (infile);\n\t    goto end;\n   }\n   if (certfile) {\n    \tif(!(certsin = BIO_new_file(certfile, "r"))) {\n\t    BIO_printf(bio_err, "Can\'t open certificate file %s\\n", certfile);\n\t    perror (certfile);\n\t    goto end;\n\t}\n    }\n    if (keyname) {\n    \tif(!(inkey = BIO_new_file(keyname, "r"))) {\n\t    BIO_printf(bio_err, "Can\'t key certificate file %s\\n", keyname);\n\t    perror (keyname);\n\t    goto end;\n\t}\n     }\n    if (!outfile) out = BIO_new_fp(stdout, BIO_NOCLOSE);\n    else out = BIO_new_file(outfile, "wb");\n    if (!out) {\n\tBIO_printf(bio_err, "Error opening output file %s\\n",\n\t\t\t\t\t\toutfile ? outfile : "<stdout>");\n\tperror (outfile);\n\tgoto end;\n    }\n    if (twopass) {\n\tif(EVP_read_pw_string (macpass, 50, "Enter MAC Password:", export_cert))\n\t{\n    \t    BIO_printf (bio_err, "Can\'t read Password\\n");\n    \t    goto end;\n       \t}\n    }\nif (export_cert) {\n\tEVP_PKEY *key;\n\tSTACK *bags, *safes;\n\tPKCS12_SAFEBAG *bag;\n\tPKCS8_PRIV_KEY_INFO *p8;\n\tPKCS7 *authsafe;\n\tX509 *cert = NULL, *ucert = NULL;\n\tSTACK_OF(X509) *certs;\n\tchar *catmp;\n\tint i;\n\tunsigned char keyid[EVP_MAX_MD_SIZE];\n\tunsigned int keyidlen = 0;\n\tkey = PEM_read_bio_PrivateKey(inkey ? inkey : in, NULL, NULL, NULL);\n\tif (!inkey) (void) BIO_reset(in);\n\tif (!key) {\n\t\tBIO_printf (bio_err, "Error loading private key\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tcerts = sk_X509_new(NULL);\n\tif(!cert_load(in, certs)) {\n\t\tBIO_printf(bio_err, "Error loading certificates from input\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t}\n\tfor(i = 0; i < sk_X509_num(certs); i++) {\n\t\tucert = sk_X509_value(certs, i);\n\t\tif(X509_check_private_key(ucert, key)) {\n\t\t\tX509_digest(cert, EVP_sha1(), keyid, &keyidlen);\n\t\t\tbreak;\n\t\t}\n\t}\n\tif(!keyidlen) {\n\t\tBIO_printf(bio_err, "No certificate matches private key\\n");\n\t\tgoto end;\n\t}\n\tbags = sk_new (NULL);\n\tif (certsin) {\n\t\tif(!cert_load(certsin, certs)) {\n\t\t\tBIO_printf(bio_err, "Error loading certificates from certfile\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t}\n\t    \tBIO_free(certsin);\n \t}\n\tif (chain) {\n        \tint vret;\n\t\tSTACK_OF(X509) *chain2;\n\t\tvret = get_cert_chain (ucert, &chain2);\n\t\tif (vret) {\n\t\t\tBIO_printf (bio_err, "Error %s getting chain.\\n",\n\t\t\t\t\tX509_verify_cert_error_string(vret));\n\t\t\tgoto end;\n\t\t}\n\t\tfor (i = 1; i < sk_X509_num (chain2) ; i++)\n\t\t\t\t sk_X509_push(certs, sk_X509_value (chain2, i));\n\t\tsk_X509_free(chain2);\n    \t}\n\tfor(i = 0; i < sk_X509_num(certs); i++) {\n\t\tcert = sk_X509_value(certs, i);\n\t\tbag = M_PKCS12_x5092certbag(cert);\n\t\tif(cert == ucert) {\n\t\t\tif(name) PKCS12_add_friendlyname(bag, name, -1);\n\t\t\tPKCS12_add_localkeyid(bag, keyid, keyidlen);\n\t\t} else if((catmp = sk_shift(canames)))\n\t\t\t\tPKCS12_add_friendlyname(bag, catmp, -1);\n\t\tsk_push(bags, (char *)bag);\n\t}\n\tif (canames) sk_free(canames);\n\tif(!noprompt &&\n\t\tEVP_read_pw_string(pass, 50, "Enter Export Password:", 1)) {\n\t    BIO_printf (bio_err, "Can\'t read Password\\n");\n\t    goto end;\n        }\n\tif (!twopass) strcpy(macpass, pass);\n\tauthsafe = PKCS12_pack_p7encdata(cert_pbe, cpass, -1, NULL, 0,\n\t\t\t\t\t\t\t\t iter, bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tif (!authsafe) {\n\t\tERR_print_errors (bio_err);\n\t\tgoto end;\n\t}\n\tsafes = sk_new (NULL);\n\tsk_push (safes, (char *)authsafe);\n\tp8 = EVP_PKEY2PKCS8 (key);\n\tEVP_PKEY_free(key);\n\tif(keytype) PKCS8_add_keyusage(p8, keytype);\n\tbag = PKCS12_MAKE_SHKEYBAG(NID_pbe_WithSHA1And3_Key_TripleDES_CBC,\n\t\t\tcpass, -1, NULL, 0, iter, p8);\n\tPKCS8_PRIV_KEY_INFO_free(p8);\n        if (name) PKCS12_add_friendlyname (bag, name, -1);\n\tPKCS12_add_localkeyid (bag, keyid, keyidlen);\n\tbags = sk_new(NULL);\n\tsk_push (bags, (char *)bag);\n\tauthsafe = PKCS12_pack_p7data (bags);\n\tsk_pop_free(bags, PKCS12_SAFEBAG_free);\n\tsk_push (safes, (char *)authsafe);\n\tp12 = PKCS12_init (NID_pkcs7_data);\n\tM_PKCS12_pack_authsafes (p12, safes);\n\tsk_pop_free(safes, PKCS7_free);\n\tPKCS12_set_mac (p12, mpass, -1, NULL, 0, maciter, NULL);\n\ti2d_PKCS12_bio (out, p12);\n\tPKCS12_free(p12);\n\tret = 0;\n\tgoto end;\n    }\n    if (!(p12 = d2i_PKCS12_bio (in, NULL))) {\n\tERR_print_errors(bio_err);\n\tgoto end;\n    }\n    if(!noprompt && EVP_read_pw_string(pass, 50, "Enter Import Password:", 0)) {\n\tBIO_printf (bio_err, "Can\'t read Password\\n");\n\tgoto end;\n    }\n    if (!twopass) strcpy(macpass, pass);\n    if (options & INFO) BIO_printf (bio_err, "MAC Iteration %ld\\n", p12->mac->iter ? ASN1_INTEGER_get (p12->mac->iter) : 1);\n    if(macver) {\n\tif (!PKCS12_verify_mac (p12, mpass, -1)) {\n\t    BIO_printf (bio_err, "Mac verify errror: invalid password?\\n");\n\t    ERR_print_errors (bio_err);\n\t    goto end;\n\t} else BIO_printf (bio_err, "MAC verified OK\\n");\n    }\n    if (!dump_certs_keys_p12 (out, p12, cpass, -1, options)) {\n\tBIO_printf(bio_err, "Error outputting keys and certificates\\n");\n\tERR_print_errors (bio_err);\n\tgoto end;\n    }\n    PKCS12_free(p12);\n    ret = 0;\n    end:\n    BIO_free(out);\n    EXIT(ret);\n}', 'int cert_load(BIO *in, STACK_OF(X509) *sk)\n{\n\tint ret;\n\tX509 *cert;\n\tret = 0;\n\twhile((cert = PEM_read_bio_X509(in, NULL, NULL, NULL))) {\n\t\tret = 1;\n\t\tsk_X509_push(sk, cert);\n\t}\n\tif(ret) ERR_clear_error();\n\treturn ret;\n}', 'IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)', 'char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,\n\t     pem_password_cb *cb, void *u)\n\t{\n\tEVP_CIPHER_INFO cipher;\n\tchar *nm=NULL,*header=NULL;\n\tunsigned char *p=NULL,*data=NULL;\n\tlong len;\n\tchar *ret=NULL;\n\tfor (;;)\n\t\t{\n\t\tif (!PEM_read_bio(bp,&nm,&header,&data,&len)) return(NULL);\n\t\tif (\t(strcmp(nm,name) == 0) ||\n\t\t\t((strcmp(nm,PEM_STRING_RSA) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_DSA) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_PKCS8) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_PKCS8INF) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_EVP_PKEY) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_X509_OLD) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_X509) == 0)) ||\n\t\t\t((strcmp(nm,PEM_STRING_X509_REQ_OLD) == 0) &&\n\t\t\t (strcmp(name,PEM_STRING_X509_REQ) == 0))\n\t\t\t)\n\t\t\tbreak;\n\t\tFree(nm);\n\t\tFree(header);\n\t\tFree(data);\n\t\t}\n\tif (!PEM_get_EVP_CIPHER_INFO(header,&cipher)) goto err;\n\tif (!PEM_do_header(&cipher,data,&len,cb,u)) goto err;\n\tp=data;\n\tif (strcmp(name,PEM_STRING_EVP_PKEY) == 0) {\n\t\tif (strcmp(nm,PEM_STRING_RSA) == 0)\n\t\t\tret=d2i(EVP_PKEY_RSA,x,&p,len);\n\t\telse if (strcmp(nm,PEM_STRING_DSA) == 0)\n\t\t\tret=d2i(EVP_PKEY_DSA,x,&p,len);\n\t\telse if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {\n\t\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\t\tp8inf=d2i_PKCS8_PRIV_KEY_INFO(\n\t\t\t\t\t(PKCS8_PRIV_KEY_INFO **) x, &p, len);\n\t\t\tret = (char *)EVP_PKCS82PKEY(p8inf);\n\t\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t\t} else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {\n\t\t\tPKCS8_PRIV_KEY_INFO *p8inf;\n\t\t\tX509_SIG *p8;\n\t\t\tint klen;\n\t\t\tchar psbuf[PEM_BUFSIZE];\n\t\t\tp8 = d2i_X509_SIG((X509_SIG **)x, &p, len);\n\t\t\tif(!p8) goto p8err;\n\t\t\tif (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);\n\t\t\telse klen=def_callback(psbuf,PEM_BUFSIZE,0,u);\n\t\t\tif (klen <= 0) {\n\t\t\t\tPEMerr(PEM_F_PEM_ASN1_READ_BIO,\n\t\t\t\t\t\tPEM_R_BAD_PASSWORD_READ);\n\t\t\t\tgoto err;\n\t\t\t}\n\t\t\tp8inf = M_PKCS8_decrypt(p8, psbuf, klen);\n\t\t\tX509_SIG_free(p8);\n\t\t\tif(!p8inf) goto p8err;\n\t\t\tret = (char *)EVP_PKCS82PKEY(p8inf);\n\t\t\tPKCS8_PRIV_KEY_INFO_free(p8inf);\n\t\t}\n\t} else\tret=d2i(x,&p,len);\np8err:\n\tif (ret == NULL)\n\t\tPEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);\nerr:\n\tFree(nm);\n\tFree(header);\n\tFree(data);\n\treturn(ret);\n\t}', 'X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length)\n\t{\n\tM_ASN1_D2I_vars(a,X509_SIG *,X509_SIG_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(ret->algor,d2i_X509_ALGOR);\n\tM_ASN1_D2I_get(ret->digest,d2i_ASN1_OCTET_STRING);\n\tM_ASN1_D2I_Finish(a,X509_SIG_free,ASN1_F_D2I_X509_SIG);\n\t}', 'int X509_check_private_key(X509 *x, EVP_PKEY *k)\n\t{\n\tEVP_PKEY *xk=NULL;\n\tint ok=0;\n\txk=X509_get_pubkey(x);\n\tif (xk->type != k->type)\n\t    {\n\t    X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);\n\t    goto err;\n\t    }\n\tswitch (k->type)\n\t\t{\n#ifndef NO_RSA\n\tcase EVP_PKEY_RSA:\n\t\tif (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0\n\t\t    || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)\n\t\t    {\n\t\t    X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t    goto err;\n\t\t    }\n\t\tbreak;\n#endif\n#ifndef NO_DSA\n\tcase EVP_PKEY_DSA:\n\t\tif (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)\n\t\t    {\n\t\t    X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);\n\t\t    goto err;\n\t\t    }\n\t\tbreak;\n#endif\n#ifndef NO_DH\n\tcase EVP_PKEY_DH:\n\t        X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);\n\t\tgoto err;\n#endif\n\tdefault:\n\t        X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);\n\t\tgoto err;\n\t\t}\n\tok=1;\nerr:\n\tEVP_PKEY_free(xk);\n\treturn(ok);\n\t}', 'EVP_PKEY *X509_get_pubkey(X509 *x)\n\t{\n\tif ((x == NULL) || (x->cert_info == NULL))\n\t\treturn(NULL);\n\treturn(X509_PUBKEY_get(x->cert_info->key));\n\t}', 'EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)\n\t{\n\tEVP_PKEY *ret=NULL;\n\tlong j;\n\tint type;\n\tunsigned char *p;\n#ifndef NO_DSA\n\tX509_ALGOR *a;\n#endif\n\tif (key == NULL) goto err;\n\tif (key->pkey != NULL)\n\t    {\n\t    CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);\n\t    return(key->pkey);\n\t    }\n\tif (key->public_key == NULL) goto err;\n\ttype=OBJ_obj2nid(key->algor->algorithm);\n\tp=key->public_key->data;\n        j=key->public_key->length;\n        if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)\n\t\t{\n\t\tX509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);\n\t\tgoto err;\n\t\t}\n\tret->save_parameters=0;\n#ifndef NO_DSA\n\ta=key->algor;\n\tif (ret->type == EVP_PKEY_DSA)\n\t\t{\n\t\tif (a->parameter->type == V_ASN1_SEQUENCE)\n\t\t\t{\n\t\t\tret->pkey.dsa->write_params=0;\n\t\t\tp=a->parameter->value.sequence->data;\n\t\t\tj=a->parameter->value.sequence->length;\n\t\t\tif (!d2i_DSAparams(&ret->pkey.dsa,&p,(long)j))\n\t\t\t\tgoto err;\n\t\t\t}\n\t\tret->save_parameters=1;\n\t\t}\n#endif\n\tkey->pkey=ret;\n\tCRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);\n\treturn(ret);\nerr:\n\tif (ret != NULL)\n\t\tEVP_PKEY_free(ret);\n\treturn(NULL);\n\t}', 'DSA *d2i_DSAparams(DSA **a, unsigned char **pp, long length)\n\t{\n\tint i=ERR_R_NESTED_ASN1_ERROR;\n\tASN1_INTEGER *bs=NULL;\n\tM_ASN1_D2I_vars(a,DSA *,DSA_new);\n\tM_ASN1_D2I_Init();\n\tM_ASN1_D2I_start_sequence();\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->p=BN_bin2bn(bs->data,bs->length,ret->p)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->q=BN_bin2bn(bs->data,bs->length,ret->q)) == NULL) goto err_bn;\n\tM_ASN1_D2I_get(bs,d2i_ASN1_INTEGER);\n\tif ((ret->g=BN_bin2bn(bs->data,bs->length,ret->g)) == NULL) goto err_bn;\n\tASN1_BIT_STRING_free(bs);\n\tM_ASN1_D2I_Finish_2(a);\nerr_bn:\n\ti=ERR_R_BN_LIB;\nerr:\n\tASN1err(ASN1_F_D2I_DSAPARAMS,i);\n\tif ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_free(ret);\n\tif (bs != NULL) ASN1_BIT_STRING_free(bs);\n\treturn(NULL);\n\t}', 'int asn1_GetSequence(ASN1_CTX *c, long *length)\n\t{\n\tunsigned char *q;\n\tq=c->p;\n\tc->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),\n\t\t*length);\n\tif (c->inf & 0x80)\n\t\t{\n\t\tc->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL;\n\t\treturn(0);\n\t\t}\n\tif (c->tag != V_ASN1_SEQUENCE)\n\t\t{\n\t\tc->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE;\n\t\treturn(0);\n\t\t}\n\t(*length)-=(c->p-q);\n\tif (c->max && (*length < 0))\n\t\t{\n\t\tc->error=ERR_R_ASN1_LENGTH_MISMATCH;\n\t\treturn(0);\n\t\t}\n\tif (c->inf == (1|V_ASN1_CONSTRUCTED))\n\t\tc->slen= *length+ *(c->pp)-c->p;\n\tc->eos=0;\n\treturn(1);\n\t}', 'int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,\n\t     long omax)\n\t{\n\tint i,ret;\n\tlong l;\n\tunsigned char *p= *pp;\n\tint tag,xclass,inf;\n\tlong max=omax;\n\tif (!max) goto err;\n\tret=(*p&V_ASN1_CONSTRUCTED);\n\txclass=(*p&V_ASN1_PRIVATE);\n\ti= *p&V_ASN1_PRIMITIVE_TAG;\n\tif (i == V_ASN1_PRIMITIVE_TAG)\n\t\t{\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\tl=0;\n\t\twhile (*p&0x80)\n\t\t\t{\n\t\t\tl<<=7L;\n\t\t\tl|= *(p++)&0x7f;\n\t\t\tif (--max == 0) goto err;\n\t\t\t}\n\t\tl<<=7L;\n\t\tl|= *(p++)&0x7f;\n\t\ttag=(int)l;\n\t\t}\n\telse\n\t\t{\n\t\ttag=i;\n\t\tp++;\n\t\tif (--max == 0) goto err;\n\t\t}\n\t*ptag=tag;\n\t*pclass=xclass;\n\tif (!asn1_get_length(&p,&inf,plength,(int)max)) goto err;\n#if 0\n\tfprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d  (%d > %d)\\n",\n\t\t(int)p,*plength,omax,(int)*pp,(int)(p+ *plength),\n\t\t(int)(omax+ *pp));\n#endif\n#if 0\n\tif ((p+ *plength) > (omax+ *pp))\n\t\t{\n\t\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG);\n\t\tret|=0x80;\n\t\t}\n#endif\n\t*pp=p;\n\treturn(ret|inf);\nerr:\n\tASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG);\n\treturn(0x80);\n\t}']