Skip to content

Commit

Permalink
Use consistent function calls for simpleEncrypt and simpleDecrypt in …
Browse files Browse the repository at this point in the history
…code.
  • Loading branch information
mark-unwin committed Apr 17, 2024
1 parent fccc272 commit a02547a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
9 changes: 3 additions & 6 deletions app/Controllers/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ public function amazon($cloud)
helper('security');
helper('network');
$db = db_connect();
$cloud->credentials = simpleDecrypt($cloud->credentials, config('Encryption')->key);
$cloud->credentials = json_decode($cloud->credentials);
$cloud->credentials = json_decode(simpleDecrypt($cloud->credentials, config('Encryption')->key));

$response = new stdClass();
$projects = array();
Expand Down Expand Up @@ -567,8 +566,7 @@ public function microsoft($cloud)
helper('security');
helper('network');
$db = db_connect();
$cloud->credentials = simpleDecrypt($cloud->credentials, config('Encryption')->key);
$cloud->credentials = json_decode($cloud->credentials);
$cloud->credentials = json_decode(simpleDecrypt($cloud->credentials, config('Encryption')->key));

$projects = array();
$projects[0] = new stdClass();
Expand Down Expand Up @@ -796,8 +794,7 @@ public function google($cloud)
helper('security');
helper('network');
$db = db_connect();
$cloud->credentials = simpleDecrypt($cloud->credentials, config('Encryption')->key);
$cloud->credentials = json_decode($cloud->credentials, true);
$cloud->credentials = json_decode(simpleDecrypt($cloud->credentials, config('Encryption')->key), true);
$jsonKey = json_decode($cloud->credentials['json'], true);


Expand Down
10 changes: 4 additions & 6 deletions app/Models/CloudsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function collection(object $resp): array
$count = count($query);
for ($i=0; $i < $count; $i++) {
if (!empty($query[$i]->credentials)) {
$query[$i]->credentials = simpleDecrypt($query[$i]->credentials, config('Encryption')->key);
$query[$i]->credentials = json_decode($query[$i]->credentials);
$query[$i]->credentials = json_decode(simpleDecrypt($query[$i]->credentials, config('Encryption')->key));
}
}
}
Expand All @@ -72,9 +71,9 @@ public function create($data = null): ?int
return null;
}
if (! empty($data->credentials) && is_string($data->credentials)) {
$data->credentials = simpleEncrypt($data->credentials, config('Encryption')->key);
$data->credentials = (string)simpleEncrypt($data->credentials, config('Encryption')->key);
} else {
$data->credentials = simpleEncrypt(json_encode($data->credentials), config('Encryption')->key);
$data->credentials = (string)simpleEncrypt(json_encode($data->credentials), config('Encryption')->key);
}
if (! empty($data->options)) {
$data->options = json_encode($data->options);
Expand Down Expand Up @@ -320,8 +319,7 @@ public function read(int $id = 0): array
}
if ($config->decrypt_credentials === 'y') {
if (!empty($cloud[0]->credentials)) {
$cloud[0]->credentials = simpleDecrypt($cloud[0]->credentials, config('Encryption')->key);
$cloud[0]->credentials = json_decode($cloud[0]->credentials);
$cloud[0]->credentials = json_decode(simpleDecrypt($cloud[0]->credentials, config('Encryption')->key));
}
}
return format_data($cloud, 'clouds');
Expand Down
4 changes: 2 additions & 2 deletions app/Models/ComponentsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ public function create($data = null): ?int
$this->db->query($sql, [intval($id), (string)$data->type]);

if (!empty($data->credentials) && is_string($data->credentials)) {
$data->credentials = simpleEncrypt($data->credentials, config('Encryption')->key);
$data->credentials = (string)simpleEncrypt($data->credentials, config('Encryption')->key);
} else {
$data->credentials = simpleEncrypt(json_encode($data->credentials), config('Encryption')->key);
$data->credentials = (string)simpleEncrypt(json_encode($data->credentials), config('Encryption')->key);
}
$sql = "INSERT INTO `credential` VALUES (null, ?, 'y', ?, ?, ?, ?, ?, NOW())";
$query = $this->db->query($sql, [$id, $data->name, $data->description, $data->type, $data->credentials, $instance->user->full_name]);
Expand Down
10 changes: 4 additions & 6 deletions app/Models/CredentialsModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public function collection(object $resp): array
$count = count($query);
for ($i=0; $i < $count; $i++) {
if (!empty($query[$i]->credentials)) {
$query[$i]->credentials = simpleDecrypt($query[$i]->credentials, config('Encryption')->key);
$query[$i]->credentials = json_decode($query[$i]->credentials);
$query[$i]->credentials = json_decode(simpleDecrypt($query[$i]->credentials, config('Encryption')->key));
}
}
}
Expand All @@ -72,9 +71,9 @@ public function create($data = null): ?int
return null;
}
if (! empty($data->credentials) && is_string($data->credentials)) {
$data->credentials = simpleEncrypt($data->credentials, config('Encryption')->key);
$data->credentials = (string)simpleEncrypt($data->credentials, config('Encryption')->key);
} else {
$data->credentials = simpleEncrypt(json_encode($data->credentials), config('Encryption')->key);
$data->credentials = (string)simpleEncrypt(json_encode($data->credentials), config('Encryption')->key);
}
$data = $this->createFieldData('credentials', $data);
if (empty($data)) {
Expand Down Expand Up @@ -190,8 +189,7 @@ public function read(int $id = 0): array
$credentials = $query->getResult();
if ($config->decrypt_credentials === 'y') {
if (!empty($credentials[0]->credentials)) {
$credentials[0]->credentials = simpleDecrypt($credentials[0]->credentials, config('Encryption')->key);
$credentials[0]->credentials = json_decode($credentials[0]->credentials);
$credentials[0]->credentials = json_decode(simpleDecrypt($credentials[0]->credentials, config('Encryption')->key));
}
}
return format_data($credentials, 'credentials');
Expand Down
3 changes: 1 addition & 2 deletions app/Models/DatabaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public function export(string $table = ''): array
if ($table === 'clouds' or $table === 'credential' or $table === 'credentials') {
if ($instance->config->decrypt_credentials === 'y') {
for ($i=0; $i < $count; $i++) {
$result[$i]->credentials = simpleDecrypt($result[$i]->credentials, config('Encryption')->key);
$result[$i]->credentials = json_decode($result[$i]->credentials);
$result[$i]->credentials = json_decode(simpleDecrypt($result[$i]->credentials, config('Encryption')->key));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Models/LogonModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function logon($username = '', $password = '')
} else {
log_message('debug', 'Successful bind using credentials for LDAP server at ' . $ldap_connect_string . ' : ' . $bind_string);
}
$ldap->dn_password = (string)simpleDecrypt($ldap->dn_password);
$ldap->dn_password = (string)simpleDecrypt($ldap->dn_password, config('Encryption')->key);
if (!empty($ldap->dn_account) && empty($ldap->dn_password)) {
$message = 'DN Account set, but no DN Password.';
// \Config\Services::session()->setFlashdata('warning', $message);
Expand Down

0 comments on commit a02547a

Please sign in to comment.