2 #include "../version.h"
4 #include <wx/tokenzr.h>
6 #include <libxml/parser.h>
7 #include <libxml/tree.h>
10 #include "../vcard/vcard.h"
11 #include "../common/dirs.h"
13 CURLcode CardDAV::SSLVerifyTest(){
20 AbortConnection = FALSE;
25 wxString ServerAddressURL;
27 wxString ServerAddressSSL;
28 wxString ServerAddressNormal;
30 conn = curl_easy_init();
32 /*struct CardDAVCURLPasser {
35 bool HeaderMode = TRUE;
37 } CardDAVHeader, CardDAVFooter;
39 CardDAVHeader.Data = this;
40 CardDAVHeader.HeaderMode = TRUE;
42 CardDAVFooter.Data = this;
43 CardDAVFooter.HeaderMode = FALSE;*/
48 ServerAddressURL = ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");
49 ServerAddressSSL = wxT("https://") + ServerAddressURL;
54 struct curl_slist *certdata;
55 struct curl_certinfo *certinfo;
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
77 if (conncode == CURLE_OK){
79 // Connection is OK. Do nothing.
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){
107 curl_easy_getinfo(connssldata, CURLINFO_CERTINFO, &ptr.certdata);
109 VerifyCertCollection = BuildSSLCollection(connssldata);
113 conncode = certfetchcode;
117 *ServerResult = FALSE;
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;
132 curl_easy_cleanup(conn);