Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Add support for self-signed certificates while creating an account (Connect() and...
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 27 Sep 2015 07:30:05 +0000 (08:30 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 27 Sep 2015 07:30:05 +0000 (08:30 +0100)
source/carddav/carddav.cpp
source/carddav/carddav.h

index 851b55c..7f0c6a7 100644 (file)
@@ -75,6 +75,7 @@ CURLcode CardDAV::claconncode;
 int CardDAV::HTTPErrorCode;\r
 wxString CardDAV::ErrorMessage;\r
 SSLCertCollection CardDAV::VerifyCertCollection;\r
 int CardDAV::HTTPErrorCode;\r
 wxString CardDAV::ErrorMessage;\r
 SSLCertCollection CardDAV::VerifyCertCollection;\r
+bool CardDAV::AllowSelfSign;\r
 \r
 CardDAV::CardDAV(){\r
        ServerPort = 8080;\r
 \r
 CardDAV::CardDAV(){\r
        ServerPort = 8080;\r
@@ -84,6 +85,7 @@ CardDAV::CardDAV(){
        ValidResponse = FALSE;\r
        HasCalDAVSupport = FALSE;\r
        SSLCertCol.SuccessCode = 0;\r
        ValidResponse = FALSE;\r
        HasCalDAVSupport = FALSE;\r
        SSLCertCol.SuccessCode = 0;\r
+       AllowSelfSign = FALSE;\r
 \r
        AbortConnection = FALSE;\r
        UploadMode = FALSE;\r
 \r
        AbortConnection = FALSE;\r
        UploadMode = FALSE;\r
@@ -188,6 +190,12 @@ bool CardDAV::AbleToLogin(){
 \r
 }\r
 \r
 \r
 }\r
 \r
+bool CardDAV::IsSelfSigned(){\r
+\r
+       return AllowSelfSign;\r
+\r
+}\r
+\r
 /*\r
 \r
 size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *stream){\r
 /*\r
 \r
 size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *stream){\r
@@ -304,14 +312,12 @@ CURLcode CardDAV::SSLVerifyTest(){
                        curl_easy_setopt(connssldata, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));\r
                        curl_easy_setopt(connssldata, CURLOPT_CERTINFO, 1);\r
                        curl_easy_setopt(connssldata, CURLOPT_VERBOSE, 1L);\r
                        curl_easy_setopt(connssldata, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));\r
                        curl_easy_setopt(connssldata, CURLOPT_CERTINFO, 1);\r
                        curl_easy_setopt(connssldata, CURLOPT_VERBOSE, 1L);\r
-                       //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, FALSE);\r
-                       //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, FALSE);\r
                        curl_easy_setopt(connssldata, CURLOPT_ERRORBUFFER, curlerrbuffer);\r
                        curl_easy_setopt(connssldata, CURLOPT_WRITEFUNCTION, WritebackFunc);\r
                        curl_easy_setopt(connssldata, CURLOPT_WRITEDATA, &PageData);\r
                        curl_easy_setopt(connssldata, CURLOPT_WRITEHEADER, &PageHeader);\r
                        curl_easy_setopt(connssldata, CURLOPT_ERRORBUFFER, curlerrbuffer);\r
                        curl_easy_setopt(connssldata, CURLOPT_WRITEFUNCTION, WritebackFunc);\r
                        curl_easy_setopt(connssldata, CURLOPT_WRITEDATA, &PageData);\r
                        curl_easy_setopt(connssldata, CURLOPT_WRITEHEADER, &PageHeader);\r
-                       //curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYPEER, FALSE);\r
-                       //curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYHOST, FALSE);\r
+                       curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYPEER, 0L);\r
+                       curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYHOST, 0L);\r
 \r
                        CURLcode certfetchcode;\r
 \r
 \r
                        CURLcode certfetchcode;\r
 \r
@@ -356,6 +362,10 @@ SSLCertCollection CardDAV::GetSSLVerifyResults(){
        return VerifyCertCollection;\r
 }\r
 \r
        return VerifyCertCollection;\r
 }\r
 \r
+void CardDAV::AllowSelfSignTest(bool AllowSelfSignIn){\r
+       AllowSelfSign = AllowSelfSignIn;\r
+}\r
+\r
 bool CardDAV::Connect(){\r
 \r
        PageData.Clear();\r
 bool CardDAV::Connect(){\r
 \r
        PageData.Clear();\r
@@ -365,8 +375,8 @@ bool CardDAV::Connect(){
        AuthPassed = TRUE;\r
        AbortConnection = FALSE;\r
 \r
        AuthPassed = TRUE;\r
        AbortConnection = FALSE;\r
 \r
-    CURL *conn;\r
-    CURLcode conncode;\r
+       CURL *conn;\r
+       CURLcode conncode;\r
        wxString ServerAddressURL;\r
        wxString ServerAuth;\r
        wxString ServerAddressSSL;\r
        wxString ServerAddressURL;\r
        wxString ServerAuth;\r
        wxString ServerAddressSSL;\r
@@ -439,8 +449,7 @@ bool CardDAV::Connect(){
 \r
                } else if (conncode == CURLE_SSL_CACERT){\r
 \r
 \r
                } else if (conncode == CURLE_SSL_CACERT){\r
 \r
-                       // Post message saying SSL certificate is invalid and \r
-\r
+                       // Post message saying SSL certificate is invalid. \r
 \r
                        curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata);\r
 \r
 \r
                        curl_easy_getinfo(conn, CURLINFO_CERTINFO, &ptr.certdata);\r
 \r
@@ -468,6 +477,11 @@ bool CardDAV::Connect(){
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
                curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);\r
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
                curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);\r
+               \r
+               if (AllowSelfSign == TRUE){\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);\r
+               }\r
 \r
                conncode = (curl_easy_perform(conn));\r
                \r
 \r
                conncode = (curl_easy_perform(conn));\r
                \r
@@ -503,6 +517,7 @@ bool CardDAV::Connect(){
                        }\r
 \r
                        *ServerResult = TRUE;\r
                        }\r
 \r
                        *ServerResult = TRUE;\r
+                       ValidResponse = TRUE;\r
                        AuthPassed = TRUE;\r
                        SSLStatus = TRUE;\r
                        return TRUE;\r
                        AuthPassed = TRUE;\r
                        SSLStatus = TRUE;\r
                        return TRUE;\r
@@ -3157,8 +3172,8 @@ wxString CardDAV::GetDefaultAddressBookURL(){
        AuthPassed = TRUE;\r
        AbortConnection = FALSE;\r
 \r
        AuthPassed = TRUE;\r
        AbortConnection = FALSE;\r
 \r
-    CURL *conn;\r
-    CURLcode conncode;\r
+       CURL *conn;\r
+       CURLcode conncode;\r
        wxString ServerAddressURL;\r
        wxString ServerAuth;\r
        wxString ServerAddressSSL;\r
        wxString ServerAddressURL;\r
        wxString ServerAuth;\r
        wxString ServerAddressSSL;\r
@@ -3208,9 +3223,24 @@ wxString CardDAV::GetDefaultAddressBookURL(){
        \r
        ServerAuth = ServerUser + wxT(":") + ServerPass;\r
        \r
        \r
        ServerAuth = ServerUser + wxT(":") + ServerPass;\r
        \r
-       wxString SAURLPrincipals = ServerAddressURL + wxT("principals/");\r
-       wxString SAURLPrincipalURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort);\r
-       wxString SAURLAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort);\r
+       wxString SAURLPrincipals;\r
+       wxString SAURLPrincipalURL;\r
+       wxString SAURLAddressURL;\r
+       \r
+       if (ServerSSL){\r
+       \r
+               SAURLPrincipals = ServerAddressSSL + wxT("principals/");\r
+               SAURLPrincipalURL = ServerAddressSSL;\r
+               SAURLAddressURL = ServerAddressSSL;\r
+       \r
+       } else {\r
+       \r
+               SAURLPrincipals = ServerAddressNormal + wxT("principals/");\r
+               SAURLPrincipalURL = ServerAddressNormal;\r
+               SAURLAddressURL = ServerAddressNormal;\r
+       \r
+       }\r
+       \r
        wxString FinalPrefix;\r
 \r
        struct UploadDataStruc UploadData;\r
        wxString FinalPrefix;\r
 \r
        struct UploadDataStruc UploadData;\r
@@ -3257,15 +3287,14 @@ wxString CardDAV::GetDefaultAddressBookURL(){
                curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);\r
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
                curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);\r
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
-\r
-               if (UploadMode == TRUE){\r
-\r
-                       UploadData.readptr = &ServerUploadData;\r
-                       UploadData.sizeleft = ServerUploadData.Len();\r
-                       curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);\r
-                       curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);\r
-                       curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);\r
+               curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");\r
+               curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);\r
+               curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));\r
+               curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd);\r
                \r
                \r
+               if (AllowSelfSign == TRUE){\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);\r
                }\r
 \r
                conncode = (curl_easy_perform(conn));\r
                }\r
 \r
                conncode = (curl_easy_perform(conn));\r
@@ -3274,8 +3303,8 @@ wxString CardDAV::GetDefaultAddressBookURL(){
 \r
                        *ServerResult = TRUE;\r
                        AuthPassed = TRUE;\r
 \r
                        *ServerResult = TRUE;\r
                        AuthPassed = TRUE;\r
+                       ValidResponse = TRUE;\r
                        SSLStatus = TRUE;\r
                        SSLStatus = TRUE;\r
-                       return wxT("");\r
 \r
                } else {\r
 \r
 \r
                } else {\r
 \r
@@ -3434,7 +3463,7 @@ wxString CardDAV::GetDefaultAddressBookURL(){
 \r
        if (ServerSSL){\r
 \r
 \r
        if (ServerSSL){\r
 \r
-               curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));\r
+               curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLPrincipalURL.mb_str(wxConvUTF8));\r
                curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);\r
                curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);\r
                curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);\r
                curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);\r
                curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);\r
                curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);\r
@@ -3445,15 +3474,14 @@ wxString CardDAV::GetDefaultAddressBookURL(){
                curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);\r
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
                curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);\r
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
+               curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");\r
+               curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query2);\r
+               curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query2));\r
+               curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd2);\r
 \r
 \r
-               if (UploadMode == TRUE){\r
-\r
-                       UploadData.readptr = &ServerUploadData;\r
-                       UploadData.sizeleft = ServerUploadData.Len();\r
-                       curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);\r
-                       curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);\r
-                       curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);\r
-               \r
+               if (AllowSelfSign == TRUE){\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);\r
                }\r
 \r
                conncode = (curl_easy_perform(conn));\r
                }\r
 \r
                conncode = (curl_easy_perform(conn));\r
@@ -3463,7 +3491,6 @@ wxString CardDAV::GetDefaultAddressBookURL(){
                        *ServerResult = TRUE;\r
                        AuthPassed = TRUE;\r
                        SSLStatus = TRUE;\r
                        *ServerResult = TRUE;\r
                        AuthPassed = TRUE;\r
                        SSLStatus = TRUE;\r
-                       return wxT("");\r
 \r
                } else {\r
 \r
 \r
                } else {\r
 \r
@@ -3471,6 +3498,7 @@ wxString CardDAV::GetDefaultAddressBookURL(){
                                        curl_easy_strerror(conncode));                                  \r
                                        \r
                        *ServerResult = FALSE;\r
                                        curl_easy_strerror(conncode));                                  \r
                                        \r
                        *ServerResult = FALSE;\r
+                       ValidResponse = FALSE;\r
                        \r
                        curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);\r
                        \r
                        \r
                        curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);\r
                        \r
@@ -3520,12 +3548,18 @@ wxString CardDAV::GetDefaultAddressBookURL(){
 \r
                        fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",\r
                                        GetHTTPCode());\r
 \r
                        fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",\r
                                        GetHTTPCode());\r
+                       \r
+                       ValidResponse = FALSE;\r
+                       \r
                        return wxT("");\r
                \r
                } else {\r
 \r
                        fprintf(stderr, "curl_easy_perform() failed: %s\n",\r
                                        curl_easy_strerror(conncode));\r
                        return wxT("");\r
                \r
                } else {\r
 \r
                        fprintf(stderr, "curl_easy_perform() failed: %s\n",\r
                                        curl_easy_strerror(conncode));\r
+                       \r
+                       ValidResponse = FALSE;\r
+                       \r
                        return wxT("");\r
 \r
                }\r
                        return wxT("");\r
 \r
                }\r
@@ -3605,7 +3639,7 @@ wxString CardDAV::GetDefaultAddressBookURL(){
 \r
        if (ServerSSL){\r
 \r
 \r
        if (ServerSSL){\r
 \r
-               curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));\r
+               curl_easy_setopt(conn, CURLOPT_URL, (const char*)SAURLAddressURL.mb_str(wxConvUTF8));\r
                curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);\r
                curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);\r
                curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);\r
                curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);\r
                curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);\r
                curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);\r
@@ -3616,15 +3650,14 @@ wxString CardDAV::GetDefaultAddressBookURL(){
                curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);\r
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
                curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);\r
                curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
+               curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "PROPFIND");\r
+               curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query3);\r
+               curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query3));\r
+               curl_easy_setopt(conn, CURLOPT_HTTPHEADER, connhd3);\r
 \r
 \r
-               if (UploadMode == TRUE){\r
-\r
-                       UploadData.readptr = &ServerUploadData;\r
-                       UploadData.sizeleft = ServerUploadData.Len();\r
-                       curl_easy_setopt(conn, CURLOPT_UPLOAD, 1);\r
-                       curl_easy_setopt(conn, CURLOPT_READDATA, &UploadData);\r
-                       curl_easy_setopt(conn, CURLOPT_READFUNCTION, UploadReadFunc);\r
-               \r
+               if (AllowSelfSign == TRUE){\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0L);\r
+                       curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0L);\r
                }\r
 \r
                conncode = (curl_easy_perform(conn));\r
                }\r
 \r
                conncode = (curl_easy_perform(conn));\r
@@ -3634,7 +3667,6 @@ wxString CardDAV::GetDefaultAddressBookURL(){
                        *ServerResult = TRUE;\r
                        AuthPassed = TRUE;\r
                        SSLStatus = TRUE;\r
                        *ServerResult = TRUE;\r
                        AuthPassed = TRUE;\r
                        SSLStatus = TRUE;\r
-                       return wxT("");\r
 \r
                } else {\r
 \r
 \r
                } else {\r
 \r
@@ -3642,6 +3674,7 @@ wxString CardDAV::GetDefaultAddressBookURL(){
                                        curl_easy_strerror(conncode));                                  \r
                                        \r
                        *ServerResult = FALSE;\r
                                        curl_easy_strerror(conncode));                                  \r
                                        \r
                        *ServerResult = FALSE;\r
+                       ValidResponse = FALSE;\r
                        \r
                        curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);\r
                        \r
                        \r
                        curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &HTTPErrorCode);\r
                        \r
@@ -3691,12 +3724,18 @@ wxString CardDAV::GetDefaultAddressBookURL(){
 \r
                        fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",\r
                                        GetHTTPCode());\r
 \r
                        fprintf(stderr, "curl_easy_perform() HTTP code was: %i\n",\r
                                        GetHTTPCode());\r
+                                       \r
+                       ValidResponse = FALSE;\r
+                                       \r
                        return wxT("");\r
                \r
                } else {\r
 \r
                        fprintf(stderr, "curl_easy_perform() failed: %s\n",\r
                                        curl_easy_strerror(conncode));\r
                        return wxT("");\r
                \r
                } else {\r
 \r
                        fprintf(stderr, "curl_easy_perform() failed: %s\n",\r
                                        curl_easy_strerror(conncode));\r
+                                       \r
+                       ValidResponse = FALSE;\r
+                                       \r
                        return wxT("");\r
 \r
                }\r
                        return wxT("");\r
 \r
                }\r
index aff2138..e38c614 100644 (file)
@@ -51,7 +51,9 @@ class CardDAV
                bool SSLVerify();
                bool AbleToLogin();
                bool HasValidResponse();
                bool SSLVerify();
                bool AbleToLogin();
                bool HasValidResponse();
-               wxString GetResponseData();             
+               bool IsSelfSigned();
+               wxString GetResponseData();
+               void AllowSelfSignTest(bool AllowSelfSignIn);           
                bool Connect();
                bool ConnectThread();
                void ProcessData();
                bool Connect();
                bool ConnectThread();
                void ProcessData();
@@ -117,6 +119,7 @@ class CardDAV
                static SSLCertCollection SSLCertCol;
                static wxString ErrorMessage;
                static wxString ErrorBufferMessage;
                static SSLCertCollection SSLCertCol;
                static wxString ErrorMessage;
                static wxString ErrorBufferMessage;
+               static bool AllowSelfSign;
        protected:
                static int SSLErrorCode;
                static int ConnectionErrorCode;
        protected:
                static int SSLErrorCode;
                static int ConnectionErrorCode;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy