curl / Mailing Lists / curl-library / Single Mail

curl-library

HTTPS hangs

From: Greg Stewart via curl-library <curl-library_at_cool.haxx.se>
Date: Fri, 5 May 2017 08:38:09 -0600

I'm working with the ESP32 hardware and the libcurl library. I need to log
into a server that requires https. When I run the code below on my mac, it
works just fine. When I move it to the ESP32, it hangs at
"curl_easy_perform". I disabled https on the server and removed the
CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST tokens from the code, and
it worked great on the ESP32. In production, I will not have this luxury.
Any ideas on what might be going wrong?

static void print_cookies(CURL *curl)
>
> {
>
> CURLcode res;
>
> struct curl_slist *cookies;
>
> struct curl_slist *nc;
>
> int i;
>
>
> printf("Cookies, curl knows:\n");
>
> res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
>
> if(res != CURLE_OK) {
>
> fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n",
>
> curl_easy_strerror(res));
>
> exit(1);
>
> }
>
> nc = cookies, i = 1;
>
> while(nc) {
>
> printf("[%d]: %s\n", i, nc->data);
>
> nc = nc->next;
>
> i++;
>
> }
>
> if(i == 1) {
>
> printf("(none)\n");
>
> }
>
> curl_slist_free_all(cookies);
>
> }
>
>
> void login_test() {
>
> printf("Begining Login Test**\n");
>
> curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
>
> printf("Curl version info\n");
>
> printf("version: %s - %d\n", data->version, data->version_num);
>
>
> CURLcode ret;
>
> CURL *hnd;
>
>
> hnd = curl_easy_init();
>
> curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/");
>
> curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
>
> curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L);
>
> curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
>
> curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
>
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0);
>
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
>
> curl_easy_setopt(hnd, CURLOPT_COOKIEFILE, "");
>
> curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
>
>
>
> printf("Before Perform\n");
>
> ret = curl_easy_perform(hnd);
>
> printf("After Perform\n");
>
> print_cookies(hnd);
>
>
>
> struct curl_httppost *post1;
>
> struct curl_httppost *postend;
>
> struct curl_slist *slist1;
>
>
> post1 = NULL;
>
> postend = NULL;
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "uri",
>
> CURLFORM_COPYCONTENTS, "/",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "username",
>
> CURLFORM_COPYCONTENTS, "admin",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "password",
>
> CURLFORM_COPYCONTENTS, "passpass",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "country",
>
> CURLFORM_COPYCONTENTS, "56",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "ui_language",
>
> CURLFORM_COPYCONTENTS, "en_US",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "lang_changed",
>
> CURLFORM_COPYCONTENTS, "no",
>
> CURLFORM_END);
>
> slist1 = NULL;
>
> slist1 = curl_slist_append(slist1, "Expect:");
>
>
> curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/login.cgi");
>
> curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
>
> curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post1);
>
> curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
>
> curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
>
> curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
>
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
>
> // curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
>
> curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
>
>
> ret = curl_easy_perform(hnd);
>
>
> curl_formfree(post1);
>
> post1 = NULL;
>
> curl_slist_free_all(slist1);
>
> slist1 = NULL;
>
>
>
> post1 = NULL;
>
> postend = NULL;
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "essid",
>
> CURLFORM_COPYCONTENTS, "SSID 123",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "security",
>
> CURLFORM_COPYCONTENTS, "wpa2aes",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "wpa_key",
>
> CURLFORM_COPYCONTENTS, "password",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "change",
>
> CURLFORM_COPYCONTENTS, "Change",
>
> CURLFORM_END);
>
> curl_formadd(&post1, &postend,
>
> CURLFORM_COPYNAME, "action",
>
> CURLFORM_COPYCONTENTS, "change",
>
> CURLFORM_END);
>
> slist1 = NULL;
>
> slist1 = curl_slist_append(slist1, "Expect:");
>
>
>
> curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/link.cgi");
>
> curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
>
> curl_easy_setopt(hnd, CURLOPT_HTTPPOST, post1);
>
> curl_easy_setopt(hnd, CURLOPT_REFERER, "https://192.168.1.20/link.cgi");
>
> curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
>
> curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, slist1);
>
> curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
>
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
>
> // curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
>
> curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
>
>
> ret = curl_easy_perform(hnd);
>
>
> curl_easy_setopt(hnd, CURLOPT_URL, "https://192.168.1.20/signal.cgi");
>
> curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L);
>
> curl_easy_setopt(hnd, CURLOPT_USERAGENT, "curl/7.50.3");
>
> curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
>
> curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L);
>
> // curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 0L);
>
> curl_easy_setopt(hnd, CURLOPT_TCP_KEEPALIVE, 1L);
>
>
> ret = curl_easy_perform(hnd);
>
>
>
>
> curl_easy_cleanup(hnd);
>
> hnd = NULL;
>
> curl_formfree(post1);
>
> post1 = NULL;
>
> curl_slist_free_all(slist1);
>
> slist1 = NULL;
>
>
> printf("Completed All\n");
>
>
> }
>

Thanks,
Greg

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-05-05