cURL / Mailing Lists / curl-users / Single Mail

curl-users

Reg:Https curl out of memory error(27)

From: praveen <praveen.trams_at_gmail.com>
Date: Wed, 15 May 2013 14:57:11 +0530

  Hi,

I have problem while posting the data into the https url using SSL
certificates(Error :27 out of memory).
The same problem while trying with curl command mode. Both c curl code
and command throwing same error.

version details:

OS : Fedora 14
curl : curl 7.21.0 (i386-redhat-linux-gnu) libcurl/7.21.0 NSS/3.12.7.0
zlib/1.2.5 libidn/1.18 libssh2/1.2.4
openssl: OpenSSL 1.0.0a-fips 1 Jun 2010

Please help to resolve this error.

curl command:

     curl "https:<ip>:<port>/request/" --cert testcert.pem --cacert
cacert.pem --pubkey testkey.pem --cert-type PEM

curl c code:

int main(void)
{

   int i;
   CURL *curl;
   CURLcode res;
   FILE *headerfile;
   FILE *out_fd = (FILE *) 0;
   const char *pPassphrase = NULL;
   char buf_url[256]="https://<ip>:<port>";

   static const char *pCertFile = "testcert.pem";
   static const char *pCACertFile="cacert.pem";

   const char *pKeyName;
   const char *pKeyType;
   const char *pEngine;

         pKeyName = "testkey.pem";
         pKeyType = "PEM";
         pEngine = NULL;

   headerfile = fopen("dumpit", "w");
   out_fd = fopen("response","w");

   //curl_global_init(CURL_GLOBAL_DEFAULT);
   curl_global_init(CURL_GLOBAL_SSL);

   curl = curl_easy_init();
         curl_easy_setopt(curl, CURLOPT_SSLVERSION, 3); //160413

   if(curl) {
     /* what call to write: */

     curl_easy_setopt(curl, CURLOPT_FILE, out_fd);
     curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
     curl_easy_setopt(curl, CURLOPT_URL, buf_url);
     curl_easy_setopt(curl, CURLOPT_WRITEHEADER, headerfile);

     for(i = 0; i < 1; i++) /* single-iteration loop, just to break out
from */
     {
       if (pEngine) /* use crypto engine */
       {
         if (curl_easy_setopt(curl, CURLOPT_SSLENGINE,pEngine) != CURLE_OK)
         { /* load the crypto engine */
           fprintf(stderr,"can't set crypto engine\n");
           break;
         }
         if (curl_easy_setopt(curl, CURLOPT_SSLENGINE_DEFAULT,1L) !=
CURLE_OK)
         { /* set the crypto engine as default */
           /* only needed for the first time you load
              a engine in a curl object... */
           fprintf(stderr,"can't set crypto engine as default\n");
           break;
         }
       }
       /* cert is stored PEM coded in file... */
       /* since PEM is default, we needn't set it for PEM */
       curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"PEM");

       /* set the cert for client authentication */
       curl_easy_setopt(curl,CURLOPT_SSLCERT,pCertFile);

       /* sorry, for engine we must set the passphrase
          (if the key has one...) */

       if (pPassphrase)
         curl_easy_setopt(curl,CURLOPT_KEYPASSWD,pPassphrase);

       /* if we use a key stored in a crypto engine,
          we must set the key type to "ENG" */

       curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType);

       /* set the private key (file or ID in engine) */
       curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName);

       /* set the file with the certs vaildating the server */
       curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile);

       /* disconnect if we can't validate server's cert */
       curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L);

       /* 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));
         printf("err_code:%d\n",res);
       /* we are done... */
     }
     /* always cleanup */
     curl_easy_cleanup(curl);
}

   curl_global_cleanup();

   return 0;
}

Thanks & Regards
Praveen
india
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-05-15