Skip to content

Commit

Permalink
#3150 scripting: handle encryption and decryption correctly
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
  • Loading branch information
pbek committed Nov 3, 2024
1 parent c61197e commit 63fbe8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
21 changes: 9 additions & 12 deletions src/services/scriptingservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,18 @@ QList<QVariant> ScriptingService::registerSettingsVariables(QObject *object, con

object->setProperty(identifier.toUtf8(), value);
} else if (type == QStringLiteral("string-secret")) {
QString value = jsonObject.value(identifier).toString().toUtf8().toBase64();
QString value;

qDebug() << __func__ << " - 'type': " << type;
qDebug() << __func__ << " - 'value': " << value;
qDebug() << __func__ << " - 'CryptoService::instance()->encryptToString(value)': "
<< CryptoService::instance()->encryptToString(value);

// if (jsonObject.value(identifier).isUndefined()) {
// value = variableMap[QStringLiteral("default")].toString();
// }
if (!jsonObject.value(identifier).isUndefined()) {
value = jsonObject.value(identifier).toString();

// Decrypt the value if the value is not empty
if (!value.isEmpty()) {
value = CryptoService::instance()->decryptToString(value);
}
}

// object->setProperty(identifier.toUtf8(), value);
object->setProperty(identifier.toUtf8(),
CryptoService::instance()->encryptToString(value));
object->setProperty(identifier.toUtf8(), value);
} else {
QString value = jsonObject.value(identifier).toString();

Expand Down
22 changes: 14 additions & 8 deletions src/widgets/scriptsettingwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ ScriptSettingWidget::ScriptSettingWidget(QWidget *parent, const Script &script,
ui->stringLineEdit->setEchoMode(QLineEdit::Normal);
ui->stringLineEdit->show();
} else if (type == "string-secret") {
QString value = CryptoService::instance()->decryptToString(
QByteArray::fromBase64(jsonObject.value(identifier).toString().toUtf8()));
// QString value = CryptoService::instance()->decryptToString(
// jsonObject.value(identifier).toString());
QString value;

// if (jsonObject.value(identifier).isUndefined()) {
// value = variableMap["default"].toString();
// }
if (!jsonObject.value(identifier).isUndefined()) {
value = jsonObject.value(identifier).toString();

// Decrypt the value if the value is not empty
if (!value.isEmpty()) {
value = CryptoService::instance()->decryptToString(value);
}
}

ui->stringLineEdit->setText(value);
ui->stringLineEdit->setEchoMode(QLineEdit::Password);
Expand Down Expand Up @@ -163,7 +165,11 @@ void ScriptSettingWidget::storeSettingsVariable(const QJsonValue &value) {
* @param arg1
*/
void ScriptSettingWidget::on_stringLineEdit_textChanged(const QString &arg1) {
storeSettingsVariable(arg1);
if (_variableMap["type"].toString() == "string-secret") {
storeSettingsVariable(CryptoService::instance()->encryptToString(arg1));
} else {
storeSettingsVariable(arg1);
}
}

/**
Expand Down

0 comments on commit 63fbe8e

Please sign in to comment.