55
|
1 |
/*
|
|
2 |
* Copyright (c) 2000 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: Implementation of policymanagement components
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "PolicyEngineUI.h"
|
|
19 |
#include <hbpopup.h>
|
|
20 |
#include <hbinputdialog.h>
|
|
21 |
#include <hbdocumentloader.h>
|
|
22 |
#include <hbdialog.h>
|
|
23 |
#include <hblabel.h>
|
|
24 |
#include <hbaction.h>
|
|
25 |
#include <hbnotificationdialog.h>
|
|
26 |
#include <hbmessagebox.h>
|
|
27 |
#include <hbdevicenotificationdialog.h>
|
|
28 |
#include "Logger.h"
|
|
29 |
|
|
30 |
const int KMaxTries = 4;
|
|
31 |
const int KMaxCodeLength = 4;
|
|
32 |
|
|
33 |
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
// PolicyEngineUI::PolicyEngineUI()
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
PolicyEngineUI::PolicyEngineUI(const QVariantMap& parameters)
|
|
38 |
{
|
|
39 |
estbTrustCount = KMaxTries;
|
|
40 |
DisplayNotificationDialog(parameters);
|
|
41 |
}
|
|
42 |
|
|
43 |
|
|
44 |
// -----------------------------------------------------------------------------
|
|
45 |
// PolicyEngineUI::~PolicyEngineUI()
|
|
46 |
// -----------------------------------------------------------------------------
|
|
47 |
PolicyEngineUI::~PolicyEngineUI()
|
|
48 |
{
|
|
49 |
|
|
50 |
}
|
|
51 |
|
|
52 |
|
|
53 |
// -----------------------------------------------------------------------------
|
|
54 |
// PolicyEngineUI::DisplayNotificationDialog()
|
|
55 |
// Read the parameters sent from client
|
|
56 |
// -----------------------------------------------------------------------------
|
|
57 |
void PolicyEngineUI::DisplayNotificationDialog(const QVariantMap& parameters)
|
|
58 |
{
|
|
59 |
LOGSTRING( "+ DisplayNotificationDialog +" );
|
|
60 |
QVariantMap::const_iterator i = parameters.constBegin();
|
|
61 |
|
|
62 |
while (i != parameters.constEnd())
|
|
63 |
{
|
|
64 |
if (i.key().toAscii() == "serverdisplayname")
|
|
65 |
{
|
|
66 |
iServerName = i.value().toString();
|
|
67 |
}
|
|
68 |
else if (i.key().toAscii() == "fingerprint")
|
|
69 |
{
|
|
70 |
iFingerprint = i.value().toString();
|
|
71 |
}
|
|
72 |
++i;
|
|
73 |
}
|
|
74 |
|
|
75 |
TBuf<50> server(iServerName.utf16());
|
|
76 |
TBuf<10> buffer(iFingerprint.utf16());
|
|
77 |
|
|
78 |
LOGSTRING2( "serverdisplayname %S", &server );
|
|
79 |
LOGSTRING2( "fingerprint %S", &buffer );
|
|
80 |
|
|
81 |
ShowInputDialog();
|
|
82 |
LOGSTRING( "- DisplayNotificationDialog -" );
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// PolicyEngineUI::ShowInputDialog()
|
|
88 |
// Show the accept control dialog
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
void PolicyEngineUI::ShowInputDialog()
|
|
91 |
{
|
|
92 |
LOGSTRING( "+ ShowInputDialog +" );
|
|
93 |
HbDocumentLoader loader;
|
|
94 |
bool ok = false;
|
|
95 |
loader.load(":/xml/dialog.docml", &ok);
|
|
96 |
if (!ok)
|
|
97 |
{
|
|
98 |
return;
|
|
99 |
}
|
|
100 |
|
|
101 |
HbDialog *dialog1 =
|
|
102 |
qobject_cast<HbDialog *> (loader.findWidget("dialog"));
|
|
103 |
|
|
104 |
//set heading content
|
|
105 |
HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
|
|
106 |
"qtl_dialog_pri_heading"));
|
|
107 |
QString heading(hbTrId("txt_device_update_title_security_information"));
|
|
108 |
contentheading->setPlainText(heading);
|
|
109 |
|
|
110 |
//set body content
|
|
111 |
HbLabel *contentbody = qobject_cast<HbLabel *> (loader.findWidget(
|
|
112 |
"qtl_dialog_pri5"));
|
|
113 |
|
|
114 |
QString body(
|
|
115 |
(hbTrId("txt_device_update_info_1_server_wants_to_contro").arg(
|
|
116 |
iServerName)));
|
|
117 |
contentbody->setTextWrapping(Hb::TextWordWrap);
|
|
118 |
contentbody->setPlainText(body);
|
|
119 |
|
|
120 |
HbAction *primaryAction = qobject_cast<HbAction *> (
|
|
121 |
dialog1->actions().at(0));
|
|
122 |
HbAction *secondaryAction = qobject_cast<HbAction *> (
|
|
123 |
dialog1->actions().at(1));
|
|
124 |
|
|
125 |
//set dialog properties
|
|
126 |
dialog1->setTimeout(HbPopup::NoTimeout);
|
|
127 |
dialog1->setDismissPolicy(HbPopup::NoDismiss);
|
|
128 |
|
|
129 |
QObject::connect(primaryAction, SIGNAL(triggered()), this,
|
|
130 |
SLOT(onOKSelected()));
|
|
131 |
QObject::connect(secondaryAction, SIGNAL(triggered()), this,
|
|
132 |
SLOT(onCancelSelected()));
|
|
133 |
|
66
|
134 |
emit applicationReady();
|
55
|
135 |
if (dialog1)
|
|
136 |
dialog1->show();
|
|
137 |
|
|
138 |
LOGSTRING( "- ShowInputDialog -" );
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
// -----------------------------------------------------------------------------
|
|
143 |
// PolicyEngineUI::onOKSelected()
|
|
144 |
// Show the user input dialog once control is accepted
|
|
145 |
// -----------------------------------------------------------------------------
|
|
146 |
void PolicyEngineUI::onOKSelected()
|
|
147 |
{
|
|
148 |
|
|
149 |
LOGSTRING( "+ onOKSelected +" );
|
|
150 |
|
|
151 |
HbDocumentLoader loader;
|
|
152 |
bool ok = false;
|
|
153 |
loader.load(":/xml/InputDialog.docml", &ok);
|
|
154 |
if (!ok)
|
|
155 |
{
|
|
156 |
return;
|
|
157 |
}
|
|
158 |
|
|
159 |
mdialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
|
|
160 |
|
|
161 |
//set heading content
|
|
162 |
HbLabel *contentheading = qobject_cast<HbLabel *> (loader.findWidget(
|
|
163 |
"qtl_dialog_pri_heading"));
|
|
164 |
QString heading(hbTrId("txt_device_update_title_security_information"));
|
|
165 |
contentheading->setPlainText(heading);
|
|
166 |
|
|
167 |
//set label
|
|
168 |
HbLabel *contentlabel = qobject_cast<HbLabel *> (loader.findWidget(
|
|
169 |
"HeadingLabel"));
|
|
170 |
contentlabel->setTextWrapping(Hb::TextWordWrap);
|
|
171 |
QString label(
|
|
172 |
(hbTrId("txt_device_update_info_enter_first_4_characters_of").arg(
|
|
173 |
iServerName)));
|
|
174 |
contentlabel ->setPlainText(label);
|
|
175 |
|
|
176 |
//set length for editline
|
|
177 |
mContentEdit = qobject_cast<HbLineEdit*> (loader.findWidget("InputLine"));
|
|
178 |
mContentEdit->setMaxLength(KMaxCodeLength);
|
|
179 |
|
|
180 |
//set dialog properties
|
|
181 |
mdialog->setTimeout(HbPopup::NoTimeout);
|
|
182 |
mdialog->setDismissPolicy(HbPopup::NoDismiss);
|
|
183 |
|
|
184 |
HbAction* primaryAction = (HbAction*) (mdialog->actions().at(0));
|
|
185 |
HbAction *secondaryAction = (HbAction*) (mdialog->actions().at(1));
|
|
186 |
primaryAction->setEnabled(false);
|
|
187 |
|
|
188 |
QObject::connect(primaryAction, SIGNAL(triggered()), this,
|
|
189 |
SLOT(establishTrust()));
|
|
190 |
QObject::connect(secondaryAction, SIGNAL(triggered()), this,
|
|
191 |
SLOT(cancelTrust()));
|
|
192 |
QObject::connect(mContentEdit, SIGNAL(contentsChanged()), this,
|
|
193 |
SLOT(codeTextChanged()));
|
|
194 |
|
|
195 |
if (mdialog)
|
|
196 |
mdialog->show();
|
|
197 |
|
|
198 |
LOGSTRING( "- onOKSelected -" );
|
|
199 |
}
|
|
200 |
|
|
201 |
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
// PolicyEngineUI::onCancelSelected()
|
|
204 |
// -----------------------------------------------------------------------------
|
|
205 |
void PolicyEngineUI::onCancelSelected()
|
|
206 |
{
|
|
207 |
LOGSTRING( "+ onCancelSelected +" );
|
|
208 |
|
|
209 |
QVariantMap result;
|
|
210 |
|
|
211 |
result.insert("keyResponse", -1);
|
|
212 |
emit
|
|
213 |
deviceDialogData(result);
|
|
214 |
|
|
215 |
emit
|
|
216 |
deviceDialogClosed();
|
|
217 |
|
|
218 |
LOGSTRING( "- onCancelSelected -" );
|
|
219 |
}
|
|
220 |
|
|
221 |
|
|
222 |
// -----------------------------------------------------------------------------
|
|
223 |
// PolicyEngineUI::onTrustCreation()
|
|
224 |
// -----------------------------------------------------------------------------
|
|
225 |
void PolicyEngineUI::onTrustCreation()
|
|
226 |
{
|
|
227 |
LOGSTRING( "+ onTrustCreation +" );
|
|
228 |
QVariantMap result;
|
|
229 |
|
|
230 |
result.insert("keyResponse", 0);
|
|
231 |
emit
|
|
232 |
deviceDialogData(result);
|
|
233 |
|
|
234 |
emit
|
|
235 |
deviceDialogClosed();
|
|
236 |
|
|
237 |
LOGSTRING( "- onTrustCreation -" );
|
|
238 |
}
|
|
239 |
|
|
240 |
|
|
241 |
// -----------------------------------------------------------------------------
|
|
242 |
// PolicyEngineUI::establishTrust()
|
|
243 |
// -----------------------------------------------------------------------------
|
|
244 |
void PolicyEngineUI::establishTrust()
|
|
245 |
{
|
|
246 |
LOGSTRING( "+ establishTrust +" );
|
|
247 |
bool retVal; // return value from code verification API.
|
|
248 |
estbTrustCount--;
|
|
249 |
retVal = verifyFingerPrint();
|
|
250 |
|
|
251 |
if (retVal)
|
|
252 |
{
|
|
253 |
LOGSTRING( "Trust Created" );
|
|
254 |
//Reset the counter.
|
|
255 |
estbTrustCount = 0;
|
|
256 |
onTrustCreation();
|
|
257 |
|
|
258 |
}
|
|
259 |
else
|
|
260 |
{
|
|
261 |
//check the number of tries.
|
|
262 |
if (estbTrustCount == 0)
|
|
263 |
{
|
|
264 |
//Access denied.
|
|
265 |
LOGSTRING( "Access Denied" );
|
|
266 |
HbMessageBox *msgBox = new HbMessageBox();
|
|
267 |
msgBox->setHeadingWidget(new HbLabel(hbTrId(
|
|
268 |
"txt_device_update_title_security_information")));
|
|
269 |
|
|
270 |
msgBox->setText(hbTrId(
|
|
271 |
"txt_device_update_info_security_info_access_denied"));
|
|
272 |
msgBox->setTimeout(HbDialog::NoTimeout);
|
|
273 |
msgBox->setDismissPolicy(HbDialog::NoDismiss);
|
|
274 |
|
|
275 |
HbAction *action = (HbAction*) (msgBox->actions().at(0));
|
|
276 |
QObject::connect(action, SIGNAL(triggered()), this,
|
|
277 |
SLOT(onCancelSelected()));
|
|
278 |
|
|
279 |
msgBox->show();
|
|
280 |
}
|
|
281 |
else
|
|
282 |
{
|
|
283 |
LOGSTRING2( "tries left %i", estbTrustCount );
|
|
284 |
//Code didnot match.
|
|
285 |
HbDocumentLoader loader;
|
|
286 |
bool ok = false;
|
|
287 |
loader.load(":/xml/InputDialog.docml", &ok);
|
|
288 |
if (!ok)
|
|
289 |
{
|
|
290 |
return;
|
|
291 |
}
|
|
292 |
|
|
293 |
mdialog = qobject_cast<HbDialog *> (loader.findWidget("dialog"));
|
|
294 |
|
|
295 |
//set heading content
|
|
296 |
HbLabel *contentheading = qobject_cast<HbLabel *> (
|
|
297 |
loader.findWidget("qtl_dialog_pri_heading"));
|
|
298 |
contentheading->setTextWrapping(Hb::TextWordWrap);
|
|
299 |
QString heading(hbTrId(
|
|
300 |
"txt_device_update_title_security_information"));
|
|
301 |
contentheading->setPlainText(heading);
|
|
302 |
|
|
303 |
//set label
|
|
304 |
HbLabel *contentlabel = qobject_cast<HbLabel *> (
|
|
305 |
loader.findWidget("HeadingLabel"));
|
|
306 |
QString
|
|
307 |
label(
|
|
308 |
(hbTrId(
|
|
309 |
"txt_device_update_info_security_information_did_no").arg(
|
|
310 |
estbTrustCount)));
|
|
311 |
|
|
312 |
contentlabel->setTextWrapping(Hb::TextWordWrap);
|
|
313 |
contentlabel->setPlainText(label);
|
|
314 |
|
|
315 |
mContentEdit = qobject_cast<HbLineEdit*> (loader.findWidget(
|
|
316 |
"InputLine"));
|
|
317 |
mContentEdit->setMaxLength(KMaxCodeLength);
|
|
318 |
|
|
319 |
mdialog->setTimeout(HbPopup::NoTimeout);
|
|
320 |
mdialog->setDismissPolicy(HbPopup::NoDismiss);
|
|
321 |
|
|
322 |
HbAction* primaryAction = qobject_cast<HbAction*> (
|
|
323 |
mdialog->actions().at(0));
|
|
324 |
HbAction *secondaryAction = qobject_cast<HbAction*> (
|
|
325 |
mdialog->actions().at(1));
|
|
326 |
primaryAction->setEnabled(false);
|
|
327 |
|
|
328 |
QObject::connect(primaryAction, SIGNAL(triggered()), this,
|
|
329 |
SLOT(establishTrust()));
|
|
330 |
QObject::connect(secondaryAction, SIGNAL(triggered()), this,
|
|
331 |
SLOT(cancelTrust()));
|
|
332 |
QObject::connect(mContentEdit, SIGNAL(contentsChanged()), this,
|
|
333 |
SLOT(codeTextChanged()));
|
|
334 |
|
|
335 |
if (mdialog)
|
|
336 |
mdialog->show();
|
|
337 |
}
|
|
338 |
}
|
|
339 |
LOGSTRING( "- establishTrust -" );
|
|
340 |
}
|
|
341 |
|
|
342 |
|
|
343 |
// -----------------------------------------------------------------------------
|
|
344 |
// PolicyEngineUI::cancelTrust()
|
|
345 |
// -----------------------------------------------------------------------------
|
|
346 |
void PolicyEngineUI::cancelTrust()
|
|
347 |
{
|
|
348 |
LOGSTRING( "+ cancelTrust +" );
|
|
349 |
//Reset the counter.
|
|
350 |
estbTrustCount = 0;
|
|
351 |
|
|
352 |
QVariantMap result;
|
|
353 |
result.insert("keyResponse", -1);
|
|
354 |
emit
|
|
355 |
deviceDialogData(result);
|
|
356 |
|
|
357 |
emit
|
|
358 |
deviceDialogClosed();
|
|
359 |
LOGSTRING( "- cancelTrust -" );
|
|
360 |
}
|
|
361 |
|
|
362 |
|
|
363 |
// -----------------------------------------------------------------------------
|
|
364 |
// PolicyEngineUI::setDeviceDialogParameters()
|
|
365 |
// -----------------------------------------------------------------------------
|
|
366 |
bool PolicyEngineUI::setDeviceDialogParameters(const QVariantMap ¶meters)
|
|
367 |
{
|
|
368 |
Q_UNUSED(parameters);
|
|
369 |
LOGSTRING( "+ setDeviceDialogParameters +" );
|
|
370 |
return true;
|
|
371 |
}
|
|
372 |
|
|
373 |
|
|
374 |
// -----------------------------------------------------------------------------
|
|
375 |
// PolicyEngineUI::deviceDialogError()
|
|
376 |
// Get error
|
|
377 |
// -----------------------------------------------------------------------------
|
|
378 |
int PolicyEngineUI::deviceDialogError() const
|
|
379 |
{
|
|
380 |
LOGSTRING( "+ deviceDialogError +" );
|
|
381 |
return 0;
|
|
382 |
}
|
|
383 |
|
|
384 |
|
|
385 |
// -----------------------------------------------------------------------------
|
|
386 |
// PolicyEngineUI::PolicyEngineUI()
|
|
387 |
// Close device dialog
|
|
388 |
// -----------------------------------------------------------------------------
|
|
389 |
void PolicyEngineUI::closeDeviceDialog(bool byClient)
|
|
390 |
{
|
|
391 |
Q_UNUSED(byClient);
|
|
392 |
LOGSTRING( "+ closeDeviceDialog +" );
|
|
393 |
close();
|
|
394 |
}
|
|
395 |
|
|
396 |
|
|
397 |
// -----------------------------------------------------------------------------
|
|
398 |
// PolicyEngineUI::PolicyEngineUI()
|
|
399 |
// Return display widget
|
|
400 |
// -----------------------------------------------------------------------------
|
|
401 |
HbDialog *PolicyEngineUI::deviceDialogWidget() const
|
|
402 |
{
|
|
403 |
LOGSTRING( "+ deviceDialogWidget +" );
|
|
404 |
return const_cast<PolicyEngineUI*> (this);
|
|
405 |
}
|
|
406 |
|
|
407 |
|
|
408 |
// -----------------------------------------------------------------------------
|
|
409 |
// PolicyEngineUI::PolicyEngineUI()
|
|
410 |
// Verify the user entered code
|
|
411 |
// -----------------------------------------------------------------------------
|
|
412 |
bool PolicyEngineUI::verifyFingerPrint()
|
|
413 |
{
|
|
414 |
LOGSTRING( "+ verifyFingerPrint +" );
|
|
415 |
|
|
416 |
QString enteredCode = mContentEdit->text();
|
|
417 |
TBuf<10> buffer(enteredCode.utf16());
|
|
418 |
|
|
419 |
LOGSTRING2( "User entered code %i", &buffer);
|
|
420 |
LOGSTRING2( "User entered code %S", &buffer);
|
|
421 |
|
|
422 |
if (enteredCode.compare(iFingerprint, Qt::CaseInsensitive) == 0)
|
|
423 |
{
|
|
424 |
LOGSTRING( "+ fingerprint MATCH !!!! +" );
|
|
425 |
return true;
|
|
426 |
}
|
|
427 |
else
|
|
428 |
{
|
|
429 |
LOGSTRING( "+ fingerprint DOESNOT MATCH +" );
|
|
430 |
return false;
|
|
431 |
}
|
|
432 |
}
|
|
433 |
|
|
434 |
|
|
435 |
// -----------------------------------------------------------------------------
|
|
436 |
// PolicyEngineUI::codeTextChanged()
|
|
437 |
// checks the entered text length and enables the OK option accordingly.
|
|
438 |
// -----------------------------------------------------------------------------
|
|
439 |
void PolicyEngineUI::codeTextChanged()
|
|
440 |
{
|
|
441 |
QString str = mContentEdit->text();
|
|
442 |
|
|
443 |
if (str.length() >= KMaxCodeLength)
|
|
444 |
mdialog->actions().at(0)->setEnabled(true);
|
|
445 |
else
|
|
446 |
mdialog->actions().at(0)->setEnabled(false);
|
|
447 |
}
|