+ if (mycert && *mycert) {
+ char *scert = NULL, *spkey = NULL;
+ if ((ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) {
+ g_error("Could not allocate memory for SSL context");
+ return NULL;
+ }
+ scert = convert_home(mycert);
+ if (mypkey && *mypkey)
+ spkey = convert_home(mypkey);
+ if (! SSL_CTX_use_certificate_file(ctx, scert, SSL_FILETYPE_PEM))
+ g_warning("Loading of client certificate '%s' failed", mycert);
+ else if (! SSL_CTX_use_PrivateKey_file(ctx, spkey ? spkey : scert, SSL_FILETYPE_PEM))
+ g_warning("Loading of private key '%s' failed", mypkey ? mypkey : mycert);
+ else if (! SSL_CTX_check_private_key(ctx))
+ g_warning("Private key does not match the certificate");
+ g_free(scert);
+ g_free(spkey);
+ }
+
+ if ((cafile && *cafile) || (capath && *capath)) {
+ char *scafile = NULL;
+ char *scapath = NULL;
+ if (! ctx && (ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) {
+ g_error("Could not allocate memory for SSL context");
+ return NULL;
+ }
+ if (cafile && *cafile)
+ scafile = convert_home(cafile);
+ if (capath && *capath)
+ scapath = convert_home(capath);
+ if (! SSL_CTX_load_verify_locations(ctx, scafile, scapath)) {
+ g_warning("Could not load CA list for verifying SSL server certificate");
+ g_free(scafile);
+ g_free(scapath);
+ SSL_CTX_free(ctx);
+ return NULL;
+ }
+ g_free(scafile);
+ g_free(scapath);
+ verify = TRUE;
+ }
+
+ if (ctx == NULL)
+ ctx = ssl_ctx;
+
+ if(!(ssl = SSL_new(ctx)))