Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using libcurl & SSL

I've found there is really very little information around on this topic. I already have a dll making successful posts using libcurl.

I've compiled libcurl with openssl for ssl functionality.

Here is an exert of my original curl setup.

    curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, errorBuffer);

    //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER , 1);
    //curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST , 1);
    //curl_easy_setopt(curl, CURLOPT_CAINFO , "./ca.cert");

    curl_easy_setopt(handle, CURLOPT_POSTFIELDS, cParam); 
    curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, strlen(cParam));
    curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, Request::writer);   
    curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buffer); 
    curl_easy_setopt(handle, CURLOPT_URL, cURL);

My question to those who've done this before, is it as easy as just adding those lines above to get SSL to work (as long as the certificate exists)? Or is it more complicated?

The funny thing is I'm not completely sure how SSL works. I've never worked with it before. Do I need to store a key in my application and send it with each request? Anyway my main question was the first. Thank you in advance.

like image 677
HGPB Avatar asked May 25 '10 21:05

HGPB


People also ask

What can you do with libcurl?

The easy interface lets you do single transfers with a synchronous and blocking function call. libcurl also offers another interface that allows multiple simultaneous transfers in a single thread, the so called multi interface.

Where is libcurl used?

libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more...

Can you use libcurl in C++?

You can use the libcurl API perfectly fine from C++.

How do I calculate libcurl?

Libcurl is then installed in $prefix/lib and its header files are installed in $prefix/include and so on. The prefix is set with "configure --prefix". --protocols Lists what particular protocols the installed libcurl was built to support.


2 Answers

Yes, it is that simple. Just make sure that the "ca.cert" file you have is a true CA cert that can verify your server's certificate.

like image 184
Daniel Stenberg Avatar answered Sep 28 '22 22:09

Daniel Stenberg


All you need to do to use SSL with libcurl is give an https url instead of an http url. The only option you need to set with curl_easy_setopt is CURLOPT_URL, although it will just print the received data to stdout if you don't specify a write callback.

CURL *handle = curl_easy_init();
char url[] = "https://google.com";
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_perform(handle);
like image 25
br1ckd Avatar answered Sep 28 '22 21:09

br1ckd