Skip to content

Commit

Permalink
Merge pull request #16 from lewmilburn/analysis-N4Ej74
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
lewmilburn authored Oct 30, 2023
2 parents daac17e + 8f75dfc commit 1108a5f
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Web/authentication/authenticationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function Login(string $username, string $password)
}
} else {
$eh = new errorHandler();
$eh->sessionRequired('authentication','authenticationManager','Login');
$eh->sessionRequired('authentication', 'authenticationManager', 'Login');
exit;
}
}
Expand All @@ -38,7 +38,7 @@ public function Logout()
return true;
} else {
$eh = new errorHandler();
$eh->sessionRequired('authentication','authenticationManager','Logout');
$eh->sessionRequired('authentication', 'authenticationManager', 'Logout');
exit;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Web/data/const.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
const DEV = 0;
const PROD = 1;
const DATABASE = 0;
const FILESYSTEM = 1;
const FILESYSTEM = 1;
13 changes: 7 additions & 6 deletions Web/data/fileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class fileManager

public function __construct()
{
$this->usersFile = __DIR__ . '/../' . SECURE_LOCATION . USERS_FILE;
$this->defaultVault = __DIR__ . '/../' . SECURE_LOCATION . DEFAULT_USER . '.vault';
$this->usersFile = __DIR__.'/../'.SECURE_LOCATION.USERS_FILE;
$this->defaultVault = __DIR__.'/../'.SECURE_LOCATION.DEFAULT_USER.'.vault';

if (!file_exists($this->usersFile)) {
$this->initialiseUsers();
Expand All @@ -26,22 +26,23 @@ public function __construct()
public function getUserData(string $username)
{
$usersFile = file_get_contents($this->usersFile);

return json_decode($usersFile);
}

private function initialiseUsers(): void
{
$UserFile = fopen($this->usersFile, "w");
fwrite($UserFile, '[{"user":"admin","passkey":"'.password_hash(TEMPORARY_PASSWORD,PASSWORD_DEFAULT).'"}]');
$UserFile = fopen($this->usersFile, 'w');
fwrite($UserFile, '[{"user":"admin","passkey":"'.password_hash(TEMPORARY_PASSWORD, PASSWORD_DEFAULT).'"}]');
fclose($UserFile);
}

private function initialiseVault(): void
{
$VaultFile = fopen($this->defaultVault, "w");
$VaultFile = fopen($this->defaultVault, 'w');

$em = new encryptionManager();
$EncryptedData = $em->encrypt('[{}]',$em->generateKey(PASSWORD_DEFAULT));
$EncryptedData = $em->encrypt('[{}]', $em->generateKey(PASSWORD_DEFAULT));

fwrite($VaultFile, $EncryptedData[0].FILE_SEPARATOR.$EncryptedData[1]);
fclose($VaultFile);
Expand Down
14 changes: 8 additions & 6 deletions Web/encryption/encryptionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ class encryptionManager
public function generateKey($password): string
{
try {
return sodium_crypto_pwhash(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, $password, '0000000000000000',SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13);
return sodium_crypto_pwhash(SODIUM_CRYPTO_SECRETBOX_KEYBYTES, $password, '0000000000000000', SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE, SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13);
} catch (SodiumException $e) {
$eh = new errorHandler();
$eh->error('encryption', 'encryptionManager','encrypt',$e,'500');
$eh->error('encryption', 'encryptionManager', 'encrypt', $e, '500');
exit;
}
}

public function encrypt($string, $key): array
{
try {
Expand All @@ -27,13 +28,14 @@ public function encrypt($string, $key): array
sodium_memzero($string);
sodium_memzero($key);

return array($encryptedData,$nonce);
return [$encryptedData, $nonce];
} catch (SodiumException|\Exception $e) {
$eh = new errorHandler();
$eh->error('encryption', 'encryptionManager','encrypt',$e,'500');
$eh->error('encryption', 'encryptionManager', 'encrypt', $e, '500');
exit;
}
}

public function decrypt($string, $key, $nonce): string|null
{
try {
Expand All @@ -47,8 +49,8 @@ public function decrypt($string, $key, $nonce): string|null
return $decryptedData;
} catch (SodiumException|\Exception $e) {
$eh = new errorHandler();
$eh->error('encryption', 'encryptionManager','decrypt',$e,'500');
$eh->error('encryption', 'encryptionManager', 'decrypt', $e, '500');
exit;
}
}
}
}
10 changes: 5 additions & 5 deletions Web/event/routeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ public function getRequest($url, $file): void
public function endRouter(): void
{
$eh = new errorHandler();
$eh->fileNotFound('event','routeHandler','endRouter');
$eh->fileNotFound('event', 'routeHandler', 'endRouter');
}

private function displayFile($file): void
{
if (file_exists(__DIR__ . '/../' .$file)) {
require_once __DIR__ . '/../' .$file;
if (file_exists(__DIR__.'/../'.$file)) {
require_once __DIR__.'/../'.$file;
} else {
$eh = new errorHandler();
$eh->fileNotFound('event','routeHandler','displayFile');
$eh->fileNotFound('event', 'routeHandler', 'displayFile');
}
exit;
}
}
}
6 changes: 2 additions & 4 deletions Web/loader.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php

use Vault\data\fileManager;
use Vault\event\errorHandler;

require_once __DIR__.'/data/const.php';
Expand All @@ -25,8 +24,7 @@

require_once __DIR__.'/event/routeHandler.php';

if (!extension_loaded('sodium'))
{
if (!extension_loaded('sodium')) {
$eh = new errorHandler();
$eh->error(null, null, null, 'Sodium not installed.', '500');
}
}
2 changes: 1 addition & 1 deletion Web/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
const DB_USER = '';
const DB_PASS = '';
const DB_PORT = '';
const DB_PREFIX = 'va_';
const DB_PREFIX = 'va_';

0 comments on commit 1108a5f

Please sign in to comment.