srand(time(NULL)); char buf[128]; for(int n = 0; n < 128; ++n) buf[n] = rand(); RAND_seed(buf, 128);
{ X509_STORE *store = SSL_CTX_get_cert_store(context); QList<Certificate> cert_list = trusted.certificates(); QList<CRL> crl_list = trusted.crls(); int n; for(n = 0; n < cert_list.count(); ++n) { const MyCertContext *cc = static_cast<const MyCertContext *>(cert_list[n].context()); X509 *x = cc->item.cert; CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509); X509_STORE_add_cert(store, x); } for(n = 0; n < crl_list.count(); ++n) { const MyCRLContext *cc = static_cast<const MyCRLContext *>(crl_list[n].context()); X509_CRL *x = cc->item.crl; CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509_CRL); X509_STORE_add_crl(store, x); } }  ssl = SSL_new(context); if(!ssl) { SSL_CTX_free(context); context = 0; return false; } SSL_set_ssl_method(ssl, method);   rbio = BIO_new(BIO_s_mem()); wbio = BIO_new(BIO_s_mem());   SSL_set_bio(ssl, rbio, wbio);   if(!cert.isNull() && !key.isNull()) { PrivateKey nkey = key;  const PKeyContext *tmp_kc = static_cast<const PKeyContext *>(nkey.context());  if(!tmp_kc->sameProvider(this)) { printf("experimental: private key supplied by a different provider\n");   EVP_PKEY *pkey; pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, createFromExisting(nkey.toRSA()));   MyPKeyContext *pk = new MyPKeyContext(provider()); PKeyBase *k = pk->pkeyToBase(pkey, true); pk->k = k; nkey.change(pk); }  const MyCertContext *cc = static_cast<const MyCertContext *>(cert.context()); const MyPKeyContext *kc = static_cast<const MyPKeyContext *>(nkey.context());  if(SSL_use_certificate(ssl, cc->item.cert) != 1) { SSL_free(ssl); SSL_CTX_free(context); return false; } if(SSL_use_PrivateKey(ssl, kc->get_pkey()) != 1) { SSL_free(ssl); SSL_CTX_free(context); return false; } }  return true;
	void init()	{		printf("init\n");		OpenSSL_add_all_algorithms();		ERR_load_crypto_strings();		srand(time(NULL));		char buf[128];		for(int n = 0; n < 128; ++n)			buf[n] = rand();		RAND_seed(buf, 128);	}