X-Git-Url: http://Server1/repobrowser/?a=blobdiff_plain;f=source%2Fcarddav%2Fcarddav.cpp;h=52ae03aa49eea14e7794553691f726e36290de01;hb=261a51c4b9015d677580aa5346b21c35e4df6283;hp=fb07b50f0d403947da7025ba5523ffefcdf98865;hpb=f7c42f023c68ec189d29e7ca8f3c75d3847f65e2;p=xestiaab%2F.git diff --git a/source/carddav/carddav.cpp b/source/carddav/carddav.cpp index fb07b50..52ae03a 100644 --- a/source/carddav/carddav.cpp +++ b/source/carddav/carddav.cpp @@ -28,7 +28,7 @@ #include "../vcard/vcard.h" #include "../common/dirs.h" -size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){ +size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){ // Writeback function for the CardDAV object. @@ -37,6 +37,41 @@ size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){ stream->Append(Data); + // Get the SSL engine pointer and trust if required on certain operating systems. + +#if defined(__APPLE__) + + const struct curl_tlssessioninfo *TLSInfo; + CURLcode TLSCode; + CURL *Connection = GetConnectionObject(); + TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo); + + if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){ + SSLCopyPeerTrust((SSLContext*)TLSInfo->internals, &SecTrustObject); + } + +#elif defined(__WIN32__) + + const struct curl_tlssessioninfo *TLSInfo; + CURLcode TLSCode; + CURL *Connection = GetConnectionObject(); + TLSCode = curl_easy_getinfo(Connection, CURLINFO_TLS_SSL_PTR, &TLSInfo); + + std::string CertName; + + if (TLSInfo->internals != nullptr && TLSCode == CURLE_OK){ + + // Free the previous certificate data. + + CertFreeCertificateContext(CertificateData); + + PCtxtHandle SSLHandle = (PCtxtHandle)TLSInfo->internals; + SECURITY_STATUS GetData = QueryContextAttributes(SSLHandle, SECPKG_ATTR_REMOTE_CERT_CONTEXT, &CertificateData); + + } + +#endif + return size * nmemb; } @@ -92,6 +127,16 @@ int CardDAV::HTTPErrorCode; wxString CardDAV::ErrorMessage; SSLCertCollection CardDAV::VerifyCertCollection; bool CardDAV::AllowSelfSign; +#if defined(__APPLE__) +SSLContext *CardDAV::SSLContextPointer; +SecTrustRef CardDAV::SecTrustObject; +#endif +#if defined(__WIN32__) +PCCERT_CONTEXT CardDAV::CertificateData; +#endif +#if defined(__APPLE__) || defined(__WIN32__) +CURL *CardDAV::ConnectionObject; +#endif CardDAV::CardDAV(){ @@ -320,13 +365,13 @@ void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString Upl // Check if ServerFilenameLocation has a / at // the start and if not then append it. - if (ServerFilenameLocation.Left(1) != wxT("/")){ + /*if (ServerFilenameLocation.Left(1) != wxT("/")){ // Not there so insert. ServerFilenameLocation = wxT("/") + ServerFilenameLocation; - } + }*/ } @@ -458,4 +503,61 @@ wxString CardDAV::GetErrorMessage(){ return ErrorMessage; -} \ No newline at end of file +} + +#if defined(__APPLE__) || defined(__WIN32__) + +CURL* CardDAV::GetConnectionObject(){ + + // Get the CardDAV connection object. + + return ConnectionObject; + +} + +void CardDAV::SetConnectionObject(CURL *ConnectionObjectIn){ + + // Set the connection object. + + ConnectionObject = ConnectionObjectIn; + +} + +#endif + +#if defined(__WIN32__) + +PCCERT_CONTEXT CardDAV::GetCertificateContextPointer(){ + + // Check that the PCCERT_CONTEXT has an address + // other than NULL. Return nullptr if this is the + // case. + + if (CertificateData == NULL){ + return NULL; + } + + // Get the certificate data. + + return CertificateData; + +} + +CERT_CONTEXT CardDAV::GetCertificateContext(){ + + // Check that the PCCERT_CONTEXT has an address + // other than NULL. Return nullptr if this is the + // case. + + if (CertificateData == NULL){ + CERT_CONTEXT EmptyCertificateData = { 0 }; + return EmptyCertificateData; + } + + // Get the certificate data. + + return *CertificateData; + +} + +#endif \ No newline at end of file