|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Device dialog plugin that shows untrusted certificate |
|
15 * dialog for TLS server authentication failure errors. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "untrustedcertificatedialog.h" |
|
20 #include "untrustedcertificatedefinitions.h" |
|
21 #include "untrustedcertificatewidget.h" |
|
22 #include <hblabel.h> |
|
23 #include <hbaction.h> |
|
24 #include <hbmessagebox.h> |
|
25 #include <QGraphicsLinearLayout> |
|
26 |
|
27 const int KNoError = 0; // KErrNone |
|
28 const int KParameterError = -6; // KErrArgument |
|
29 |
|
30 // TODO: replace with OST tracing |
|
31 #ifdef _DEBUG |
|
32 #include <QDebug> |
|
33 #define TRACE(x) qDebug() << x |
|
34 #define TRACE1(x,y) qDebug() << x << y |
|
35 #else |
|
36 #define TRACE(x) |
|
37 #define TRACE1(x,y) |
|
38 #endif |
|
39 |
|
40 |
|
41 // ---------------------------------------------------------------------------- |
|
42 // UntrustedCertificateDialog::UntrustedCertificateDialog() |
|
43 // ---------------------------------------------------------------------------- |
|
44 // |
|
45 UntrustedCertificateDialog::UntrustedCertificateDialog(const QVariantMap ¶meters) : |
|
46 HbDialog(), mLastError(KNoError), mContent(0), mResultMap(), |
|
47 mShowEventReceived(false), mOkAction(0) |
|
48 { |
|
49 constructDialog(parameters); |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // UntrustedCertificateDialog::~UntrustedCertificateDialog() |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 UntrustedCertificateDialog::~UntrustedCertificateDialog() |
|
57 { |
|
58 } |
|
59 |
|
60 // ---------------------------------------------------------------------------- |
|
61 // UntrustedCertificateDialog::setDeviceDialogParameters() |
|
62 // ---------------------------------------------------------------------------- |
|
63 // |
|
64 bool UntrustedCertificateDialog::setDeviceDialogParameters(const QVariantMap ¶meters) |
|
65 { |
|
66 return updateFromParameters(parameters); |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // UntrustedCertificateDialog::deviceDialogError() |
|
71 // ---------------------------------------------------------------------------- |
|
72 // |
|
73 int UntrustedCertificateDialog::deviceDialogError() const |
|
74 { |
|
75 return mLastError; |
|
76 } |
|
77 |
|
78 // ---------------------------------------------------------------------------- |
|
79 // UntrustedCertificateDialog::closeDeviceDialog() |
|
80 // ---------------------------------------------------------------------------- |
|
81 // |
|
82 void UntrustedCertificateDialog::closeDeviceDialog(bool byClient) |
|
83 { |
|
84 Q_UNUSED(byClient); |
|
85 TRACE("UntrustedCertificateDialog::closeDeviceDialog"); |
|
86 close(); |
|
87 |
|
88 // If show event has been received, close is signalled from hide event. |
|
89 // If not, hide event does not come and close is signalled from here. |
|
90 if (!mShowEventReceived) { |
|
91 emit deviceDialogClosed(); |
|
92 } |
|
93 } |
|
94 |
|
95 // ---------------------------------------------------------------------------- |
|
96 // UntrustedCertificateDialog::deviceDialogWidget() |
|
97 // ---------------------------------------------------------------------------- |
|
98 // |
|
99 HbDialog *UntrustedCertificateDialog::deviceDialogWidget() const |
|
100 { |
|
101 return const_cast<UntrustedCertificateDialog*>(this); |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------------------------------- |
|
105 // UntrustedCertificateDialog::hideEvent() |
|
106 // ---------------------------------------------------------------------------- |
|
107 // |
|
108 void UntrustedCertificateDialog::hideEvent(QHideEvent *event) |
|
109 { |
|
110 TRACE("UntrustedCertificateDialog::hideEvent"); |
|
111 HbDialog::hideEvent(event); |
|
112 emit deviceDialogClosed(); |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------------------------------- |
|
116 // UntrustedCertificateDialog::showEvent() |
|
117 // ---------------------------------------------------------------------------- |
|
118 // |
|
119 void UntrustedCertificateDialog::showEvent(QShowEvent *event) |
|
120 { |
|
121 TRACE("UntrustedCertificateDialog::showEvent"); |
|
122 HbDialog::showEvent(event); |
|
123 mShowEventReceived = true; |
|
124 } |
|
125 |
|
126 // ---------------------------------------------------------------------------- |
|
127 // UntrustedCertificateDialog::isParametersValid() |
|
128 // ---------------------------------------------------------------------------- |
|
129 // |
|
130 bool UntrustedCertificateDialog::isParametersValid(const QVariantMap ¶meters) |
|
131 { |
|
132 if (parameters.contains(KUntrustedCertEncodedCertificate) && |
|
133 parameters.contains(KUntrustedCertServerName) && |
|
134 parameters.contains(KUntrustedCertValidationError)) { |
|
135 return true; |
|
136 } |
|
137 mLastError = KParameterError; |
|
138 return false; |
|
139 } |
|
140 |
|
141 // ---------------------------------------------------------------------------- |
|
142 // UntrustedCertificateDialog::constructDialog() |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 bool UntrustedCertificateDialog::constructDialog(const QVariantMap ¶meters) |
|
146 { |
|
147 TRACE("UntrustedCertificateDialog::constructDialog"); |
|
148 if (!isParametersValid(parameters)) { |
|
149 return false; |
|
150 } |
|
151 |
|
152 setTimeout(HbPopup::NoTimeout); |
|
153 setDismissPolicy(HbPopup::NoDismiss); |
|
154 setModal(true); |
|
155 |
|
156 //: Title text in untrusted certificate dialog. User is opening secure |
|
157 //: connection to site or service, which authenticity cannot be proved, |
|
158 //: or there are other problems in the site certificate. User needs to |
|
159 //: decide if she/he accepts the risk and opens the secure connection |
|
160 //: anyway, or if the connection is rejected. |
|
161 //TODO: localised UI string |
|
162 //QString titleText = hbTrId(""); |
|
163 QString titleText = tr("Untrusted certificate"); |
|
164 setHeadingWidget(new HbLabel(titleText, this)); |
|
165 |
|
166 Q_ASSERT(mContent == 0); |
|
167 mContent = new UntrustedCertificateWidget(this); |
|
168 mContent->constructFromParameters(parameters); |
|
169 setContentWidget(mContent); |
|
170 |
|
171 if (mContent->isCertificateValid()) { |
|
172 mOkAction = new HbAction(qtTrId("txt_common_button_ok"), this); |
|
173 addAction(mOkAction); |
|
174 disconnect(mOkAction, SIGNAL(triggered()), this, SLOT(close())); |
|
175 connect(mOkAction, SIGNAL(triggered()), this, SLOT(handleAccepted())); |
|
176 |
|
177 HbAction *cancelAction = new HbAction(qtTrId("txt_common_button_cancel"), this); |
|
178 addAction(cancelAction); |
|
179 disconnect(cancelAction, SIGNAL(triggered()), this, SLOT(close())); |
|
180 connect(cancelAction, SIGNAL(triggered()), this, SLOT(handleRejected())); |
|
181 } else { |
|
182 HbAction *closeAction = new HbAction(qtTrId("txt_common_button_close"), this); |
|
183 addAction(closeAction); |
|
184 disconnect(closeAction, SIGNAL(triggered()), this, SLOT(close())); |
|
185 connect(closeAction, SIGNAL(triggered()), this, SLOT(handleRejected())); |
|
186 } |
|
187 |
|
188 return true; |
|
189 } |
|
190 |
|
191 // ---------------------------------------------------------------------------- |
|
192 // UntrustedCertificateDialog::updateFromParameters() |
|
193 // ---------------------------------------------------------------------------- |
|
194 // |
|
195 bool UntrustedCertificateDialog::updateFromParameters(const QVariantMap ¶meters) |
|
196 { |
|
197 TRACE("UntrustedCertificateDialog::updateFromParameters"); |
|
198 if (!isParametersValid(parameters)) { |
|
199 return false; |
|
200 } |
|
201 |
|
202 Q_ASSERT(mContent != 0); |
|
203 mContent->updateFromParameters(parameters); |
|
204 return true; |
|
205 } |
|
206 |
|
207 // ---------------------------------------------------------------------------- |
|
208 // UntrustedCertificateDialog::sendResult() |
|
209 // ---------------------------------------------------------------------------- |
|
210 // |
|
211 void UntrustedCertificateDialog::sendResult(int result) |
|
212 { |
|
213 TRACE1("UntrustedCertificateDialog::sendResult", result); |
|
214 QVariant resultValue(result); |
|
215 mResultMap.insert(KUntrustedCertificateDialogResult, resultValue); |
|
216 emit deviceDialogData(mResultMap); |
|
217 } |
|
218 |
|
219 // ---------------------------------------------------------------------------- |
|
220 // UntrustedCertificateDialog::confirmPermanentAccept() |
|
221 // ---------------------------------------------------------------------------- |
|
222 // |
|
223 void UntrustedCertificateDialog::confirmPermanentAccept() |
|
224 { |
|
225 TRACE("UntrustedCertificateDialog::confirmPermanentAccept"); |
|
226 |
|
227 HbDialog *dialog = new HbDialog(); |
|
228 dialog->setAttribute(Qt::WA_DeleteOnClose, true); |
|
229 dialog->setTimeout(HbPopup::NoTimeout); |
|
230 dialog->setDismissPolicy(HbDialog::NoDismiss); |
|
231 dialog->setModal(true); |
|
232 |
|
233 // TODO: localised UI string needed |
|
234 QString questionTitle = tr("Certificate access"); |
|
235 dialog->setHeadingWidget(new HbLabel(questionTitle)); |
|
236 |
|
237 HbWidget *widget = new HbWidget(); |
|
238 QGraphicsLinearLayout* layout = new QGraphicsLinearLayout(); |
|
239 // TODO: localized UI string needed |
|
240 QString questionText = |
|
241 tr("Connections to '%1' will be made without warnings. Continue?") |
|
242 .arg(mContent->serverName()); |
|
243 HbLabel *textLabel = new HbLabel(questionText); |
|
244 textLabel->setTextWrapping(Hb::TextWordWrap); |
|
245 layout->addItem(textLabel); |
|
246 widget->setLayout(layout); |
|
247 dialog->setContentWidget(widget); |
|
248 |
|
249 HbAction *yesAction = new HbAction(hbTrId("txt_common_button_yes")); |
|
250 dialog->addAction(yesAction); |
|
251 disconnect(yesAction, SIGNAL(triggered()), this, SLOT(close())); |
|
252 connect(yesAction, SIGNAL(triggered()), this, SLOT(handlePermanentAcceptance())); |
|
253 dialog->addAction(new HbAction(hbTrId("txt_common_button_no"))); |
|
254 |
|
255 dialog->show(); |
|
256 } |
|
257 |
|
258 // ---------------------------------------------------------------------------- |
|
259 // UntrustedCertificateDialog::handleAccepted() |
|
260 // ---------------------------------------------------------------------------- |
|
261 // |
|
262 void UntrustedCertificateDialog::handleAccepted() |
|
263 { |
|
264 TRACE("UntrustedCertificateDialog::handleAccepted"); |
|
265 if (mContent->isPermanentAcceptChecked()) { |
|
266 confirmPermanentAccept(); |
|
267 } else { |
|
268 sendResult(KDialogAccepted); |
|
269 close(); |
|
270 } |
|
271 } |
|
272 |
|
273 // ---------------------------------------------------------------------------- |
|
274 // UntrustedCertificateDialog::handleRejected() |
|
275 // ---------------------------------------------------------------------------- |
|
276 // |
|
277 void UntrustedCertificateDialog::handleRejected() |
|
278 { |
|
279 TRACE("UntrustedCertificateDialog::handleRejected"); |
|
280 sendResult(KDialogRejected); |
|
281 close(); |
|
282 } |
|
283 |
|
284 // ---------------------------------------------------------------------------- |
|
285 // UntrustedCertificateDialog::handlePermanentAcceptance() |
|
286 // ---------------------------------------------------------------------------- |
|
287 // |
|
288 void UntrustedCertificateDialog::handlePermanentAcceptance() |
|
289 { |
|
290 TRACE("UntrustedCertificateDialog::handlePermanentAcceptance"); |
|
291 sendResult(KDialogAcceptedPermanently); |
|
292 close(); |
|
293 } |
|
294 |