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: |
|
15 * Control Panel QT UI for TLS-based EAP methods configuration |
|
16 * |
|
17 */ |
|
18 |
|
19 /* |
|
20 * %version: 24 % |
|
21 */ |
|
22 |
|
23 // System includes |
|
24 #include <HbDataForm> |
|
25 #include <HbDataFormModel> |
|
26 #include <HbDataFormViewItem> |
|
27 #include <HbParameterLengthLimiter> |
|
28 #include <HbMessageBox> |
|
29 #include <HbAction> |
|
30 #include <HbLineEdit> |
|
31 #include <cpsettingformitemdata.h> |
|
32 #include <cpitemdatahelper.h> |
|
33 #include <eapqtvalidator.h> |
|
34 #include <eapqtexpandedeaptype.h> |
|
35 #include <eapqtcertificateinfo.h> |
|
36 #include <cppluginutility.h> |
|
37 |
|
38 // User includes |
|
39 #include "cpeapciphersuiteui.h" |
|
40 #include "cpeaptlsmethodsui.h" |
|
41 #include "cpeaptlsmethodsinnereapui.h" |
|
42 |
|
43 /*! |
|
44 * \class CpEapTlsMethodsUi |
|
45 * \brief Implementes TLS based methods configuration ui. |
|
46 */ |
|
47 |
|
48 // External function prototypes |
|
49 |
|
50 // Local constants |
|
51 |
|
52 /*! |
|
53 * ComboBox index is unkown |
|
54 */ |
|
55 static const int UnknownIndex = -1; |
|
56 /*! |
|
57 * Default index for ComboBox, used if no value has been stored |
|
58 */ |
|
59 static const int DefaultIndex = 0; |
|
60 /*! |
|
61 * Index of 'Not in use'in certificate selection lists. |
|
62 */ |
|
63 static const int NotInUseIndex = 0; |
|
64 |
|
65 // ======== LOCAL FUNCTIONS ======== |
|
66 |
|
67 // ======== MEMBER FUNCTIONS ======== |
|
68 |
|
69 /*! |
|
70 * Constructor. |
|
71 * |
|
72 * @param bearer Bearer type of the accessed configuration. |
|
73 * @param iapId IAP ID of the accessed configuration. |
|
74 * @param plugin Plugin. |
|
75 * @param outerHandle Outer handle. |
|
76 */ |
|
77 |
|
78 CpEapTlsMethodsUi::CpEapTlsMethodsUi( |
|
79 const EapQtConfigInterface::EapBearerType bearer, |
|
80 const int iapId, |
|
81 const EapQtPluginInfo &plugin, |
|
82 const EapQtPluginHandle& outerHandle) : |
|
83 mConfigIf(NULL), |
|
84 mPluginInfo(plugin), |
|
85 mOuterHandle(outerHandle), |
|
86 mForm(NULL), |
|
87 mModel(NULL), |
|
88 mItemDataHelper(NULL), |
|
89 mGroupItem(NULL), |
|
90 mUsernameAutomatic(NULL), |
|
91 mUsername(NULL), |
|
92 mRealmAutomatic(NULL), |
|
93 mRealm(NULL), |
|
94 mCaCertAutomatic(NULL), |
|
95 mCaCert(NULL), |
|
96 mPeapVersion(NULL), |
|
97 mInnerEapType(NULL), |
|
98 mGroupItemCs(NULL), |
|
99 mCurrentUserCert(0), |
|
100 mCurrentAuthorityCert(0), |
|
101 mCurrentPeapVersion(0), |
|
102 mCurrentInnerPlugin(0), |
|
103 mInnerEapMschapv2(0), |
|
104 mInnerEapGtc(0), |
|
105 mDefaultPluginInUse(false) |
|
106 { |
|
107 qDebug("CpEapTlsMethodsUi::CpEapTlsMethodsUi()"); |
|
108 |
|
109 // IAP must be valid in construction (check includes |
|
110 // EapQtConfigInterface::IapIdUndefined) |
|
111 if (iapId < 0) { |
|
112 QT_THROW(std::bad_alloc()); |
|
113 // scoped pointer gets deleted automaticaly on exception |
|
114 } |
|
115 |
|
116 // Get EAP config interface |
|
117 mConfigIf.reset(new EapQtConfigInterface(bearer, iapId)); |
|
118 |
|
119 // Request supported inner EAP types |
|
120 mPlugins.append(mConfigIf->supportedInnerTypes(mPluginInfo.pluginHandle())); |
|
121 |
|
122 // Create UI |
|
123 createUi(); |
|
124 } |
|
125 |
|
126 /*! |
|
127 * Destructor. |
|
128 */ |
|
129 CpEapTlsMethodsUi::~CpEapTlsMethodsUi() |
|
130 { |
|
131 qDebug("CpEapTlsMethodsUi::~CpEapTlsMethodsUi()"); |
|
132 |
|
133 // mEapQtConfigInterface: scoped pointer deleted automatically |
|
134 // mValidatorRealm: scoped pointer deleted automatically |
|
135 // mValidatorUsername: scoped pointer deleted automatically |
|
136 } |
|
137 |
|
138 /*! |
|
139 * Calls inner UI instance |
|
140 * |
|
141 * @return pointer to inner UI instance |
|
142 */ |
|
143 CpBaseSettingView *CpEapTlsMethodsUi::innerUiInstance() |
|
144 { |
|
145 return mConfigIf->uiInstance(mPluginInfo.pluginHandle(), |
|
146 mPlugins.at(mCurrentInnerPlugin).pluginHandle()); |
|
147 } |
|
148 |
|
149 /*! |
|
150 * Creates TLS based methods UI and initilizes settings read via |
|
151 * EapQtConfigInterface |
|
152 */ |
|
153 void CpEapTlsMethodsUi::createUi() |
|
154 { |
|
155 qDebug("CpEapTlsMethodsUi::createUi()"); |
|
156 |
|
157 // Read EAP Configurations |
|
158 bool configurationRead = mConfigIf->readConfiguration(mOuterHandle, mPluginInfo.pluginHandle(), |
|
159 mEapConfig); |
|
160 if (!configurationRead) { |
|
161 qDebug("CpEapTlsMethodsUi::createUi - read configuration failed."); |
|
162 } |
|
163 |
|
164 // Construct TLS based methods settings UI |
|
165 mForm = new HbDataForm(); |
|
166 this->setWidget(mForm); |
|
167 CpPluginUtility::addCpItemPrototype(mForm); |
|
168 mModel = new HbDataFormModel(mForm); |
|
169 |
|
170 // Create settings group |
|
171 mGroupItem = new HbDataFormModelItem(HbDataFormModelItem::GroupItem, |
|
172 HbParameterLengthLimiter( |
|
173 hbTrId("txt_occ_subhead_eap_module_settings")).arg( |
|
174 mPluginInfo.localizationId())); |
|
175 mModel->appendDataFormItem(mGroupItem); |
|
176 |
|
177 // The parameter given as 0 is a HbDataForm pointer, not parent |
|
178 mItemDataHelper = new CpItemDataHelper(0); |
|
179 mItemDataHelper->setParent(this); |
|
180 |
|
181 // Create method specific UI |
|
182 if (mPluginInfo.pluginHandle() == EapQtPluginHandle::PluginEapTls) { |
|
183 createTlsUi(); |
|
184 } |
|
185 else if (mPluginInfo.pluginHandle() == EapQtPluginHandle::PluginEapTtls) { |
|
186 createTtlsUi(); |
|
187 } |
|
188 else if (mPluginInfo.pluginHandle() == EapQtPluginHandle::PluginPeap) { |
|
189 createPeapUi(); |
|
190 } |
|
191 else { |
|
192 qDebug("CpEapTlsMethodsUi::createUi() - unknown EAP method"); |
|
193 } |
|
194 |
|
195 // Load cipher suites view |
|
196 QVariant variant; |
|
197 variant = mEapConfig.value(EapQtConfig::CipherSuites); |
|
198 mGroupItemCs = new CpEapCiphersuiteUi(variant); |
|
199 mModel->appendDataFormItem(mGroupItemCs); |
|
200 |
|
201 mItemDataHelper->bindToForm(mForm); |
|
202 mForm->setModel(mModel); |
|
203 |
|
204 // Connect signal to add validators |
|
205 bool connected = connect(mForm, SIGNAL( itemShown(const QModelIndex&) ), this, |
|
206 SLOT( setValidator(const QModelIndex) )); |
|
207 Q_ASSERT(connected); |
|
208 |
|
209 // Expand TLS based method settings group |
|
210 mForm->setExpanded(mModel->indexFromItem(mGroupItem), true); |
|
211 } |
|
212 |
|
213 /*! |
|
214 * Creates EAP-TLS settings UI |
|
215 */ |
|
216 void CpEapTlsMethodsUi::createTlsUi() |
|
217 { |
|
218 qDebug("CpEapTlsMethodsUi::createTlsUi()"); |
|
219 // Create common TLS settings componenets |
|
220 createAuthorityCerts(); |
|
221 createUserCerts(); |
|
222 createUsername(); |
|
223 createRealm(); |
|
224 } |
|
225 |
|
226 /*! |
|
227 * Creates EAP-TTLS settings UI |
|
228 */ |
|
229 void CpEapTlsMethodsUi::createTtlsUi() |
|
230 { |
|
231 qDebug("CpEapTlsMethodsUi::createTtlsUi()"); |
|
232 // Create common TLS settings componenets |
|
233 createAuthorityCerts(); |
|
234 createUserCerts(); |
|
235 createUsername(); |
|
236 createRealm(); |
|
237 |
|
238 // Create Inner Eap type selection comboBox and configuration button |
|
239 createInnerMethod(); |
|
240 } |
|
241 |
|
242 /*! |
|
243 * Creates PEAP settings UI |
|
244 */ |
|
245 void CpEapTlsMethodsUi::createPeapUi() |
|
246 { |
|
247 qDebug("CpEapTlsMethodsUi::createPeapUi()"); |
|
248 // Create common TLS settings componenets |
|
249 createAuthorityCerts(); |
|
250 createUserCerts(); |
|
251 createUsername(); |
|
252 createRealm(); |
|
253 |
|
254 // Create PEAP version selection comboBox |
|
255 createPeapVersion(); |
|
256 |
|
257 // Create Inner Eap type selection comboBox and configuration button |
|
258 createInnerMethod(); |
|
259 |
|
260 // If not stored inner Eap type, set default inner EAP method |
|
261 // according PEAP version |
|
262 if (mDefaultPluginInUse) { |
|
263 defaultInnerPlugin(); |
|
264 } |
|
265 } |
|
266 /*! |
|
267 * Creates Username group: |
|
268 * Generate automatically checkBox and username lineEdit |
|
269 */ |
|
270 void CpEapTlsMethodsUi::createUsername() |
|
271 { |
|
272 qDebug("CpEapTlsMethodsUi::createUsername()"); |
|
273 // UsernameAutomatic |
|
274 mUsernameAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId( |
|
275 "txt_occ_setlabel_user_name")); |
|
276 mUsernameAutomatic->setContentWidgetData("text", hbTrId( |
|
277 "txt_occ_setlabel_user_name_val_generate_automatica")); |
|
278 // Initialize the value from EapQtConfig |
|
279 // Generate username automatically is selected by default |
|
280 mUsernameAutomatic->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value( |
|
281 EapQtConfig::UsernameAutomatic).toBool())); |
|
282 // Connect signal to disable/enable username when usernameAutomatic changed |
|
283 mForm->addConnection(mUsernameAutomatic, SIGNAL(stateChanged(int)), this, |
|
284 SLOT(usernameAutomaticChanged(int))); |
|
285 mGroupItem->appendChild(mUsernameAutomatic); |
|
286 |
|
287 //Username |
|
288 mUsername = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId( |
|
289 "txt_occ_setlabel_user_name")); |
|
290 mUsername->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Username)); |
|
291 // Dim username if usernameAutomatic selected |
|
292 usernameAutomaticChanged(mUsernameAutomatic->contentWidgetData("checkState") == Qt::Checked); |
|
293 mGroupItem->appendChild(mUsername); |
|
294 } |
|
295 |
|
296 /*! |
|
297 * Creates Realm group: |
|
298 * Generate automatically checkBox and realm lineEdit |
|
299 */ |
|
300 void CpEapTlsMethodsUi::createRealm() |
|
301 { |
|
302 qDebug("CpEapTlsMethodsUi::createRealm()"); |
|
303 // RealmAutomatic |
|
304 mRealmAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId( |
|
305 "txt_occ_setlabel_realm")); |
|
306 mRealmAutomatic->setContentWidgetData("text", hbTrId( |
|
307 "txt_occ_setlabel_realm_val_generate_automatically")); |
|
308 // Initialize the value from EapQtConfig |
|
309 // Generate realm automatically is selected by default |
|
310 mRealmAutomatic->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value( |
|
311 EapQtConfig::RealmAutomatic).toBool())); |
|
312 // connect signal to disable/enable realm when realmAutomatic changed |
|
313 mForm->addConnection(mRealmAutomatic, SIGNAL(stateChanged(int)), this, |
|
314 SLOT(realmAutomaticChanged(int))); |
|
315 mGroupItem->appendChild(mRealmAutomatic); |
|
316 |
|
317 //Realm |
|
318 mRealm = new CpSettingFormItemData(HbDataFormModelItem::TextItem, hbTrId( |
|
319 "txt_occ_setlabel_realm")); |
|
320 mRealm->setContentWidgetData("text", mEapConfig.value(EapQtConfig::Realm)); |
|
321 // Dim realm if realmAutomatic selected |
|
322 realmAutomaticChanged(mRealmAutomatic->contentWidgetData("checkState") == Qt::Checked); |
|
323 mGroupItem->appendChild(mRealm); |
|
324 } |
|
325 |
|
326 /*! |
|
327 * Creates User certificate selection comboBox |
|
328 */ |
|
329 void CpEapTlsMethodsUi::createUserCerts() |
|
330 { |
|
331 qDebug("CpEapTlsMethodsUi::createUserCerts()"); |
|
332 // Create User certificate comboBox |
|
333 CpSettingFormItemData *userCertList = new CpSettingFormItemData( |
|
334 HbDataFormModelItem::ComboBoxItem, |
|
335 hbTrId("txt_occ_setlabel_user_certificate")); |
|
336 |
|
337 // Stored certificate |
|
338 QList<QVariant> storedCertsList = mEapConfig.value(EapQtConfig::UserCertificate).toList(); |
|
339 EapQtCertificateInfo storedCert; |
|
340 if (!storedCertsList.empty() && storedCertsList[0].canConvert<EapQtCertificateInfo> ()) { |
|
341 // Stored certificate found, index is still unknown |
|
342 storedCert = storedCertsList[0].value<EapQtCertificateInfo> (); |
|
343 mCurrentUserCert = UnknownIndex; |
|
344 } |
|
345 else { |
|
346 // no stored certificate, use 'not in use' |
|
347 mCurrentUserCert = DefaultIndex; |
|
348 } |
|
349 |
|
350 // User certificates found from system |
|
351 mUserCerts = mConfigIf->userCertificates(); |
|
352 |
|
353 // List of comboBox items |
|
354 QStringList items; |
|
355 // Add 'Not in use' to comboBox list |
|
356 items << hbTrId("txt_occ_setlabel_user_certificate_val_not_in_use"); |
|
357 // Add certificates to comboBox list and find index of stored certificate |
|
358 for (int i = 0; i < mUserCerts.count(); ++i) { |
|
359 items << mUserCerts.at(i).value(EapQtCertificateInfo::CertificateLabel).toString(); |
|
360 if (mCurrentUserCert == UnknownIndex |
|
361 && storedCert.value(EapQtCertificateInfo::SubjectKeyId) |
|
362 == mUserCerts.at(i).value(EapQtCertificateInfo::SubjectKeyId)) { |
|
363 mCurrentUserCert = i + 1; |
|
364 } |
|
365 } |
|
366 if (mCurrentUserCert == UnknownIndex) { |
|
367 // Stored certificate not found in the certificate list |
|
368 qDebug("CpEapTlsMethodsUi::createUserCerts() - stored certificate not in the list"); |
|
369 mCurrentUserCert = DefaultIndex; |
|
370 } |
|
371 |
|
372 // Initialize comboBox |
|
373 userCertList->setContentWidgetData("items", items); |
|
374 userCertList->setContentWidgetData("currentIndex", mCurrentUserCert); |
|
375 |
|
376 // Get info when user certificate selection has been changed |
|
377 mForm->addConnection(userCertList, SIGNAL(currentIndexChanged(int)), this, |
|
378 SLOT(userCertChanged(int))); |
|
379 mGroupItem->appendChild(userCertList); |
|
380 } |
|
381 |
|
382 /*! |
|
383 * Creates Authority certs group: |
|
384 * Select automatically check box and certificate comboBox |
|
385 */ |
|
386 void CpEapTlsMethodsUi::createAuthorityCerts() |
|
387 { |
|
388 qDebug("CpEapTlsMethodsUi::createAuthorityCerts()"); |
|
389 // Select Authority Certificate Automatically |
|
390 mCaCertAutomatic = new CpSettingFormItemData(HbDataFormModelItem::CheckBoxItem, hbTrId( |
|
391 "txt_occ_setlabel_authority_certificate")); |
|
392 mCaCertAutomatic->setContentWidgetData("text", hbTrId( |
|
393 "txt_occ_setlabel_authority_certificate_val_select")); |
|
394 // Initialize the value from EapQtConfig |
|
395 // Select CA Cert automatically is selected by default |
|
396 mCaCertAutomatic->setContentWidgetData("checkState", boolToCheckState(mEapConfig.value( |
|
397 EapQtConfig::AuthorityCertificateAutomatic).toBool())); |
|
398 // connect signal to disable/enable CA cert when CaCertAutomatic changed |
|
399 mForm->addConnection(mCaCertAutomatic, SIGNAL(stateChanged(int)), this, |
|
400 SLOT(authorityCertAutomaticChanged(int))); |
|
401 mGroupItem->appendChild(mCaCertAutomatic); |
|
402 |
|
403 // Authority certificate comboBox |
|
404 mCaCert = new CpSettingFormItemData(HbDataFormModelItem::ComboBoxItem, |
|
405 hbTrId("txt_occ_setlabel_authority_certificate")); |
|
406 |
|
407 // Stored certificate from EAP configuration |
|
408 QList<QVariant> storedCertsList = mEapConfig.value(EapQtConfig::AuthorityCertificate).toList(); |
|
409 EapQtCertificateInfo storedCert; |
|
410 if (!storedCertsList.empty() && storedCertsList[0].canConvert<EapQtCertificateInfo> ()) { |
|
411 // Stored certificate found, index is still unknown |
|
412 storedCert = storedCertsList[0].value<EapQtCertificateInfo> (); |
|
413 mCurrentAuthorityCert = UnknownIndex; |
|
414 } |
|
415 else { |
|
416 // no selected certificate, use 'not in use' |
|
417 mCurrentAuthorityCert = DefaultIndex; |
|
418 } |
|
419 |
|
420 // Authority certificates found from system |
|
421 mAuthorityCerts = mConfigIf->certificateAuthorityCertificates(); |
|
422 |
|
423 // List of comboBox items |
|
424 QStringList items; |
|
425 // Add 'Not in use' to comboBox list |
|
426 items << hbTrId("txt_occ_setlabel_authority_certificate_val_not_in"); |
|
427 // Add certificates to comboBox list and find index of stored certificate |
|
428 for (int i = 0; i < mAuthorityCerts.count(); ++i) { |
|
429 items << mAuthorityCerts.at(i).value(EapQtCertificateInfo::CertificateLabel).toString(); |
|
430 if (mCurrentAuthorityCert == UnknownIndex |
|
431 && storedCert.value(EapQtCertificateInfo::SubjectKeyId) |
|
432 == mAuthorityCerts.at(i).value(EapQtCertificateInfo::SubjectKeyId)) { |
|
433 mCurrentAuthorityCert = i + 1; |
|
434 } |
|
435 } |
|
436 if (mCurrentAuthorityCert == UnknownIndex) { |
|
437 // Selected certificate not found in the certificate list |
|
438 mCurrentAuthorityCert = DefaultIndex; |
|
439 } |
|
440 |
|
441 // Initialize Authority certificates comboBox |
|
442 mCaCert->setContentWidgetData("items", items); |
|
443 mCaCert->setContentWidgetData("currentIndex", mCurrentAuthorityCert); |
|
444 |
|
445 // Get info when authority certificate selection has been changed |
|
446 mForm->addConnection(mCaCert, SIGNAL(currentIndexChanged(int)), this, |
|
447 SLOT(authorityCertChanged(int))); |
|
448 // Dim authority certificate if select automatically checked |
|
449 authorityCertAutomaticChanged(mCaCertAutomatic->contentWidgetData("checkState") == Qt::Checked); |
|
450 mGroupItem->appendChild(mCaCert); |
|
451 } |
|
452 |
|
453 /*! |
|
454 * Creates PEAP version selection comboBox |
|
455 */ |
|
456 void CpEapTlsMethodsUi::createPeapVersion() |
|
457 { |
|
458 qDebug("CpEapTlsMethodsUi::createPeapVersion()"); |
|
459 // Create PEAP version comboBox |
|
460 mPeapVersion = new CpSettingFormItemData( |
|
461 HbDataFormModelItem::ComboBoxItem, |
|
462 hbTrId("txt_occ_setlabel_peap_version")); |
|
463 |
|
464 // Add items to comboBox List |
|
465 QStringList items; |
|
466 items << hbTrId("txt_occ_setlabel_peap_version_val_peapv0") |
|
467 << hbTrId("txt_occ_setlabel_peap_version_val_peapv1") |
|
468 << hbTrId("txt_occ_setlabel_peap_version_val_peapv0_or_peapv1"); |
|
469 mPeapVersion->setContentWidgetData("items", items); |
|
470 |
|
471 // Initialize PEAP version from EAP configuration |
|
472 if (mEapConfig.value(EapQtConfig::PeapVersion0Allowed).toBool() |
|
473 && mEapConfig.value(EapQtConfig::PeapVersion1Allowed).toBool()) { |
|
474 // PEAPv0 or PEAPv1 |
|
475 mCurrentPeapVersion = PeapVersionBoth; |
|
476 } |
|
477 else if (mEapConfig.value(EapQtConfig::PeapVersion1Allowed).toBool()) { |
|
478 // PEAPv1 |
|
479 mCurrentPeapVersion = PeapVersion1; |
|
480 } |
|
481 else if (mEapConfig.value(EapQtConfig::PeapVersion0Allowed).toBool()) { |
|
482 // PEAPv0 |
|
483 mCurrentPeapVersion = PeapVersion0; |
|
484 } |
|
485 else { |
|
486 qDebug("CpEapTlsMethodsUi::createPeapVersion() - unknown version"); |
|
487 // Set default (PEAPv0 or PEAPv1) |
|
488 mCurrentPeapVersion = PeapVersionBoth; |
|
489 } |
|
490 mPeapVersion->setContentWidgetData("currentIndex", mCurrentPeapVersion); |
|
491 |
|
492 // Get info when PEAP version selection has been changed |
|
493 mForm->addConnection(mPeapVersion, SIGNAL(currentIndexChanged(int)), this, |
|
494 SLOT(peapVersionChanged(int))); |
|
495 mGroupItem->appendChild(mPeapVersion); |
|
496 } |
|
497 |
|
498 /*! |
|
499 * Creates inner EAP type selection comboBox and configure button |
|
500 */ |
|
501 void CpEapTlsMethodsUi::createInnerMethod() |
|
502 { |
|
503 qDebug("CpEapTlsMethodsUi::createInnerMethod()"); |
|
504 // Create inner EAP type selection combo box |
|
505 createEapSelector(); |
|
506 // Create 'configure inner EAP type' button |
|
507 EapInnerMethodEntryItemData *eapEntry = NULL; |
|
508 eapEntry = new EapInnerMethodEntryItemData(this, *mItemDataHelper, |
|
509 hbTrId("txt_occ_button_inner_eap_type")); |
|
510 mGroupItem->appendChild(eapEntry); |
|
511 } |
|
512 |
|
513 /*! |
|
514 * Creates Combo box for inner EAP type selection |
|
515 */ |
|
516 void CpEapTlsMethodsUi::createEapSelector() |
|
517 { |
|
518 mInnerEapType = new CpSettingFormItemData( |
|
519 HbDataFormModelItem::ComboBoxItem, |
|
520 hbTrId("txt_occ_setlabel_inner_eap_type")); |
|
521 |
|
522 // Selected inner EAP type stored into the database |
|
523 QList<QVariant> currentEapList = mEapConfig.value(EapQtConfig::InnerType).toList(); |
|
524 EapQtPluginHandle readInnerEap; |
|
525 if (!currentEapList.empty() && currentEapList[0].canConvert<EapQtPluginHandle> ()) { |
|
526 readInnerEap = currentEapList[0].value<EapQtPluginHandle> (); |
|
527 mCurrentInnerPlugin = UnknownIndex; |
|
528 } |
|
529 else { |
|
530 // no selected inner EAP type, use the first one |
|
531 mCurrentInnerPlugin = DefaultIndex; |
|
532 mDefaultPluginInUse = true; |
|
533 } |
|
534 |
|
535 QStringList items; |
|
536 for (int i = 0; i < mPlugins.count(); ++i) { |
|
537 // Add certificate to comboBox list |
|
538 items << mPlugins.at(i).localizationId(); |
|
539 if (mCurrentInnerPlugin == UnknownIndex && readInnerEap.pluginId() |
|
540 == mPlugins.at(i).pluginHandle().pluginId()) { |
|
541 // Store index of selected certificate |
|
542 mCurrentInnerPlugin = i; |
|
543 } |
|
544 if (mPlugins.at(i).pluginHandle().pluginId() == EapQtPluginHandle::PluginEapMschapv2) { |
|
545 // Store index of EAP-MSCHAPv2 (used as default with PEAP and unauthenticated FAST) |
|
546 mInnerEapMschapv2 = i; |
|
547 } |
|
548 else if (mPlugins.at(i).pluginHandle().pluginId() == EapQtPluginHandle::PluginEapGtc) { |
|
549 // Store index of EAP-GTC (Used as default with PEAPv1) |
|
550 mInnerEapGtc = i; |
|
551 } |
|
552 } |
|
553 if (mCurrentInnerPlugin == UnknownIndex) { |
|
554 // Selected inner EAP type not found |
|
555 mCurrentInnerPlugin = DefaultIndex; |
|
556 mDefaultPluginInUse = true; |
|
557 } |
|
558 |
|
559 mInnerEapType->setContentWidgetData("items", items); |
|
560 mInnerEapType->setContentWidgetData("currentIndex", mCurrentInnerPlugin); |
|
561 |
|
562 mForm->addConnection(mInnerEapType, SIGNAL(currentIndexChanged(int)), this, |
|
563 SLOT(innerEapTypeChanged(int))); |
|
564 |
|
565 mGroupItem->appendChild(mInnerEapType); |
|
566 } |
|
567 |
|
568 /*! |
|
569 * Adds validators. |
|
570 * |
|
571 * @param modelIndex Model index |
|
572 */ |
|
573 void CpEapTlsMethodsUi::setValidator(const QModelIndex modelIndex) |
|
574 { |
|
575 qDebug("CpEapTlsMethodsUi::itemActivated"); |
|
576 |
|
577 HbDataFormViewItem *viewItem = qobject_cast<HbDataFormViewItem *> |
|
578 (mForm->itemByIndex(modelIndex)); |
|
579 HbDataFormModelItem *modelItem = mModel->itemFromIndex(modelIndex); |
|
580 |
|
581 if (modelItem == mUsername) { |
|
582 // When username lineEdit is activated (shown) first time, validator is added |
|
583 mValidatorUsername.reset(mConfigIf->validatorEap(mPluginInfo.pluginHandle().type(), |
|
584 EapQtConfig::Username)); |
|
585 HbLineEdit *edit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget()); |
|
586 mValidatorUsername->updateEditor(edit); |
|
587 } |
|
588 else if (modelItem == mRealm) { |
|
589 // When realm lineEdit is activated (shown) first time, validator is added |
|
590 mValidatorRealm.reset(mConfigIf->validatorEap(mPluginInfo.pluginHandle().type(), |
|
591 EapQtConfig::Realm)); |
|
592 HbLineEdit *edit = qobject_cast<HbLineEdit *> (viewItem->dataItemContentWidget()); |
|
593 mValidatorRealm->updateEditor(edit); |
|
594 } |
|
595 } |
|
596 |
|
597 /*! |
|
598 * Sets default Inner EAP method according PEAP version |
|
599 */ |
|
600 void CpEapTlsMethodsUi::defaultInnerPlugin() |
|
601 { |
|
602 qDebug("CpEapTlsMethodsUi::defaultInnerPlugin()"); |
|
603 if (mCurrentPeapVersion == PeapVersion1) { |
|
604 mInnerEapType->setContentWidgetData("currentIndex", mInnerEapGtc); |
|
605 mCurrentInnerPlugin = mInnerEapGtc; |
|
606 } |
|
607 else { |
|
608 mInnerEapType->setContentWidgetData("currentIndex", mInnerEapMschapv2); |
|
609 mCurrentInnerPlugin = mInnerEapMschapv2; |
|
610 } |
|
611 } |
|
612 |
|
613 /*! |
|
614 * Stores the index of selected user certificate |
|
615 * |
|
616 * @param value Index of selected certificate. |
|
617 */ |
|
618 void CpEapTlsMethodsUi::userCertChanged(int value) |
|
619 { |
|
620 qDebug("CpEapTlsMethodsUi::userCertChanged()"); |
|
621 mCurrentUserCert = value; |
|
622 } |
|
623 |
|
624 /*! |
|
625 * Stores the index of selected authority certificate |
|
626 * |
|
627 * @param value Index of selected certificate. |
|
628 */ |
|
629 void CpEapTlsMethodsUi::authorityCertChanged(int value) |
|
630 { |
|
631 qDebug("CpEapTlsMethodsUi::authorityCertChanged()"); |
|
632 mCurrentAuthorityCert = value; |
|
633 } |
|
634 |
|
635 /*! |
|
636 * Stores the index of selected PEAP version |
|
637 * |
|
638 * @param value Index of selected PEAP version. |
|
639 */ |
|
640 void CpEapTlsMethodsUi::peapVersionChanged(int value) |
|
641 { |
|
642 qDebug("CpEapTlsMethodsUi::peapVersionChanged()"); |
|
643 mCurrentPeapVersion = value; |
|
644 defaultInnerPlugin(); |
|
645 } |
|
646 |
|
647 /*! |
|
648 * Stores the index of selected inner EAP type |
|
649 * |
|
650 * @param value Index of selected ineer EAP type. |
|
651 */ |
|
652 void CpEapTlsMethodsUi::innerEapTypeChanged(int value) |
|
653 { |
|
654 qDebug("CpEapTlsMethodsUi::innerEapTypeChanged()"); |
|
655 mCurrentInnerPlugin = value; |
|
656 } |
|
657 |
|
658 /*! |
|
659 * Dims the username if generate username automatically has been selected. |
|
660 * |
|
661 * @param state Tells is generate automatically checked. |
|
662 */ |
|
663 void CpEapTlsMethodsUi::usernameAutomaticChanged(int state) |
|
664 { |
|
665 qDebug("CpEapTlsMethodsUi::usernameAutomaticChanged"); |
|
666 |
|
667 mUsername->setContentWidgetData("enabled", !checkStateToBool(state)); |
|
668 } |
|
669 |
|
670 /*! |
|
671 * Dims the realm if generate realm automatically has been selected. |
|
672 * |
|
673 * @param state Tells is generate automatically checked. |
|
674 */ |
|
675 void CpEapTlsMethodsUi::realmAutomaticChanged(int state) |
|
676 { |
|
677 qDebug("CpEapTlsMethodsUi::realmAutomaticChanged"); |
|
678 |
|
679 mRealm->setContentWidgetData("enabled", !checkStateToBool(state)); |
|
680 } |
|
681 |
|
682 /*! |
|
683 * Dims the authority certificate if select caCert automatically has been selected. |
|
684 * |
|
685 * @param state Tells is select automatically checked. |
|
686 */ |
|
687 void CpEapTlsMethodsUi::authorityCertAutomaticChanged(int state) |
|
688 { |
|
689 qDebug("CpEapTlsMethodsUi::authorityCertAutomaticChanged"); |
|
690 |
|
691 mCaCert->setContentWidgetData("enabled", !checkStateToBool(state)); |
|
692 } |
|
693 |
|
694 /*! |
|
695 * Converts check box state to boolean. |
|
696 * |
|
697 * @param state Check box state |
|
698 * |
|
699 * @return true if Check box is checked, false otherwise. |
|
700 */ |
|
701 bool CpEapTlsMethodsUi::checkStateToBool(const int state) |
|
702 { |
|
703 return (Qt::Unchecked == state ? false : true); |
|
704 } |
|
705 |
|
706 /*! |
|
707 * Converts boolean to check box state. |
|
708 * |
|
709 * @param state Tells is check box checked. |
|
710 * |
|
711 * @return Qt check state |
|
712 */ |
|
713 int CpEapTlsMethodsUi::boolToCheckState(const bool state) |
|
714 { |
|
715 return (false == state ? Qt::Unchecked : Qt::Checked); |
|
716 } |
|
717 |
|
718 /*! |
|
719 * This is called when user is about to exit the view. |
|
720 * Validates configuration and saves settings. |
|
721 * If configuration is not valid prompts question dialog. |
|
722 * If user chooses "OK" leaves without saving. |
|
723 * |
|
724 */ |
|
725 void CpEapTlsMethodsUi::close() |
|
726 { |
|
727 qDebug("CpEapTlsMethodsUi::close"); |
|
728 |
|
729 // Validate configuration |
|
730 if (validate()) { |
|
731 qDebug("CpEapTlsMethodsUi::close - Validation OK"); |
|
732 |
|
733 // Store settings |
|
734 if (storeSettings()){ |
|
735 qDebug("CpEapTlsMethodsUi::close - Settings stored, close view"); |
|
736 // Close view |
|
737 CpBaseSettingView::close(); |
|
738 } |
|
739 else { |
|
740 qDebug("CpEapTlsMethodsUi::close - Store settings failed, prompt warning"); |
|
741 // Store failed. Show error note to user |
|
742 QScopedPointer<HbMessageBox> infoBox; |
|
743 infoBox.reset(new HbMessageBox( |
|
744 HbMessageBox::MessageTypeWarning)); |
|
745 infoBox->setText(hbTrId("txt_occ_info_unable_to_save_setting")); |
|
746 infoBox->clearActions(); |
|
747 // Connect 'OK'-button to CpBaseSettingView 'aboutToClose'-signal |
|
748 HbAction *okAction = new HbAction(hbTrId("txt_common_button_ok")); |
|
749 infoBox->addAction(okAction); |
|
750 bool connected = connect( |
|
751 okAction, |
|
752 SIGNAL(triggered()), |
|
753 this, |
|
754 SIGNAL(aboutToClose())); |
|
755 Q_ASSERT(connected); |
|
756 infoBox->open(); |
|
757 infoBox.take(); |
|
758 } |
|
759 } |
|
760 else { |
|
761 qDebug("CpEapTlsMethodsUi::close - validation failed. Prompt question."); |
|
762 |
|
763 // Validate failed. Request user to exit anyway |
|
764 QScopedPointer<HbMessageBox> messageBox; |
|
765 messageBox.reset(new HbMessageBox( |
|
766 HbMessageBox::MessageTypeQuestion)); |
|
767 messageBox->setAttribute(Qt::WA_DeleteOnClose); |
|
768 messageBox->setText(hbTrId("txt_occ_info_incomplete_details_return_without_sa")); |
|
769 messageBox->clearActions(); |
|
770 // Connect 'YES'-button to CpBaseSettingView 'aboutToClose'-signal |
|
771 HbAction *okAction = new HbAction(hbTrId("txt_common_button_yes")); |
|
772 messageBox->addAction(okAction); |
|
773 bool connected = connect( |
|
774 okAction, |
|
775 SIGNAL(triggered()), |
|
776 this, |
|
777 SIGNAL(aboutToClose())); |
|
778 Q_ASSERT(connected); |
|
779 // Clicking 'NO'-button does nothing |
|
780 HbAction *cancelAction = new HbAction(hbTrId("txt_common_button_no")); |
|
781 messageBox->addAction(cancelAction); |
|
782 messageBox->setTimeout(HbPopup::NoTimeout); |
|
783 messageBox->open(); |
|
784 messageBox.take(); |
|
785 } |
|
786 } |
|
787 |
|
788 /*! |
|
789 * Validates settings configuration. |
|
790 * |
|
791 * @return true if configuration OK, false otherwise. |
|
792 */ |
|
793 bool CpEapTlsMethodsUi::validate() |
|
794 { |
|
795 qDebug("CpEapTlsMethodsUi::validate()"); |
|
796 bool valid = false; |
|
797 |
|
798 if (validateUsernameGroup() |
|
799 && validateRealmGroup() |
|
800 && validateAuthorityCertificate() |
|
801 && validateUserCertificate() |
|
802 && validateCiphersuites()) { |
|
803 valid = true; |
|
804 } |
|
805 |
|
806 return valid; |
|
807 } |
|
808 |
|
809 /*! |
|
810 * Validates username checkBox and lineEdit group. |
|
811 * |
|
812 * @return true if OK, false otherwise. |
|
813 */ |
|
814 bool CpEapTlsMethodsUi::validateUsernameGroup() |
|
815 { |
|
816 bool status = false; |
|
817 // true if generate automatically is checked or given value is valid |
|
818 if (mUsernameAutomatic->contentWidgetData("checkState") == Qt::Checked |
|
819 || EapQtValidator::StatusOk == mValidatorUsername->validate( |
|
820 mUsername->contentWidgetData("text"))) { |
|
821 status = true; |
|
822 } |
|
823 qDebug("CpEapTlsMethodsUi::validateUsernameGroup() - status: %d", status); |
|
824 return status; |
|
825 } |
|
826 |
|
827 /*! |
|
828 * Validates realm checkBox and lineEdit group. |
|
829 * |
|
830 * @return true if OK, false otherwise. |
|
831 */ |
|
832 bool CpEapTlsMethodsUi::validateRealmGroup() |
|
833 { |
|
834 bool status = false; |
|
835 // true if generate automatically is checked or given value is valid |
|
836 if (mRealmAutomatic->contentWidgetData("checkState") == Qt::Checked |
|
837 || EapQtValidator::StatusOk == mValidatorRealm->validate( |
|
838 mRealm->contentWidgetData("text"))) { |
|
839 status = true; |
|
840 } |
|
841 qDebug("CpEapTlsMethodsUi::validateRealmGroup() - status: %d", status); |
|
842 return status; |
|
843 } |
|
844 |
|
845 /*! |
|
846 * Validates authority certificate checkBox and comboBox group. |
|
847 * |
|
848 * @return true if OK, false otherwise. |
|
849 */ |
|
850 bool CpEapTlsMethodsUi::validateAuthorityCertificate() |
|
851 { |
|
852 bool status = false; |
|
853 //true if select automatically is checked or certificate is selected |
|
854 if (mCaCertAutomatic->contentWidgetData("checkState") == Qt::Checked |
|
855 || mCurrentAuthorityCert > NotInUseIndex) { |
|
856 status = true; |
|
857 } |
|
858 qDebug("CpEapTlsMethodsUi::validateAuthorityCertificate()- status: %d", status); |
|
859 return status; |
|
860 } |
|
861 |
|
862 /*! |
|
863 * Validates user certificate selection. |
|
864 * |
|
865 * @return false if EAP-TLS and no certificate, true otherwise |
|
866 */ |
|
867 bool CpEapTlsMethodsUi::validateUserCertificate() |
|
868 { |
|
869 bool status = true; |
|
870 // false if EAP-TLS and not selected user certificate |
|
871 if (mPluginInfo.pluginHandle() == EapQtPluginHandle::PluginEapTls |
|
872 && mCurrentUserCert == NotInUseIndex) { |
|
873 status = false; |
|
874 } |
|
875 qDebug("CpEapTlsMethodsUi::validateUserCertificate() - status: %d", status); |
|
876 return status; |
|
877 } |
|
878 |
|
879 /*! |
|
880 * Validates cipher suites selection. |
|
881 * |
|
882 * @return false if no cipher suite is selected, true otherwise |
|
883 */ |
|
884 bool CpEapTlsMethodsUi::validateCiphersuites() |
|
885 { |
|
886 bool status = true; |
|
887 QVariant cipherSuites = mGroupItemCs->ciphersuites(); |
|
888 QList<QVariant> cipherList = cipherSuites.toList(); |
|
889 if (cipherList.count() == 0){ |
|
890 status = false; |
|
891 } |
|
892 qDebug("CpEapTlsMethodsUi::validateCiphersuites() - status: %d", status); |
|
893 return status; |
|
894 } |
|
895 |
|
896 /*! |
|
897 * Write PEAP specific values into the EAP configuration |
|
898 * |
|
899 * @param eapConfig |
|
900 */ |
|
901 void CpEapTlsMethodsUi::setPeapVersion(EapQtConfig &eapConfig) |
|
902 { |
|
903 qDebug("CpEapTlsMethodsUi::setPeapVersion()"); |
|
904 if (mCurrentPeapVersion == PeapVersion0) { |
|
905 eapConfig.setValue(EapQtConfig::PeapVersion0Allowed, true); |
|
906 eapConfig.setValue(EapQtConfig::PeapVersion1Allowed, false); |
|
907 } |
|
908 else if (mCurrentPeapVersion == PeapVersion1) { |
|
909 eapConfig.setValue(EapQtConfig::PeapVersion0Allowed, false); |
|
910 eapConfig.setValue(EapQtConfig::PeapVersion1Allowed, true); |
|
911 } |
|
912 else { |
|
913 Q_ASSERT(mCurrentPeapVersion == PeapVersionBoth); |
|
914 eapConfig.setValue(EapQtConfig::PeapVersion0Allowed, true); |
|
915 eapConfig.setValue(EapQtConfig::PeapVersion1Allowed, true); |
|
916 } |
|
917 } |
|
918 |
|
919 /*! |
|
920 * Stores settings given via TLS based methods setting UI |
|
921 * |
|
922 * @return false if saving failed, true otherwise |
|
923 */ |
|
924 bool CpEapTlsMethodsUi::storeSettings() |
|
925 { |
|
926 qDebug("CpEapTlsMethodsUi::storeSettings"); |
|
927 |
|
928 EapQtConfig eapConfig; |
|
929 |
|
930 // Store common settings |
|
931 qDebug("CpEapTlsMethodsUi::storeSettings - Common settings"); |
|
932 eapConfig.setValue(EapQtConfig::OuterType, qVariantFromValue(mOuterHandle)); |
|
933 eapConfig.setValue(EapQtConfig::UsernameAutomatic, checkStateToBool( |
|
934 mUsernameAutomatic->contentWidgetData("checkState").toInt())); |
|
935 eapConfig.setValue(EapQtConfig::Username, mUsername->contentWidgetData("text")); |
|
936 eapConfig.setValue(EapQtConfig::RealmAutomatic, checkStateToBool( |
|
937 mRealmAutomatic->contentWidgetData("checkState").toInt())); |
|
938 eapConfig.setValue(EapQtConfig::Realm, mRealm->contentWidgetData("text")); |
|
939 |
|
940 // User certificate |
|
941 qDebug("CpEapTlsMethodsUi::storeSettings - User certificate"); |
|
942 if (mCurrentUserCert > NotInUseIndex) { |
|
943 QList<QVariant> userCerts; |
|
944 userCerts.append(qVariantFromValue(mUserCerts.at(mCurrentUserCert - 1))); |
|
945 // The first item in UI(index 0) is 'not in use' |
|
946 eapConfig.setValue(EapQtConfig::UserCertificate, userCerts); |
|
947 } |
|
948 |
|
949 // Authority certificate |
|
950 qDebug("CpEapTlsMethodsUi::storeSettings - Authority certificate"); |
|
951 eapConfig.setValue(EapQtConfig::AuthorityCertificateAutomatic, checkStateToBool( |
|
952 mCaCertAutomatic->contentWidgetData("checkState").toInt())); |
|
953 if (mCurrentAuthorityCert > NotInUseIndex && !checkStateToBool( |
|
954 mCaCertAutomatic->contentWidgetData("checkState").toInt())) { |
|
955 QList<QVariant> authorityCerts; |
|
956 authorityCerts.append(qVariantFromValue(mAuthorityCerts.at(mCurrentAuthorityCert - 1))); |
|
957 // The first item in UI(index 0) is 'not in use' |
|
958 eapConfig.setValue(EapQtConfig::AuthorityCertificate, authorityCerts); |
|
959 } |
|
960 |
|
961 // Inner EAP method (Not valid for EAP-TLS) |
|
962 if (!(mPluginInfo.pluginHandle() == EapQtPluginHandle::PluginEapTls)) { |
|
963 qDebug("CpEapTlsMethodsUi::storeSettings - Inner EAP method"); |
|
964 QList<QVariant> innerEaps; |
|
965 innerEaps.append(qVariantFromValue(mPlugins.at(mCurrentInnerPlugin).pluginHandle())); |
|
966 eapConfig.setValue(EapQtConfig::InnerType, innerEaps); |
|
967 } |
|
968 |
|
969 // Cipher suites |
|
970 qDebug("CpEapTlsMethodsUi::storeSettings - Cipher suites"); |
|
971 eapConfig.setValue(EapQtConfig::CipherSuites, mGroupItemCs->ciphersuites()); |
|
972 |
|
973 // PEAP version (valid only for PEAP) |
|
974 if (mPluginInfo.pluginHandle() == EapQtPluginHandle::PluginPeap) { |
|
975 setPeapVersion(eapConfig); |
|
976 } |
|
977 |
|
978 // Save configuration |
|
979 if (!mConfigIf->saveConfiguration(mPluginInfo.pluginHandle(), eapConfig)) { |
|
980 qDebug("CpEapTlsMethodsUi::storeSettings - configuration saving failed."); |
|
981 return false; |
|
982 } |
|
983 return true; |
|
984 } |
|
985 |
|