refactor: secure password transmission by QDBusUnixFileDescriptor#292
Open
GongHeng2017 wants to merge 1 commit into
Open
refactor: secure password transmission by QDBusUnixFileDescriptor#292GongHeng2017 wants to merge 1 commit into
GongHeng2017 wants to merge 1 commit into
Conversation
5d13571 to
ecae51d
Compare
Changed from using base64-encoded password strings to using QDBusUnixFileDescriptor for transmitting passwords during network mount operations Log: Enhanced security of password transmission in network mounting Influence: 1. Test network mount with password to ensure successful authentication 2. Verify anonymous mount still works without password 3. Validate password saving functionality when savePasswd is enabled 4. Test mount failure scenarios (wrong password, network error) to ensure error handling 5. Ensure compatibility with existing D-Bus service (MountControl) that expects file descriptor feat: 在网络挂载中使用文件描述符安全传输密码 将密码传输从 base64 编码字符串改为使用 QDBusUnixFileDescriptor Log: 改进了网络挂载中密码传输的安全性 Task: https://pms.uniontech.com/task-view-389921.html Influence: 1. 测试带密码的网络挂载,确保认证成功 2. 验证匿名挂载在无密码时仍能正常工作 3. 验证启用 savePasswd 时的密码保存功能 4. 测试挂载失败场景(错误密码、网络错误)以确保错误处理正常 5. 确保与现有 D-Bus 服务(MountControl)的兼容性,该服务期望接收文件描述符
ecae51d to
6d2b32f
Compare
deepin pr auto review你好!我是CodeGeeX。我已仔细审查了你提供的 Git Diff。本次代码变更的核心是将网络挂载(CIFS)的密码传输方式从 Base64编码字符串 改为了通过 不过,在语法逻辑、代码质量、性能和安全性方面,这段代码仍有不少需要改进和优化的地方。以下是详细的审查意见: 1. 语法与逻辑
2. 代码质量
3. 代码性能
4. 代码安全
改进后的代码建议#include <unistd.h>
#include <string.h>
#include <QDBusUnixFileDescriptor>
// 安全擦除 QByteArray 内存的辅助函数
static void secureClearByteArray(QByteArray &ba) {
if (ba.capacity() > 0) {
// 使用 volatile 防止编译器优化掉 memset
volatile char *ptr = ba.data();
size_t size = ba.size();
while (size--) {
*ptr++ = 0;
}
}
ba.clear();
}
static QVariant preparePasswd(const QString &passwd)
{
if (passwd.isEmpty()) {
// 返回空 QVariant 表示无需密码,而不是空字符串,以区分错误状态
return QVariant();
}
int fd = memfd_create("DNetworkMounterPasswd", MFD_CLOEXEC);
if (fd < 0) {
qCritical() << "Failed to create memfd for data transfer, error:" << strerror(errno);
return QVariant();
}
QByteArray byteData = passwd.toUtf8();
ssize_t written = ::write(fd, byteData.constData(), byteData.size());
// 写入后立即安全擦除内存中的明文
secureClearByteArray(byteData);
if (written < 0 || static_cast<ssize_t>(passwd.toUtf8().size()) != written) {
qCritical() << "Failed to write data to memfd, error:" << strerror(errno);
::close(fd);
return QVariant();
}
off_t seek_pos = lseek(fd, 0, SEEK_SET);
if (seek_pos < 0 || seek_pos != 0) {
qCritical() << "Failed to seek memfd to beginning, error:" << strerror(errno);
::close(fd);
return QVariant();
}
QDBusUnixFileDescriptor dbusFd;
dbusFd.giveFileDescriptor(fd);
// 注意:fd 的所有权已移交给 dbusFd,后续无需手动 close
return QVariant::fromValue(dbusFd);
}总结你从 Base64 转向 FD 传输的思路非常正确,有效提升了 D-Bus 通信层面的安全性。主要需要关注的是错误处理机制的完善(不要用空字符串代表错误)、内存中明文密码的擦除,以及确认 |
Johnson-zs
approved these changes
May 21, 2026
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: GongHeng2017, Johnson-zs The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changed from using base64-encoded password strings to using QDBusUnixFileDescriptor for transmitting passwords during network mount operations
Log: Enhanced security of password transmission in network mounting
Influence:
feat: 在网络挂载中使用文件描述符安全传输密码
将密码传输从 base64 编码字符串改为使用 QDBusUnixFileDescriptor
Log: 改进了网络挂载中密码传输的安全性
Task: https://pms.uniontech.com/task-view-389921.html
Influence: