Skip to content

Commit e3ad294

Browse files
itsXuStdeepin-bot[bot]
authored andcommitted
fix: disk encryption is not working
- fix wrong dbus address; - refact checkAuth function, use polkit directly - fix encryption error on higher cryptsetup - bump version. Log: as above. Bug: https://pms.uniontech.com/bug-view-289139.html
1 parent adcab84 commit e3ad294

6 files changed

Lines changed: 55 additions & 8 deletions

File tree

debian/changelog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
dde-file-manager-extensions (1.5.1) unstable; urgency=medium
2+
3+
* fix encrypt issues on V23/25
4+
*
5+
6+
-- XuShitong <xushitong@uniontech.com> Thu, 28 Nov 2024 16:46:46 +0800
7+
18
dde-file-manager-extensions (1.5.0) unstable; urgency=medium
29

310
* update version to 1.5.0

src/dde-file-manager/dfmplugin-disk-encrypt-entry/dfmplugin_disk_encrypt_global.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ enum TPMModuleEncType {
2424
kUseTpmAndPrcAndPin
2525
};
2626

27-
inline constexpr char kDaemonBusName[] { "org.deepin.Filemanager" };
27+
inline constexpr char kDaemonBusName[] { "org.deepin.Filemanager.DiskEncrypt" };
2828
inline constexpr char kDaemonBusPath[] { "/org/deepin/Filemanager/DiskEncrypt" };
2929
inline constexpr char kDaemonBusIface[] { "org.deepin.Filemanager.DiskEncrypt" };
3030

src/service/diskencrypt/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ find_package(dfm-mount REQUIRED)
1717
find_package(dfm-base REQUIRED)
1818
find_package(PkgConfig REQUIRED)
1919
pkg_check_modules(CryptSetup REQUIRED libcryptsetup)
20+
pkg_check_modules(Polkit REQUIRED polkit-agent-1 polkit-qt5-1)
2021

2122
add_definitions(-DSERVICE_CONFIG_DIR="${CMAKE_INSTALL_PREFIX}/share/deepin-service-manager/")
2223

@@ -51,6 +52,7 @@ target_link_libraries(${BIN_NAME} PRIVATE
5152
${dfm-mount_LIBRARIES}
5253
${dfm-base_LIBRARIES}
5354
${deepin-qdbus-service_LIBRARIES}
55+
${Polkit_LIBRARIES}
5456
)
5557

5658
target_include_directories(${BIN_NAME}

src/service/diskencrypt/diskencryptdbus.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <QDBusConnection>
1919

2020
#include <libcryptsetup.h>
21+
#include <polkit-qt5-1/PolkitQt1/Authority>
2122

2223
FILE_ENCRYPT_USE_NS
2324
using namespace disk_encrypt;
@@ -248,9 +249,17 @@ void DiskEncryptDBus::onFstabDiskEncFinished(const QString &dev, int result, con
248249

249250
bool DiskEncryptDBus::checkAuth(const QString &actID)
250251
{
251-
return dpfSlotChannel->push("daemonplugin_core", "slot_Polkit_CheckAuth",
252-
actID, message().service())
253-
.toBool();
252+
using namespace PolkitQt1;
253+
254+
QString appBusName = message().service();
255+
if (appBusName.isEmpty())
256+
return false;
257+
258+
// PolkitUnixProcess表示 UNIX 进程的对象。注意:这个设计的对象现在已知已损坏;确定了一种利用 Linux 内核中启动时间延迟的机制。避免调用 `polkit_subject_equal()` 来比较两个进程。
259+
Authority::Result result = Authority::instance()->checkAuthorizationSync(actID,
260+
SystemBusNameSubject(appBusName),
261+
Authority::AllowUserInteraction);
262+
return result == Authority::Yes;
254263
}
255264

256265
bool DiskEncryptDBus::triggerReencrypt(const QString &device)

src/service/diskencrypt/encrypt/diskencrypt.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <QJsonDocument>
1515
#include <QJsonObject>
1616
#include <QDBusInterface>
17+
#include <QString>
18+
#include <QRandomGenerator>
19+
1720

1821
#include <dfm-base/utils/finallyutil.h>
1922
#include <dfm-mount/dmount.h>
@@ -84,12 +87,13 @@ struct crypt_params_reencrypt *resumeParams()
8487
static struct crypt_params_reencrypt params
8588
{
8689
.mode = CRYPT_REENCRYPT_REENCRYPT,
87-
.direction = CRYPT_REENCRYPT_FORWARD,
88-
.resilience = "checksum",
90+
.direction = CRYPT_REENCRYPT_BACKWARD,
91+
.resilience = "datashift",
8992
.hash = "sha256",
93+
.data_shift = 32 * 1024,
9094
.max_hotzone_size = 0,
9195
.device_size = 0,
92-
.flags = CRYPT_REENCRYPT_RESUME_ONLY
96+
.flags = CRYPT_REENCRYPT_RESUME_ONLY | CRYPT_REENCRYPT_MOVE_FIRST_SEGMENT
9397
};
9498
return &params;
9599
}
@@ -148,14 +152,38 @@ bool disk_encrypt_utils::bcValidateParams(const EncryptParams &params)
148152
return true;
149153
}
150154

155+
156+
QString disk_encrypt_utils::generateRandomString(int length)
157+
{
158+
// 定义字符集
159+
const QString charset = QString("0123456789"
160+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
161+
"abcdefghijklmnopqrstuvwxyz");
162+
163+
QString result;
164+
result.reserve(length);
165+
166+
// 获取全局随机生成器实例
167+
QRandomGenerator *generator = QRandomGenerator::global();
168+
169+
// 生成随机字符串
170+
for (int i = 0; i < length; ++i) {
171+
int index = generator->bounded(charset.length());
172+
result.append(charset.at(index));
173+
}
174+
175+
return result;
176+
}
177+
151178
QString disk_encrypt_utils::bcGenRecKey()
152179
{
153180
QString recKey;
154181
QLibrary lib("usec-recoverykey");
155182
dfmbase::FinallyUtil finalClear([&] { if (lib.isLoaded()) lib.unload(); });
156183

157184
if (!lib.load()) {
158-
qWarning() << "libusec-recoverykey load failed. use uuid as recovery key";
185+
qWarning() << "libusec-recoverykey load failed. use default generator";
186+
recKey = generateRandomString();
159187
return recKey;
160188
}
161189

src/service/diskencrypt/encrypt/diskencrypt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ EncryptParams bcConvertParams(const QVariantMap &params);
6161
bool bcValidateParams(const EncryptParams &params);
6262
bool bcReadEncryptConfig(disk_encrypt::EncryptConfig *config, const QString &device = QString());
6363

64+
QString generateRandomString(int length = 24);
6465
QString bcGenRecKey();
6566
bool bcSaveRecoveryKey(const QString &dev, const QString &key, const QString &path);
6667
bool bcHasEncryptConfig(const QString &dev);

0 commit comments

Comments
 (0)