const char *CAfile, const char *cert, const char *key)
const char *CAfile, const char *cert, const char *key, const char *cipher_list, int out_state)
static SSL_CTX *initialise_ssl_ctx(int server_mode, const char *engine_id,		const char *CAfile, const char *cert, const char *key){	SSL_CTX *ctx, *ret = NULL;	SSL_METHOD *meth;	ENGINE *e = NULL;	FILE *fp = NULL;	X509 *x509 = NULL;	EVP_PKEY *pkey = NULL;        OpenSSL_add_ssl_algorithms();        SSL_load_error_strings();	meth = (server_mode ? SSLv23_server_method() : SSLv23_client_method());	if(meth == NULL)		goto err;	if(engine_id) {		if((e = ENGINE_by_id(engine_id)) == NULL) {			fprintf(stderr, "Error obtaining '%s' engine, openssl "					"errors follow\n", engine_id);			goto err;		}		if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {			fprintf(stderr, "Error assigning '%s' engine, openssl "					"errors follow\n", engine_id);			goto err;		}		ENGINE_free(e);	}	if((ctx = SSL_CTX_new(meth)) == NULL)		goto err;	/* cacert */	if(CAfile) {		if(!X509_STORE_load_locations(SSL_CTX_get_cert_store(ctx),					CAfile, NULL)) {			fprintf(stderr, "Error loading CA cert(s) in '%s'\n",					CAfile);			goto err;		}		fprintf(stderr, "Info, operating with CA cert(s) in '%s'\n",				CAfile);	} else		fprintf(stderr, "Info, operating without a CA cert(-list)\n");	if(!SSL_CTX_set_default_verify_paths(ctx)) {		fprintf(stderr, "Error setting default verify paths\n");		goto err;	}	/* cert */	if(cert) {		if((fp = fopen(cert, "r")) == NULL) {			fprintf(stderr, "Error opening cert file '%s'\n", cert);			goto err;		}		if(!PEM_read_X509(fp, &x509, NULL, NULL)) {			fprintf(stderr, "Error reading PEM cert from '%s'\n",					cert);			goto err;		}		if(!SSL_CTX_use_certificate(ctx, x509)) {			fprintf(stderr, "Error, cert in '%s' can not be used\n",					cert);			goto err;		}		fprintf(stderr, "Info, operating with cert in '%s'\n", cert);		fclose(fp);		fp = NULL;		/* If a cert was given without matching key, we assume the same		 * file contains the required key. */		if(!key)			key = cert;	} else		if(key) {			fprintf(stderr, "Error, can't specify a key without a "					"corresponding certificate\n");			goto err;		}	/* key */	if(key) {		if((fp = fopen(key, "r")) == NULL) {			fprintf(stderr, "Error opening key file '%s'\n", key);			goto err;		}		if(!PEM_read_PrivateKey(fp, &pkey, NULL, NULL)) {			fprintf(stderr, "Error reading PEM key from '%s'\n",					key);			goto err;		}		if(!SSL_CTX_use_PrivateKey(ctx, pkey)) {			fprintf(stderr, "Error, key in '%s' can not be used\n",					key);			goto err;		}		fprintf(stderr, "Info, operating with key in '%s'\n", key);	} else		fprintf(stderr, "Info, operating without a cert or key\n");	/* Success! */	ret = ctx;err:	if(!ret) {		ERR_print_errors_fp(stderr);		if(ctx)			SSL_CTX_free(ctx);	}	if(fp)		fclose(fp);	if(x509)		X509_free(x509);	if(pkey)		EVP_PKEY_free(pkey);	return ret;}