Skip to content

Commit

Permalink
feat(Security): add Factory for IP addresses and ranges
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
  • Loading branch information
Altahrim committed Jul 19, 2024
1 parent fb9866d commit e511bab
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@
'OCP\\Security\\ISecureRandom' => $baseDir . '/lib/public/Security/ISecureRandom.php',
'OCP\\Security\\ITrustedDomainHelper' => $baseDir . '/lib/public/Security/ITrustedDomainHelper.php',
'OCP\\Security\\Ip\\IAddress' => $baseDir . '/lib/public/Security/Ip/IAddress.php',
'OCP\\Security\\Ip\\IFactory' => $baseDir . '/lib/public/Security/Ip/IFactory.php',
'OCP\\Security\\Ip\\IRange' => $baseDir . '/lib/public/Security/Ip/IRange.php',
'OCP\\Security\\Ip\\IRemoteAddress' => $baseDir . '/lib/public/Security/Ip/IRemoteAddress.php',
'OCP\\Security\\RateLimiting\\ILimiter' => $baseDir . '/lib/public/Security/RateLimiting/ILimiter.php',
Expand Down Expand Up @@ -1812,6 +1813,7 @@
'OC\\Security\\IdentityProof\\Manager' => $baseDir . '/lib/private/Security/IdentityProof/Manager.php',
'OC\\Security\\IdentityProof\\Signer' => $baseDir . '/lib/private/Security/IdentityProof/Signer.php',
'OC\\Security\\Ip\\Address' => $baseDir . '/lib/private/Security/Ip/Address.php',
'OC\\Security\\Ip\\Factory' => $baseDir . '/lib/private/Security/Ip/Factory.php',
'OC\\Security\\Ip\\Range' => $baseDir . '/lib/private/Security/Ip/Range.php',
'OC\\Security\\Ip\\RemoteAddress' => $baseDir . '/lib/private/Security/Ip/RemoteAddress.php',
'OC\\Security\\Normalizer\\IpAddress' => $baseDir . '/lib/private/Security/Normalizer/IpAddress.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Security\\ISecureRandom' => __DIR__ . '/../../..' . '/lib/public/Security/ISecureRandom.php',
'OCP\\Security\\ITrustedDomainHelper' => __DIR__ . '/../../..' . '/lib/public/Security/ITrustedDomainHelper.php',
'OCP\\Security\\Ip\\IAddress' => __DIR__ . '/../../..' . '/lib/public/Security/Ip/IAddress.php',
'OCP\\Security\\Ip\\IFactory' => __DIR__ . '/../../..' . '/lib/public/Security/Ip/IFactory.php',
'OCP\\Security\\Ip\\IRange' => __DIR__ . '/../../..' . '/lib/public/Security/Ip/IRange.php',
'OCP\\Security\\Ip\\IRemoteAddress' => __DIR__ . '/../../..' . '/lib/public/Security/Ip/IRemoteAddress.php',
'OCP\\Security\\RateLimiting\\ILimiter' => __DIR__ . '/../../..' . '/lib/public/Security/RateLimiting/ILimiter.php',
Expand Down Expand Up @@ -1845,6 +1846,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Security\\IdentityProof\\Manager' => __DIR__ . '/../../..' . '/lib/private/Security/IdentityProof/Manager.php',
'OC\\Security\\IdentityProof\\Signer' => __DIR__ . '/../../..' . '/lib/private/Security/IdentityProof/Signer.php',
'OC\\Security\\Ip\\Address' => __DIR__ . '/../../..' . '/lib/private/Security/Ip/Address.php',
'OC\\Security\\Ip\\Factory' => __DIR__ . '/../../..' . '/lib/private/Security/Ip/Factory.php',
'OC\\Security\\Ip\\Range' => __DIR__ . '/../../..' . '/lib/private/Security/Ip/Range.php',
'OC\\Security\\Ip\\RemoteAddress' => __DIR__ . '/../../..' . '/lib/private/Security/Ip/RemoteAddress.php',
'OC\\Security\\Normalizer\\IpAddress' => __DIR__ . '/../../..' . '/lib/private/Security/Normalizer/IpAddress.php',
Expand Down
23 changes: 23 additions & 0 deletions lib/private/Security/Ip/Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Security\Ip;

use OCP\Security\Ip\IAddress;
use OCP\Security\Ip\IFactory;
use OCP\Security\Ip\IRange;

class Factory implements IFactory {
public function rangeFromString(string $range): IRange {
return new Range($range);
}

public function addressFromString(string $ip): IAddress {
return new Address($ip);
}
}
2 changes: 2 additions & 0 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,8 @@ public function __construct($webRoot, \OC\Config $config) {

$this->registerAlias(IRemoteAddress::class, RemoteAddress::class);

$this->registerAlias(\OCP\Security\Ip\Factory::class, \OC\Security\Ip\Factory::class);

Check failure

Code scanning / Psalm

UndefinedClass Error

Class, interface or enum named OCP\Security\Ip\Factory does not exist

Check failure on line 1411 in lib/private/Server.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedClass

lib/private/Server.php:1411:24: UndefinedClass: Class, interface or enum named OCP\Security\Ip\Factory does not exist (see https://psalm.dev/019)

$this->connectDispatcher();
}

Expand Down
30 changes: 30 additions & 0 deletions lib/public/Security/Ip/IFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCP\Security\Ip;

/**
* @since 30.0.0
*/
interface IFactory {
/**
* Creates a range from string
*
* @since 30.0.0
* @throws on invalid range

Check failure on line 19 in lib/public/Security/Ip/IFactory.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

UndefinedDocblockClass

lib/public/Security/Ip/IFactory.php:19:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Security\Ip\on does not exist (see https://psalm.dev/200)

Check failure

Code scanning / Psalm

UndefinedDocblockClass Error

Docblock-defined class, interface or enum named OCP\Security\Ip\on does not exist

Check failure on line 19 in lib/public/Security/Ip/IFactory.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedDocblockClass

lib/public/Security/Ip/IFactory.php:19:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Security\Ip\on does not exist (see https://psalm.dev/200)
*/
public function rangeFromString(string $range): IRange;

/**
* Creates a address from string
*
* @since 30.0.0
* @throws on invalid IP

Check failure on line 27 in lib/public/Security/Ip/IFactory.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

UndefinedDocblockClass

lib/public/Security/Ip/IFactory.php:27:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Security\Ip\on does not exist (see https://psalm.dev/200)

Check failure

Code scanning / Psalm

UndefinedDocblockClass Error

Docblock-defined class, interface or enum named OCP\Security\Ip\on does not exist

Check failure on line 27 in lib/public/Security/Ip/IFactory.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

UndefinedDocblockClass

lib/public/Security/Ip/IFactory.php:27:13: UndefinedDocblockClass: Docblock-defined class, interface or enum named OCP\Security\Ip\on does not exist (see https://psalm.dev/200)
*/
public function addressFromString(string $ip): IAddress;
}

0 comments on commit e511bab

Please sign in to comment.