X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Fcarddav2%2Fcarddav2.cpp;h=cdec0c5dff81b9373ccf2454ac495e0971729621;hp=37bbdf9ea3093d72f2d46d9bfc182ee990b12b9a;hb=7fa91827ecc70fcc5b96fa5283884a20a504b819;hpb=547ab1fe605cdb4884179ab011dabba4d0bd7bc2 diff --git a/source/carddav2/carddav2.cpp b/source/carddav2/carddav2.cpp index 37bbdf9..cdec0c5 100644 --- a/source/carddav2/carddav2.cpp +++ b/source/carddav2/carddav2.cpp @@ -18,8 +18,6 @@ #include "carddav2.h" -#include - using namespace std; CardDAV2::CardDAV2(string ServerAddress, int ServerPort, string ServerUser, string ServerPass, bool ServerSSL){ @@ -72,11 +70,13 @@ size_t CardDAV2::WritebackFuncImplementation(char *ptr, size_t size, size_t nmem const struct curl_tlssessioninfo *TLSInfo; CURLcode TLSCode; - CURL *Connection = GetConnectionObject(); - TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo); + TLSCode = curl_easy_getinfo(data->ConnectionSessionObject, CURLINFO_TLS_SSL_PTR, &TLSInfo); + SecTrustRef CertificateData; + if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK) { - SSLCopyPeerTrust((SSLContext*)TLSInfo->internals, &SecTrustObject); + SSLCopyPeerTrust((SSLContext*)TLSInfo->internals, &CertificateData); + data->SSLContext = CertificateData; } #elif defined(__WIN32__) @@ -136,6 +136,12 @@ CardDAV2::~CardDAV2(){ #if defined(__APPLE__) +SecTrustRef CardDAV2::BuildSSLCollection(){ + + return CertificateData; + +} + #elif defined(__WIN32__) PCCERT_CONTEXT CardDAV2::BuildSSLCollection(){ @@ -161,13 +167,13 @@ SSLCertCollectionString CardDAV2::BuildSSLCollection(){ certptr.certdata = NULL; - curl_easy_getinfo(ConnectionSession, CURLINFO_CERTINFO, &certptr.certinfo); - + CURLcode result = curl_easy_getinfo(ConnectionSession, CURLINFO_CERTINFO, &certptr.certinfo); + std::string CertPropName; std::string CertPropValue; - + for (int i = 0; i < certptr.certinfo->num_of_certs; i++){ - + struct curl_slist *slist; SSLCertDataString SSLCertDataInc; @@ -225,7 +231,7 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){ COConnectResult ConnectResult = COCONNECT_UNITTESTFAIL; string ServerAddressURL = BuildURL("/principals/"); - + curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str()); if (TestMode == true){ @@ -233,7 +239,7 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){ } else { SessionResult = curl_easy_perform(ConnectionSession); } - + switch(SessionResult){ case CURLE_OK: case CURLE_HTTP_RETURNED_ERROR: @@ -241,6 +247,7 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){ SSLVerified = COSSL_VERIFIED; ConnectResult = COCONNECT_OK; break; + case CURLE_SSL_INVALIDCERTSTATUS: case CURLE_SSL_CACERT: case CURLE_SSL_CONNECT_ERROR: SSLStatus = true; @@ -254,7 +261,15 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){ // Set the certificate data (if required). -#if defined(__WIN32__) +#if defined(__APPLE__) + + if (ServerSSL) { + + CertificateData = PageHeaderObject.SSLContext; + + } + +#elif defined(__WIN32__) if (ServerSSL) { @@ -1254,8 +1269,6 @@ COContactList CardDAV2::GetContactList(std::string SyncToken){ std::string SyncData; - // TODO: Copy old code from CardDAV class as needed. - if (SyncToken.size() > 0){ SyncData = "\n" @@ -1285,8 +1298,6 @@ COContactList CardDAV2::GetContactList(std::string SyncToken){ string ServerAddressURL = BuildURL(ServerPrefix); - std::cout << SyncData << std::endl; - curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str()); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, SyncData.c_str()); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, strlen(SyncData.c_str())); @@ -1398,7 +1409,7 @@ void CardDAV2::SetupDefaultParametersNonSSL(bool DoAuthentication){ PageHeaderObject.ConnectionSessionObject = ConnectionSession; PageHeaderObject.DataSetting = &PageHeader; PageHeaderObject.ServerUsingSSL = false; - + curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddress.c_str()); curl_easy_setopt(ConnectionSession, CURLOPT_NOPROGRESS, 1L); curl_easy_setopt(ConnectionSession, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC); @@ -1408,7 +1419,7 @@ void CardDAV2::SetupDefaultParametersNonSSL(bool DoAuthentication){ curl_easy_setopt(ConnectionSession, CURLOPT_WRITEFUNCTION, CardDAV2::WritebackFunc); curl_easy_setopt(ConnectionSession, CURLOPT_WRITEDATA, &PageDataObject); curl_easy_setopt(ConnectionSession, CURLOPT_WRITEHEADER, &PageHeaderObject); - curl_easy_setopt(ConnectionSession, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(ConnectionSession, CURLOPT_NOSIGNAL, 1L); curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, nullptr); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, nullptr); @@ -1438,20 +1449,18 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ PageHeaderObject.ConnectionSessionObject = ConnectionSession; PageHeaderObject.DataSetting = &PageHeader; PageHeaderObject.ServerUsingSSL = true; - + curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str()); curl_easy_setopt(ConnectionSession, CURLOPT_NOPROGRESS, 1L); + curl_easy_setopt(ConnectionSession, CURLOPT_CERTINFO, 1L); curl_easy_setopt(ConnectionSession, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST|CURLAUTH_BASIC); curl_easy_setopt(ConnectionSession, CURLOPT_TIMEOUT, 60); - curl_easy_setopt(ConnectionSession, CURLOPT_FAILONERROR, true); + curl_easy_setopt(ConnectionSession, CURLOPT_FAILONERROR, 0L); curl_easy_setopt(ConnectionSession, CURLOPT_USERAGENT, XSDAB_USERAGENT); curl_easy_setopt(ConnectionSession, CURLOPT_WRITEFUNCTION, CardDAV2::WritebackFunc); curl_easy_setopt(ConnectionSession, CURLOPT_WRITEDATA, &PageDataObject); curl_easy_setopt(ConnectionSession, CURLOPT_WRITEHEADER, &PageHeaderObject); curl_easy_setopt(ConnectionSession, CURLOPT_ERRORBUFFER, SessionErrorBuffer); - curl_easy_setopt(ConnectionSession, CURLOPT_NOSIGNAL, 1); - curl_easy_setopt(ConnectionSession, CURLOPT_CERTINFO, 1); - curl_easy_setopt(ConnectionSession, CURLOPT_VERBOSE, 1); curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "GET"); curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, nullptr); curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, nullptr); @@ -1463,17 +1472,17 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, NULL); } -#if !defined(__APPLE__) - if (EnableSSLBypass == true){ - curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYHOST, 0); - curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYHOST, 0L); + curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYSTATUS, 0L); } else { - curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYHOST, 2); - curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYPEER, 1); + curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYHOST, 2L); + curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYPEER, 1L); + curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYSTATUS, 1L); } - -#endif + +#if !defined(__APPLE__) || defined(__WIN32__) if (TestMode == false && ServerAccount.size() > 0){ @@ -1488,6 +1497,8 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ } } + +#endif } @@ -1495,10 +1506,10 @@ string CardDAV2::BuildURL(string URI){ string ServerAddressURL; - if (SSLStatus == true){ + if (ServerSSL == true){ ServerAddressURL = "https://" + ServerAddress + ":" + to_string(ServerPort) + URI; } else { - ServerAddressURL = "https://" + ServerAddress + ":" + to_string(ServerPort) + URI; + ServerAddressURL = "http://" + ServerAddress + ":" + to_string(ServerPort) + URI; } return ServerAddressURL; @@ -1998,4 +2009,4 @@ void CardDAV2::ProcessContactData(COContactList *ContactList){ return; -} \ No newline at end of file +}