Initializing SSL and libcurl and getting “out of memory”

馋奶兔 提交于 2020-01-11 11:18:29

问题


I intend to do https requests with libcurl and openssl with a C++ program.

I initialized libcurl with curl_global_init(CURL_GLOBAL_ALL) as described in the documentation. Then I use an curl_easy handle that I initialize, populate with headers and a body, and send everything out to ´https://example.com:443/foo´. It works for non-https connections.

Looking around I find that there may be other libraries that are already getting an SSL context which is what causes libcurl to fail in doing precisely that. I get the following error message:

curl_easy_perform failed: Out of memory

In my case I am using libmicrohttpd which I initialize with

mhdDaemon = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION | MHD_USE_SSL,
                               htons(port),
                               NULL,
                               NULL,
                               connectionTreat,                     NULL,
                               MHD_OPTION_HTTPS_MEM_KEY,            httpsKey,
                               MHD_OPTION_HTTPS_MEM_CERT,           httpsCertificate,
                               MHD_OPTION_CONNECTION_MEMORY_LIMIT,  memoryLimit,
                               MHD_OPTION_SOCK_ADDR,                (struct sockaddr*) &sad,
                               MHD_OPTION_NOTIFY_COMPLETED,         requestCompleted, NULL,
                               MHD_OPTION_END);

So I am indeed using openSSL somewhere else. The thing is, if I take out the MHD_USE_SSL part it does not fix the problem.

This is the list of libraries that are linked to the application (I'm using cmake):

-lmicrohttpd
-lmongoclient
-lboost_thread
-lboost_filesystem
-lboost_system
-lpthread

Is there any of the others that could be loading SSL? Is microhttpd loading it anyways even if I comment out the MHD_USE_SSL flag (plus all other related flags)? Could there be any other reason for this error?


回答1:


I'm not aware of any problem in libcurl that would cause this error code to get returned if indeed a memory allocation function doesn't fail. Using OpenSSL in multiple modules does not cause such a failure. (I am the lead developer of libcurl.)

So, run your app with VERBOSE set to libcurl, or even strace to see which syscall that fails and it should give you more clues.




回答2:


As the descibed in this answer, you might need to disable SSLv3 if you are on Ubuntu 16.04 like so

curl_easy_setopt(curl_, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2));

It was disabled on Ubuntu 16.04 for security reasons, see more here.



来源:https://stackoverflow.com/questions/28048885/initializing-ssl-and-libcurl-and-getting-out-of-memory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!