diff -r 7a0216d033ac -r fe6b6762fccd securitysettings/qtconfigutils/eapqtconfiginterface/src/eapqtconfiginterface_p.cpp --- a/securitysettings/qtconfigutils/eapqtconfiginterface/src/eapqtconfiginterface_p.cpp Wed Jun 23 18:14:55 2010 +0300 +++ b/securitysettings/qtconfigutils/eapqtconfiginterface/src/eapqtconfiginterface_p.cpp Tue Jul 06 14:18:35 2010 +0300 @@ -2,7 +2,7 @@ * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available - * under the terms of the License "Eclipse Public License v1.0" + * under the terms of "Eclipse Public License v1.0" * which accompanies this distribution, and is available * at the URL "http://www.eclipse.org/legal/epl-v10.html". * @@ -17,9 +17,10 @@ */ /* - * %version: 41 % + * %version: 49 % */ +// System includes #include #include #include @@ -28,25 +29,35 @@ #include #include #include - #include #include #include - #include #include +// User includes #include "cpeapplugininterface.h" #include "eapqtconfiginterface_p.h" - -// validators #include "eapqtvalidatorpassword.h" #include "eapqtvalidatorusername.h" #include "eapqtvalidatorrealm.h" +#include "eapqtvalidatorpacstorepassword.h" +#include "eapqtvalidatorpacstorepasswordconfirm.h" -static const QString eapPluginDir("\\resource\\qt\\plugins\\controlpanel\\eapsecurity"); +/*! + * \class EapQtConfigInterfacePrivate + * \brief Private implementation of EAP QT configuration interface + */ + +// External function prototypes + +// Local constants static const QString eapTranslationFile("cpeapuiplugins"); +// ======== LOCAL FUNCTIONS ======== + +// ======== MEMBER FUNCTIONS ======== + EapQtConfigInterfacePrivate::EapQtConfigInterfacePrivate() : mValidatorInstance(true), mLastOuterHandle(EapQtPluginHandle::PluginUndefined), @@ -59,10 +70,9 @@ mEapDbIndexValid(false) { qDebug("EapQtConfigInterfacePrivate() - created validator instance, this = 0x%08x", this); - } -EapQtConfigInterfacePrivate::EapQtConfigInterfacePrivate(/* EapQtConfigInterface *configIf, */ +EapQtConfigInterfacePrivate::EapQtConfigInterfacePrivate( const EapQtConfigInterface::EapBearerType bearerType, const int iapId) : mValidatorInstance(false), mLastOuterHandle(EapQtPluginHandle::PluginUndefined), @@ -76,7 +86,6 @@ { qDebug("EapQtConfigInterfacePrivate() - creating non-validator instance, this = 0x%08x", this); - switch (bearerType) { case EapQtConfigInterface::EapBearerTypeVpn: mEapBearer = EVpn; @@ -112,7 +121,6 @@ { qDebug("EapQtConfigInterfacePrivate::shutdown(), this = 0x%08x", this); - mOuterEapsOn.Close(); mOuterEapsOff.Close(); @@ -227,7 +235,6 @@ { qDebug("EapQtConfigInterfacePrivate::setEapWlanDbIndex - requested id: %d, this = 0x%08x", iapId, this); - RCmManager cmm; TRAPD(err, cmm.OpenL()); if (err != KErrNone) { @@ -274,7 +281,6 @@ { qDebug("EapQtConfigInterfacePrivate::appendEapTypes(), this = 0x%08x", this); - Q_ASSERT(eapTypes); Q_ASSERT(eapList); @@ -294,7 +300,6 @@ { qDebug("EapQtConfigInterfacePrivate::supportedOuterTypes(), this = 0x%08x", this); - checkInstanceThrowing(); if (mEapGsIf.isNull()) { @@ -359,6 +364,10 @@ } } + // sort the list + qSort(mSupportedOuterTypes.begin(), mSupportedOuterTypes.end(), + EapQtConfigInterfacePrivate::pluginLessThan); + qDebug("EapQtConfigInterfacePrivate - supportedOuterTypes: supported EAP count: %d", mSupportedOuterTypes.count()); @@ -385,11 +394,10 @@ } QList EapQtConfigInterfacePrivate::supportedInnerTypes( - const EapQtPluginHandle& outer) + const EapQtPluginHandle &outer) { qDebug("EapQtConfigInterfacePrivate::supportedInnerTypes(), this = 0x%08x", this); - checkInstanceThrowing(); // check if we already have up-to-date data @@ -453,6 +461,13 @@ mLastOuterHandle = outer; + // sort the list + qSort(mSupportedInnerTypes.begin(), mSupportedInnerTypes.end(), + EapQtConfigInterfacePrivate::pluginLessThan); + + qDebug("EapQtConfigInterfacePrivate - supportedInnerTypes: supported EAP count: %d", + mSupportedInnerTypes.count()); + return mSupportedInnerTypes; } @@ -462,7 +477,6 @@ { qDebug("EapQtConfigInterfacePrivate::copyCertificateInfo(), this = 0x%08x", this); - Q_ASSERT(certEntries); Q_ASSERT(certInfos); @@ -475,6 +489,9 @@ for (ind = 0; ind < certEntries->Count(); ind++) { + // cleanup cert + cert.clear(); + EapCertificateEntry* certPtr = (*certEntries)[ind]; qDebug() << "EapQtConfigInterfacePrivate - copyCertificateInfo *** certificate starts *** "; @@ -547,15 +564,13 @@ { qDebug("EapQtConfigInterfacePrivate::fetchCertificates(), this = 0x%08x", this); - - Q_ASSERT(caInfos != NULL || clientInfos != NULL || !mEapGsIf.isNull()); + Q_ASSERT(caInfos != NULL || clientInfos != NULL); + Q_ASSERT(!mEapGsIf.isNull()); TInt err(KErrNone); RPointerArray clientCerts; RPointerArray caCerts; - // lists are always queried again as the user might have installed new certificates - // during the life time of the object err = mEapGsIf->GetCertificateLists(clientCerts, caCerts); if (err != KErrNone) { qDebug("EapQtConfigInterfacePrivate - fetchCertificates failed: %d", err); @@ -578,41 +593,48 @@ return true; } +bool EapQtConfigInterfacePrivate::updateCertificates() { + + qDebug("EapQtConfigInterfacePrivate::updateCertificates(), this = 0x%08x", this); + + checkInstanceThrowing(); + + // empty current state + mCaCertificates.clear(); + mUserCertificates.clear(); + + return fetchCertificates(&mCaCertificates, &mUserCertificates); +} + QList EapQtConfigInterfacePrivate::certificateAuthorityCertificates() { qDebug("EapQtConfigInterfacePrivate::certificateAuthorityCertificates(), this = 0x%08x", this); - checkInstanceThrowing(); - QList list; - if (!fetchCertificates(&list, 0)) { - // query failed - list.clear(); + // update only if the list is empty + if(mCaCertificates.length() == 0) { + qDebug() << "EapQtConfigInterfacePrivate::certificateAuthorityCertificates() - updates certificate lists"; + updateCertificates(); } - return list; + + return mCaCertificates; } QList EapQtConfigInterfacePrivate::userCertificates() { qDebug("EapQtConfigInterfacePrivate::userCertificates(), this = 0x%08x", this); - - checkInstanceThrowing(); - - QList list; - if (!fetchCertificates(0, &list)) { - // query failed - list.clear(); - } - return list; + // use the CA certificates method, it will update both the lists + // if CA list is empty + (void) certificateAuthorityCertificates(); + return mUserCertificates; } -void EapQtConfigInterfacePrivate::getEapTypeIf(const EapQtPluginHandle& pluginHandle) +void EapQtConfigInterfacePrivate::getEapTypeIf(const EapQtPluginHandle &pluginHandle) { qDebug("EapQtConfigInterfacePrivate::getEapTypeIf(), this = 0x%08x", this); - // dig up the EAP type in TEapExpandedType format TEapExpandedType eapServerType; QByteArray eapType = pluginHandle.type().eapExpandedData(); @@ -659,12 +681,11 @@ // if OuterType is not defined, pluginHandle is for an outer type // if InnerType is defined, the defined inner types in config are activated for pluginHandle // if InnerType is not defined, the pluginHandle does not activate any inner type (or they do not exist) -bool EapQtConfigInterfacePrivate::saveConfiguration(const EapQtPluginHandle& pluginHandle, - EapQtConfig& config) +bool EapQtConfigInterfacePrivate::saveConfiguration(const EapQtPluginHandle &pluginHandle, + const EapQtConfig &config) { qDebug("EapQtConfigInterfacePrivate::saveConfiguration(), this = 0x%08x", this); - checkInstanceThrowing(); if (!mEapDbIndexValid) { @@ -672,13 +693,27 @@ return false; } - // only check if EAP ui is supported here, - // getEapTypeIf checks the EAP server support - int dummy = 0; - if (!isUiSupported(pluginHandle.type().eapExpandedData(), dummy)) { - qDebug( - "ERROR: EapQtConfigInterfacePrivate::saveConfiguration() - UI not supported for the requested EAP"); - return false; + // set tunneling type & check if the requested EAP is supported + // if we are configuring outer type, OuterType == QVariant::Invalid or + // EapQtPluginHandle::PluginUndefined + + EapQtPluginHandle tmpOuterHandle; + QVariant varValue = config.value(EapQtConfig::OuterType); + if (varValue != QVariant::Invalid && !(varValue.value () == EapQtPluginHandle::PluginUndefined)) { + tmpOuterHandle = varValue.value (); + // check if supported + if(!isSupportedInnerType(tmpOuterHandle, pluginHandle)) { + qDebug("ERROR: EapQtConfigInterfacePrivate::saveConfiguration() - not supported outer/inner type combination"); + return false; + } + } + else { + tmpOuterHandle = EapQtPluginHandle::PluginUndefined; + // check if supported + if(!isSupportedOuterType(pluginHandle)) { + qDebug("ERROR: EapQtConfigInterfacePrivate::saveConfiguration() - not supported outer type"); + return false; + } } getEapTypeIf(pluginHandle); @@ -687,18 +722,6 @@ return false; } - // set tunneling type - // if we are configuring outer type, OuterType == Invalid or EapQtPluginHandle::PluginUndefined - - EapQtPluginHandle tmpOuterHandle; - QVariant varValue = config.value(EapQtConfig::OuterType); - if (varValue != QVariant::Invalid) { - tmpOuterHandle = varValue.value (); - } - else { - tmpOuterHandle = EapQtPluginHandle::PluginUndefined; - } - TEapExpandedType tmpOuterEap; tmpOuterEap.SetValue(tmpOuterHandle.type().eapExpandedData().data(), tmpOuterHandle.type().eapExpandedData().length()); @@ -733,8 +756,8 @@ } // config must be empty when calling -bool EapQtConfigInterfacePrivate::readConfiguration(const EapQtPluginHandle& outerHandle, - const EapQtPluginHandle& pluginHandle, EapQtConfig& config) +bool EapQtConfigInterfacePrivate::readConfiguration(const EapQtPluginHandle &outerHandle, + const EapQtPluginHandle &pluginHandle, EapQtConfig &config) { qDebug("EapQtConfigInterfacePrivate::readConfiguration(), this = 0x%08x", this); @@ -748,13 +771,17 @@ return false; } - // only check if UI is supported for pluginHandle here, - // getEapTypeIf checks the EAP server support - int dummy = 0; - if (!isUiSupported(pluginHandle.type().eapExpandedData(), dummy)) { - qDebug( - "ERROR: EapQtConfigInterfacePrivate::readConfiguration - UI not supported for the requested EAP"); - return false; + // check EAP type support + if(!(outerHandle == EapQtPluginHandle::PluginUndefined)) { + if(!isSupportedInnerType(outerHandle, pluginHandle)) { + qDebug("ERROR: EapQtConfigInterfacePrivate::readConfiguration() - not supported outer/inner type combination"); + return false; + } + } else { + if(!isSupportedOuterType(pluginHandle)) { + qDebug("ERROR: EapQtConfigInterfacePrivate::readConfiguration() - not supported outer type"); + return false; + } } getEapTypeIf(pluginHandle); @@ -808,12 +835,10 @@ return (value ? ETrue : EFalse); } -void EapQtConfigInterfacePrivate::copyToEapSettings(EapQtConfig& config, EAPSettings& eapSettings) +void EapQtConfigInterfacePrivate::copyToEapSettings(const EapQtConfig &config, EAPSettings &eapSettings) { - qDebug("EapQtConfigInterfacePrivate::copyToEapSettings(), this = 0x%08x", this); - int ind = 0; QVariant varValue = config.value(EapQtConfig::UsernameAutomatic); @@ -926,6 +951,12 @@ eapSettings.iPEAPv0Allowed = convertToTbool(varValue.toBool()); qDebug() << "EapQtConfigInterfacePrivate - copyToEapSettings PeapVersion0Allowed: " << varValue.toBool(); + } else { + // in any other case disable PEAP version; + // no need to set eapSettings.iPEAPVersionsPresent, + // it will be set if one of the other PEAP versions is enabled, + // otherwise this setting is redundant and can be ignored + eapSettings.iPEAPv0Allowed = EFalse; } varValue = config.value(EapQtConfig::PeapVersion1Allowed); @@ -934,6 +965,12 @@ eapSettings.iPEAPv1Allowed = convertToTbool(varValue.toBool()); qDebug() << "EapQtConfigInterfacePrivate - copyToEapSettings PeapVersion1Allowed: " << varValue.toBool(); + } else { + // in any other case disable PEAP version; + // no need to set eapSettings.iPEAPVersionsPresent, + // it will be set if one of the other PEAP versions is enabled, + // otherwise this setting is redundant and can be ignored + eapSettings.iPEAPv1Allowed = EFalse; } varValue = config.value(EapQtConfig::PeapVersion2Allowed); @@ -942,6 +979,12 @@ eapSettings.iPEAPv2Allowed = convertToTbool(varValue.toBool()); qDebug() << "EapQtConfigInterfacePrivate - copyToEapSettings PeapVersion2Allowed: " << varValue.toBool(); + } else { + // in any other case disable PEAP version; + // no need to set eapSettings.iPEAPVersionsPresent, + // it will be set if one of the other PEAP versions is enabled, + // otherwise this setting is redundant and can be ignored + eapSettings.iPEAPv2Allowed = EFalse; } varValue = config.value(EapQtConfig::ProvisioningModeAuthenticated); @@ -965,7 +1008,8 @@ varValue = config.value(EapQtConfig::PACGroupReference); // do not copy if too large string if (varValue.type() == QVariant::String && varValue.toString().count() <= StringMaxLength) { - // not supported + eapSettings.iPACGroupReference.Copy(varValue.toString().utf16()); + eapSettings.iPACGroupReferencePresent = ETrue; qDebug() << "EapQtConfigInterfacePrivate - copyToEapSettings PACGroupReference: " << varValue.toString(); } @@ -1037,11 +1081,12 @@ qDebug() << "EapQtConfigInterfacePrivate::copyToEapSettings() - CipherSuites present"; QList varCiphers = varValue.toList(); + // clears the ciphersuite configuration if the provided list is empty + eapSettings.iCipherSuitesPresent = ETrue; + for (ind = 0; ind < varCiphers.count(); ind++) { // check that the item is of correct type (int also accepted to not be too strict) if (varCiphers[ind].type() == QVariant::UInt || varCiphers[ind].type() == QVariant::Int) { - // set to true only if at least item cipher is ok - eapSettings.iCipherSuitesPresent = ETrue; eapSettings.iCipherSuites.Append(varCiphers[ind].toUInt()); qDebug( "EapQtConfigInterfacePrivate::copyToEapSettings() - CipherSuites at %d: 0x%08x", @@ -1050,6 +1095,13 @@ } } + // set always to true to support clearing previously configured CA/user certificates + // if the EAP method in question does not use certificates, + // EAP server will ignore the setting; + // CA/user certificates get cleared if EapQtConfig::Authority/UserCertificate is QVariant::Invalid or + // the provided lists are empty + eapSettings.iCertificatesPresent = ETrue; + varValue = config.value(EapQtConfig::AuthorityCertificate); if (varValue.type() == QVariant::List) { @@ -1060,8 +1112,6 @@ for (ind = 0; ind < varCerts.count(); ind++) { // check that the item is of correct type if (varCerts[ind].canConvert ()) { - // set to true only if at least one item is ok - eapSettings.iCertificatesPresent = ETrue; appendCertificateInfo(true, varCerts[ind].value (), &(eapSettings.iCertificates)); qDebug() @@ -1079,8 +1129,6 @@ for (ind = 0; ind < varCerts.count(); ind++) { // check that the item is of correct type if (varCerts[ind].canConvert ()) { - // set to true only if at least one item is ok - eapSettings.iCertificatesPresent = ETrue; appendCertificateInfo(false, varCerts[ind].value (), &(eapSettings.iCertificates)); qDebug() @@ -1097,7 +1145,6 @@ { qDebug("EapQtConfigInterfacePrivate::appendCertificateInfo(), this = 0x%08x", this); - Q_ASSERT(certList); // use scoped pointer to make sure memory is not leaked in failures @@ -1200,7 +1247,7 @@ (void) certEntry.take(); } -void EapQtConfigInterfacePrivate::copyFromEapSettings(EAPSettings& eapSettings, EapQtConfig& config) +void EapQtConfigInterfacePrivate::copyFromEapSettings(EAPSettings &eapSettings, EapQtConfig &config) { qDebug("EapQtConfigInterfacePrivate::copyFromEapSettings(), this = 0x%08x", this); @@ -1483,7 +1530,6 @@ { qDebug("EapQtConfigInterfacePrivate::selectedOuterTypes(), this = 0x%08x", this); - checkInstanceThrowing(); if (!mEapDbIndexValid) { @@ -1512,11 +1558,10 @@ return selectedOuterTypes; } -bool EapQtConfigInterfacePrivate::isSupportedOuterType(const EapQtPluginHandle& handle) +bool EapQtConfigInterfacePrivate::isSupportedOuterType(const EapQtPluginHandle &handle) { qDebug("EapQtConfigInterfacePrivate::isSupportedOuterType(), this = 0x%08x", this); - checkInstanceThrowing(); // check if mSupportedOuterTypes is up-to-date @@ -1535,11 +1580,10 @@ } bool EapQtConfigInterfacePrivate::setSelectedOuterTypes( - const QList& outerHandles) + const QList &outerHandles) { qDebug("EapQtConfigInterfacePrivate::setSelectedOuterTypes()"); - checkInstanceThrowing(); if (!mEapDbIndexValid || mEapGsIf.isNull()) { @@ -1591,12 +1635,11 @@ return ret; } -bool EapQtConfigInterfacePrivate::isSupportedInnerType(const EapQtPluginHandle& outerHandle, - const EapQtPluginHandle& innerHandle) +bool EapQtConfigInterfacePrivate::isSupportedInnerType(const EapQtPluginHandle &outerHandle, + const EapQtPluginHandle &innerHandle) { qDebug("EapQtConfigInterfacePrivate::isSupportedInnerType(), this = 0x%08x", this); - checkInstanceThrowing(); // update mSupportedInnerTypes @@ -1614,7 +1657,6 @@ { qDebug("EapQtConfigInterfacePrivate::deleteConfiguration(), this = 0x%08x", this); - checkInstanceThrowing(); if (!mEapDbIndexValid || mEapGsIf.isNull()) { @@ -1637,7 +1679,8 @@ checkInstanceThrowing(); - QDir pluginsDir(eapPluginDir); + // plugin directory defined in cpeapplugininterface.h + QDir pluginsDir(CpEapPluginInterfacePluginDirectory); foreach( QString fileName, pluginsDir.entryList(QDir::Files) ) { QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); @@ -1655,14 +1698,26 @@ for (iter = mPlugins.begin(); iter != mPlugins.end(); ++iter) { mPluginInfos.append((*iter)->pluginInfo()); } + + // sort the UI plugins according to their order number + qSort(mPluginInfos.begin(), mPluginInfos.end(), EapQtConfigInterfacePrivate::pluginLessThan); + + qDebug("EapQtConfigInterfacePrivate - loadPlugins: supported EAP plugin count: %d", + mPluginInfos.count()); } -CpBaseSettingView *EapQtConfigInterfacePrivate::uiInstance(const EapQtPluginHandle& outerHandle, - const EapQtPluginHandle& pluginHandle) +bool EapQtConfigInterfacePrivate::pluginLessThan( + const EapQtPluginInfo &plugin1, + const EapQtPluginInfo &plugin2) +{ + return plugin1.orderNumber() < plugin2.orderNumber(); +} + +CpBaseSettingView *EapQtConfigInterfacePrivate::uiInstance(const EapQtPluginHandle &outerHandle, + const EapQtPluginHandle &pluginHandle) { qDebug("EapQtConfigInterfacePrivate::uiInstance(), this = 0x%08x", this); - checkInstanceThrowing(); // if outer type UI is requested, outerHandle must be undefined and pluginHandle @@ -1725,11 +1780,14 @@ return ret; } -EapQtValidator *EapQtConfigInterfacePrivate::validatorEap(EapQtExpandedEapType type, - EapQtConfig::SettingsId id) +EapQtValidator *EapQtConfigInterfacePrivate::validatorEap(const EapQtExpandedEapType &type, + const EapQtConfig::SettingsId id) { qDebug("EapQtConfigInterfacePrivate::validatorEap(), this = 0x%08x", this); + qDebug() << "EapQtConfigInterfacePrivate::validatorEap() - requested EAP: " + << type.eapExpandedData().toHex(); + qDebug() << "EapQtConfigInterfacePrivate::validatorEap() - setting: " << id; EapQtValidator *ret = NULL; @@ -1789,5 +1847,40 @@ } + qDebug() << "EapQtConfigInterfacePrivate::validatorEap() - is returning NULL: " << (ret == NULL); + return ret; } + +bool EapQtConfigInterfacePrivate::readPacStoreConfiguration(EapQtPacStoreConfig& /* config */) +{ + // not supported + return false; +} + +bool EapQtConfigInterfacePrivate::savePacStoreConfiguration(const EapQtPacStoreConfig& /* config */) +{ + // not supported + return false; +} + +EapQtValidator *EapQtConfigInterfacePrivate::validatorPacStore( + const EapQtPacStoreConfig::PacStoreSettings id) +{ + qDebug("EapQtConfigInterfacePrivate::validatorPacStore(), this = 0x%08x", this); + + EapQtValidator *ret = NULL; + + switch (id) { + case EapQtPacStoreConfig::PacStorePassword: + ret = new EapQtValidatorPacStorePassword(); + break; + case EapQtPacStoreConfig::PacStorePasswordConfirmation: + ret = new EapQtValidatorPacStorePasswordConfirm(); + break; + default: + ret = NULL; + } + + return ret; +}