Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Move INSTALL, LICENSE, README, THANKS and TODO into root directory
[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(wxT(""));
28         lblServerResponse->SetLabel(wxT(""));
29         lblServerSSLResult->SetLabel(wxT(""));
30         lblServerSSLValid->SetLabel(wxT(""));
31         lblAbleToLoginResult->SetLabel(wxT(""));
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() ? true : false);
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                 
52                 TestConnection.BypassSSLVerification(true);
53                 
54                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
55                 
56                 TestConnection.BypassSSLVerification(false);
57                 
58                 int SSLResult = DisplayTrustPanel(&TestConnection);
59                 
60                 if (SSLResult != NSOKButton){
61                         
62                         lblServerConnResult->SetLabel(_("Failed"));
63                         lblServerResponse->SetLabel(_("Not applicable"));
64                         lblServerSSLResult->SetLabel(_("Used"));
65                         lblServerSSLValid->SetLabel(_("No"));
66                         lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage());
67                         btnPrevious->Enable(true);
68                         return;
69                         
70                 } else {
71                         
72                         // Evalulate the trust object.
73                         
74                         SecTrustResultType EvalResult = ProcessResultType(&TestConnection);
75                         
76                         switch(EvalResult){
77                                 case kSecTrustResultProceed:
78                                         lblServerSSLValid->SetLabel(_("Verified"));
79                                         break;
80                                 case kSecTrustResultConfirm:
81                                         lblServerSSLValid->SetLabel(_("Verified (user)"));
82                                         break;
83                                 default:
84                                         lblServerSSLValid->SetLabel(_("Unable to verify"));
85                         }
86                         
87                         lblServerResponse->SetLabel(_("Not applicable"));
88                         lblServerSSLResult->SetLabel(_("Used"));
89                         
90                         if (EvalResult != kSecTrustResultProceed){
91                                 return;
92                         }
93                         
94                 }
95                 
96 #elif defined(__WIN32__)
98                 TestConnection.BypassSSLVerification(true);
100                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
102                 TestConnection.BypassSSLVerification(false);
104                 BOOL ModifiedCertificateData = false;
106                 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertificateDialogData = BuildCertificateData(&TestConnection, (HWND)this->GetHandle());
108                 if (!CryptUIDlgViewCertificate(&CertificateDialogData, &ModifiedCertificateData)){
109                         wxMessageBox(_("An error occured while trying to open the certificate dialog."), _("Error opening Certificate Information dialog"));
110                 }
112                 if (ModifiedCertificateData == false){
114                         lblServerConnResult->SetLabel(_("Failed"));
115                         lblServerResponse->SetLabel(_("Not applicable"));
116                         lblServerSSLResult->SetLabel(_("Used"));
117                         lblServerSSLValid->SetLabel(_("No"));
118                         lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + TestConnection.GetErrorMessage());
119                         btnPrevious->Enable(true);
120                         return;
122                 }
124 #else
125         
126                 // Connect again and fetch SSL certificate information.
127                 
128                 TestConnection.BypassSSLVerification(true);
129                 
130                 COConnectResult TestConnectionResult = TestConnection.Connect(false);
131                 
132                 TestConnection.BypassSSLVerification(false);
134                 SSLCertCollectionString CertData = TestConnection.BuildSSLCollection();
135                 frmInvalidSSLCertificate *frmICPtr = new frmInvalidSSLCertificate(this);
136                 
137                 frmICPtr->LoadDataNew(CertData, txtServerAddress->GetValue().ToStdString());
138                 frmICPtr->ShowModal();
139                                                                 
140                 int SSLResult = frmICPtr->GetResult();
141                                                         
142                 // Clean up before processing response.
143                                 
144                 delete frmICPtr;
145                 frmICPtr = NULL;
146                                                         
147                 // Process the response from the user.
148                                                         
149                 if (SSLResult == 1){
150                                                                 
151                         // Accept the Certificate.
152                         
153                         UsingSSLBypass = true;
154                         TestConnection.BypassSSLVerification(true);
155                 
156                         COConnectResult TestConnectionResult = TestConnection.Connect(true);
157                 
158                         TestConnection.BypassSSLVerification(false);
159                                                                 
160                 } else if (SSLResult == 2){
161                                                                 
162                         // Reject the certificate, abort the task and mark as failed.
164                         // TODO: Integrate into the code.
165                         
166                         //lblConnectionResultText->SetLabel(_("An error occured whilst connnecting: ") + CardDAVConn.GetErrorMessage() + wxString::Format(wxT(" (%i)\n%s"), sslcode, CardDAVConn.GetErrorBuffer().mb_str()));
167                                                                 
168                 }               
169                 
170 #endif
171         }
172         
173         TestConnectionResult = TestConnection.Connect(true);
175         // Get the server prefix if the connection was successful.
176         
177         if (TestConnectionResult == COCONNECT_OK){
179                 if (UsingSSLBypass == true){
180                         TestConnection.BypassSSLVerification(true);                     
181                 }
182                 
183                 std::string ReceivedServerPrefix;
184                 COServerResponse PrefixRequestResult = TestConnection.GetDefaultPrefix(&ReceivedServerPrefix);
185                 ServerPrefix = ReceivedServerPrefix;
186                 
187                 if (UsingSSLBypass == true){
188                         TestConnection.BypassSSLVerification(true);                     
189                 }
190                 
191         }
192         
193         TestConnectionResult == COCONNECT_OK ? ResultData->Connected = true : ResultData->Connected = false;
194         
195         ResultData->SSLStatus = TestConnection.CanDoSSL();
196         ResultData->SSLVerified = TestConnection.SSLVerify();
197         ResultData->ValidResponse = TestConnection.HasValidResponse();
198         ResultData->AuthPassed = TestConnection.AbleToLogin();
199         ResultData->CanProcess = TestConnection.CanDoProcessing();
200         ResultData->ErrorMessage = TestConnection.GetErrorMessage();
201         
202         // Post event back confirming the tests.
203         
204         wxCommandEvent ResultsEvent(UPDATERESULTS);
205         ResultsEvent.SetClientData(ResultData);
206         wxPostEvent(this, ResultsEvent);
207         
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