diff --git a/src/modules/partition/Config.cpp b/src/modules/partition/Config.cpp index 3a5e80a7c..4519bd278 100644 --- a/src/modules/partition/Config.cpp +++ b/src/modules/partition/Config.cpp @@ -373,7 +373,7 @@ Config::fillConfigurationFSTypes( const QVariantMap& configurationMap ) luksGeneration = Config::LuksGeneration::Luks1; } m_luksFileSystemType = luksGeneration; - gs->insert( "luksFileSystemType", luksGenerationNames().find(luksGeneration) ); + gs->insert( "luksFileSystemType", luksGenerationNames().find( luksGeneration ) ); Q_ASSERT( !m_eraseFsTypes.isEmpty() ); Q_ASSERT( m_eraseFsTypes.contains( fsRealName ) ); @@ -409,6 +409,8 @@ Config::setConfigurationMap( const QVariantMap& configurationMap ) } setSwapChoice( m_initialSwapChoice ); + m_allowZfsEncryption = CalamaresUtils::getBool( configurationMap, "allowZfsEncryption", true ); + m_allowManualPartitioning = CalamaresUtils::getBool( configurationMap, "allowManualPartitioning", true ); m_requiredPartitionTableType = CalamaresUtils::getStringList( configurationMap, "requiredPartitionTableType" ); diff --git a/src/modules/partition/Config.h b/src/modules/partition/Config.h index e59ee6887..0146d1a3e 100644 --- a/src/modules/partition/Config.h +++ b/src/modules/partition/Config.h @@ -159,6 +159,9 @@ public: */ LuksGeneration luksFileSystemType() const { return m_luksFileSystemType; } + /// @brief If zfs encryption should be allowed + bool allowZfsEncryption() const { return m_allowZfsEncryption; } + public Q_SLOTS: void setInstallChoice( int ); ///< Translates a button ID or so to InstallChoice void setInstallChoice( InstallChoice ); @@ -189,7 +192,7 @@ private: InstallChoice m_installChoice = NoChoice; qreal m_requiredStorageGiB = 0.0; // May duplicate setting in the welcome module QStringList m_requiredPartitionTableType; - + bool m_allowZfsEncryption = true; bool m_allowManualPartitioning = true; }; diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 7832196db..b31d042fd 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -4,6 +4,7 @@ * SPDX-FileCopyrightText: 2017-2019 Adriaan de Groot * SPDX-FileCopyrightText: 2019 Collabora Ltd * SPDX-FileCopyrightText: 2021 Anubhav Choudhary + * SPDX-FileCopyrightText: 2023 Evan James * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is Free Software: see the License-Identifier above. @@ -464,6 +465,18 @@ ChoicePage::continueApplyDeviceChoice() void ChoicePage::onActionChanged() { + if ( m_enableEncryptionWidget ) + { + if ( m_config->installChoice() == InstallChoice::Erase && m_eraseFsTypesChoiceComboBox ) + { + m_encryptWidget->setFilesystem( FileSystem::typeForName( m_eraseFsTypesChoiceComboBox->currentText() ) ); + } + else if ( m_config->installChoice() == InstallChoice::Replace && m_replaceFsTypesChoiceComboBox ) + { + m_encryptWidget->setFilesystem( FileSystem::typeForName( m_replaceFsTypesChoiceComboBox->currentText() ) ); + } + } + Device* currd = selectedDevice(); if ( currd ) { @@ -1747,16 +1760,16 @@ ChoicePage::createBootloaderPanel() bool ChoicePage::shouldShowEncryptWidget( Config::InstallChoice choice ) const { - // If there are any choices for FS, check it's not ZFS because that doesn't - // support the kind of encryption we enable here. bool suitableFS = true; - if ( ( m_eraseFsTypesChoiceComboBox && m_eraseFsTypesChoiceComboBox->isVisible() - && m_eraseFsTypesChoiceComboBox->currentText() == "zfs" ) - || ( m_replaceFsTypesChoiceComboBox && m_replaceFsTypesChoiceComboBox->isVisible() - && m_replaceFsTypesChoiceComboBox->currentText() == "zfs" ) ) + if ( !m_config->allowZfsEncryption() + && ( ( m_eraseFsTypesChoiceComboBox && m_eraseFsTypesChoiceComboBox->isVisible() + && m_eraseFsTypesChoiceComboBox->currentText() == "zfs" ) + || ( m_replaceFsTypesChoiceComboBox && m_replaceFsTypesChoiceComboBox->isVisible() + && m_replaceFsTypesChoiceComboBox->currentText() == "zfs" ) ) ) { suitableFS = false; } + const bool suitableChoice = choice == InstallChoice::Erase || choice == InstallChoice::Alongside || choice == InstallChoice::Replace; return suitableChoice && m_enableEncryptionWidget && suitableFS; diff --git a/src/modules/partition/gui/ChoicePage.h b/src/modules/partition/gui/ChoicePage.h index 684a55018..7deb4dec6 100644 --- a/src/modules/partition/gui/ChoicePage.h +++ b/src/modules/partition/gui/ChoicePage.h @@ -3,6 +3,7 @@ * SPDX-FileCopyrightText: 2014-2016 Teo Mrnjavac * SPDX-FileCopyrightText: 2018-2019 Adriaan de Groot * SPDX-FileCopyrightText: 2019 Collabora Ltd + * SPDX-FileCopyrightText: 2023 Evan James * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is Free Software: see the License-Identifier above. diff --git a/src/modules/partition/gui/EncryptWidget.cpp b/src/modules/partition/gui/EncryptWidget.cpp index 7c17de7af..f2ed1d17e 100644 --- a/src/modules/partition/gui/EncryptWidget.cpp +++ b/src/modules/partition/gui/EncryptWidget.cpp @@ -2,6 +2,7 @@ * * SPDX-FileCopyrightText: 2016 Teo Mrnjavac * SPDX-FileCopyrightText: 2020 Adriaan de Groot + * SPDX-FileCopyrightText: 2023 Evan James * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is Free Software: see the License-Identifier above. @@ -17,6 +18,8 @@ #include "utils/CalamaresUtilsGui.h" #include "utils/Retranslator.h" +constexpr int ZFS_MIN_LENGTH = 8; + /** @brief Does this system support whole-disk encryption? * * Returns @c true if the system is likely to support encryption @@ -143,7 +146,7 @@ applyPixmap( QLabel* label, CalamaresUtils::ImageType pixmap ) } void -EncryptWidget::updateState() +EncryptWidget::updateState( const bool notify ) { if ( m_ui->m_passphraseLineEdit->isVisible() ) { @@ -155,6 +158,11 @@ EncryptWidget::updateState() applyPixmap( m_ui->m_iconLabel, CalamaresUtils::StatusWarning ); m_ui->m_iconLabel->setToolTip( tr( "Please enter the same passphrase in both boxes." ) ); } + else if ( m_filesystem == FileSystem::Zfs && p1.length() < ZFS_MIN_LENGTH ) + { + applyPixmap( m_ui->m_iconLabel, CalamaresUtils::StatusError ); + m_ui->m_iconLabel->setToolTip( tr( "Password must be a minimum of %1 characters" ).arg( ZFS_MIN_LENGTH ) ); + } else if ( p1 == p2 ) { applyPixmap( m_ui->m_iconLabel, CalamaresUtils::StatusOk ); @@ -172,7 +180,10 @@ EncryptWidget::updateState() if ( newState != m_state ) { m_state = newState; - Q_EMIT stateChanged( m_state ); + if ( notify ) + { + Q_EMIT stateChanged( m_state ); + } } } @@ -201,3 +212,13 @@ EncryptWidget::onCheckBoxStateChanged( int checked ) updateState(); } + +void +EncryptWidget::setFilesystem( const FileSystem::Type fs ) +{ + m_filesystem = fs; + if ( m_state != Encryption::Disabled ) + { + updateState( false ); + } +} diff --git a/src/modules/partition/gui/EncryptWidget.h b/src/modules/partition/gui/EncryptWidget.h index 9a3b8ab1f..9669b4d21 100644 --- a/src/modules/partition/gui/EncryptWidget.h +++ b/src/modules/partition/gui/EncryptWidget.h @@ -2,6 +2,7 @@ * * SPDX-FileCopyrightText: 2016 Teo Mrnjavac * SPDX-FileCopyrightText: 2020 Adriaan de Groot + * SPDX-FileCopyrightText: 2023 Evan James * SPDX-License-Identifier: GPL-3.0-or-later * * Calamares is Free Software: see the License-Identifier above. @@ -14,6 +15,8 @@ #include +#include + namespace Ui { class EncryptWidget; @@ -38,6 +41,12 @@ public: Encryption state() const; void setText( const QString& text ); + /** + * @brief setFilesystem sets the filesystem name used for password validation + * @param fs A QString containing the name of the filesystem + */ + void setFilesystem( const FileSystem::Type fs ); + QString passphrase() const; void retranslate(); @@ -46,12 +55,14 @@ signals: void stateChanged( Encryption ); private: - void updateState(); + void updateState( const bool notify = true ); void onPassphraseEdited(); void onCheckBoxStateChanged( int checked ); Ui::EncryptWidget* m_ui; Encryption m_state; + + FileSystem::Type m_filesystem; }; #endif // ENCRYPTWIDGET_H diff --git a/src/modules/partition/partition.conf b/src/modules/partition/partition.conf index ad8ab994a..ecd183ca1 100644 --- a/src/modules/partition/partition.conf +++ b/src/modules/partition/partition.conf @@ -78,6 +78,16 @@ userSwapChoices: # luksGeneration: luks1 +# This setting determines if encryption should be allowed when using zfs. This +# setting has no effect unless zfs support is provided. +# +# This setting is to handle the fact that some bootloaders(such as grub) do not +# support zfs encryption. +# +# The default is true +# +# allowZfsEncryption: true + # Correctly draw nested (e.g. logical) partitions as such. drawNestedPartitions: false diff --git a/src/modules/partition/partition.schema.yaml b/src/modules/partition/partition.schema.yaml index 64c261d26..dafdc5851 100644 --- a/src/modules/partition/partition.schema.yaml +++ b/src/modules/partition/partition.schema.yaml @@ -1,4 +1,5 @@ # SPDX-FileCopyrightText: 2020 Adriaan de Groot +# SPDX-FileCopyrightText: 2023 Evan James # SPDX-License-Identifier: GPL-3.0-or-later --- $schema: https://json-schema.org/schema# @@ -14,6 +15,7 @@ properties: # ensureSuspendToDisk: { type: boolean, default: true } # Legacy # neverCreateSwap: { type: boolean, default: false } # Legacy + allowZfsEncryption: { type: boolean, default: true } drawNestedPartitions: { type: boolean, default: false } alwaysShowPartitionLabels: { type: boolean, default: true }