cURL / Mailing Lists / curl-library / Single Mail

curl-library

passing certificates for the cCURL with openssl in android

From: Indtiny s <indtiny_at_gmail.com>
Date: Thu, 20 Sep 2012 12:07:20 -0400

Hi.

> I have cross built the curl and openssl for the android with help of this
> link Using cURL in Android
> http://stackoverflow.com/questions/4952169/using-curl-in-android
> .. I am able to build succesfully . and now I am trying to run my
> application , in my application I need to add my own certificates , when I
> tried to add the certificates which are stored in sdcard via my native code
> ,I am getting the following error response from the curl i.e
> CURLE_SSL_CERTPROBLEM (58)=>problem with the local client certificate. and
> if remove all certificates in my below application and if I use the simple
> https curl client with out certificates get the following error
> CURLE_SSL_CACERT_BADFILE (77) .
>
> Here with I have put my code , and in that I am just trying to read the
> certificates from sdcard(I had copied and pasted in the sdcard) .
>
> am I loading the certificates properly ?
>
> {
> pageInfo_t page;
> CURL *curl;
> CURLcode res;
> char *buffer;
>
> static const char *pCertFile = "/mnt//sdcard/sslcerts/33330001-root.x509";
> static const char *pCACertFile="/mnt//sdcard/sslcerts/root.x509.crt";
> pKeyName = "/mnt/sdcard/sslcerts/33330001-root-privkey.der";
>
> const char *pKeyName;
> const char *pKeyType;
>
> const char *pEngine;
> const jbyte *webpage;
>
> pKeyType = "DER";
> pEngine = NULL;
>
> webpage = (*env)->GetStringUTFChars(env, webpageJStr, NULL);
> if (webpage == NULL) {
> return NULL; /* OutOfMemoryError already thrown */
> }
>
> page.data = (char *)malloc(16 * 1024);
> page.len = 0;
> if (page.data)
> memset(page.data, 32, 16 * 1024);
>
> buffer = (char *)malloc(1024);
>
> curl = curl_easy_init();
> if(curl) {
> curl_easy_setopt(curl, CURLOPT_URL, webpage);
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HTTPData);
> curl_easy_setopt(curl, CURLOPT_WRITEDATA, &page);
> curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
>
> curl_easy_setopt(curl,CURLOPT_SSLCERTTYPE,"DER");
>
> curl_easy_setopt(curl,CURLOPT_SSLCERT,pCertFile);
>
> curl_easy_setopt(curl,CURLOPT_SSLKEYTYPE,pKeyType);
>
> curl_easy_setopt(curl,CURLOPT_SSLKEY,pKeyName);
>
> curl_easy_setopt(curl,CURLOPT_CAINFO,pCACertFile);
>
> curl_easy_setopt(curl,CURLOPT_SSL_VERIFYPEER,1L);
> res = curl_easy_perform(curl);
> /* always cleanup */
> curl_easy_cleanup(curl);
> (*env)->ReleaseStringUTFChars(env, webpageJStr, webpage);
> if(res == 0) {
> if (buffer) {
> page.data[page.len < 256 ? page.len : 256] = '\0';
> sprintf(buffer, "pagedata(%d): %s. done.\n", page.len, page.data);
> return (*env)->NewStringUTF(env, buffer);
> }
> }
> sprintf(buffer, "Result %d", res);
> return (*env)->NewStringUTF(env, buffer);
> } else {
> return (*env)->NewStringUTF(env, "Unable to init cURL");
> }
> }
>

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-09-20