| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2000-2006 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq 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 |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | // written by Graham Roff <graham@licq.org> |
|---|
| 22 | // ----------------------------------------------------------------------------- |
|---|
| 23 | |
|---|
| 24 | #include "keyrequestdlg.h" |
|---|
| 25 | |
|---|
| 26 | #include <QDialogButtonBox> |
|---|
| 27 | #include <QLabel> |
|---|
| 28 | #include <QPushButton> |
|---|
| 29 | #include <QTimer> |
|---|
| 30 | #include <QVBoxLayout> |
|---|
| 31 | |
|---|
| 32 | #include <licq_icqd.h> |
|---|
| 33 | |
|---|
| 34 | #include "core/licqgui.h" |
|---|
| 35 | #include "core/signalmanager.h" |
|---|
| 36 | |
|---|
| 37 | #include "helpers/support.h" |
|---|
| 38 | |
|---|
| 39 | using namespace LicqQtGui; |
|---|
| 40 | /* TRANSLATOR LicqQtGui::KeyRequestDlg */ |
|---|
| 41 | |
|---|
| 42 | KeyRequestDlg::KeyRequestDlg(QString id, unsigned long ppid, QWidget* parent) |
|---|
| 43 | : QDialog(parent), |
|---|
| 44 | myId(id), |
|---|
| 45 | myPpid(ppid), |
|---|
| 46 | myIcqEventTag(0) |
|---|
| 47 | { |
|---|
| 48 | Support::setWidgetProps(this, "KeyRequestDialog"); |
|---|
| 49 | setAttribute(Qt::WA_DeleteOnClose, true); |
|---|
| 50 | |
|---|
| 51 | const ICQUser* u = gUserManager.FetchUser(myId.toLatin1(), myPpid, LOCK_R); |
|---|
| 52 | setWindowTitle(tr("Licq - Secure Channel with %1") |
|---|
| 53 | .arg(QString::fromUtf8(u->GetAlias()))); |
|---|
| 54 | |
|---|
| 55 | QVBoxLayout* top_lay = new QVBoxLayout(this); |
|---|
| 56 | |
|---|
| 57 | QString t1 = tr("Secure channel is established using SSL\n" |
|---|
| 58 | "with Diffie-Hellman key exchange and\n" |
|---|
| 59 | "the TLS version 1 protocol.\n\n"); |
|---|
| 60 | QString t2; |
|---|
| 61 | switch (u->SecureChannelSupport()) |
|---|
| 62 | { |
|---|
| 63 | case SECURE_CHANNEL_SUPPORTED: |
|---|
| 64 | t2 = tr("The remote uses Licq %1/SSL.") |
|---|
| 65 | .arg(CUserEvent::LicqVersionToString(u->LicqVersion())); |
|---|
| 66 | if (gLicqDaemon->CryptoEnabled()) |
|---|
| 67 | QTimer::singleShot(0, this, SLOT(startSend())); |
|---|
| 68 | break; |
|---|
| 69 | |
|---|
| 70 | case SECURE_CHANNEL_NOTSUPPORTED: |
|---|
| 71 | t2 = tr("The remote uses Licq %1, however it\n" |
|---|
| 72 | "has no secure channel support compiled in.\n" |
|---|
| 73 | "This probably won't work.") |
|---|
| 74 | .arg(CUserEvent::LicqVersionToString(u->LicqVersion())); |
|---|
| 75 | break; |
|---|
| 76 | |
|---|
| 77 | default: |
|---|
| 78 | t2 = tr("This only works with other Licq clients >= v0.85\n" |
|---|
| 79 | "The remote doesn't seem to use such a client.\n" |
|---|
| 80 | "This might not work."); |
|---|
| 81 | break; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | QLabel* lbl = new QLabel(t1 + t2); |
|---|
| 85 | top_lay->addWidget(lbl); |
|---|
| 86 | |
|---|
| 87 | lblStatus = new QLabel(); |
|---|
| 88 | lblStatus->setFrameStyle(QLabel::Box | QLabel::Sunken); |
|---|
| 89 | lblStatus->setAlignment(Qt::AlignHCenter); |
|---|
| 90 | top_lay->addWidget(lblStatus); |
|---|
| 91 | |
|---|
| 92 | QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Close); |
|---|
| 93 | |
|---|
| 94 | btnSend = buttons->addButton(tr("&Send"), QDialogButtonBox::ActionRole); |
|---|
| 95 | |
|---|
| 96 | connect(btnSend, SIGNAL(clicked()), SLOT(startSend())); |
|---|
| 97 | connect(buttons, SIGNAL(rejected()), SLOT(close())); |
|---|
| 98 | |
|---|
| 99 | top_lay->addWidget(buttons); |
|---|
| 100 | |
|---|
| 101 | if (gLicqDaemon->CryptoEnabled()) |
|---|
| 102 | { |
|---|
| 103 | myOpen = !u->Secure(); |
|---|
| 104 | if (u->Secure()) |
|---|
| 105 | lblStatus->setText(tr("Ready to close channel")); |
|---|
| 106 | else |
|---|
| 107 | lblStatus->setText(tr("Ready to request channel")); |
|---|
| 108 | } |
|---|
| 109 | else |
|---|
| 110 | { |
|---|
| 111 | lblStatus->setText(tr("Client does not support OpenSSL.\n" |
|---|
| 112 | "Rebuild Licq with OpenSSL support.")); |
|---|
| 113 | btnSend->setEnabled(false); |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | gUserManager.DropUser(u); |
|---|
| 117 | |
|---|
| 118 | show(); |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | KeyRequestDlg::~KeyRequestDlg() |
|---|
| 122 | { |
|---|
| 123 | if (myIcqEventTag != 0) |
|---|
| 124 | { |
|---|
| 125 | gLicqDaemon->CancelEvent(myIcqEventTag); |
|---|
| 126 | myIcqEventTag = 0; |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | void KeyRequestDlg::startSend() |
|---|
| 131 | { |
|---|
| 132 | connect(LicqGui::instance()->signalManager(), |
|---|
| 133 | SIGNAL(doneUserFcn(ICQEvent*)), SLOT(doneEvent(ICQEvent*))); |
|---|
| 134 | btnSend->setEnabled(false); |
|---|
| 135 | |
|---|
| 136 | if (myOpen) |
|---|
| 137 | { |
|---|
| 138 | lblStatus->setText(tr("Requesting secure channel...")); |
|---|
| 139 | QTimer::singleShot(100, this, SLOT(openConnection())); |
|---|
| 140 | } |
|---|
| 141 | else |
|---|
| 142 | { |
|---|
| 143 | lblStatus->setText(tr("Closing secure channel...")); |
|---|
| 144 | QTimer::singleShot(100, this, SLOT(closeConnection())); |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | void KeyRequestDlg::openConnection() |
|---|
| 149 | { |
|---|
| 150 | if (myPpid == LICQ_PPID) |
|---|
| 151 | myIcqEventTag = gLicqDaemon->icqOpenSecureChannel(myId.toLatin1().data()); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | void KeyRequestDlg::closeConnection() |
|---|
| 155 | { |
|---|
| 156 | if (myPpid == LICQ_PPID) |
|---|
| 157 | myIcqEventTag = gLicqDaemon->icqCloseSecureChannel(myId.toLatin1().data()); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | void KeyRequestDlg::doneEvent(ICQEvent* e) |
|---|
| 161 | { |
|---|
| 162 | if (!e->Equals(myIcqEventTag)) |
|---|
| 163 | return; |
|---|
| 164 | |
|---|
| 165 | QString result = "<center><font color=\"|\">#</font></center>"; |
|---|
| 166 | QString color, text; |
|---|
| 167 | if (e == NULL) |
|---|
| 168 | { |
|---|
| 169 | color = "yellow"; |
|---|
| 170 | if (myOpen) |
|---|
| 171 | text = tr("Secure channel already established."); |
|---|
| 172 | else |
|---|
| 173 | text = tr("Secure channel not established."); |
|---|
| 174 | |
|---|
| 175 | btnSend->setEnabled(false); |
|---|
| 176 | } |
|---|
| 177 | else |
|---|
| 178 | { |
|---|
| 179 | color = "red"; |
|---|
| 180 | switch (e->Result()) |
|---|
| 181 | { |
|---|
| 182 | case EVENT_FAILED: |
|---|
| 183 | text = tr("Remote client does not support OpenSSL."); |
|---|
| 184 | break; |
|---|
| 185 | case EVENT_ERROR: // could not connect to remote host (or out of memory) |
|---|
| 186 | text = tr("Could not connect to remote client."); |
|---|
| 187 | break; |
|---|
| 188 | case EVENT_SUCCESS: |
|---|
| 189 | if (myOpen) |
|---|
| 190 | { |
|---|
| 191 | color = "ForestGreen"; |
|---|
| 192 | text = tr("Secure channel established."); |
|---|
| 193 | } |
|---|
| 194 | else |
|---|
| 195 | { |
|---|
| 196 | color = "blue"; |
|---|
| 197 | text = tr("Secure channel closed."); |
|---|
| 198 | } |
|---|
| 199 | break; |
|---|
| 200 | default: |
|---|
| 201 | text = tr("Unknown state."); |
|---|
| 202 | break; |
|---|
| 203 | } |
|---|
| 204 | if (e->Result() == EVENT_SUCCESS) |
|---|
| 205 | { |
|---|
| 206 | btnSend->setEnabled(false); |
|---|
| 207 | QTimer::singleShot(500, this, SLOT(close())); |
|---|
| 208 | } |
|---|
| 209 | else |
|---|
| 210 | btnSend->setEnabled(true); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | result.replace('|', color); |
|---|
| 214 | result.replace('#', text); |
|---|
| 215 | lblStatus->setText(result); |
|---|
| 216 | |
|---|
| 217 | myIcqEventTag = 0; |
|---|
| 218 | } |
|---|