cURL / Mailing Lists / curl-library / Single Mail


Re: Using certificate from memory - Mutal authentication

From: Itay Dagan <>
Date: Wed, 31 Dec 2008 11:25:24 +0200 (IST)

Thanks Daniel
Maybe as a start I would do it for ssl-lib

I am now trying to do it on the other way too (mutual authentication)
meaning client will upload a certificate from memory (not a file) and send it to the server.

Can you advise on that ?
has it been talked about in the past ? (didnt saw it :)



No, there doesn't exist anything like that - then the example code would've used it!

One little problem would be to make it SSL library agnostic so that it'd be possible to make the feature work with other libs than OpenSSL as well.

----- Original Message -----
To: "libcurl development" <>
Sent: Tuesday, December 30, 2008 2:22:44 PM (GMT+0200) Auto-Detected
Subject: Re: Using certificate from memory

Hi Jeff

finally I got it.

I think there should be somthing more friendly though (maybe there is ... and I dont know about it )
e.g : this set --> will get a buffer with our certificate

url_easy_setopt(curl, CURLOPT_SSLVERIFY_FROM_MEM, buf);

and add it to X509 sturct.

Does it exist ?
If not maybe I will add it :)

Thanks again for the link.


----- Original Message -----
To: "libcurl development" <>
Sent: Monday, December 29, 2008 3:59:53 PM (GMT+0200) Auto-Detected
Subject: Re: Using certificate from memory

Hi Jeff

Thanks for the help

I tried to use both advise I got from you and open-ssl guys
still have some problems to verify the certificate with CURL

using this code :

                curl_easy_setopt(curl, CURLOPT_URL, url);
                curl_easy_setopt(curl, CURLOPT_USERPWD, user_pwd);
                curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1);
                curl_easy_setopt(curl, CURLOPT_WRITEDATA, &serverdata);
                curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeDataFunction);
                curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, writeHeaderFunction);
                curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);

        curl_easy_setopt(curl,CURLOPT_SSL_CTX_FUNCTION, &Connector::loadFromMemory);  //suppose to load the certificate
        curl_easy_setopt (curl, CURLOPT_SSL_VERIFYPEER, TRUE);

        ret = curl_easy_perform(curl);


It behaves like no certificate has been uploaded to the database (looking for a file path ---> ret = 60)

It seems I am still doing something that makes it look for the certificate in a file though I already upload it from the memory

here is the function I am using (with a great help from opsn-ssl forum) :

int    loadFromMemory(char *buf, int bufLen)
    BIO *bp = NULL;
    X509 *cert = NULL;

     #define retFree(x) do { \
        if(bp) \
            BIO_free(bp); \
        if(cert) \
            X509_free(cert); \
       return x; \
    } while(0);

    if(!buf || bufLen < 1)
        return 1;
    bp = BIO_new(BIO_s_mem());
        return 2;

    cert = X509_new();

    if(!BIO_write(bp, buf, bufLen))
    cert = PEM_read_bio_X509(bp, NULL, NULL);
    if(!cert) {
        bp = BIO_new(BIO_s_mem());

        if(!BIO_write(bp, (char *) buf, bufLen))
       cert = d2i_X509_bio(bp, NULL);

   return 0;


thanks for the help :)


----- Original Message -----
From: "Jeff Pohlmeyer" <>
To: "libcurl development" <>
Sent: Sunday, December 28, 2008 1:30:50 PM (GMT+0200) Auto-Detected
Subject: Re: Using certificate from memory

On Sun, Dec 28, 2008 at 1:56 AM, Itay Dagan <> wrote:

> Can I load the certificate to curl structure from memory , instead of using
>  "curl_easy_setopt(curl,CURLOPT_CAINFO, "C://server_wrong.crt"); "

This might help:

 - Jeff
Received on 2008-12-31