diff options
Diffstat (limited to 'kcontrol/hwmanager/devicepropsdlg.cpp')
-rw-r--r-- | kcontrol/hwmanager/devicepropsdlg.cpp | 432 |
1 files changed, 410 insertions, 22 deletions
diff --git a/kcontrol/hwmanager/devicepropsdlg.cpp b/kcontrol/hwmanager/devicepropsdlg.cpp index 12de8cea9..885dc7a7a 100644 --- a/kcontrol/hwmanager/devicepropsdlg.cpp +++ b/kcontrol/hwmanager/devicepropsdlg.cpp @@ -32,13 +32,19 @@ #undef Unsorted // Required for --enable-final (tqdir.h) #include <tqfiledialog.h> +#include <kpassdlg.h> +#include <kactivelabel.h> #include <kbuttonbox.h> #include <kcombobox.h> #include <tdelocale.h> #include <tdeapplication.h> #include <klineedit.h> +#include <kpushbutton.h> #include <kstdguiitem.h> #include <tdemessagebox.h> +#include <ksslcertificate.h> + +#include "cryptpassworddlg.h" #include "devicepropsdlg.h" @@ -255,6 +261,7 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge // Remove all non-applicable tabs if (m_device->type() != TDEGenericDeviceType::Disk) { base->tabBarWidget->removePage(base->tabDisk); + base->tabBarWidget->removePage(base->tabDiskCrypt); } if (m_device->type() != TDEGenericDeviceType::CPU) { base->tabBarWidget->removePage(base->tabCPU); @@ -283,13 +290,29 @@ DevicePropertiesDialog::DevicePropertiesDialog(TDEGenericDevice* device, TQWidge if (m_device->type() != TDEGenericDeviceType::Event) { base->tabBarWidget->removePage(base->tabEvent); } + if (m_device->type() != TDEGenericDeviceType::CryptographicCard) { + base->tabBarWidget->removePage(base->tabCryptographicCard); + } if (m_device->type() == TDEGenericDeviceType::CPU) { connect(base->comboCPUGovernor, TQT_SIGNAL(activated(const TQString &)), this, TQT_SLOT(setCPUGovernor(const TQString &))); } if (m_device->type() == TDEGenericDeviceType::Disk) { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); connect(base->buttonDiskMount, TQT_SIGNAL(clicked()), this, TQT_SLOT(mountDisk())); connect(base->buttonDiskUnmount, TQT_SIGNAL(clicked()), this, TQT_SLOT(unmountDisk())); + if (sdevice->isDiskOfType(TDEDiskDeviceType::LUKS)) { + connect(base->cryptLUKSAddKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSAddKey())); + connect(base->cryptLUKSDelKey, TQT_SIGNAL(clicked()), this, TQT_SLOT(cryptLUKSDelKey())); + connect(base->cryptLUKSKeySlotList, TQT_SIGNAL(selectionChanged()), this, TQT_SLOT(processLockouts())); + base->cryptLUKSKeySlotList->setAllColumnsShowFocus(true); + base->cryptLUKSKeySlotList->setFullWidth(true); + cryptLUKSPopulateList(); + processLockouts(); + } + else { + base->tabBarWidget->removePage(base->tabDiskCrypt); + } } if ((m_device->type() == TDEGenericDeviceType::OtherSensor) || (m_device->type() == TDEGenericDeviceType::ThermalSensor)) { @@ -340,17 +363,21 @@ TQString assembleSwitchList(TDESwitchType::TDESwitchType switches) { return (TDEEventDevice::friendlySwitchList(switches).join("<br>")); } +static TQString formatDisplayString(TQString input) { + return TQStyleSheet::escape(input); +} + void DevicePropertiesDialog::populateDeviceInformation() { if (m_device) { base->labelDeviceType->setText(m_device->friendlyDeviceType()); base->iconDeviceType->setPixmap(m_device->icon(TDEIcon::SizeSmall)); - base->labelDeviceName->setText(m_device->friendlyName()); - base->labelDeviceNode->setText((m_device->deviceNode().isNull())?i18n("<none>"):m_device->deviceNode()); - base->labelSystemPath->setText(m_device->systemPath()); - base->labelSubsytemType->setText(m_device->subsystem()); - base->labelDeviceDriver->setText((m_device->deviceDriver().isNull())?i18n("<none>"):m_device->deviceDriver()); - base->labelDeviceClass->setText((m_device->PCIClass().isNull())?i18n("<n/a>"):m_device->PCIClass()); - base->labelModalias->setText((m_device->moduleAlias().isNull())?i18n("<none>"):m_device->moduleAlias()); + base->labelDeviceName->setText(formatDisplayString(m_device->friendlyName())); + base->labelDeviceNode->setText(formatDisplayString((m_device->deviceNode().isNull())?i18n("<none>"):m_device->deviceNode())); + base->labelSystemPath->setText(formatDisplayString(m_device->systemPath())); + base->labelSubsytemType->setText(formatDisplayString(m_device->subsystem())); + base->labelDeviceDriver->setText(formatDisplayString((m_device->deviceDriver().isNull())?i18n("<none>"):m_device->deviceDriver())); + base->labelDeviceClass->setText(formatDisplayString((m_device->PCIClass().isNull())?i18n("<n/a>"):m_device->PCIClass())); + base->labelModalias->setText(formatDisplayString((m_device->moduleAlias().isNull())?i18n("<none>"):m_device->moduleAlias())); // These might be redundant #if 0 @@ -362,10 +389,10 @@ void DevicePropertiesDialog::populateDeviceInformation() { base->labelVendorModel->hide(); base->stocklabelVendorModel->hide(); #endif - base->labelSerialNumber->setText((m_device->serialNumber().isNull())?i18n("<unknown>"):m_device->serialNumber()); + base->labelSerialNumber->setText(formatDisplayString((m_device->serialNumber().isNull())?i18n("<unknown>"):m_device->serialNumber())); if (m_device->subsystem() == "pci") { - base->labelBusID->setText(m_device->busID()); + base->labelBusID->setText(formatDisplayString(m_device->busID())); base->labelBusID->show(); base->stocklabelBusID->show(); } @@ -379,15 +406,15 @@ void DevicePropertiesDialog::populateDeviceInformation() { TQString mountPoint = sdevice->mountPath(); if (mountPoint == "") mountPoint = i18n("<none>"); - base->labelDiskMountpoint->setText(mountPoint); + base->labelDiskMountpoint->setText(formatDisplayString(mountPoint)); TQString fsName = sdevice->fileSystemName(); if (fsName == "") fsName = i18n("<unknown>"); - base->labelDiskFileSystemType->setText(fsName); + base->labelDiskFileSystemType->setText(formatDisplayString(fsName)); TQString volUUID = sdevice->diskUUID(); if (volUUID == "") volUUID = i18n("<none>"); - base->labelDiskUUID->setText(volUUID); + base->labelDiskUUID->setText(formatDisplayString(volUUID)); // Show status TQString status_text = "<qt>"; @@ -663,19 +690,22 @@ void DevicePropertiesDialog::populateDeviceInformation() { if ((*it) == TDESystemPowerState::Active) { powerStatesString += i18n("Active<br>"); } - if ((*it) == TDESystemPowerState::Standby) { + else if ((*it) == TDESystemPowerState::Standby) { powerStatesString += i18n("Standby<br>"); } - if ((*it) == TDESystemPowerState::Freeze) { + else if ((*it) == TDESystemPowerState::Freeze) { powerStatesString += i18n("Freeze<br>"); } - if ((*it) == TDESystemPowerState::Suspend) { + else if ((*it) == TDESystemPowerState::Suspend) { powerStatesString += i18n("Suspend<br>"); } - if ((*it) == TDESystemPowerState::Hibernate) { + else if ((*it) == TDESystemPowerState::Hibernate) { powerStatesString += i18n("Hibernate<br>"); } - if ((*it) == TDESystemPowerState::PowerOff) { + else if ((*it) == TDESystemPowerState::HybridSuspend) { + powerStatesString += i18n("Hybrid Suspend<br>"); + } + else if ((*it) == TDESystemPowerState::PowerOff) { powerStatesString += i18n("Power Off<br>"); } } @@ -697,19 +727,22 @@ void DevicePropertiesDialog::populateDeviceInformation() { if ((*it) == TDESystemHibernationMethod::Unsupported) { label = i18n("<none>"); } - if ((*it) == TDESystemHibernationMethod::Platform) { + else if ((*it) == TDESystemHibernationMethod::Platform) { label = i18n("Platform"); } - if ((*it) == TDESystemHibernationMethod::Shutdown) { + else if ((*it) == TDESystemHibernationMethod::Suspend) { + label = i18n("Suspend"); + } + else if ((*it) == TDESystemHibernationMethod::Shutdown) { label = i18n("Shutdown"); } - if ((*it) == TDESystemHibernationMethod::Reboot) { + else if ((*it) == TDESystemHibernationMethod::Reboot) { label = i18n("Reboot"); } - if ((*it) == TDESystemHibernationMethod::TestProc) { + else if ((*it) == TDESystemHibernationMethod::TestProc) { label = i18n("Test Procedure"); } - if ((*it) == TDESystemHibernationMethod::Test) { + else if ((*it) == TDESystemHibernationMethod::Test) { label = i18n("Test"); } base->comboSystemHibernationMethod->insertItem(label, i); @@ -723,6 +756,7 @@ void DevicePropertiesDialog::populateDeviceInformation() { base->labelSystemUserCanFreeze->setText((rdevice->canFreeze())?i18n("Yes"):i18n("No")); base->labelSystemUserCanSuspend->setText((rdevice->canSuspend())?i18n("Yes"):i18n("No")); base->labelSystemUserCanHibernate->setText((rdevice->canHibernate())?i18n("Yes"):i18n("No")); + base->labelSystemUserCanHybridSuspend->setText((rdevice->canHybridSuspend())?i18n("Yes"):i18n("No")); base->labelSystemUserCanPowerOff->setText((rdevice->canPowerOff())?i18n("Yes"):i18n("No")); base->labelSystemHibernationSpace->setText((rdevice->diskSpaceNeededForHibernation()<0)?i18n("<unknown>"):TDEHardwareDevices::bytesToFriendlySizeString(rdevice->diskSpaceNeededForHibernation())); @@ -753,6 +787,73 @@ void DevicePropertiesDialog::populateDeviceInformation() { } base->labelEventSwitchActive->setText(activeSwitches); } + + if (m_device->type() == TDEGenericDeviceType::CryptographicCard) { + TDECryptographicCardDevice* cdevice = static_cast<TDECryptographicCardDevice*>(m_device); + + connect(cdevice, TQT_SIGNAL(cardInserted(TDECryptographicCardDevice*)), this, TQT_SLOT(cryptographicCardInserted())); + connect(cdevice, TQT_SIGNAL(cardRemoved(TDECryptographicCardDevice*)), this, TQT_SLOT(cryptographicCardRemoved())); + + updateCryptographicCardStatusDisplay(); + } + } +} + +void DevicePropertiesDialog::cryptographicCardInserted() { + updateCryptographicCardStatusDisplay(); +} + +void DevicePropertiesDialog::cryptographicCardRemoved() { + updateCryptographicCardStatusDisplay(); +} + +void DevicePropertiesDialog::updateCryptographicCardStatusDisplay() { + TDECryptographicCardDevice* cdevice = static_cast<TDECryptographicCardDevice*>(m_device); + + int status = cdevice->cardPresent(); + if ((status < 0) ||(status > 1)) { + base->labelCardStatus->setText(i18n("Unknown")); + base->labelCardCertificates->setText(""); + base->groupCardCerts->hide(); + } + else if (status == 0) { + base->labelCardStatus->setText(i18n("Empty")); + base->labelCardCertificates->setText(""); + base->groupCardCerts->hide(); + } + else if (status == 1) { + base->labelCardStatus->setText(i18n("Inserted") + TQString("<br>") + i18n("ATR: %1").arg(cdevice->cardATR())); + + X509CertificatePtrList certList = cdevice->cardX509Certificates(); + + if (certList.count() > 0) { + // Assemble list of certificates on card + unsigned int certificate_number = 1; + TQString certInfo = "<qt>"; + X509CertificatePtrList::iterator it; + for (it = certList.begin(); it != certList.end(); ++it) { + KSSLCertificate* tdeCert = KSSLCertificate::fromX509(*it); + KSSLCertificate::KSSLValidation validationStatus = tdeCert->validate(); + certInfo += i18n("Certificate #%1").arg(certificate_number) + ":<br>"; + certInfo += i18n("Subject") + ": " + tdeCert->getSubject() + "<br>"; + certInfo += i18n("Issuer") + ": " + tdeCert->getIssuer() + "<br>"; + certInfo += i18n("Status") + ": " + KSSLCertificate::verifyText(validationStatus) + "<br>"; + certInfo += i18n("Valid From") + ": " + tdeCert->getNotBefore() + "<br>"; + certInfo += i18n("Valid Until") + ": " + tdeCert->getNotAfter() + "<br>"; + certInfo += i18n("Serial Number") + ": " + tdeCert->getSerialNumber() + "<br>"; + certInfo += i18n("MD5 Digest") + ": " + tdeCert->getMD5DigestText() + "<br>"; + certInfo += "<p>"; + delete tdeCert; + certificate_number++; + } + certInfo += "</qt>"; + base->labelCardCertificates->setText(certInfo); + base->groupCardCerts->show(); + } + else { + base->labelCardCertificates->setText(""); + base->groupCardCerts->hide(); + } } } @@ -825,6 +926,293 @@ void DevicePropertiesDialog::unmountDisk() { populateDeviceInformation(); } +void DevicePropertiesDialog::cryptLUKSAddKey() { + int retcode; + + if (m_device->type() == TDEGenericDeviceType::Disk) { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + TQListViewItem* lvi = base->cryptLUKSKeySlotList->selectedItem(); + if (lvi) { + TDECryptographicCardDevice* cdevice = NULL; + unsigned int key_slot = lvi->text(0).toUInt(); + bool allow_card = false; + bool use_card = false; + bool luks_card_key_modified = false; + KSSLCertificate* card_cert = NULL; + X509* card_cert_x509; + TQString disk_uuid = sdevice->diskUUID(); + TDEGenericDevice *hwdevice; + TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices(); + TDEGenericHardwareList cardReaderList = hwdevices->listByDeviceClass(TDEGenericDeviceType::CryptographicCard); + for (hwdevice = cardReaderList.first(); hwdevice; hwdevice = cardReaderList.next()) { + cdevice = static_cast<TDECryptographicCardDevice*>(hwdevice); + X509CertificatePtrList certList = cdevice->cardX509Certificates(); + if (certList.count() > 0) { + allow_card = true; + card_cert_x509 = certList[0]; + card_cert = KSSLCertificate::fromX509(certList[0]); + } + } + TQByteArray new_password; + CryptPasswordDialog* passDlg = new CryptPasswordDialog(this, i18n("Enter the new LUKS password for key slot %1").arg(key_slot), TQString::null, allow_card, card_cert, &use_card); + if (passDlg->exec() == TQDialog::Accepted) { + new_password = passDlg->password(); + if (allow_card && use_card) { + // Create new private key for disk device + if (!TQDir("/etc/trinity/luks").exists()) { + TQDir directory; + if (!directory.mkdir("/etc/trinity/luks", true)) { + KMessageBox::error(this, i18n("<qt><b>Key creation failed</b><br>Please check that you have write access to /etc/trinity and try again</qt>"), i18n("Key creation failure")); + delete card_cert; + return; + } + } + if (!TQDir("/etc/trinity/luks/card").exists()) { + TQDir directory; + if (!directory.mkdir("/etc/trinity/luks/card", true)) { + KMessageBox::error(this, i18n("<qt><b>Key creation failed</b><br>Please check that you have write access to /etc/trinity/luks and try again</qt>"), i18n("Key creation failure")); + delete card_cert; + return; + } + } + TQString cryptoFileName = TQString("/etc/trinity/luks/card/%1_slot%2").arg(disk_uuid).arg(key_slot); + TQFile file(cryptoFileName); + if (file.exists()) { + if (KMessageBox::warningYesNo(this, i18n("<qt><b>You are about to overwrite an existing card key for LUKS key slot %1</b><br>This action cannot be undone<p>Are you sure you want to proceed?</qt>").arg(key_slot), i18n("Confirmation Required")) != KMessageBox::Yes) { + delete card_cert; + return; + } + } + if (file.open(IO_WriteOnly)) { + TQByteArray randomKey; + TQByteArray encryptedRandomKey; + + // Create a new secret key using the public key from the card certificate + if (TDECryptographicCardDevice::createNewSecretRSAKeyFromCertificate(randomKey, encryptedRandomKey, card_cert_x509) < 0) { + KMessageBox::error(this, i18n("<qt><b>Key creation failed</b><br>Unable to create new secret key using the provided X509 certificate</qt>"), i18n("Key creation failure")); + delete card_cert; + return; + } + + // Write the encrypted key file to disk + file.writeBlock(encryptedRandomKey, encryptedRandomKey.size()); + file.close(); + + // Use the secret key as the LUKS passcode + new_password = randomKey; + luks_card_key_modified = true; + } + else { + KMessageBox::error(this, i18n("<qt><b>Key creation failed</b><br>Please check that you have write access to /etc/trinity/luks/card and try again</qt>"), i18n("Key creation failure")); + delete card_cert; + return; + } + } + delete passDlg; + if (!sdevice->cryptOperationsUnlockPasswordSet()) { + TQCString password; + passDlg = new CryptPasswordDialog(this, i18n("Enter the LUKS device unlock password"), TQString::null, allow_card, card_cert, &use_card); + if (passDlg->exec() == TQDialog::Accepted) { + TQByteArray unlockPassword = passDlg->password(); + if (use_card) { + // List all matching keys in directory and try each in turn... + TQDir luksKeyDir("/etc/trinity/luks/card/"); + luksKeyDir.setFilter(TQDir::Files); + luksKeyDir.setSorting(TQDir::Unsorted); + + TQValueList<TQByteArray> luksCryptedList; + TQValueList<TQByteArray> luksDecryptedList; + TQValueList<int> luksSlotNumberList; + + const TQFileInfoList *luksKeyDirList = luksKeyDir.entryInfoList(); + TQFileInfoListIterator it(*luksKeyDirList); + TQFileInfo *luksKeyFileInfo; + TQString errstr; + while ((luksKeyFileInfo = it.current()) != 0) { + if (luksKeyFileInfo->fileName().startsWith(disk_uuid) && luksKeyFileInfo->fileName().contains("_slot")) { + // Found candidate, try decryption + TQFile luksKeyFile(luksKeyFileInfo->absFilePath()); + if (luksKeyFile.open(IO_ReadOnly)) { + TQByteArray keycrypted = luksKeyFile.readAll(); + luksCryptedList.append(keycrypted); + + // Parse the file name and find the matching key slot + int current_card_keyslot = -1; + TQString fileName = luksKeyFile.name(); + int pos = fileName.find("_slot"); + if (pos >= 0) { + fileName.remove(0, pos + strlen("_slot")); + current_card_keyslot = fileName.toInt(); + luksSlotNumberList.append(current_card_keyslot); + } + } + } + ++it; + } + + // Decrypt LUKS keys + TQValueList<int> retCodeList; + retcode = cdevice->decryptDataEncryptedWithCertPublicKey(luksCryptedList, luksDecryptedList, retCodeList, &errstr); + TQValueList<TQByteArray>::iterator it2; + TQValueList<int>::iterator it3; + TQValueList<int>::iterator it4; + for (it2 = luksDecryptedList.begin(), it3 = retCodeList.begin(), it4 = luksSlotNumberList.begin(); it2 != luksDecryptedList.end(); ++it2, ++it3, ++it4) { + TQByteArray luksKeyData = *it2; + retcode = *it3; + int current_card_keyslot = *it4; + if (retcode == -3) { + // User cancelled + break; + } + if (retcode < 0) { + // ERROR + } + else { + // Key decryption successful, try to open LUKS device... + sdevice->cryptSetOperationsUnlockPassword(luksKeyData); + if (sdevice->cryptCheckKey(current_card_keyslot) == TDELUKSResult::Success) { + break; + } + else { + sdevice->cryptClearOperationsUnlockPassword(); + } + } + } + if (!sdevice->cryptOperationsUnlockPasswordSet()) { + KMessageBox::error(this, i18n("<qt><b>Key write failed</b><br>Please check the LUKS password and try again</qt>"), i18n("Key write failure")); + } + } + else { + sdevice->cryptSetOperationsUnlockPassword(unlockPassword); + } + } + delete passDlg; + } + if (sdevice->cryptOperationsUnlockPasswordSet()) { + if ((lvi->text(1) == sdevice->cryptKeySlotFriendlyName(TDELUKSKeySlotStatus::Inactive)) || (KMessageBox::warningYesNo(this, i18n("<qt><b>You are about to overwrite the key in key slot %1</b><br>This action cannot be undone<p>Are you sure you want to proceed?</qt>").arg(key_slot), i18n("Confirmation Required")) == KMessageBox::Yes)) { + if (sdevice->cryptAddKey(key_slot, new_password) != TDELUKSResult::Success) { + sdevice->cryptClearOperationsUnlockPassword(); + KMessageBox::error(this, i18n("<qt><b>Key write failed</b><br>Please check the LUKS password and try again</qt>"), i18n("Key write failure")); + } + else { + if (luks_card_key_modified) { + if (KMessageBox::warningYesNo(this, i18n("<qt><b>You have created a new card-dependent key</b><br>Card-dependent keys work in conjunction with an encrypted key file stored on the host system.<br>When a card is used to boot, card-dependent keys must be updated in the initramfs image to become usable.<p>Would you like to update the initramfs image now?</qt>"), i18n("Update Required")) == KMessageBox::Yes) { + // Update the initramfs + if (system("update-initramfs -u -k all") != 0) { + KMessageBox::error(this, i18n("<qt><b>Initramfs update failed</b><br>Card-dependent keys may not be available for use until the root storage device is available / unlocked</qt>"), i18n("Initramfs update failure")); + } + } + } + } + } + } + } + else { + delete passDlg; + } + delete card_cert; + } + } + + cryptLUKSPopulateList(); +} + +void DevicePropertiesDialog::cryptLUKSDelKey() { + if (m_device->type() == TDEGenericDeviceType::Disk) { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + TQListViewItem* lvi = base->cryptLUKSKeySlotList->selectedItem(); + if (lvi) { + unsigned int key_slot = lvi->text(0).toUInt(); + if (KMessageBox::warningYesNo(this, i18n("<qt><b>You are about to purge the key in key slot %1</b><br>This action cannot be undone<p>Are you sure you want to proceed?</qt>").arg(lvi->text(0)), i18n("Confirmation Required")) == KMessageBox::Yes) { + if (sdevice->cryptKeySlotStatus()[key_slot] & TDELUKSKeySlotStatus::Last) { + if (KMessageBox::warningYesNo(this, i18n("<qt><b>You are about to purge the last active key from the device!</b><p>This action will render the contents of the encrypted device permanently inaccessable and cannot be undone<p>Are you sure you want to proceed?</qt>"), i18n("Confirmation Required")) != KMessageBox::Yes) { + cryptLUKSPopulateList(); + return; + } + } + if (sdevice->cryptDelKey(key_slot) != TDELUKSResult::Success) { + sdevice->cryptClearOperationsUnlockPassword(); + KMessageBox::error(this, i18n("<qt><b>Key purge failed</b><br>The key in key slot %1 is still active</qt>").arg(lvi->text(0)), i18n("Key purge failure")); + } + else { + // See if there was a cryptographic card key associated with this device and slot + TQString disk_uuid = sdevice->diskUUID(); + TQDir luksKeyDir("/etc/trinity/luks/card/"); + luksKeyDir.setFilter(TQDir::Files); + luksKeyDir.setSorting(TQDir::Unsorted); + + const TQFileInfoList *luksKeyDirList = luksKeyDir.entryInfoList(); + TQFileInfoListIterator it(*luksKeyDirList); + TQFileInfo *luksKeyFileInfo; + TQString errstr; + while ((luksKeyFileInfo = it.current()) != 0) { + if (luksKeyFileInfo->fileName().startsWith(disk_uuid) && luksKeyFileInfo->fileName().contains("_slot")) { + // Parse the file name and find the matching key slot + int current_card_keyslot = -1; + TQString fileName = luksKeyFileInfo->absFilePath(); + TQString fileNameSlot = fileName; + int pos = fileNameSlot.find("_slot"); + if (pos >= 0) { + fileNameSlot.remove(0, pos + strlen("_slot")); + current_card_keyslot = fileNameSlot.toInt(); + if (current_card_keyslot >= 0) { + if ((unsigned int)current_card_keyslot == key_slot) { + if (!TQFile(fileName).remove()) { + KMessageBox::error(this, i18n("<qt><b>Card key purge failed</b><br>The card key for slot %1 has been fully deactivated but is still present on your system<br>This does not present a significant security risk</qt>").arg(lvi->text(0)), i18n("Key purge failure")); + } + break; + } + } + } + } + ++it; + } + } + } + } + } + + cryptLUKSPopulateList(); +} + +void DevicePropertiesDialog::cryptLUKSPopulateList() { + unsigned int i; + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + base->cryptLUKSKeySlotList->clear(); + unsigned int count = sdevice->cryptKeySlotCount(); + TDELUKSKeySlotStatusList status = sdevice->cryptKeySlotStatus(); + for (i = 0; i < count; i++) { + new TQListViewItem(base->cryptLUKSKeySlotList, TQString("%1").arg(i), sdevice->cryptKeySlotFriendlyName(status[i])); + } + + processLockouts(); +} + +void DevicePropertiesDialog::processLockouts() { + if (m_device->type() == TDEGenericDeviceType::Disk) { + TDEStorageDevice* sdevice = static_cast<TDEStorageDevice*>(m_device); + + TQListViewItem* lvi = base->cryptLUKSKeySlotList->selectedItem(); + if (lvi) { + if (lvi->text(1) == sdevice->cryptKeySlotFriendlyName(TDELUKSKeySlotStatus::Active)) { + base->cryptLUKSAddKey->setEnabled(true); + base->cryptLUKSDelKey->setEnabled(true); + } + else { + base->cryptLUKSAddKey->setEnabled(true); + base->cryptLUKSDelKey->setEnabled(false); + } + } + else { + base->cryptLUKSAddKey->setEnabled(false); + base->cryptLUKSDelKey->setEnabled(false); + } + } +} + void DevicePropertiesDialog::virtual_hook( int id, void* data ) { KDialogBase::virtual_hook( id, data ); } |