Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit 1973e0c

Browse files
committed
Replace deprecated usages of (en|de)crypt methods; fix password escaping
1 parent 9fd8daf commit 1973e0c

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

ajax/ajax.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
$ws->getConnexion($_POST['host'],
8686
$_POST['url'],
8787
$_POST['login'],
88-
Toolbox::sodiumDecrypt($_POST['pwd']));
88+
(new GLPIKey())->decrypt($_POST['pwd']));
8989
$result = $ws->getStateMantis();
9090

9191
if (! $result) {

front/config.form.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
$PluginMantisConfig = new PluginMantisConfig();
3838

3939
if (isset($_POST["update"])) {
40+
if (array_key_exists('pwd', $_POST)) {
41+
// Password must not be altered, it will be encrypted and never displayed, so sanitize is not necessary.
42+
$_POST['pwd'] = $_UPOST['pwd'];
43+
}
44+
4045
$PluginMantisConfig->check($_POST["id"], UPDATE);
4146
$PluginMantisConfig->update($_POST);
4247
Html::back();

inc/config.class.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ static function getTypeName($nb = 0) {
5050
**/
5151
function prepareInputForUpdate($input) {
5252

53-
if (isset($input["pwd"]) AND !empty($input["pwd"])) {
54-
$input["pwd"] = Toolbox::sodiumEncrypt(stripslashes($input["pwd"]));
53+
if (isset($input["pwd"]) && !empty($input["pwd"])) {
54+
$input["pwd"] = (new GLPIKey())->encrypt($input["pwd"]);
5555
}
5656
return $input;
5757
}
@@ -117,7 +117,7 @@ function showForm($ID, $options = []) {
117117
echo "<tr class='tab_bg_1'>";
118118
echo "<td>" . __("MantisBT user password", "mantis") . "</td>";
119119
echo "<td><input id='pwd' name='pwd' type='password' size='30'
120-
value='" . Toolbox::sodiumDecrypt($this->fields["pwd"]) . "' /></td>";
120+
value='" . Html::entities_deep((new GLPIKey())->decrypt($this->fields["pwd"])) . "' /></td>";
121121
echo "<td></td>";
122122
echo "</tr>";
123123

@@ -296,12 +296,7 @@ static function install(Migration $migration) {
296296
$DB->buildUpdate(
297297
'glpi_plugin_mantis_configs',
298298
[
299-
'pwd' => Toolbox::sodiumEncrypt(
300-
$key->decryptUsingLegacyKey(
301-
$config->fields['pwd'],
302-
$key->getLegacyKey()
303-
)
304-
)
299+
'pwd' => $key->encrypt($key->decryptUsingLegacyKey($config->fields['pwd']))
305300
],
306301
[
307302
'id' => 1,

inc/mantis.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public function showForm($item) {
492492
if ($ws->testConnectionWS($conf->getField('host'),
493493
$conf->getField('url'),
494494
$conf->getField('login'),
495-
Toolbox::sodiumDecrypt($conf->getField('pwd')))) {
495+
(new GLPIKey())->decrypt($conf->getField('pwd')))) {
496496

497497
if ($item->fields['status'] == $conf->fields['neutralize_escalation']
498498
|| $item->fields['status'] > $conf->fields['neutralize_escalation']) {

inc/mantisws.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function initializeConnection() {
6363
$this->_host = $conf->fields["host"];
6464
$this->_url = $conf->fields["url"];
6565
$this->_login = $conf->fields["login"];
66-
$this->_password = Toolbox::sodiumDecrypt($conf->fields["pwd"]);
66+
$this->_password = (new GLPIKey())->decrypt($conf->fields["pwd"]);
6767

6868
$this->_client = new SoapClient($this->_host . "/" . $this->_url, self::getOptionsStreamContext());
6969
return true;

0 commit comments

Comments
 (0)