Skip to content

Commit

Permalink
Use getSystemValueString to fetch instanceid
Browse files Browse the repository at this point in the history
Signed-off-by: J0WI <[email protected]>
  • Loading branch information
J0WI committed Dec 5, 2022
1 parent 5305ee2 commit bd589e8
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion apps/encryption/lib/Crypto/Crypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private function addPadding($data) {
* @return string
*/
protected function generatePasswordHash($password, $cipher, $uid = '') {
$instanceId = $this->config->getSystemValue('instanceid');
$instanceId = $this->config->getSystemValueString('instanceid');
$instanceSecret = $this->config->getSystemValueString('secret');
$salt = hash('sha256', $uid . $instanceId . $instanceSecret, true);
$keySize = $this->getKeySize($cipher);
Expand Down
4 changes: 2 additions & 2 deletions apps/files/lib/Command/ScanAppData.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ protected function reconnectToDatabase(OutputInterface $output): Connection {
* @throws NotFoundException
*/
private function getAppDataFolder() {
$instanceId = $this->config->getSystemValue('instanceid', null);
$instanceId = $this->config->getSystemValueString('instanceid');

if ($instanceId === null) {
if ($instanceId === '') {
throw new NotFoundException();
}

Expand Down
4 changes: 2 additions & 2 deletions core/BackgroundJobs/BackgroundCleanupUpdaterBackupsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public function __construct(IConfig $config, LoggerInterface $log, ITimeFactory
*/
public function run($arguments) {
$updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
$instanceId = $this->config->getSystemValue('instanceid', null);
$instanceId = $this->config->getSystemValueString('instanceid');

if (!is_string($instanceId) || empty($instanceId)) {
if ($instanceId === '') {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/private/Encryption/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function __construct(
$this->config = $config;

$this->excludedPaths[] = 'files_encryption';
$this->excludedPaths[] = 'appdata_' . $config->getSystemValue('instanceid', null);
$this->excludedPaths[] = 'appdata_' . $config->getSystemValueString('instanceid');
$this->excludedPaths[] = 'files_external';
}

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Repair/MoveUpdaterStepFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function getName() {

public function run(IOutput $output) {
$updateDir = $this->config->getSystemValue('updatedirectory', null) ?? $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data');
$instanceId = $this->config->getSystemValue('instanceid', null);
$instanceId = $this->config->getSystemValueString('instanceid');

if (!is_string($instanceId) || empty($instanceId)) {
if ($instanceId === '') {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Repair/NC25/AddMissingSecretJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function getName(): string {
}

public function run(IOutput $output): void {
$passwordSalt = $this->config->getSystemValue('passwordsalt', null);
if ($passwordSalt === null || $passwordSalt === '') {
$passwordSalt = $this->config->getSystemValueString('passwordsalt');
if ($passwordSalt === '') {
try {
$this->config->setSystemValue('passwordsalt', $this->random->generate(30));
} catch (HintException $e) {
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Security/IdentityProof/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public function getKey(IUser $user): Key {
* @throws \RuntimeException
*/
public function getSystemKey(): Key {
$instanceId = $this->config->getSystemValue('instanceid', null);
if ($instanceId === null) {
$instanceId = $this->config->getSystemValueString('instanceid');
if ($instanceId === '') {
throw new \RuntimeException('no instance id!');
}
return $this->retrieveKey('system-' . $instanceId);
Expand Down
4 changes: 2 additions & 2 deletions lib/private/legacy/OC_Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public static function copySkeleton($userId, \OCP\Files\Folder $userDirectory) {
}
}

$instanceId = \OC::$server->getConfig()->getSystemValue('instanceid', '');
$instanceId = \OC::$server->getConfig()->getSystemValueString('instanceid');

if ($instanceId === null) {
if ($instanceId === '') {
throw new \RuntimeException('no instance id!');
}
$appdata = 'appdata_' . $instanceId;
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Security/IdentityProof/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function testGetSystemKey() {
/** @var Key|\PHPUnit\Framework\MockObject\MockObject $key */
$key = $this->createMock(Key::class);

$this->config->expects($this->once())->method('getSystemValue')
$this->config->expects($this->once())->method('getSystemValueString')
->with('instanceid', null)->willReturn('instanceId');

$manager->expects($this->once())->method('retrieveKey')->with('system-instanceId')
Expand All @@ -229,7 +229,7 @@ public function testGetSystemKeyFailure() {
/** @var Key|\PHPUnit\Framework\MockObject\MockObject $key */
$key = $this->createMock(Key::class);

$this->config->expects($this->once())->method('getSystemValue')
$this->config->expects($this->once())->method('getSystemValueString')
->with('instanceid', null)->willReturn(null);

$manager->getSystemKey();
Expand Down

0 comments on commit bd589e8

Please sign in to comment.