From: Steve Brokenshire Date: Sun, 20 Sep 2015 12:02:03 +0000 (+0100) Subject: Updated SSL code for it to work properly and added curl_easy_cleanup where required. X-Git-Tag: release-0.05~77 X-Git-Url: http://Server1/repobrowser/?a=commitdiff_plain;h=bb8795209bee5b27eb620398bb596e774438d838;p=xestiaab%2F.git Updated SSL code for it to work properly and added curl_easy_cleanup where required. --- diff --git a/source/carddav/carddav.cpp b/source/carddav/carddav.cpp index 4b08fbb..851b55c 100644 --- a/source/carddav/carddav.cpp +++ b/source/carddav/carddav.cpp @@ -456,7 +456,7 @@ bool CardDAV::Connect(){ } - /*curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); + curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); @@ -470,11 +470,6 @@ bool CardDAV::Connect(){ curl_easy_setopt(conn, CURLOPT_CERTINFO, 1); conncode = (curl_easy_perform(conn)); - - union { - struct curl_slist *certdata; - struct curl_certinfo *certinfo; - } ptr; ptr.certdata = NULL; @@ -958,7 +953,7 @@ void CardDAV::ProcessDataThread(){ SSLCertCol = BuildSSLCollection(sslerrconn); SSLCertCol.SuccessCode = 1; - return; + return; } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){ @@ -1171,7 +1166,7 @@ void CardDAV::ProcessDataThread(){ // Catch all. - ActIter->second = 1; + //ActIter->second = 1; *ServerResult = TRUE; return; @@ -1357,21 +1352,22 @@ void CardDAV::GetServerContactData() wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); - curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); - curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT); - curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); - curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc); - curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); - curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); - curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); + curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 1L); + curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60); + curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE); + curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT); + curl_easy_setopt(sslerrconn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8)); + curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc); + curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData); + curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader); + curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); //UploadData.readptr = &CardDAVDataQuery; //UploadData.sizeleft = CardDAVDataQuery.Len(); curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); wxString SSLLocalData; @@ -1394,9 +1390,6 @@ void CardDAV::GetServerContactData() // Load the recovery database for tasks not done. if (SSLLocalFile.IsOpened() == TRUE){ - - // Check if we are using wxWidgets version 2.8 or less and - // execute the required command accordingly. SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto()); @@ -1592,7 +1585,8 @@ void CardDAV::GetServerETagValueThread() SSLStatus = TRUE; AuthPassed = TRUE; AbortConnection = FALSE; - + + bool FilenameIsDirectory = FALSE; CURL *conn; CURLcode conncode; wxString ServerAddressURL; @@ -1624,6 +1618,14 @@ void CardDAV::GetServerETagValueThread() ServerAuth = ServerUser + wxT(":") + ServerPass; + // Workout if path is directory or filename. + + /*if (ServerAddress){ + FilenameIsDirectory = TRUE; + } else { + FilenameIsDirectory = FALSE; + }*/ + // Try SSL first. @@ -1727,7 +1729,7 @@ void CardDAV::GetServerETagValueThread() curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); + curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); claconncode = (curl_easy_perform(conn)); @@ -1760,6 +1762,9 @@ void CardDAV::GetServerETagValueThread() wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/"); + PageData.clear(); + PageHeader.clear(); + curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8)); curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); @@ -1774,6 +1779,9 @@ void CardDAV::GetServerETagValueThread() curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1); + curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 1); + curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 2); + curl_easy_setopt(sslerrconn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8)); wxString SSLLocalData; wxString SSLServerData; @@ -1791,7 +1799,7 @@ void CardDAV::GetServerETagValueThread() #else SSLLocalFile.Open(ServerCertFilename, wxT("r")); #endif - + // Load the recovery database for tasks not done. if (SSLLocalFile.IsOpened() == TRUE){ @@ -1832,7 +1840,9 @@ void CardDAV::GetServerETagValueThread() curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT"); curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query); - curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); + curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query)); + curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0); claconncode = (curl_easy_perform(conn)); @@ -1851,8 +1861,6 @@ void CardDAV::GetServerETagValueThread() } - - // Sort out SSL error. // When SSL cert error occurs, connect again and fetch certificates. @@ -1892,6 +1900,9 @@ void CardDAV::GetServerETagValueThread() SSLCertCol = BuildSSLCollection(sslerrconn); SSLCertCol.SuccessCode = 1; + curl_easy_cleanup(conn); + curl_easy_cleanup(sslerrconn); + return; } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){ @@ -1901,6 +1912,8 @@ void CardDAV::GetServerETagValueThread() int http_code = 0; curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); fprintf(stderr, "Error code was: %d\n", http_code); + + curl_easy_cleanup(conn); return; @@ -1912,6 +1925,8 @@ void CardDAV::GetServerETagValueThread() curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code); fprintf(stderr, "Error code was: %d\n", http_code); + curl_easy_cleanup(conn); + return; } @@ -1958,7 +1973,7 @@ void CardDAV::GetServerETagValueThread() fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(conncode)); - + return; } else { @@ -1997,6 +2012,9 @@ void CardDAV::GetServerETagValueThread() nodeLevel1 = nodeLevel1->next) { + bool HREFFound = FALSE; + bool ETagFound = FALSE; + for (nodeLevel2 = nodeLevel1->children; nodeLevel2 != NULL; nodeLevel2 = nodeLevel2->next) @@ -2007,9 +2025,6 @@ void CardDAV::GetServerETagValueThread() nodeLevel3 = nodeLevel3->next) { - bool HREFFound = FALSE; - bool ETagFound = FALSE; - if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") || !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") || !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href") @@ -2088,21 +2103,19 @@ void CardDAV::GetServerETagValueThread() } - if (HREFFound == TRUE && ETagFound == TRUE){ + } + + } + + if (HREFFound == TRUE && ETagFound == TRUE){ - // Add to the map data. + // Add to the map data. - xmlDataMap.insert(std::make_pair(DataFilename, ETagData)); - - } + xmlDataMap.insert(std::make_pair(DataFilename, ETagData)); - // Reset the values. + HREFFound = FALSE; + ETagFound = FALSE; - HREFFound = FALSE; - ETagFound = FALSE; - - } - }