if (sk != NULL) sk_free(sk); if (x509 != NULL) X509_free(x509);
sk_free(sk); X509_free(x509); EVP_PKEY_free(pkey);
int ssl2_set_certificate(s, type, len, data)SSL *s;int type;int len;unsigned char *data;	{	STACK *sk=NULL;	EVP_PKEY *pkey=NULL;	CERT *c=NULL;	int i;	X509 *x509=NULL;	int ret=0;		x509=d2i_X509(NULL,&data,(long)len);	if (x509 == NULL)		{		SSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_X509_LIB);		goto err;		}	if (((sk=sk_new_null()) == NULL) ||		(!sk_push(sk,(char *)x509)))		{		SSLerr(SSL_F_SSL2_SET_CERTIFICATE,ERR_R_MALLOC_FAILURE);		goto err;		}	i=ssl_verify_cert_chain(s,sk);			if ((s->verify_mode != SSL_VERIFY_NONE) && (!i))		{		SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_CERTIFICATE_VERIFY_FAILED);		goto err;		}	/* cert for ssl */	c=ssl_cert_new();	if (c == NULL)		{		ret= -1;		goto err;		}	/* cert for session */	if (s->session->cert) ssl_cert_free(s->session->cert);	s->session->cert=c;/*	c->cert_type=type; */	c->pkeys[SSL_PKEY_RSA_ENC].x509=x509;	c->key= &(c->pkeys[SSL_PKEY_RSA_ENC]);	pkey=X509_get_pubkey(x509);	x509=NULL;	if (pkey == NULL)		{		SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY);		goto err;		}	if (pkey->type != EVP_PKEY_RSA)		{		SSLerr(SSL_F_SSL2_SET_CERTIFICATE,SSL_R_PUBLIC_KEY_NOT_RSA);		goto err;		}	if (!ssl_set_cert_type(c,SSL2_CT_X509_CERTIFICATE))		goto err;	ret=1;err:	if (sk != NULL) sk_free(sk);	if (x509 != NULL) X509_free(x509);	return(ret);	}