From 71fe3c25d1299666d5752df3e3263b03fa85594e Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Thu, 12 May 2016 21:47:41 +0100 Subject: [PATCH] Win32 Support: Add basic SSL verification. --- source/carddav/carddav-sslverify.cpp | 12 +++++--- source/carddav/carddav.cpp | 42 +++++++++++++++++++++++++++- source/carddav/carddav.h | 18 ++++++++++-- 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/source/carddav/carddav-sslverify.cpp b/source/carddav/carddav-sslverify.cpp index 9418e5a..57b11c0 100644 --- a/source/carddav/carddav-sslverify.cpp +++ b/source/carddav/carddav-sslverify.cpp @@ -74,10 +74,10 @@ CURLcode CardDAV::SSLVerifyTest(){ curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData); curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader); -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__WIN32__) SetConnectionObject(conn); - + #endif conncode = (curl_easy_perform(conn)); @@ -107,16 +107,18 @@ CURLcode CardDAV::SSLVerifyTest(){ curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYHOST, 0L); -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__WIN32__) SetConnectionObject(connssldata); - + #endif CURLcode certfetchcode; certfetchcode = (curl_easy_perform(connssldata)); +#if !defined(__APPLE__) && !defined(__WIN32__) + VerifyCertCollection = BuildSSLCollection(connssldata); if (certfetchcode == CURLE_OK){ @@ -131,6 +133,8 @@ CURLcode CardDAV::SSLVerifyTest(){ } +#endif + *ServerResult = FALSE; } else { diff --git a/source/carddav/carddav.cpp b/source/carddav/carddav.cpp index 8cbc71e..5276cb7 100644 --- a/source/carddav/carddav.cpp +++ b/source/carddav/carddav.cpp @@ -50,6 +50,21 @@ size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *st 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){ + PCtxtHandle SSLHandle = (PCtxtHandle)TLSInfo->internals; + SECURITY_STATUS GetData = QueryContextAttributes(SSLHandle, SECPKG_ATTR_REMOTE_CERT_CONTEXT, &CertificateData); + //QueryContextAttributesA(TLSInfo->internals, SECPKG_); + } + #endif return size * nmemb; @@ -110,6 +125,11 @@ 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 @@ -480,7 +500,7 @@ wxString CardDAV::GetErrorMessage(){ } -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__WIN32__) CURL* CardDAV::GetConnectionObject(){ @@ -498,4 +518,24 @@ void CardDAV::SetConnectionObject(CURL *ConnectionObjectIn){ } +#endif + +#if defined(__WIN32__) + +PCCERT_CONTEXT CardDAV::GetCertificateContextPointer(){ + + // Get the certificate data. + + return CertificateData; + +} + +CERT_CONTEXT CardDAV::GetCertificateContext(){ + + // Get the certificate data. + + return *CertificateData; + +} + #endif \ No newline at end of file diff --git a/source/carddav/carddav.h b/source/carddav/carddav.h index 6afc3f8..9bdd973 100644 --- a/source/carddav/carddav.h +++ b/source/carddav/carddav.h @@ -25,6 +25,10 @@ #include #include #include +#if defined(__WIN32__) +#include +#include +#endif #include "../vcard/vcard.h" #include "../actmgr/frmActivityMgr.h" #include "../common/sslcertstructs.h" @@ -107,10 +111,16 @@ class CardDAV wxString ETagValueResult(); wxString GetErrorMessage(); static size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream); -#if defined(__APPLE__) +#if defined(__APPLE__) || defined(__WIN32__) static CURL* GetConnectionObject(); static void SetConnectionObject(CURL *ConnectionObject); +#endif + +#if defined(__APPLE__) SecTrustRef GetTrustObject(); +#elif defined(__WIN32__) + PCCERT_CONTEXT GetCertificateContextPointer(); + CERT_CONTEXT GetCertificateContext(); #endif // SSL Verification tests when connecting. @@ -120,10 +130,14 @@ class CardDAV //size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *userdata); private: +#if defined(__APPLE__) || defined(__WIN32__) + static CURL* ConnectionObject; +#endif #if defined(__APPLE__) static SSLContext *SSLContextPointer; static SecTrustRef SecTrustObject; - static CURL* ConnectionObject; +#elif defined(__WIN32__) + static PCCERT_CONTEXT CertificateData; #endif static wxString ServerAddress; static int ServerPort; -- 2.39.5