securitysettings/qtconfigutils/eapqtconfiginterface/src/eapqtconfiginterface_p.cpp
changeset 42 53085837e73a
parent 39 fe6b6762fccd
child 52 c23bdf5a328a
equal deleted inserted replaced
39:fe6b6762fccd 42:53085837e73a
    15  *   EAP method configuration QT interface
    15  *   EAP method configuration QT interface
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 /*
    19 /*
    20  * %version: 49 %
    20  * %version: 52 %
    21  */
    21  */
    22 
    22 
    23 // System includes
    23 // System includes
    24 #include <QDir>
    24 #include <QDir>
    25 #include <QList>
    25 #include <QList>
   435     // get outer EAP settings
   435     // get outer EAP settings
   436     EAPSettings eapSettings;
   436     EAPSettings eapSettings;
   437     TRAPD(err, mEapTypeIf->GetConfigurationL(eapSettings));
   437     TRAPD(err, mEapTypeIf->GetConfigurationL(eapSettings));
   438     // getEapTypeIf has set mCurrentServerEapType correctly for comparison
   438     // getEapTypeIf has set mCurrentServerEapType correctly for comparison
   439     if (err != KErrNone || eapSettings.iEAPExpandedType != mCurrentServerEapType) {
   439     if (err != KErrNone || eapSettings.iEAPExpandedType != mCurrentServerEapType) {
   440         qDebug("ERROR: EapQtConfigInterfacePrivate::supportedInnerTypes - GetConfigurationL failed");
   440         qDebug()
       
   441             << "ERROR: EapQtConfigInterfacePrivate::supportedInnerTypes - GetConfigurationL failed, code:"
       
   442             << err;
   441         // clear the instance so that the next attempt starts from scratch
   443         // clear the instance so that the next attempt starts from scratch
   442         mEapTypeIf.reset(NULL);
   444         mEapTypeIf.reset(NULL);
   443         // return empty list
   445         // return empty list
   444         return mSupportedInnerTypes;
   446         return mSupportedInnerTypes;
   445     }
   447     }
   812     EAPSettings eapSettings;
   814     EAPSettings eapSettings;
   813     TRAPD(err, mEapTypeIf->GetConfigurationL(eapSettings));
   815     TRAPD(err, mEapTypeIf->GetConfigurationL(eapSettings));
   814 
   816 
   815     // check if failed or something strange happened (incorrect EAP type settings received)  
   817     // check if failed or something strange happened (incorrect EAP type settings received)  
   816     if (err != KErrNone || eapSettings.iEAPExpandedType != mCurrentServerEapType) {
   818     if (err != KErrNone || eapSettings.iEAPExpandedType != mCurrentServerEapType) {
   817         qDebug("ERROR: EapQtConfigInterfacePrivate - readConfiguration: GetConfigurationL failed");
   819         qDebug()
       
   820             << "ERROR: EapQtConfigInterfacePrivate - readConfiguration: GetConfigurationL failed"
       
   821             << "wanted EAP:" << pluginHandle.type().eapExpandedData().toHex()
       
   822             << "- got EAP vendor ID:" << eapSettings.iEAPExpandedType.GetVendorId()
       
   823             << ", vendor type" << eapSettings.iEAPExpandedType.GetVendorType() << ", error code:"
       
   824             << err;
   818         // clear the instance so that the next attempt starts from scratch
   825         // clear the instance so that the next attempt starts from scratch
   819         mEapTypeIf.reset(NULL);
   826         mEapTypeIf.reset(NULL);
   820         mCurrentServerEapType = *EapExpandedTypeNone.GetType();
   827         mCurrentServerEapType = *EapExpandedTypeNone.GetType();
   821         // nothing to be set to config
   828         // nothing to be set to config
   822         return false;
   829         return false;
   887     }
   894     }
   888 
   895 
   889     varValue = config.value(EapQtConfig::PasswordClear);
   896     varValue = config.value(EapQtConfig::PasswordClear);
   890     if (varValue.type() == QVariant::Bool) {
   897     if (varValue.type() == QVariant::Bool) {
   891         eapSettings.iPasswordExistPresent = ETrue;
   898         eapSettings.iPasswordExistPresent = ETrue;
   892         eapSettings.iPasswordExist = convertToTbool(varValue.toBool());
   899         // eapSettings.iPasswordExist = false cleans the password from database, true does nothing
       
   900         eapSettings.iPasswordExist = convertToTbool(!varValue.toBool());
   893         qDebug() << "EapQtConfigInterfacePrivate - copyToEapSettings PasswordClear: "
   901         qDebug() << "EapQtConfigInterfacePrivate - copyToEapSettings PasswordClear: "
   894             << varValue.toBool();
   902             << varValue.toBool();
   895     }
   903     }
   896 
   904 
   897     varValue = config.value(EapQtConfig::RealmAutomatic);
   905     varValue = config.value(EapQtConfig::RealmAutomatic);
  1055         qDebug() << "EapQtConfigInterfacePrivate::copyToEapSettings() - InnerType present";
  1063         qDebug() << "EapQtConfigInterfacePrivate::copyToEapSettings() - InnerType present";
  1056 
  1064 
  1057         QList<QVariant> varList = varValue.toList();
  1065         QList<QVariant> varList = varValue.toList();
  1058         TEapExpandedType tmpEap;
  1066         TEapExpandedType tmpEap;
  1059         EapQtPluginHandle tmpHandle;
  1067         EapQtPluginHandle tmpHandle;
       
  1068         TUint err(KErrNone);
  1060 
  1069 
  1061         for (ind = 0; ind < varList.count(); ind++) {
  1070         for (ind = 0; ind < varList.count(); ind++) {
  1062             if (varList[ind].canConvert<EapQtPluginHandle> ()) {
  1071             if (varList[ind].canConvert<EapQtPluginHandle> ()) {
  1063                 // set to true only if at least one item is ok
  1072                 // set to true only if at least one item is ok
  1064                 eapSettings.iEnabledEncapsulatedEAPExpandedTypesPresent = ETrue;
  1073                 eapSettings.iEnabledEncapsulatedEAPExpandedTypesPresent = ETrue;
  1065 
  1074 
  1066                 tmpHandle = varList[ind].value<EapQtPluginHandle> ();
  1075                 tmpHandle = varList[ind].value<EapQtPluginHandle> ();
  1067                 tmpEap.SetValue(tmpHandle.type().eapExpandedData().data(),
  1076                 tmpEap.SetValue(tmpHandle.type().eapExpandedData().data(),
  1068                     tmpHandle.type().eapExpandedData().length());
  1077                     tmpHandle.type().eapExpandedData().length());
  1069                 eapSettings.iEnabledEncapsulatedEAPExpandedTypes.Append(tmpEap);
  1078                 err = eapSettings.iEnabledEncapsulatedEAPExpandedTypes.Append(tmpEap);
       
  1079                 if(err != KErrNone)
       
  1080                 {
       
  1081                     qDebug() << "ERROR: EapQtConfigInterfacePrivate::copyToEapSettings() - RArray::Append failed for inner types";
       
  1082                     eapSettings.iEnabledEncapsulatedEAPExpandedTypes.Reset();
       
  1083                     // no dynamic memory allocated for tmpEap, just continue with
       
  1084                     // the rest of the settings; EapSettings takes care of deallocations in its destructor
       
  1085                     break;
       
  1086                 }
  1070 
  1087 
  1071                 qDebug()
  1088                 qDebug()
  1072                     << "EapQtConfigInterfacePrivate::copyToEapSettings() - Added to InnerType: "
  1089                     << "EapQtConfigInterfacePrivate::copyToEapSettings() - Added to InnerType: "
  1073                     << tmpHandle.type().eapExpandedData().toHex();
  1090                     << tmpHandle.type().eapExpandedData().toHex();
  1074             }
  1091             }
  1081         qDebug() << "EapQtConfigInterfacePrivate::copyToEapSettings() - CipherSuites present";
  1098         qDebug() << "EapQtConfigInterfacePrivate::copyToEapSettings() - CipherSuites present";
  1082         QList<QVariant> varCiphers = varValue.toList();
  1099         QList<QVariant> varCiphers = varValue.toList();
  1083 
  1100 
  1084         // clears the ciphersuite configuration if the provided list is empty
  1101         // clears the ciphersuite configuration if the provided list is empty
  1085         eapSettings.iCipherSuitesPresent = ETrue;
  1102         eapSettings.iCipherSuitesPresent = ETrue;
       
  1103         TUint err(KErrNone);
  1086 
  1104 
  1087         for (ind = 0; ind < varCiphers.count(); ind++) {
  1105         for (ind = 0; ind < varCiphers.count(); ind++) {
  1088             // check that the item is of correct type (int also accepted to not be too strict)
  1106             // check that the item is of correct type (int also accepted to not be too strict)
  1089             if (varCiphers[ind].type() == QVariant::UInt || varCiphers[ind].type() == QVariant::Int) {
  1107             if (varCiphers[ind].type() == QVariant::UInt || varCiphers[ind].type() == QVariant::Int) {
  1090                 eapSettings.iCipherSuites.Append(varCiphers[ind].toUInt());
  1108 
       
  1109                 err = eapSettings.iCipherSuites.Append(varCiphers[ind].toUInt());
       
  1110                 if(err != KErrNone)
       
  1111                 {
       
  1112                     qDebug() << "ERROR: EapQtConfigInterfacePrivate::copyToEapSettings() - RArray::Append failed for ciphersuites";
       
  1113                     eapSettings.iCipherSuites.Reset();
       
  1114                     // continue with the rest of the settings, no dynamic
       
  1115                     // memory allocated for varCiphers[ind].toUInt()
       
  1116                     break;
       
  1117                 }
       
  1118 
  1091                 qDebug(
  1119                 qDebug(
  1092                     "EapQtConfigInterfacePrivate::copyToEapSettings() - CipherSuites at %d: 0x%08x",
  1120                     "EapQtConfigInterfacePrivate::copyToEapSettings() - CipherSuites at %d: 0x%08x",
  1093                     ind, varCiphers[ind].toUInt());
  1121                     ind, varCiphers[ind].toUInt());
  1094             }
  1122             }
  1095         }
  1123         }
  1234 
  1262 
  1235         qDebug() << "EapQtConfigInterfacePrivate::appendCertificateInfo() - SubjectKeyId: "
  1263         qDebug() << "EapQtConfigInterfacePrivate::appendCertificateInfo() - SubjectKeyId: "
  1236             << varValue.toByteArray().toHex();
  1264             << varValue.toByteArray().toHex();
  1237     }
  1265     }
  1238 
  1266 
  1239     // EapSettings destructor takes care of deallocating the entry
  1267     TUint err = certList->Append(certEntry.data());
  1240     certList->Append(certEntry.data());
  1268     if (err != KErrNone) {
  1241 
  1269         qDebug() << "ERROR: EapQtConfigInterfacePrivate::appendCertificateInfo()"
  1242     qDebug()
  1270             << "- RPointerArray::Append failed for certificate entry";
  1243         << "EapQtConfigInterfacePrivate::appendCertificateInfo()"
  1271         // scoped certEntry pointer deleted automatically
  1244         << "- *** certificate appended to list";
  1272         // no need to touch the array, it is handled by the caller
  1245 
  1273     }
  1246     // all ok, remove the ownerhsip from scoped pointer
  1274     else {
  1247     (void) certEntry.take();
  1275         qDebug() << "EapQtConfigInterfacePrivate::appendCertificateInfo()"
       
  1276             << "- *** certificate appended to list";
       
  1277         // remove the ownerhsip from scoped pointer, entry owned by the array now
       
  1278         (void) certEntry.take();
       
  1279     }
       
  1280 
       
  1281     // EapSettings destructor takes care of deallocating the array entries
  1248 }
  1282 }
  1249 
  1283 
  1250 void EapQtConfigInterfacePrivate::copyFromEapSettings(EAPSettings &eapSettings, EapQtConfig &config)
  1284 void EapQtConfigInterfacePrivate::copyFromEapSettings(EAPSettings &eapSettings, EapQtConfig &config)
  1251 {
  1285 {
  1252     qDebug("EapQtConfigInterfacePrivate::copyFromEapSettings(), this = 0x%08x", this);
  1286     qDebug("EapQtConfigInterfacePrivate::copyFromEapSettings(), this = 0x%08x", this);
  1371                 << convertToBool(eapSettings.iCertificates[ind]->GetIsEnabled());
  1405                 << convertToBool(eapSettings.iCertificates[ind]->GetIsEnabled());
  1372 
  1406 
  1373             // only enabled certificates are reported
  1407             // only enabled certificates are reported
  1374             if (eapSettings.iCertificates[ind]->GetCertType() == EapCertificateEntry::EUser
  1408             if (eapSettings.iCertificates[ind]->GetCertType() == EapCertificateEntry::EUser
  1375                 && eapSettings.iCertificates[ind]->GetIsEnabled() != EFalse) {
  1409                 && eapSettings.iCertificates[ind]->GetIsEnabled() != EFalse) {
  1376                 serverClientCerts.Append(eapSettings.iCertificates[ind]);
  1410                 // no need to check the return value for failures,
       
  1411                 // serverClientCerts does not own the pointed data,
       
  1412                 // eapSettings owns and deallocates it
       
  1413                 (void) serverClientCerts.Append(eapSettings.iCertificates[ind]);
  1377             }
  1414             }
  1378             // only enabled certificates are reported
  1415             // only enabled certificates are reported
  1379             else if (eapSettings.iCertificates[ind]->GetCertType() == EapCertificateEntry::ECA
  1416             else if (eapSettings.iCertificates[ind]->GetCertType() == EapCertificateEntry::ECA
  1380                 && eapSettings.iCertificates[ind]->GetIsEnabled() != EFalse) {
  1417                 && eapSettings.iCertificates[ind]->GetIsEnabled() != EFalse) {
  1381                 serverCaCerts.Append(eapSettings.iCertificates[ind]);
  1418                 // no need to check the return value for failures,
       
  1419                 // serverCaCerts does not own the pointed data,
       
  1420                 // eapSettings owns and deallocates it
       
  1421                 (void) serverCaCerts.Append(eapSettings.iCertificates[ind]);
  1382             }
  1422             }
  1383             else {
  1423             else {
  1384                 qDebug()
  1424                 qDebug()
  1385                     << "WARNING: EapQtConfigInterfacePrivate - copyFromEapSettings certificates, "
  1425                     << "WARNING: EapQtConfigInterfacePrivate - copyFromEapSettings certificates, "
  1386                     << "unknown certificate type in the list or certificate not enabled";
  1426                     << "unknown certificate type in the list or certificate not enabled";
  1602     mOuterEapsOn.Reset();
  1642     mOuterEapsOn.Reset();
  1603     mOuterEapsOff.Reset();
  1643     mOuterEapsOff.Reset();
  1604 
  1644 
  1605     // pick only the supported ones from outerHandles
  1645     // pick only the supported ones from outerHandles
  1606     TEapExpandedType tmpEap;
  1646     TEapExpandedType tmpEap;
       
  1647     TUint err(KErrNone);
  1607     for (int ind = 0; ind < mSupportedOuterTypes.count(); ind++) {
  1648     for (int ind = 0; ind < mSupportedOuterTypes.count(); ind++) {
  1608         if (outerHandles.contains(mSupportedOuterTypes[ind].pluginHandle())) {
  1649         if (outerHandles.contains(mSupportedOuterTypes[ind].pluginHandle())) {
  1609 
  1650 
  1610             // convert to TEapExpandedType
  1651             // convert to TEapExpandedType
  1611             tmpEap.SetValue(
  1652             tmpEap.SetValue(
  1612                 mSupportedOuterTypes[ind].pluginHandle().type().eapExpandedData().data(),
  1653                 mSupportedOuterTypes[ind].pluginHandle().type().eapExpandedData().data(),
  1613                 mSupportedOuterTypes[ind].pluginHandle().type().eapExpandedData().length());
  1654                 mSupportedOuterTypes[ind].pluginHandle().type().eapExpandedData().length());
  1614 
  1655 
  1615             // add to mOuterEapsOn
  1656             // add to mOuterEapsOn
  1616             mOuterEapsOn.Append(tmpEap);
  1657             err = mOuterEapsOn.Append(tmpEap);
       
  1658             if(err != KErrNone)
       
  1659             {
       
  1660                 qDebug() << "ERROR: EapQtConfigInterfacePrivate - setSelectedOuterTypes RArray::Append failed";
       
  1661                 // reset the array, no dynamic memory allocated for tmpEap
       
  1662                 mOuterEapsOn.Reset();
       
  1663                 return false;
       
  1664             }
  1617 
  1665 
  1618             qDebug()
  1666             qDebug()
  1619                 << "EapQtConfigInterfacePrivate - setSelectedOuterTypes adding to enabledOuterHandles: "
  1667                 << "EapQtConfigInterfacePrivate - setSelectedOuterTypes adding to enabledOuterHandles: "
  1620                 << mSupportedOuterTypes[ind].pluginHandle().type().eapExpandedData().toHex();
  1668                 << mSupportedOuterTypes[ind].pluginHandle().type().eapExpandedData().toHex();
  1621         }
  1669         }
  1623 
  1671 
  1624     bool ret = true;
  1672     bool ret = true;
  1625 
  1673 
  1626     // set selection to EAP server, no need to have correct content in mOuterEapsOff,  
  1674     // set selection to EAP server, no need to have correct content in mOuterEapsOff,  
  1627     // EAP server handles it, mOuterEapsOn is only important
  1675     // EAP server handles it, mOuterEapsOn is only important
  1628     TUint err = mEapGsIf->SetEapMethods(mOuterEapsOn, mOuterEapsOff);
  1676     err = mEapGsIf->SetEapMethods(mOuterEapsOn, mOuterEapsOff);
  1629     if (err != KErrNone) {
  1677     if (err != KErrNone) {
  1630         qDebug("EapQtConfigInterfacePrivate::setSelectedOuterTypes() - SetEapMethods failed: %d",
  1678         qDebug("EapQtConfigInterfacePrivate::setSelectedOuterTypes() - SetEapMethods failed: %d",
  1631             err);
  1679             err);
  1632         // nothing we can do to recover, just exit
  1680         // nothing we can do to recover, just exit
  1633         ret = false;
  1681         ret = false;