diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-02-11 13:55:22 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-02-11 14:00:08 +0100 |
commit | 80eb1aada52c4b9d8e6a1ab0ce165c1977794071 (patch) | |
tree | 3fbef9ee1193babf34e4dc155ea4cd5d1189e4b0 /apps/files_external/service | |
parent | 06af9b817edb1fdf230f71c2fc77bc9c12031bc6 (diff) | |
download | nextcloud-server-80eb1aada52c4b9d8e6a1ab0ce165c1977794071.tar.gz nextcloud-server-80eb1aada52c4b9d8e6a1ab0ce165c1977794071.zip |
encrypt passwords for files_external
Diffstat (limited to 'apps/files_external/service')
-rw-r--r-- | apps/files_external/service/dbconfigservice.php | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/apps/files_external/service/dbconfigservice.php b/apps/files_external/service/dbconfigservice.php index d52bf51e4aa..07f9942e05c 100644 --- a/apps/files_external/service/dbconfigservice.php +++ b/apps/files_external/service/dbconfigservice.php @@ -23,6 +23,7 @@ namespace OCA\Files_External\Service; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\Security\ICrypto; /** * Stores the mount config in the database @@ -41,12 +42,19 @@ class DBConfigService { private $connection; /** + * @var ICrypto + */ + private $crypto; + + /** * DBConfigService constructor. * * @param IDBConnection $connection + * @param ICrypto $crypto */ - public function __construct(IDBConnection $connection) { + public function __construct(IDBConnection $connection, ICrypto $crypto) { $this->connection = $connection; + $this->crypto = $crypto; } /** @@ -246,6 +254,9 @@ class DBConfigService { * @param string $value */ public function setConfig($mountId, $key, $value) { + if ($key === 'password') { + $value = $this->encryptValue($value); + } $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [ 'mount_id' => $mountId, 'key' => $key, @@ -267,6 +278,7 @@ class DBConfigService { * @param string $value */ public function setOption($mountId, $key, $value) { + $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [ 'mount_id' => $mountId, 'key' => $key, @@ -398,13 +410,31 @@ class DBConfigService { * @return array ['key1' => $value1, ...] */ private function createKeyValueMap(array $keyValuePairs) { + $decryptedPairts = array_map(function ($pair) { + if ($pair['key'] === 'password') { + $pair['value'] = $this->decryptValue($pair['value']); + } + return $pair; + }, $keyValuePairs); $keys = array_map(function ($pair) { return $pair['key']; - }, $keyValuePairs); + }, $decryptedPairts); $values = array_map(function ($pair) { return $pair['value']; - }, $keyValuePairs); + }, $decryptedPairts); return array_combine($keys, $values); } + + private function encryptValue($value) { + return $this->crypto->encrypt($value); + } + + private function decryptValue($value) { + try { + return $this->crypto->decrypt($value); + } catch (\Exception $e) { + return $value; + } + } } |