int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
		       STACK_OF(X509) *chain, int build_chain)
	{
	if (cert == NULL)
		return 1;
	if (SSL_CTX_use_certificate(ctx,cert) <= 0)
		{
		BIO_printf(bio_err,"error setting certificate\n");
		ERR_print_errors(bio_err);
		return 0;
		}

 	if (SSL_CTX_use_PrivateKey(ctx,key) <= 0)
 		{
 		BIO_printf(bio_err,"error setting private key\n");
 		ERR_print_errors(bio_err);
 		return 0;
 		}
		 
	/* Now we know that a key and cert have been set against
 	 * the SSL context */
	if (!SSL_CTX_check_private_key(ctx))
		{
		BIO_printf(bio_err,"Private key does not match the certificate public key\n");
		return 0;
		}
	if (chain && !SSL_CTX_set1_chain(ctx, chain))
		{
		BIO_printf(bio_err,"error setting certificate chain\n");
		ERR_print_errors(bio_err);
		return 0;
		}
	if (!chain && build_chain && !SSL_CTX_build_cert_chain(ctx, 0))
		{
		BIO_printf(bio_err,"error building certificate chain\n");
		ERR_print_errors(bio_err);
		return 0;
		}
		
	return 1;
	}
int set_cert_key_stuff(SSL_CTX *ctx, X509 *cert, EVP_PKEY *key,
		       STACK_OF(X509) *chain, int build_chain)
	{
	if (cert == NULL)
		return 1;
	if (SSL_CTX_use_certificate(ctx,cert) <= 0)
		{
		BIO_printf(bio_err,"error setting certificate\n");
		ERR_print_errors(bio_err);
		return 0;
		}

 	if (SSL_CTX_use_PrivateKey(ctx,key) <= 0)
 		{
 		BIO_printf(bio_err,"error setting private key\n");
 		ERR_print_errors(bio_err);
 		return 0;
 		}
		 
	 
	if (!SSL_CTX_check_private_key(ctx))
		{
		BIO_printf(bio_err,"Private key does not match the certificate public key\n");
		return 0;
		}
	if (chain && !SSL_CTX_set1_chain(ctx, chain))
		{
		BIO_printf(bio_err,"error setting certificate chain\n");
		ERR_print_errors(bio_err);
		return 0;
		}
	if (!chain && build_chain && !SSL_CTX_build_cert_chain(ctx, 0))
		{
		BIO_printf(bio_err,"error building certificate chain\n");
		ERR_print_errors(bio_err);
		return 0;
		}
		
	return 1;
	}