Initializing SSL and libcurl and retrieving from memory

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

I initialized libcurl with curl_global_init(CURL_GLOBAL_ALL)as described in the documentation. Then I use the descriptor curl_easythat I initialize, fill in the headers and body, and send everything to https://example.com:443/foo '. It works for connections other than https.

Looking around, I discovered that there may be other libraries that are already receiving the SSL context, which is the reason that libcurl fails to do just that. The following error message appears:

curl_easy_perform failed: Out of memory

In my case, I use 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);

openSSL - . , MHD_USE_SSL, .

, ( cmake):

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

, SSL? microhttpd , MHD_USE_SSL ( )? ?

+2
3

- libcurl, , . OpenSSL . ( libcurl.)

, VERBOSE, libcurl, strace, , syscall , .

+2

, SSLv3, Ubuntu 16.04,

curl_easy_setopt(curl_, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2));

Ubuntu 16.04 , . .

0

I am new to curl, I am encountering a problem when establishing an https connection. I can establish an HTTP connection, but when I establish an HTTPS connection, I get a low memory error.

Below is my code snippet

CURL *curl;
    CURLcode res;

    curl_global_init(CURL_GLOBAL_ALL);

    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_SSLVERSION, 3);
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_easy_setopt(curl, CURLOPT_URL, "https://<hostname>:41443/3dpassport/login?action=get_auth_params");

        /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);
        /* Check for errors */
        if (res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(res));

        /* always cleanup */
        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();

    return 0;
}
0
source

All Articles