2 * Licensed to UCAID under one or more contributor license agreements.
3 * See the NOTICE file distributed with this work for additional information
4 * regarding copyright ownership. The ASF licenses this file to you under
5 * the Apache License, Version 2.0 (the "License"); you may not use this
6 * file except in compliance with the License. You may obtain a copy of the
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * CURLSOAPTransport.cpp
21 * libcurl-based SOAPTransport implementation.
25 #include "exceptions.h"
27 #include "security/CredentialCriteria.h"
28 #include "security/OpenSSLTrustEngine.h"
29 #include "security/OpenSSLCredential.h"
30 #include "soap/HTTPSOAPTransport.h"
31 #include "soap/OpenSSLSOAPTransport.h"
33 #include "util/Threads.h"
36 #include <curl/curl.h>
37 #include <openssl/x509_vfy.h>
39 using namespace xmltooling::logging;
40 using namespace xmltooling;
43 namespace xmltooling {
45 // Manages cache of socket connections via CURL handles.
46 class XMLTOOL_DLLLOCAL CURLPool
49 CURLPool() : m_size(0), m_lock(Mutex::create()),
50 m_log(Category::getInstance(XMLTOOLING_LOGCAT".SOAPTransport.CURL")) {}
53 CURL* get(const SOAPTransport::Address& addr);
54 void put(const char* from, const char* to, const char* endpoint, CURL* handle);
57 typedef map<string,vector<CURL*> > poolmap_t;
58 poolmap_t m_bindingMap;
59 list< vector<CURL*>* > m_pools;
65 static XMLTOOL_DLLLOCAL CURLPool* g_CURLPool = nullptr;
67 class XMLTOOL_DLLLOCAL CURLSOAPTransport : public HTTPSOAPTransport, public OpenSSLSOAPTransport
70 CURLSOAPTransport(const Address& addr)
71 : m_sender(addr.m_from ? addr.m_from : ""), m_peerName(addr.m_to ? addr.m_to : ""), m_endpoint(addr.m_endpoint),
72 m_handle(nullptr), m_headers(nullptr),
73 #ifndef XMLTOOLING_NO_XMLSEC
74 m_cred(nullptr), m_trustEngine(nullptr), m_peerResolver(nullptr), m_mandatory(false),
76 m_openssl_ops(SSL_OP_ALL|SSL_OP_NO_SSLv2), m_ssl_callback(nullptr), m_ssl_userptr(nullptr),
77 m_chunked(true), m_authenticated(false), m_cacheTag(nullptr) {
78 m_handle = g_CURLPool->get(addr);
79 curl_easy_setopt(m_handle,CURLOPT_URL,addr.m_endpoint);
80 curl_easy_setopt(m_handle,CURLOPT_CONNECTTIMEOUT,15);
81 curl_easy_setopt(m_handle,CURLOPT_TIMEOUT,30);
82 curl_easy_setopt(m_handle,CURLOPT_HTTPAUTH,0);
83 curl_easy_setopt(m_handle,CURLOPT_USERPWD,nullptr);
84 curl_easy_setopt(m_handle,CURLOPT_SSL_VERIFYHOST,2);
85 curl_easy_setopt(m_handle,CURLOPT_HEADERDATA,this);
86 m_headers=curl_slist_append(m_headers,"Content-Type: text/xml");
89 virtual ~CURLSOAPTransport() {
90 curl_slist_free_all(m_headers);
91 curl_easy_setopt(m_handle, CURLOPT_USERAGENT, nullptr);
92 curl_easy_setopt(m_handle, CURLOPT_ERRORBUFFER, nullptr);
93 curl_easy_setopt(m_handle, CURLOPT_PRIVATE, m_authenticated ? "secure" : nullptr); // Save off security "state".
94 g_CURLPool->put(m_sender.c_str(), m_peerName.c_str(), m_endpoint.c_str(), m_handle);
97 bool isConfidential() const {
98 return m_endpoint.find("https")==0;
101 bool setConnectTimeout(long timeout) {
102 return (curl_easy_setopt(m_handle,CURLOPT_CONNECTTIMEOUT,timeout)==CURLE_OK);
105 bool setTimeout(long timeout) {
106 return (curl_easy_setopt(m_handle,CURLOPT_TIMEOUT,timeout)==CURLE_OK);
109 bool setAuth(transport_auth_t authType, const char* username=nullptr, const char* password=nullptr);
111 bool setVerifyHost(bool verify) {
112 return (curl_easy_setopt(m_handle,CURLOPT_SSL_VERIFYHOST,verify ? 2 : 0)==CURLE_OK);
115 #ifndef XMLTOOLING_NO_XMLSEC
116 bool setCredential(const Credential* cred=nullptr) {
117 const OpenSSLCredential* down = dynamic_cast<const OpenSSLCredential*>(cred);
120 return (cred==nullptr);
127 const X509TrustEngine* trustEngine=nullptr,
128 const CredentialResolver* peerResolver=nullptr,
129 CredentialCriteria* criteria=nullptr,
132 const OpenSSLTrustEngine* down = dynamic_cast<const OpenSSLTrustEngine*>(trustEngine);
134 m_trustEngine = nullptr;
135 m_peerResolver = nullptr;
136 m_criteria = nullptr;
137 return (trustEngine==nullptr);
139 m_trustEngine = down;
140 m_peerResolver = peerResolver;
141 m_criteria = criteria;
142 m_mandatory = mandatory;
148 bool useChunkedEncoding(bool chunked=true) {
153 bool followRedirects(bool follow, unsigned int maxRedirs) {
155 curl_easy_setopt(m_handle, CURLOPT_FOLLOWLOCATION, (follow ? 1 : 0)) == CURLE_OK &&
156 curl_easy_setopt(m_handle, CURLOPT_MAXREDIRS, (follow ? maxRedirs : 0)) == CURLE_OK
160 bool setCacheTag(string* cacheTag) {
161 m_cacheTag = cacheTag;
165 bool setProviderOption(const char* provider, const char* option, const char* value);
167 void send(istream& in) {
171 void send(istream* in=nullptr);
177 bool isAuthenticated() const {
178 return m_authenticated;
181 void setAuthenticated(bool auth) {
182 m_authenticated = auth;
185 string getContentType() const;
186 long getStatusCode() const;
188 bool setRequestHeader(const char* name, const char* val) {
190 temp=temp + ": " + val;
191 m_headers=curl_slist_append(m_headers,temp.c_str());
195 const vector<string>& getResponseHeader(const char* val) const;
197 bool setSSLCallback(ssl_ctx_callback_fn fn, void* userptr=nullptr) {
199 m_ssl_userptr=userptr;
205 string m_sender,m_peerName,m_endpoint,m_simplecreds;
207 stringstream m_stream;
208 struct curl_slist* m_headers;
210 map<string,vector<string> > m_response_headers;
211 vector<string> m_saved_options;
212 #ifndef XMLTOOLING_NO_XMLSEC
213 const OpenSSLCredential* m_cred;
214 const OpenSSLTrustEngine* m_trustEngine;
215 const CredentialResolver* m_peerResolver;
216 CredentialCriteria* m_criteria;
220 ssl_ctx_callback_fn m_ssl_callback;
223 bool m_authenticated;
226 friend size_t XMLTOOL_DLLLOCAL curl_header_hook(void* ptr, size_t size, size_t nmemb, void* stream);
227 friend CURLcode XMLTOOL_DLLLOCAL xml_ssl_ctx_callback(CURL* curl, SSL_CTX* ssl_ctx, void* userptr);
228 friend int XMLTOOL_DLLLOCAL verify_callback(X509_STORE_CTX* x509_ctx, void* arg);
231 // libcurl callback functions
232 size_t XMLTOOL_DLLLOCAL curl_header_hook(void* ptr, size_t size, size_t nmemb, void* stream);
233 size_t XMLTOOL_DLLLOCAL curl_write_hook(void* ptr, size_t size, size_t nmemb, void* stream);
234 size_t XMLTOOL_DLLLOCAL curl_read_hook( void *ptr, size_t size, size_t nmemb, void *stream);
235 int XMLTOOL_DLLLOCAL curl_debug_hook(CURL* handle, curl_infotype type, char* data, size_t len, void* ptr);
236 CURLcode XMLTOOL_DLLLOCAL xml_ssl_ctx_callback(CURL* curl, SSL_CTX* ssl_ctx, void* userptr);
237 #ifndef XMLTOOLING_NO_XMLSEC
238 int XMLTOOL_DLLLOCAL verify_callback(X509_STORE_CTX* x509_ctx, void* arg);
241 SOAPTransport* CURLSOAPTransportFactory(const SOAPTransport::Address& addr)
243 return new CURLSOAPTransport(addr);
247 void xmltooling::registerSOAPTransports()
249 XMLToolingConfig& conf=XMLToolingConfig::getConfig();
250 conf.SOAPTransportManager.registerFactory("http", CURLSOAPTransportFactory);
251 conf.SOAPTransportManager.registerFactory("https", CURLSOAPTransportFactory);
254 void xmltooling::initSOAPTransports()
256 g_CURLPool=new CURLPool();
259 void xmltooling::termSOAPTransports()
262 g_CURLPool = nullptr;
265 OpenSSLSOAPTransport::OpenSSLSOAPTransport()
269 OpenSSLSOAPTransport::~OpenSSLSOAPTransport()
273 CURLPool::~CURLPool()
275 for (poolmap_t::iterator i=m_bindingMap.begin(); i!=m_bindingMap.end(); i++) {
276 for (vector<CURL*>::iterator j=i->second.begin(); j!=i->second.end(); j++)
277 curl_easy_cleanup(*j);
282 CURL* CURLPool::get(const SOAPTransport::Address& addr)
285 xmltooling::NDC("get");
287 m_log.debug("getting connection handle to %s", addr.m_endpoint);
288 string key(addr.m_endpoint);
290 key = key + '|' + addr.m_from;
292 key = key + '|' + addr.m_to;
294 poolmap_t::iterator i=m_bindingMap.find(key);
296 if (i!=m_bindingMap.end()) {
297 // Move this pool to the front of the list.
298 m_pools.remove(&(i->second));
299 m_pools.push_front(&(i->second));
301 // If a free connection exists, return it.
302 if (!(i->second.empty())) {
303 CURL* handle=i->second.back();
304 i->second.pop_back();
307 m_log.debug("returning existing connection handle from pool");
313 m_log.debug("nothing free in pool, returning new connection handle");
315 // Create a new connection and set non-varying options.
316 CURL* handle=curl_easy_init();
319 curl_easy_setopt(handle,CURLOPT_NOPROGRESS,1);
320 curl_easy_setopt(handle,CURLOPT_NOSIGNAL,1);
321 curl_easy_setopt(handle,CURLOPT_FAILONERROR,1);
322 curl_easy_setopt(handle,CURLOPT_SSL_CIPHER_LIST,"ALL:!aNULL:!LOW:!EXPORT:!SSLv2");
323 // Verification of the peer is via TrustEngine only.
324 curl_easy_setopt(handle,CURLOPT_SSL_VERIFYPEER,0);
325 curl_easy_setopt(handle,CURLOPT_CAINFO,nullptr);
326 curl_easy_setopt(handle,CURLOPT_HEADERFUNCTION,&curl_header_hook);
327 curl_easy_setopt(handle,CURLOPT_WRITEFUNCTION,&curl_write_hook);
328 curl_easy_setopt(handle,CURLOPT_DEBUGFUNCTION,&curl_debug_hook);
332 void CURLPool::put(const char* from, const char* to, const char* endpoint, CURL* handle)
334 string key(endpoint);
336 key = key + '|' + from;
338 key = key + '|' + to;
340 poolmap_t::iterator i=m_bindingMap.find(key);
341 if (i==m_bindingMap.end())
342 m_pools.push_front(&(m_bindingMap.insert(poolmap_t::value_type(key,vector<CURL*>(1,handle))).first->second));
344 i->second.push_back(handle);
346 CURL* killit=nullptr;
347 if (++m_size > 256) {
348 // Kick a handle out from the back of the bus.
350 vector<CURL*>* corpse=m_pools.back();
351 if (!corpse->empty()) {
352 killit=corpse->back();
358 // Move an empty pool up to the front so we don't keep hitting it.
360 m_pools.push_front(corpse);
365 curl_easy_cleanup(killit);
367 xmltooling::NDC("put");
369 m_log.info("conn_pool_max limit reached, dropping an old connection");
373 bool CURLSOAPTransport::setAuth(transport_auth_t authType, const char* username, const char* password)
375 if (authType==transport_auth_none) {
376 if (curl_easy_setopt(m_handle,CURLOPT_HTTPAUTH,0)!=CURLE_OK)
378 return (curl_easy_setopt(m_handle,CURLOPT_USERPWD,nullptr)==CURLE_OK);
382 case transport_auth_basic: flag = CURLAUTH_BASIC; break;
383 case transport_auth_digest: flag = CURLAUTH_DIGEST; break;
384 case transport_auth_ntlm: flag = CURLAUTH_NTLM; break;
385 case transport_auth_gss: flag = CURLAUTH_GSSNEGOTIATE; break;
386 default: return false;
388 if (curl_easy_setopt(m_handle,CURLOPT_HTTPAUTH,flag)!=CURLE_OK)
390 m_simplecreds = string(username ? username : "") + ':' + (password ? password : "");
391 return (curl_easy_setopt(m_handle,CURLOPT_USERPWD,m_simplecreds.c_str())==CURLE_OK);
394 bool CURLSOAPTransport::setProviderOption(const char* provider, const char* option, const char* value)
396 if (!provider || !option || !value) {
399 else if (!strcmp(provider, "OpenSSL")) {
400 if (!strcmp(option, "SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION") && (*value=='1' || *value=='t')) {
401 // If the new option to enable buggy rengotiation is available, set it.
402 // Otherwise, signal false if this is newer than 0.9.8k, because that
403 // means it's 0.9.8l, which blocks renegotiation, and therefore will
404 // not honor this request. Older versions are buggy, so behave as though
405 // the flag was set anyway, so we signal true.
406 #if defined(SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION)
407 m_openssl_ops |= SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION;
409 #elif (OPENSSL_VERSION_NUMBER > 0x009080bfL)
417 else if (strcmp(provider, "CURL")) {
421 // For libcurl, the option is an enum and the value type depends on the option.
422 CURLoption opt = static_cast<CURLoption>(strtol(option, nullptr, 10));
423 if (opt < CURLOPTTYPE_OBJECTPOINT)
424 return (curl_easy_setopt(m_handle, opt, strtol(value, nullptr, 10)) == CURLE_OK);
425 #ifdef CURLOPTTYPE_OFF_T
426 else if (opt < CURLOPTTYPE_OFF_T) {
428 m_saved_options.push_back(value);
429 return (curl_easy_setopt(m_handle, opt, value ? m_saved_options.back().c_str() : nullptr) == CURLE_OK);
431 # ifdef HAVE_CURL_OFF_T
432 else if (sizeof(curl_off_t) == sizeof(long))
433 return (curl_easy_setopt(m_handle, opt, strtol(value, nullptr, 10)) == CURLE_OK);
435 else if (sizeof(off_t) == sizeof(long))
436 return (curl_easy_setopt(m_handle, opt, strtol(value, nullptr, 10)) == CURLE_OK);
442 m_saved_options.push_back(value);
443 return (curl_easy_setopt(m_handle, opt, value ? m_saved_options.back().c_str() : nullptr) == CURLE_OK);
448 const vector<string>& CURLSOAPTransport::getResponseHeader(const char* name) const
450 static vector<string> emptyVector;
452 map<string,vector<string> >::const_iterator i=m_response_headers.find(name);
453 if (i!=m_response_headers.end())
456 for (map<string,vector<string> >::const_iterator j=m_response_headers.begin(); j!=m_response_headers.end(); j++) {
457 #ifdef HAVE_STRCASECMP
458 if (!strcasecmp(j->first.c_str(), name))
460 if (!stricmp(j->first.c_str(), name))
468 string CURLSOAPTransport::getContentType() const
470 char* content_type=nullptr;
471 curl_easy_getinfo(m_handle,CURLINFO_CONTENT_TYPE,&content_type);
472 return content_type ? content_type : "";
475 long CURLSOAPTransport::getStatusCode() const
478 if (curl_easy_getinfo(m_handle, CURLINFO_RESPONSE_CODE, &code) != CURLE_OK)
483 void CURLSOAPTransport::send(istream* in)
486 xmltooling::NDC ndc("send");
488 Category& log=Category::getInstance(XMLTOOLING_LOGCAT".SOAPTransport.CURL");
489 Category& log_curl=Category::getInstance(XMLTOOLING_LOGCAT".libcurl");
491 // For this implementation, it's sufficient to check for https as a sign of transport security.
492 if (m_mandatory && !isConfidential())
493 throw IOException("Blocking unprotected HTTP request, transport authentication by server required.");
497 // By this time, the handle has been prepared with the URL to use and the
498 // caller should have executed any set functions to manipulate it.
500 // Setup standard per-call curl properties.
501 curl_easy_setopt(m_handle,CURLOPT_DEBUGDATA,&log_curl);
502 curl_easy_setopt(m_handle,CURLOPT_FILE,&m_stream);
503 if (m_chunked && in) {
504 curl_easy_setopt(m_handle,CURLOPT_POST,1);
505 m_headers=curl_slist_append(m_headers,"Transfer-Encoding: chunked");
506 curl_easy_setopt(m_handle,CURLOPT_READFUNCTION,&curl_read_hook);
507 curl_easy_setopt(m_handle,CURLOPT_READDATA,in);
513 msg.append(buf,in->gcount());
515 curl_easy_setopt(m_handle,CURLOPT_POST,1);
516 curl_easy_setopt(m_handle,CURLOPT_READFUNCTION,nullptr);
517 curl_easy_setopt(m_handle,CURLOPT_POSTFIELDS,msg.c_str());
518 curl_easy_setopt(m_handle,CURLOPT_POSTFIELDSIZE,msg.length());
521 curl_easy_setopt(m_handle,CURLOPT_HTTPGET,1);
522 curl_easy_setopt(m_handle,CURLOPT_FOLLOWLOCATION,1);
523 curl_easy_setopt(m_handle,CURLOPT_MAXREDIRS,6);
526 char curl_errorbuf[CURL_ERROR_SIZE];
528 curl_easy_setopt(m_handle,CURLOPT_ERRORBUFFER,curl_errorbuf);
529 if (log_curl.isDebugEnabled())
530 curl_easy_setopt(m_handle,CURLOPT_VERBOSE,1);
532 // Check for cache tag.
533 if (m_cacheTag && !m_cacheTag->empty()) {
534 string hdr("If-None-Match: ");
536 m_headers = curl_slist_append(m_headers, hdr.c_str());
539 m_useragent = XMLToolingConfig::getConfig().user_agent;
540 if (!m_useragent.empty()) {
541 curl_version_info_data* curlver = curl_version_info(CURLVERSION_NOW);
542 m_useragent += " libcurl/";
544 m_useragent = m_useragent + curlver->version + ' ' + curlver->ssl_version;
546 m_useragent = m_useragent + LIBCURL_VERSION + ' ' + OPENSSL_VERSION_TEXT;
547 curl_easy_setopt(m_handle, CURLOPT_USERAGENT, m_useragent.c_str());
550 // Set request headers.
551 curl_easy_setopt(m_handle,CURLOPT_HTTPHEADER,m_headers);
553 #ifndef XMLTOOLING_NO_XMLSEC
554 if (m_ssl_callback || m_cred || m_trustEngine) {
556 if (m_ssl_callback) {
558 curl_easy_setopt(m_handle,CURLOPT_SSL_CTX_FUNCTION,xml_ssl_ctx_callback);
559 curl_easy_setopt(m_handle,CURLOPT_SSL_CTX_DATA,this);
561 // Restore security "state". Necessary because the callback only runs
562 // when handshakes occur. Even new TCP connections won't execute it.
564 curl_easy_getinfo(m_handle,CURLINFO_PRIVATE,&priv);
566 m_authenticated=true;
569 curl_easy_setopt(m_handle,CURLOPT_SSL_CTX_FUNCTION,nullptr);
570 curl_easy_setopt(m_handle,CURLOPT_SSL_CTX_DATA,nullptr);
574 log.debug("sending SOAP message to %s", m_endpoint.c_str());
575 if (curl_easy_perform(m_handle) != CURLE_OK) {
577 string("CURLSOAPTransport failed while contacting SOAP endpoint (") + m_endpoint + "): " +
578 (curl_errorbuf[0] ? curl_errorbuf : "no further information available"));
581 // Check for outgoing cache tag.
583 const vector<string>& tags = getResponseHeader("ETag");
585 *m_cacheTag = tags.front();
589 // callback to buffer headers from server
590 size_t xmltooling::curl_header_hook(void* ptr, size_t size, size_t nmemb, void* stream)
592 // only handle single-byte data
595 CURLSOAPTransport* ctx = reinterpret_cast<CURLSOAPTransport*>(stream);
596 char* buf = (char*)malloc(nmemb + 1);
598 memset(buf,0,nmemb + 1);
599 memcpy(buf,ptr,nmemb);
600 char* sep=(char*)strchr(buf,':');
605 char* white=buf+nmemb-1;
606 while (isspace(*white))
608 ctx->m_response_headers[buf].push_back(sep);
616 // callback to send data to server
617 size_t xmltooling::curl_read_hook(void* ptr, size_t size, size_t nmemb, void* stream)
619 // stream is actually an istream pointer
620 istream* buf=reinterpret_cast<istream*>(stream);
621 buf->read(reinterpret_cast<char*>(ptr),size*nmemb);
622 return buf->gcount();
625 // callback to buffer data from server
626 size_t xmltooling::curl_write_hook(void* ptr, size_t size, size_t nmemb, void* stream)
628 size_t len = size*nmemb;
629 reinterpret_cast<stringstream*>(stream)->write(reinterpret_cast<const char*>(ptr),len);
633 // callback for curl debug data
634 int xmltooling::curl_debug_hook(CURL* handle, curl_infotype type, char* data, size_t len, void* ptr)
636 // *ptr is actually a logging object
638 CategoryStream log=reinterpret_cast<Category*>(ptr)->debugStream();
639 for (unsigned char* ch=(unsigned char*)data; len && (isprint(*ch) || isspace(*ch)); len--)
644 #ifndef XMLTOOLING_NO_XMLSEC
645 int xmltooling::verify_callback(X509_STORE_CTX* x509_ctx, void* arg)
647 Category& log=Category::getInstance(XMLTOOLING_LOGCAT".SOAPTransport.CURL");
648 log.debug("invoking custom X.509 verify callback");
649 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
650 CURLSOAPTransport* ctx = reinterpret_cast<CURLSOAPTransport*>(arg);
652 // Yes, this sucks. I'd use TLS, but there's no really obvious spot to put the thread key
653 // and global variables suck too. We can't access the X509_STORE_CTX depth directly because
654 // OpenSSL only copies it into the context if it's >=0, and the unsigned pointer may be
655 // negative in the SSL structure's int member.
656 CURLSOAPTransport* ctx = reinterpret_cast<CURLSOAPTransport*>(
657 SSL_get_verify_depth(
658 reinterpret_cast<SSL*>(X509_STORE_CTX_get_ex_data(x509_ctx,SSL_get_ex_data_X509_STORE_CTX_idx()))
664 if (ctx->m_criteria) {
665 ctx->m_criteria->setUsage(Credential::TLS_CREDENTIAL);
666 // Bypass name check (handled for us by curl).
667 ctx->m_criteria->setPeerName(nullptr);
668 success = ctx->m_trustEngine->validate(x509_ctx->cert,x509_ctx->untrusted,*(ctx->m_peerResolver),ctx->m_criteria);
671 // Bypass name check (handled for us by curl).
672 CredentialCriteria cc;
673 cc.setUsage(Credential::TLS_CREDENTIAL);
674 success = ctx->m_trustEngine->validate(x509_ctx->cert,x509_ctx->untrusted,*(ctx->m_peerResolver),&cc);
678 log.error("supplied TrustEngine failed to validate SSL/TLS server certificate");
679 x509_ctx->error=X509_V_ERR_APPLICATION_VERIFICATION; // generic error, check log for plugin specifics
680 ctx->setAuthenticated(false);
681 return ctx->m_mandatory ? 0 : 1;
684 // Signal success. Hopefully it doesn't matter what's actually in the structure now.
685 ctx->setAuthenticated(true);
690 // callback to invoke a caller-defined SSL callback
691 CURLcode xmltooling::xml_ssl_ctx_callback(CURL* curl, SSL_CTX* ssl_ctx, void* userptr)
693 CURLSOAPTransport* conf = reinterpret_cast<CURLSOAPTransport*>(userptr);
695 // Default flags manually disable SSLv2 so we're not dependent on libcurl to do it.
696 // Also disable the ticket option where implemented, since this breaks a variety
697 // of servers. Newer libcurl also does this for us.
698 #ifdef SSL_OP_NO_TICKET
699 SSL_CTX_set_options(ssl_ctx, conf->m_openssl_ops|SSL_OP_NO_TICKET);
701 SSL_CTX_set_options(ssl_ctx, conf->m_openssl_ops);
704 #ifndef XMLTOOLING_NO_XMLSEC
706 conf->m_cred->attach(ssl_ctx);
708 if (conf->m_trustEngine) {
709 SSL_CTX_set_verify(ssl_ctx,SSL_VERIFY_PEER,nullptr);
710 #if (OPENSSL_VERSION_NUMBER >= 0x00907000L)
711 // With 0.9.7, we can pass a callback argument directly.
712 SSL_CTX_set_cert_verify_callback(ssl_ctx,verify_callback,userptr);
714 // With 0.9.6, there's no argument, so we're going to use a really embarrassing hack and
715 // stuff the argument in the depth property where it will get copied to the context object
716 // that's handed to the callback.
717 SSL_CTX_set_cert_verify_callback(ssl_ctx,reinterpret_cast<int (*)()>(verify_callback),nullptr);
718 SSL_CTX_set_verify_depth(ssl_ctx,reinterpret_cast<int>(userptr));
723 if (conf->m_ssl_callback && !conf->m_ssl_callback(conf, ssl_ctx, conf->m_ssl_userptr))
724 return CURLE_SSL_CERTPROBLEM;