Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [safety] string encrypt. #2051

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/dde-file-manager-daemon/disk/diskmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ void DiskManager::changeDiskPassword(const QString &oldPwd, const QString &newPw
return;
}

const QByteArray &tmpOldPwd = oldPwd.toLocal8Bit();
const QByteArray &tmpNewPwd = newPwd.toLocal8Bit();
QByteArray decodedByteArray = oldPwd.toUtf8();
const QByteArray &tmpOldPwd = QByteArray::fromBase64(decodedByteArray);

decodedByteArray = oldPwd.toUtf8();
const QByteArray &tmpNewPwd = QByteArray::fromBase64(decodedByteArray);

int ret = Unknown;
QStringList successList;
Expand Down
18 changes: 13 additions & 5 deletions src/dde-file-manager-daemon/usershare/usersharemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,27 @@ bool UserShareManager::addGroup(const QString &groupName)

bool UserShareManager::setUserSharePassword(const QString &username, const QString &passward)
{
QByteArray encodedByteArray = username.toUtf8();
QByteArray decodedByteArray = QByteArray::fromBase64(encodedByteArray);
const QString &decodedUsername = QString::fromUtf8(decodedByteArray);

encodedByteArray = passward.toUtf8();
decodedByteArray = QByteArray::fromBase64(encodedByteArray);
const QString &decodedPassward = QString::fromUtf8(decodedByteArray);

if (!checkAuthentication()) {
qDebug() << "setUserSharePassword failed" << username;
qDebug() << "setUserSharePassword failed" << decodedUsername;
return false;
}

qDebug() << username;// << passward; // log password?
qDebug() << decodedUsername;// << passward; // log password?
QStringList args;
args << "-a" << username << "-s";
args << "-a" << decodedUsername << "-s";
QProcess p;
p.start("smbpasswd", args);
p.write(passward.toStdString().c_str());
p.write(decodedPassward.toStdString().c_str());
p.write("\n");
p.write(passward.toStdString().c_str());
p.write(decodedPassward.toStdString().c_str());
p.closeWriteChannel();
bool ret = p.waitForFinished();
qDebug() << p.readAll() << p.readAllStandardError() << p.readAllStandardOutput();
Expand Down
10 changes: 9 additions & 1 deletion src/dde-file-manager-lib/diskpwdmanager/pwdconfirmwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ void PwdConfirmWidget::onSaveBtnClicked()
if (m_parentWidget)
DWindowManagerHelper::instance()->setMotifFunctions(m_parentWidget->windowHandle(), DWindowManagerHelper::FUNC_CLOSE, false);

m_diskInterface->changeDiskPassword(m_oldPwdEdit->text(), m_newPwdEdit->text());
QByteArray byteArray = m_oldPwdEdit->text().toUtf8();
QByteArray encodedByteArray = byteArray.toBase64();
const QString &encodedOldPwd = QString::fromUtf8(encodedByteArray);

byteArray = m_newPwdEditv->text().toUtf8();
encodedByteArray = byteArray.toBase64();
const QString &encodedNewPwd = QString::fromUtf8(encodedByteArray);

m_diskInterface->changeDiskPassword(encodedOldPwd, encodedNewPwd);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/usershare/usersharemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,15 @@ void UserShareManager::updateUserShareInfo(bool sendSignal)

void UserShareManager::setSambaPassword(const QString &userName, const QString &password)
{
QDBusReply<bool> reply = m_userShareInterface->setUserSharePassword(userName, password);
QByteArray byteArray = userName.toUtf8();
QByteArray encodedByteArray = byteArray.toBase64();
const QString &encodedUserName = QString::fromUtf8(encodedByteArray);

byteArray = password.toUtf8();
encodedByteArray = byteArray.toBase64();
const QString &encodedPassword = QString::fromUtf8(encodedByteArray);

QDBusReply<bool> reply = m_userShareInterface->setUserSharePassword(encodedUserName, encodedPassword);
if (reply.isValid()) {
qDebug() << "set usershare password:" << reply.value();
} else {
Expand Down
Loading