Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented support using ConnectionObject/CardDAV2 on Win32 systems.
[xestiaab/.git] / source / frmNewAccount-CardDAV2.cpp
1 // frmNewAccount.cpp - New Account form (CardDAV2 account section).
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Address Book is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Address Book. If not, see <http://www.gnu.org/licenses/> 
19 #include "frmNewAccount.h"
20 #include <iostream>
22 void frmNewAccount::RunCardDAV2Test( wxCommandEvent& event ){
23         
24         NewAccountResult *ResultData = new NewAccountResult;
25         
26         lblServerConnResult->SetLabel(_("Testing..."));
27         lblCardDAVSupportResult->SetLabel(_(""));
28         lblServerResponse->SetLabel(_(""));
29         lblServerSSLResult->SetLabel(_(""));
30         lblServerSSLValid->SetLabel(_(""));
31         lblAbleToLoginResult->SetLabel(_(""));
32         bool UsingSSLBypass = false;
33         
34         // Setup a CardDAV2 connection object for testing.
36         CardDAV2 TestConnection(txtServerAddress->GetValue().ToStdString(),
37                 wxAtoi(txtServerPort->GetValue()),
38                 txtUsername->GetValue().ToStdString(),
39                 txtPassword->GetValue().ToStdString(),
40                 chkUseSSL->GetValue());
41         
42         // Test the connection.
43         
44         TestConnection.SetupConnectionObject();
45         COConnectResult TestConnectionResult = TestConnection.Connect(false);
46         
47         // If server is using SSL, verify that the SSL connection is valid.
48         
49         if (TestConnection.SSLVerify() == COSSL_UNABLETOVERIFY){
50 #if defined(__APPLE__)
51 #elif defined(__WIN32__)
53                 TestConnection.BypassSSLVerification(true);
55                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
57                 TestConnection.BypassSSLVerification(false);
59                 BOOL ModifiedCertificateData = false;
61                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateDialogData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle());
63                 if (!CryptUIDlgViewCertificate(&CertificateDialogData, &ModifiedCertificateData)){
64                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
65                 }
67                 if (ModifiedCertificateData == false){
69                         lblServerConnResult->SetLabel(_("Failed"));
70                         lblServerResponse->SetLabel(_("Not applicable"));
71                         lblServerSSLResult->SetLabel(_("Used"));
72                         lblServerSSLValid->SetLabel(_("No"));
73                         lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage());
74                         btnPrevious->Enable(true);
75                         return;
77                 }
79 #else
80         
81                 // Connect again and fetch SSL certificate information.
82                 
83                 TestConnection.BypassSSLVerification(true);
84                 
85                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
86                 
87                 TestConnection.BypassSSLVerification(false);
89                 SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
90                 frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
91                 
92                 frmICPtr->LoadDataNew(CertData, txtServerAddress->GetValue().ToStdString());
93                 frmICPtr->ShowModal();
94                                                                 
95                 int SSLResult = frmICPtr->GetResult();
96                                                         
97                 // Clean up before processing response.
98                                 
99                 delete frmICPtr;
100                 frmICPtr = NULL;
101                                                         
102                 // Process the response from the user.
103                                                         
104                 if (SSLResult == 1){
105                                                                 
106                         // Accept the Certificate.
107                         
108                         UsingSSLBypass = true;
109                         TestConnection.BypassSSLVerification(true);
110                 
111                         COConnectResult TestConnectionResult = TestConnection.Connect(true);
112                 
113                         TestConnection.BypassSSLVerification(false);
114                                                                 
115                 } else if (SSLResult == 2){
116                                                                 
117                         // Reject the certificate, abort the task and mark as failed.
119                         // TODO: Integrate into the code.
120                         
121                         //lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
122                                                                 
123                 }               
124                 
125 #endif
126         }
127         
128         TestConnectionResult = TestConnection.Connect(true);
130         // Get the server prefix if the connection was successful.
131         
132         if (TestConnectionResult == COCONNECT_OK){
134                 if (UsingSSLBypass == true){
135                         TestConnection.BypassSSLVerification(true);                     
136                 }
137                 
138                 std::string ReceivedServerPrefix;
139                 COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
140                 ServerPrefix = ReceivedServerPrefix;
141                 
142                 if (UsingSSLBypass == true){
143                         TestConnection.BypassSSLVerification(true);                     
144                 }
145                 
146         }
147         
148         TestConnectionResult == COCONNECT_OK ? ResultData->Connected = true : ResultData->Connected = false;
149         
150         ResultData->SSLStatus = TestConnection.CanDoSSL();
151         ResultData->SSLVerified = TestConnection.SSLVerify();
152         ResultData->ValidResponse = TestConnection.HasValidResponse();
153         ResultData->AuthPassed = TestConnection.AbleToLogin();
154         ResultData->CanProcess = TestConnection.CanDoProcessing();
155         ResultData->ErrorMessage = TestConnection.GetErrorMessage();
156         
157         // Post event back confirming the tests.
158         
159         wxCommandEvent ResultsEvent(UPDATERESULTS);
160         ResultsEvent.SetClientData(ResultData);
161         wxPostEvent(this, ResultsEvent);
162         
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