Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Split carddav/carddav.cpp down into 8 files to make it manageable.
[xestiaab/.git] / source / carddav / carddav-sslverify.cpp
1 #include "carddav.h"
2 #include "../version.h"
3 #include <wx/wx.h>
4 #include <wx/tokenzr.h>
5 #include <wx/ffile.h>
6 #include <libxml/parser.h>
7 #include <libxml/tree.h>
8 #include <map>
9 #include <thread>
10 #include "../vcard/vcard.h"
11 #include "../common/dirs.h"
13 CURLcode CardDAV::SSLVerifyTest(){
15         PageData.Clear();
16         PageHeader.Clear();
18         SSLStatus = TRUE;
19         AuthPassed = TRUE;
20         AbortConnection = FALSE;
22         CURL *conn;
23         CURL *connssldata;
24         CURLcode conncode;
25         wxString ServerAddressURL;
26         wxString ServerAuth;
27         wxString ServerAddressSSL;
28         wxString ServerAddressNormal;
30         conn = curl_easy_init();
32         /*struct CardDAVCURLPasser {
34                 CardDAV *Data;
35                 bool HeaderMode = TRUE;
37         } CardDAVHeader, CardDAVFooter;
39         CardDAVHeader.Data = this;
40         CardDAVHeader.HeaderMode = TRUE;
42         CardDAVFooter.Data = this;
43         CardDAVFooter.HeaderMode = FALSE;*/
45         wxString Data1;
46         wxString Data2;
48         ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
49         ServerAddressSSL = wxT("https://") + ServerAddressURL;
51         if (ServerSSL){
53                 union {
54                         struct curl_slist       *certdata;
55                         struct curl_certinfo    *certinfo;
56                 } ptr;
58                 ptr.certdata = NULL;
60                 // Setup two initial connections and attempt to get the certificate data.
62                 curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
63                 curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);
64                 curl_easy_setopt(conn, CURLOPT_VERBOSE, 1L);
65                 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, FALSE);
66                 //curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, FALSE);
67                 curl_easy_setopt(conn, CURLOPT_ERRORBUFFER, curlerrbuffer);
68                 curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);
69                 curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
70                 curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
72                 conncode = (curl_easy_perform(conn));
74                 // Check if the SSL certificate is valid or self-signed or some other
75                 // error occured.
77                 if (conncode == CURLE_OK){
79                         // Connection is OK. Do nothing.
81                         *ServerResult = TRUE;
83                 } else if (conncode == CURLE_SSL_CACERT || conncode == CURLE_SSL_CONNECT_ERROR){
85                         connssldata = curl_easy_init();
87                         // Retry but get the certificates without peer/host verification.
89                         curl_easy_setopt(connssldata, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));
90                         curl_easy_setopt(connssldata, CURLOPT_CERTINFO, 1);
91                         curl_easy_setopt(connssldata, CURLOPT_VERBOSE, 1L);
92                         curl_easy_setopt(connssldata, CURLOPT_ERRORBUFFER, curlerrbuffer);
93                         curl_easy_setopt(connssldata, CURLOPT_WRITEFUNCTION, WritebackFunc);
94                         curl_easy_setopt(connssldata, CURLOPT_WRITEDATA, &PageData);
95                         curl_easy_setopt(connssldata, CURLOPT_WRITEHEADER, &PageHeader);
96                         curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYPEER, 0L);
97                         curl_easy_setopt(connssldata, CURLOPT_SSL_VERIFYHOST, 0L);
99                         CURLcode certfetchcode;
101                         certfetchcode = (curl_easy_perform(connssldata));
103                         VerifyCertCollection = BuildSSLCollection(connssldata);
105                         if (certfetchcode == CURLE_OK){
106                                 
107                                 curl_easy_getinfo(connssldata, CURLINFO_CERTINFO, &ptr.certdata);
109                                 VerifyCertCollection = BuildSSLCollection(connssldata);
111                         } else {
113                                 conncode = certfetchcode;
115                         }
117                         *ServerResult = FALSE;
119                 } else {
121                         fprintf(stderr, "curl_easy_perform() failed: %s\n",
122                                 curl_easy_strerror(conncode));
124                         ErrorMessage = wxString::Format(wxT("%s"), curl_easy_strerror(conncode));
126                         *ServerResult = FALSE;
128                 }
130         }
132         curl_easy_cleanup(conn);
134         return conncode;
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