~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/miniclient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include <QtCrypto>
22
22
#include <QMessageBox>
 
23
#include <QUrl>
23
24
 
 
25
#include "applicationinfo.h"
24
26
#include "miniclient.h"
25
27
#include "proxy.h"
26
 
#include "certutil.h"
 
28
#include "Certificates/CertificateHelpers.h"
 
29
#include "Certificates/CertificateErrorDialog.h"
27
30
#include "psiaccount.h"
28
 
#include "sslcertdlg.h"
29
31
#include "xmpp_tasks.h"
30
32
 
31
33
using namespace XMPP;
77
79
        }
78
80
 
79
81
        AdvancedConnector::Proxy p;
80
 
        if(proxy != "") {
 
82
        if(!proxy.isEmpty()) {
81
83
                const ProxyItem &pi = pm->getItem(proxy);
82
84
                if(pi.type == "http") // HTTP Connect
83
85
                        p.setHttpConnect(pi.settings.host, pi.settings.port);
89
91
                                if (useHost)
90
92
                                        u.addQueryItem("server",host + ':' + QString::number(port));
91
93
                                else
92
 
                                        u.addQueryItem("server",jid.host());
 
94
                                        u.addQueryItem("server",jid.domain());
93
95
                        }
94
96
                        p.setHttpPoll(pi.settings.host, pi.settings.port, u.toString());
95
97
                        p.setPollInterval(2);
96
98
                }
97
99
 
98
 
                if(pi.settings.useAuth)
 
100
                if(pi.settings.useAuth) {
99
101
                        p.setUserPass(pi.settings.user, pi.settings.pass);
 
102
                }
100
103
        }
101
104
 
102
105
        conn = new AdvancedConnector;
103
 
        tls = new QCA::TLS;
104
 
        tls->setTrustedCertificates(CertUtil::allCertificates());
105
 
        tlsHandler = new QCATLSHandler(tls);
106
 
        tlsHandler->setXMPPCertCheck(true);
107
 
        connect(tlsHandler, SIGNAL(tlsHandshaken()), SLOT(tls_handshaken()));
 
106
        if (QCA::isSupported("tls")) {
 
107
                tls = new QCA::TLS;
 
108
                tls->setTrustedCertificates(CertificateHelpers::allCertificates(ApplicationInfo::getCertificateStoreDirs()));
 
109
                tlsHandler = new QCATLSHandler(tls);
 
110
                tlsHandler->setXMPPCertCheck(true);
 
111
                connect(tlsHandler, SIGNAL(tlsHandshaken()), SLOT(tls_handshaken()));
 
112
        }
 
113
 
108
114
        conn->setProxy(p);
109
115
        if (useHost) {
110
116
                conn->setOptHostPort(host, port);
153
159
 
154
160
void MiniClient::tls_handshaken()
155
161
{
156
 
        QCA::Certificate cert = tls->peerCertificateChain().primary();
157
 
        int r = tls->peerIdentityResult();
158
 
        if (r == QCA::TLS::Valid && !tlsHandler->certMatchesHostname()) r = QCA::TLS::HostMismatch;
159
 
        if(r != QCA::TLS::Valid) {
160
 
                QCA::Validity validity =  tls->peerCertificateValidity();
161
 
                QString str = CertUtil::resultToString(r,validity);
162
 
                while(1) {
163
 
                        int n = QMessageBox::warning(0,
164
 
                                tr("Server Authentication"),
165
 
                                tr("The %1 certificate failed the authenticity test.").arg(j.host()) + '\n' + tr("Reason: %1.").arg(str),
166
 
                                tr("&Details..."),
167
 
                                tr("Co&ntinue"),
168
 
                                tr("&Cancel"), 0, 2);
169
 
                        if(n == 0) {
170
 
                                SSLCertDlg::showCert(cert, r, validity);
171
 
                        }
172
 
                        else if(n == 1) {
173
 
                                tlsHandler->continueAfterHandshake();
174
 
                                break;
175
 
                        }
176
 
                        else if(n == 2) {
177
 
                                close();
178
 
                                error();
179
 
                                break;
180
 
                        }
181
 
                }
182
 
        }
183
 
        else
 
162
        if (CertificateHelpers::checkCertificate(tls, tlsHandler, tlsOverrideDomain, tlsOverrideCert, 0,
 
163
                                                                                 tr("Server Authentication"),
 
164
                                                                                 j.domain())) {
184
165
                tlsHandler->continueAfterHandshake();
 
166
        } else {
 
167
                close();
 
168
                error();
 
169
        }
185
170
}
186
171
 
187
172
void MiniClient::cs_connected()
195
180
void MiniClient::cs_needAuthParams(bool user, bool password, bool realm)
196
181
{
197
182
        if(user) 
198
 
                stream->setUsername(j.user());
 
183
                stream->setUsername(j.node());
199
184
        if(password)
200
185
                stream->setPassword(pass);
201
186
        if(realm)
205
190
 
206
191
void MiniClient::cs_authenticated()
207
192
{
208
 
        _client->start(j.host(), j.user(), "", "");
 
193
        _client->start(j.domain(), j.node(), "", "");
209
194
 
210
195
        if (!stream->old() && auth) {
211
196
                JT_Session *j = new JT_Session(_client->rootTask());