aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Security
diff options
context:
space:
mode:
authorStephan Orbaugh <62374139+sorbaugh@users.noreply.github.com>2024-07-22 10:40:50 +0200
committerGitHub <noreply@github.com>2024-07-22 10:40:50 +0200
commit9ed2d3e4958ffb5fdd80d67c489a7a19b106ac0a (patch)
treeaebb7e82c352069803e5798c44b18917b0455f10 /lib/private/Security
parentc2a571e435bebb08a4b6429eea343c350d3ccaf6 (diff)
parent9716b0d7350aa28481a5a9642b74da847c0fa211 (diff)
downloadnextcloud-server-9ed2d3e4958ffb5fdd80d67c489a7a19b106ac0a.tar.gz
nextcloud-server-9ed2d3e4958ffb5fdd80d67c489a7a19b106ac0a.zip
Merge pull request #46571 from nextcloud/chore/migrate-to-filenamevalidator
refactor: Migrate some legacy and core functions to `IFilenameValidator`
Diffstat (limited to 'lib/private/Security')
-rw-r--r--lib/private/Security/CertificateManager.php29
1 files changed, 15 insertions, 14 deletions
diff --git a/lib/private/Security/CertificateManager.php b/lib/private/Security/CertificateManager.php
index f9fd2b160b8..00babff735f 100644
--- a/lib/private/Security/CertificateManager.php
+++ b/lib/private/Security/CertificateManager.php
@@ -8,7 +8,6 @@ declare(strict_types=1);
*/
namespace OC\Security;
-use OC\Files\Filesystem;
use OC\Files\View;
use OCP\ICertificate;
use OCP\ICertificateManager;
@@ -150,20 +149,19 @@ class CertificateManager implements ICertificateManager {
* @throws \Exception If the certificate could not get added
*/
public function addCertificate(string $certificate, string $name): ICertificate {
- if (!Filesystem::isValidPath($name) or Filesystem::isFileBlacklisted($name)) {
- throw new \Exception('Filename is not valid');
- }
+ $path = $this->getPathToCertificates() . 'uploads/' . $name;
+ $directory = dirname($path);
+
+ $this->view->verifyPath($directory, basename($path));
$this->bundlePath = null;
- $dir = $this->getPathToCertificates() . 'uploads/';
- if (!$this->view->file_exists($dir)) {
- $this->view->mkdir($dir);
+ if (!$this->view->file_exists($directory)) {
+ $this->view->mkdir($directory);
}
try {
- $file = $dir . $name;
$certificateObject = new Certificate($certificate, $name);
- $this->view->file_put_contents($file, $certificate);
+ $this->view->file_put_contents($path, $certificate);
$this->createCertificateBundle();
return $certificateObject;
} catch (\Exception $e) {
@@ -175,14 +173,17 @@ class CertificateManager implements ICertificateManager {
* Remove the certificate and re-generate the certificate bundle
*/
public function removeCertificate(string $name): bool {
- if (!Filesystem::isValidPath($name)) {
+ $path = $this->getPathToCertificates() . 'uploads/' . $name;
+
+ try {
+ $this->view->verifyPath(dirname($path), basename($path));
+ } catch (\Exception) {
return false;
}
- $this->bundlePath = null;
- $path = $this->getPathToCertificates() . 'uploads/';
- if ($this->view->file_exists($path . $name)) {
- $this->view->unlink($path . $name);
+ $this->bundlePath = null;
+ if ($this->view->file_exists($path)) {
+ $this->view->unlink($path);
$this->createCertificateBundle();
}
return true;