@@ -34,13 +34,13 @@ |
||
34 | 34 | */ |
35 | 35 | class BackupCode extends Entity { |
36 | 36 | |
37 | - /** @var string */ |
|
38 | - protected $userId; |
|
37 | + /** @var string */ |
|
38 | + protected $userId; |
|
39 | 39 | |
40 | - /** @var string */ |
|
41 | - protected $code; |
|
40 | + /** @var string */ |
|
41 | + protected $code; |
|
42 | 42 | |
43 | - /** @var int */ |
|
44 | - protected $used; |
|
43 | + /** @var int */ |
|
44 | + protected $used; |
|
45 | 45 | |
46 | 46 | } |
@@ -21,17 +21,17 @@ |
||
21 | 21 | */ |
22 | 22 | // @codeCoverageIgnoreStart |
23 | 23 | return [ |
24 | - 'routes' => [ |
|
25 | - [ |
|
26 | - 'name' => 'settings#state', |
|
27 | - 'url' => '/settings/state', |
|
28 | - 'verb' => 'GET' |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'settings#createCodes', |
|
32 | - 'url' => '/settings/create', |
|
33 | - 'verb' => 'POST' |
|
34 | - ], |
|
35 | - ] |
|
24 | + 'routes' => [ |
|
25 | + [ |
|
26 | + 'name' => 'settings#state', |
|
27 | + 'url' => '/settings/state', |
|
28 | + 'verb' => 'GET' |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'settings#createCodes', |
|
32 | + 'url' => '/settings/create', |
|
33 | + 'verb' => 'POST' |
|
34 | + ], |
|
35 | + ] |
|
36 | 36 | ]; |
37 | 37 | // @codeCoverageIgnoreEnd |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | print_unescaped($l->t("Hey there,\n\nthe admin enabled server-side-encryption. Your files were encrypted using the password '%s'.\n\nPlease login to the web interface, go to the section 'basic encryption module' of your personal settings and update your encryption password by entering this password into the 'old log-in password' field and your current login-password.\n\n", array($_['password']))); |
6 | 6 | if ( isset($_['expiration']) ) { |
7 | - print_unescaped($l->t("The share will expire on %s.", array($_['expiration']))); |
|
8 | - print_unescaped("\n\n"); |
|
7 | + print_unescaped($l->t("The share will expire on %s.", array($_['expiration']))); |
|
8 | + print_unescaped("\n\n"); |
|
9 | 9 | } |
10 | 10 | // TRANSLATORS term at the end of a mail |
11 | 11 | p($l->t("Cheers!")); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | /** @var array $_ */ |
4 | 4 | |
5 | 5 | print_unescaped($l->t("Hey there,\n\nthe admin enabled server-side-encryption. Your files were encrypted using the password '%s'.\n\nPlease login to the web interface, go to the section 'basic encryption module' of your personal settings and update your encryption password by entering this password into the 'old log-in password' field and your current login-password.\n\n", array($_['password']))); |
6 | -if ( isset($_['expiration']) ) { |
|
6 | +if (isset($_['expiration'])) { |
|
7 | 7 | print_unescaped($l->t("The share will expire on %s.", array($_['expiration']))); |
8 | 8 | print_unescaped("\n\n"); |
9 | 9 | } |
@@ -12,5 +12,5 @@ discard block |
||
12 | 12 | ?> |
13 | 13 | |
14 | 14 | -- |
15 | -<?php p($theme->getName() . ' - ' . $theme->getSlogan()); ?> |
|
15 | +<?php p($theme->getName().' - '.$theme->getSlogan()); ?> |
|
16 | 16 | <?php print_unescaped("\n".$theme->getBaseUrl()); |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | - /** @var array $_ */ |
|
3 | - /** @var \OCP\IL10N $l */ |
|
2 | + /** @var array $_ */ |
|
3 | + /** @var \OCP\IL10N $l */ |
|
4 | 4 | script('encryption', 'settings-personal'); |
5 | 5 | script('core', 'multiselect'); |
6 | 6 | ?> |
@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | <br /> |
21 | 21 | <?php p( $l->t( "Set your old private key password to your current log-in password:" ) ); ?> |
22 | 22 | <?php if ( $_["recoveryEnabledForUser"] ): |
23 | - p( $l->t( " If you don't remember your old password you can ask your administrator to recover your files." ) ); |
|
24 | - endif; ?> |
|
23 | + p( $l->t( " If you don't remember your old password you can ask your administrator to recover your files." ) ); |
|
24 | + endif; ?> |
|
25 | 25 | <br /> |
26 | 26 | <input |
27 | 27 | type="password" |
@@ -7,49 +7,49 @@ discard block |
||
7 | 7 | <form id="ocDefaultEncryptionModule" class="section"> |
8 | 8 | <h2 data-anchor-name="basic-encryption-module"><?php p($l->t('Basic encryption module')); ?></h2> |
9 | 9 | |
10 | - <?php if ($_["initialized"] === \OCA\Encryption\Session::NOT_INITIALIZED ): ?> |
|
10 | + <?php if ($_["initialized"] === \OCA\Encryption\Session::NOT_INITIALIZED): ?> |
|
11 | 11 | |
12 | 12 | <?php p($l->t("Encryption App is enabled, but your keys are not initialized. Please log-out and log-in again.")); ?> |
13 | 13 | |
14 | - <?php elseif ( $_["initialized"] === \OCA\Encryption\Session::INIT_EXECUTED ): ?> |
|
14 | + <?php elseif ($_["initialized"] === \OCA\Encryption\Session::INIT_EXECUTED): ?> |
|
15 | 15 | <p> |
16 | 16 | <a name="changePKPasswd" /> |
17 | 17 | <label for="changePrivateKeyPasswd"> |
18 | - <em><?php p( $l->t( "Your private key password no longer matches your log-in password." ) ); ?></em> |
|
18 | + <em><?php p($l->t("Your private key password no longer matches your log-in password.")); ?></em> |
|
19 | 19 | </label> |
20 | 20 | <br /> |
21 | - <?php p( $l->t( "Set your old private key password to your current log-in password:" ) ); ?> |
|
22 | - <?php if ( $_["recoveryEnabledForUser"] ): |
|
23 | - p( $l->t( " If you don't remember your old password you can ask your administrator to recover your files." ) ); |
|
21 | + <?php p($l->t("Set your old private key password to your current log-in password:")); ?> |
|
22 | + <?php if ($_["recoveryEnabledForUser"]): |
|
23 | + p($l->t(" If you don't remember your old password you can ask your administrator to recover your files.")); |
|
24 | 24 | endif; ?> |
25 | 25 | <br /> |
26 | 26 | <input |
27 | 27 | type="password" |
28 | 28 | name="changePrivateKeyPassword" |
29 | 29 | id="oldPrivateKeyPassword" /> |
30 | - <label for="oldPrivateKeyPassword"><?php p($l->t( "Old log-in password" )); ?></label> |
|
30 | + <label for="oldPrivateKeyPassword"><?php p($l->t("Old log-in password")); ?></label> |
|
31 | 31 | <br /> |
32 | 32 | <input |
33 | 33 | type="password" |
34 | 34 | name="changePrivateKeyPassword" |
35 | 35 | id="newPrivateKeyPassword" /> |
36 | - <label for="newRecoveryPassword"><?php p($l->t( "Current log-in password" )); ?></label> |
|
36 | + <label for="newRecoveryPassword"><?php p($l->t("Current log-in password")); ?></label> |
|
37 | 37 | <br /> |
38 | 38 | <button |
39 | 39 | type="button" |
40 | 40 | name="submitChangePrivateKeyPassword" |
41 | - disabled><?php p($l->t( "Update Private Key Password" )); ?> |
|
41 | + disabled><?php p($l->t("Update Private Key Password")); ?> |
|
42 | 42 | </button> |
43 | 43 | <span class="msg"></span> |
44 | 44 | </p> |
45 | 45 | |
46 | - <?php elseif ( $_["recoveryEnabled"] && $_["privateKeySet"] && $_["initialized"] === \OCA\Encryption\Session::INIT_SUCCESSFUL ): ?> |
|
46 | + <?php elseif ($_["recoveryEnabled"] && $_["privateKeySet"] && $_["initialized"] === \OCA\Encryption\Session::INIT_SUCCESSFUL): ?> |
|
47 | 47 | <br /> |
48 | 48 | <p id="userEnableRecovery"> |
49 | - <label for="userEnableRecovery"><?php p( $l->t( "Enable password recovery:" ) ); ?></label> |
|
49 | + <label for="userEnableRecovery"><?php p($l->t("Enable password recovery:")); ?></label> |
|
50 | 50 | <span class="msg"></span> |
51 | 51 | <br /> |
52 | - <em><?php p( $l->t( "Enabling this option will allow you to reobtain access to your encrypted files in case of password loss" ) ); ?></em> |
|
52 | + <em><?php p($l->t("Enabling this option will allow you to reobtain access to your encrypted files in case of password loss")); ?></em> |
|
53 | 53 | <br /> |
54 | 54 | <input |
55 | 55 | type="radio" |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | id="userEnableRecoveryCheckbox" |
58 | 58 | name="userEnableRecovery" |
59 | 59 | value="1" |
60 | - <?php echo ( $_["recoveryEnabledForUser"] ? 'checked="checked"' : '' ); ?> /> |
|
61 | - <label for="userEnableRecoveryCheckbox"><?php p( $l->t( "Enabled" ) ); ?></label> |
|
60 | + <?php echo ($_["recoveryEnabledForUser"] ? 'checked="checked"' : ''); ?> /> |
|
61 | + <label for="userEnableRecoveryCheckbox"><?php p($l->t("Enabled")); ?></label> |
|
62 | 62 | <br /> |
63 | 63 | |
64 | 64 | <input |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | id="userDisableRecoveryCheckbox" |
68 | 68 | name="userEnableRecovery" |
69 | 69 | value="0" |
70 | - <?php echo ( $_["recoveryEnabledForUser"] === false ? 'checked="checked"' : '' ); ?> /> |
|
71 | - <label for="userDisableRecoveryCheckbox"><?php p( $l->t( "Disabled" ) ); ?></label> |
|
70 | + <?php echo ($_["recoveryEnabledForUser"] === false ? 'checked="checked"' : ''); ?> /> |
|
71 | + <label for="userDisableRecoveryCheckbox"><?php p($l->t("Disabled")); ?></label> |
|
72 | 72 | </p> |
73 | 73 | <?php endif; ?> |
74 | 74 | </form> |
@@ -15,10 +15,10 @@ |
||
15 | 15 | <td width="20px"> </td> |
16 | 16 | <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;"> |
17 | 17 | <?php |
18 | - print_unescaped($l->t('Hey there,<br><br>the admin enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br>Please login to the web interface, go to the section "basic encryption module" of your personal settings and update your encryption password by entering this password into the "old log-in password" field and your current login-password.<br><br>', array($_['password']))); |
|
19 | - // TRANSLATORS term at the end of a mail |
|
20 | - p($l->t('Cheers!')); |
|
21 | - ?> |
|
18 | + print_unescaped($l->t('Hey there,<br><br>the admin enabled server-side-encryption. Your files were encrypted using the password <strong>%s</strong>.<br><br>Please login to the web interface, go to the section "basic encryption module" of your personal settings and update your encryption password by entering this password into the "old log-in password" field and your current login-password.<br><br>', array($_['password']))); |
|
19 | + // TRANSLATORS term at the end of a mail |
|
20 | + p($l->t('Cheers!')); |
|
21 | + ?> |
|
22 | 22 | </td> |
23 | 23 | </tr> |
24 | 24 | <tr><td colspan="2"> </td></tr> |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | <tr><td> |
28 | 28 | <table cellspacing="0" cellpadding="0" border="0" width="600px"> |
29 | 29 | <tr> |
30 | - <td colspan="2" bgcolor="<?php p($theme->getColorPrimary());?>"> |
|
30 | + <td colspan="2" bgcolor="<?php p($theme->getColorPrimary()); ?>"> |
|
31 | 31 | <img src="<?php p(\OC::$server->getURLGenerator()->getAbsoluteURL(image_path('', 'logo-mail.png'))); ?>" alt="<?php p($theme->getName()); ?>"/> |
32 | 32 | </td> |
33 | 33 | </tr> |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | <td style="font-weight:normal; font-size:0.8em; line-height:1.2em; font-family:verdana,'arial',sans;">--<br> |
53 | 53 | <?php p($theme->getName()); ?> - |
54 | 54 | <?php p($theme->getSlogan()); ?> |
55 | - <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl());?></a> |
|
55 | + <br><a href="<?php p($theme->getBaseUrl()); ?>"><?php p($theme->getBaseUrl()); ?></a> |
|
56 | 56 | </td> |
57 | 57 | </tr> |
58 | 58 | <tr> |
@@ -348,8 +348,9 @@ |
||
348 | 348 | $systemMountPoints = $this->getSystemMountPoints(); |
349 | 349 | foreach ($systemMountPoints as $mountPoint) { |
350 | 350 | $normalizedMountPoint = \OC\Files\Filesystem::normalizePath($mountPoint['mountpoint']) . '/'; |
351 | - if (strpos($normalized, $normalizedMountPoint) === 0) |
|
352 | - return $targetDir; |
|
351 | + if (strpos($normalized, $normalizedMountPoint) === 0) { |
|
352 | + return $targetDir; |
|
353 | + } |
|
353 | 354 | } |
354 | 355 | } else if ($trash === false && $this->view->file_exists('/' . $user. '/files/' . $filePath)) { |
355 | 356 | return $targetDir; |
@@ -33,362 +33,362 @@ |
||
33 | 33 | |
34 | 34 | class Migration { |
35 | 35 | |
36 | - private $moduleId; |
|
37 | - /** @var \OC\Files\View */ |
|
38 | - private $view; |
|
39 | - /** @var \OCP\IDBConnection */ |
|
40 | - private $connection; |
|
41 | - /** @var IConfig */ |
|
42 | - private $config; |
|
43 | - /** @var ILogger */ |
|
44 | - private $logger; |
|
45 | - /** @var string*/ |
|
46 | - protected $installedVersion; |
|
47 | - /** @var IAppManager */ |
|
48 | - protected $appManager; |
|
49 | - |
|
50 | - /** |
|
51 | - * @param IConfig $config |
|
52 | - * @param View $view |
|
53 | - * @param IDBConnection $connection |
|
54 | - * @param ILogger $logger |
|
55 | - */ |
|
56 | - public function __construct(IConfig $config, View $view, IDBConnection $connection, ILogger $logger, IAppManager $appManager) { |
|
57 | - $this->view = $view; |
|
58 | - $this->view->disableCacheUpdate(); |
|
59 | - $this->connection = $connection; |
|
60 | - $this->moduleId = \OCA\Encryption\Crypto\Encryption::ID; |
|
61 | - $this->config = $config; |
|
62 | - $this->logger = $logger; |
|
63 | - $this->installedVersion = $this->config->getAppValue('files_encryption', 'installed_version', '-1'); |
|
64 | - $this->appManager = $appManager; |
|
65 | - } |
|
66 | - |
|
67 | - public function finalCleanUp() { |
|
68 | - $this->view->deleteAll('files_encryption/public_keys'); |
|
69 | - $this->updateFileCache(); |
|
70 | - $this->config->deleteAppValue('files_encryption', 'installed_version'); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * update file cache, copy unencrypted_size to the 'size' column |
|
75 | - */ |
|
76 | - private function updateFileCache() { |
|
77 | - // make sure that we don't update the file cache multiple times |
|
78 | - // only update during the first run |
|
79 | - if ($this->installedVersion !== '-1') { |
|
80 | - $query = $this->connection->getQueryBuilder(); |
|
81 | - $query->update('filecache') |
|
82 | - ->set('size', 'unencrypted_size') |
|
83 | - ->where($query->expr()->eq('encrypted', $query->createParameter('encrypted'))) |
|
84 | - ->setParameter('encrypted', 1); |
|
85 | - $query->execute(); |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * iterate through users and reorganize the folder structure |
|
91 | - */ |
|
92 | - public function reorganizeFolderStructure() { |
|
93 | - $this->reorganizeSystemFolderStructure(); |
|
94 | - |
|
95 | - $limit = 500; |
|
96 | - $offset = 0; |
|
97 | - do { |
|
98 | - $users = \OCP\User::getUsers('', $limit, $offset); |
|
99 | - foreach ($users as $user) { |
|
100 | - $this->reorganizeFolderStructureForUser($user); |
|
101 | - } |
|
102 | - $offset += $limit; |
|
103 | - } while (count($users) >= $limit); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * reorganize system wide folder structure |
|
108 | - */ |
|
109 | - public function reorganizeSystemFolderStructure() { |
|
110 | - |
|
111 | - $this->createPathForKeys('/files_encryption'); |
|
112 | - |
|
113 | - // backup system wide folders |
|
114 | - $this->backupSystemWideKeys(); |
|
115 | - |
|
116 | - // rename system wide mount point |
|
117 | - $this->renameFileKeys('', '/files_encryption/keys'); |
|
118 | - |
|
119 | - // rename system private keys |
|
120 | - $this->renameSystemPrivateKeys(); |
|
121 | - |
|
122 | - $storage = $this->view->getMount('')->getStorage(); |
|
123 | - $storage->getScanner()->scan('files_encryption'); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * reorganize folder structure for user |
|
129 | - * |
|
130 | - * @param string $user |
|
131 | - */ |
|
132 | - public function reorganizeFolderStructureForUser($user) { |
|
133 | - // backup all keys |
|
134 | - \OC_Util::tearDownFS(); |
|
135 | - \OC_Util::setupFS($user); |
|
136 | - if ($this->backupUserKeys($user)) { |
|
137 | - // rename users private key |
|
138 | - $this->renameUsersPrivateKey($user); |
|
139 | - $this->renameUsersPublicKey($user); |
|
140 | - // rename file keys |
|
141 | - $path = '/files_encryption/keys'; |
|
142 | - $this->renameFileKeys($user, $path); |
|
143 | - $trashPath = '/files_trashbin/keys'; |
|
144 | - if ($this->appManager->isEnabledForUser('files_trashbin') && $this->view->is_dir($user . '/' . $trashPath)) { |
|
145 | - $this->renameFileKeys($user, $trashPath, true); |
|
146 | - $this->view->deleteAll($trashPath); |
|
147 | - } |
|
148 | - // delete old folders |
|
149 | - $this->deleteOldKeys($user); |
|
150 | - $this->view->getMount('/' . $user)->getStorage()->getScanner()->scan('files_encryption'); |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * update database |
|
156 | - */ |
|
157 | - public function updateDB() { |
|
158 | - |
|
159 | - // make sure that we don't update the file cache multiple times |
|
160 | - // only update during the first run |
|
161 | - if ($this->installedVersion === '-1') { |
|
162 | - return; |
|
163 | - } |
|
164 | - |
|
165 | - // delete left-over from old encryption which is no longer needed |
|
166 | - $this->config->deleteAppValue('files_encryption', 'ocsid'); |
|
167 | - $this->config->deleteAppValue('files_encryption', 'types'); |
|
168 | - $this->config->deleteAppValue('files_encryption', 'enabled'); |
|
169 | - |
|
170 | - $oldAppValues = $this->connection->getQueryBuilder(); |
|
171 | - $oldAppValues->select('*') |
|
172 | - ->from('appconfig') |
|
173 | - ->where($oldAppValues->expr()->eq('appid', $oldAppValues->createParameter('appid'))) |
|
174 | - ->setParameter('appid', 'files_encryption'); |
|
175 | - $appSettings = $oldAppValues->execute(); |
|
176 | - |
|
177 | - while ($row = $appSettings->fetch()) { |
|
178 | - // 'installed_version' gets deleted at the end of the migration process |
|
179 | - if ($row['configkey'] !== 'installed_version' ) { |
|
180 | - $this->config->setAppValue('encryption', $row['configkey'], $row['configvalue']); |
|
181 | - $this->config->deleteAppValue('files_encryption', $row['configkey']); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - $oldPreferences = $this->connection->getQueryBuilder(); |
|
186 | - $oldPreferences->select('*') |
|
187 | - ->from('preferences') |
|
188 | - ->where($oldPreferences->expr()->eq('appid', $oldPreferences->createParameter('appid'))) |
|
189 | - ->setParameter('appid', 'files_encryption'); |
|
190 | - $preferenceSettings = $oldPreferences->execute(); |
|
191 | - |
|
192 | - while ($row = $preferenceSettings->fetch()) { |
|
193 | - $this->config->setUserValue($row['userid'], 'encryption', $row['configkey'], $row['configvalue']); |
|
194 | - $this->config->deleteUserValue($row['userid'], 'files_encryption', $row['configkey']); |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * create backup of system-wide keys |
|
200 | - */ |
|
201 | - private function backupSystemWideKeys() { |
|
202 | - $backupDir = 'encryption_migration_backup_' . date("Y-m-d_H-i-s"); |
|
203 | - $this->view->mkdir($backupDir); |
|
204 | - $this->view->copy('files_encryption', $backupDir . '/files_encryption'); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * create backup of user specific keys |
|
209 | - * |
|
210 | - * @param string $user |
|
211 | - * @return bool |
|
212 | - */ |
|
213 | - private function backupUserKeys($user) { |
|
214 | - $encryptionDir = $user . '/files_encryption'; |
|
215 | - if ($this->view->is_dir($encryptionDir)) { |
|
216 | - $backupDir = $user . '/encryption_migration_backup_' . date("Y-m-d_H-i-s"); |
|
217 | - $this->view->mkdir($backupDir); |
|
218 | - $this->view->copy($encryptionDir, $backupDir); |
|
219 | - return true; |
|
220 | - } |
|
221 | - return false; |
|
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * rename system-wide private keys |
|
226 | - */ |
|
227 | - private function renameSystemPrivateKeys() { |
|
228 | - $dh = $this->view->opendir('files_encryption'); |
|
229 | - $this->createPathForKeys('/files_encryption/' . $this->moduleId ); |
|
230 | - if (is_resource($dh)) { |
|
231 | - while (($privateKey = readdir($dh)) !== false) { |
|
232 | - if (!\OC\Files\Filesystem::isIgnoredDir($privateKey) ) { |
|
233 | - if (!$this->view->is_dir('/files_encryption/' . $privateKey)) { |
|
234 | - $this->view->rename('files_encryption/' . $privateKey, 'files_encryption/' . $this->moduleId . '/' . $privateKey); |
|
235 | - $this->renameSystemPublicKey($privateKey); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - closedir($dh); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * rename system wide public key |
|
245 | - * |
|
246 | - * @param string $privateKey private key for which we want to rename the corresponding public key |
|
247 | - */ |
|
248 | - private function renameSystemPublicKey($privateKey) { |
|
249 | - $publicKey = substr($privateKey,0 , strrpos($privateKey, '.privateKey')) . '.publicKey'; |
|
250 | - $this->view->rename('files_encryption/public_keys/' . $publicKey, 'files_encryption/' . $this->moduleId . '/' . $publicKey); |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * rename user-specific private keys |
|
255 | - * |
|
256 | - * @param string $user |
|
257 | - */ |
|
258 | - private function renameUsersPrivateKey($user) { |
|
259 | - $oldPrivateKey = $user . '/files_encryption/' . $user . '.privateKey'; |
|
260 | - $newPrivateKey = $user . '/files_encryption/' . $this->moduleId . '/' . $user . '.privateKey'; |
|
261 | - if ($this->view->file_exists($oldPrivateKey)) { |
|
262 | - $this->createPathForKeys(dirname($newPrivateKey)); |
|
263 | - $this->view->rename($oldPrivateKey, $newPrivateKey); |
|
264 | - } |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * rename user-specific public keys |
|
269 | - * |
|
270 | - * @param string $user |
|
271 | - */ |
|
272 | - private function renameUsersPublicKey($user) { |
|
273 | - $oldPublicKey = '/files_encryption/public_keys/' . $user . '.publicKey'; |
|
274 | - $newPublicKey = $user . '/files_encryption/' . $this->moduleId . '/' . $user . '.publicKey'; |
|
275 | - if ($this->view->file_exists($oldPublicKey)) { |
|
276 | - $this->createPathForKeys(dirname($newPublicKey)); |
|
277 | - $this->view->rename($oldPublicKey, $newPublicKey); |
|
278 | - } |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * rename file keys |
|
283 | - * |
|
284 | - * @param string $user |
|
285 | - * @param string $path |
|
286 | - * @param bool $trash |
|
287 | - */ |
|
288 | - private function renameFileKeys($user, $path, $trash = false) { |
|
289 | - |
|
290 | - if ($this->view->is_dir($user . '/' . $path) === false) { |
|
291 | - $this->logger->info('Skip dir /' . $user . '/' . $path . ': does not exist'); |
|
292 | - return; |
|
293 | - } |
|
294 | - |
|
295 | - $dh = $this->view->opendir($user . '/' . $path); |
|
296 | - |
|
297 | - if (is_resource($dh)) { |
|
298 | - while (($file = readdir($dh)) !== false) { |
|
299 | - if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
300 | - if ($this->view->is_dir($user . '/' . $path . '/' . $file)) { |
|
301 | - $this->renameFileKeys($user, $path . '/' . $file, $trash); |
|
302 | - } else { |
|
303 | - $target = $this->getTargetDir($user, $path, $file, $trash); |
|
304 | - if ($target !== false) { |
|
305 | - $this->createPathForKeys(dirname($target)); |
|
306 | - $this->view->rename($user . '/' . $path . '/' . $file, $target); |
|
307 | - } else { |
|
308 | - $this->logger->warning( |
|
309 | - 'did not move key "' . $file |
|
310 | - . '" could not find the corresponding file in /data/' . $user . '/files.' |
|
311 | - . 'Most likely the key was already moved in a previous migration run and is already on the right place.'); |
|
312 | - } |
|
313 | - } |
|
314 | - } |
|
315 | - } |
|
316 | - closedir($dh); |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * get system mount points |
|
322 | - * wrap static method so that it can be mocked for testing |
|
323 | - * |
|
324 | - * @internal |
|
325 | - * @return array |
|
326 | - */ |
|
327 | - protected function getSystemMountPoints() { |
|
328 | - return \OC_Mount_Config::getSystemMountPoints(); |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * generate target directory |
|
333 | - * |
|
334 | - * @param string $user |
|
335 | - * @param string $keyPath |
|
336 | - * @param string $filename |
|
337 | - * @param bool $trash |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - private function getTargetDir($user, $keyPath, $filename, $trash) { |
|
341 | - if ($trash) { |
|
342 | - $filePath = substr($keyPath, strlen('/files_trashbin/keys/')); |
|
343 | - $targetDir = $user . '/files_encryption/keys/files_trashbin/' . $filePath . '/' . $this->moduleId . '/' . $filename; |
|
344 | - } else { |
|
345 | - $filePath = substr($keyPath, strlen('/files_encryption/keys/')); |
|
346 | - $targetDir = $user . '/files_encryption/keys/files/' . $filePath . '/' . $this->moduleId . '/' . $filename; |
|
347 | - } |
|
348 | - |
|
349 | - if ($user === '') { |
|
350 | - // for system wide mounts we need to check if the mount point really exists |
|
351 | - $normalized = \OC\Files\Filesystem::normalizePath($filePath); |
|
352 | - $systemMountPoints = $this->getSystemMountPoints(); |
|
353 | - foreach ($systemMountPoints as $mountPoint) { |
|
354 | - $normalizedMountPoint = \OC\Files\Filesystem::normalizePath($mountPoint['mountpoint']) . '/'; |
|
355 | - if (strpos($normalized, $normalizedMountPoint) === 0) |
|
356 | - return $targetDir; |
|
357 | - } |
|
358 | - } else if ($trash === false && $this->view->file_exists('/' . $user. '/files/' . $filePath)) { |
|
359 | - return $targetDir; |
|
360 | - } else if ($trash === true && $this->view->file_exists('/' . $user. '/files_trashbin/' . $filePath)) { |
|
361 | - return $targetDir; |
|
362 | - } |
|
363 | - |
|
364 | - return false; |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * delete old keys |
|
369 | - * |
|
370 | - * @param string $user |
|
371 | - */ |
|
372 | - private function deleteOldKeys($user) { |
|
373 | - $this->view->deleteAll($user . '/files_encryption/keyfiles'); |
|
374 | - $this->view->deleteAll($user . '/files_encryption/share-keys'); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * create directories for the keys recursively |
|
379 | - * |
|
380 | - * @param string $path |
|
381 | - */ |
|
382 | - private function createPathForKeys($path) { |
|
383 | - if (!$this->view->file_exists($path)) { |
|
384 | - $sub_dirs = explode('/', $path); |
|
385 | - $dir = ''; |
|
386 | - foreach ($sub_dirs as $sub_dir) { |
|
387 | - $dir .= '/' . $sub_dir; |
|
388 | - if (!$this->view->is_dir($dir)) { |
|
389 | - $this->view->mkdir($dir); |
|
390 | - } |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
36 | + private $moduleId; |
|
37 | + /** @var \OC\Files\View */ |
|
38 | + private $view; |
|
39 | + /** @var \OCP\IDBConnection */ |
|
40 | + private $connection; |
|
41 | + /** @var IConfig */ |
|
42 | + private $config; |
|
43 | + /** @var ILogger */ |
|
44 | + private $logger; |
|
45 | + /** @var string*/ |
|
46 | + protected $installedVersion; |
|
47 | + /** @var IAppManager */ |
|
48 | + protected $appManager; |
|
49 | + |
|
50 | + /** |
|
51 | + * @param IConfig $config |
|
52 | + * @param View $view |
|
53 | + * @param IDBConnection $connection |
|
54 | + * @param ILogger $logger |
|
55 | + */ |
|
56 | + public function __construct(IConfig $config, View $view, IDBConnection $connection, ILogger $logger, IAppManager $appManager) { |
|
57 | + $this->view = $view; |
|
58 | + $this->view->disableCacheUpdate(); |
|
59 | + $this->connection = $connection; |
|
60 | + $this->moduleId = \OCA\Encryption\Crypto\Encryption::ID; |
|
61 | + $this->config = $config; |
|
62 | + $this->logger = $logger; |
|
63 | + $this->installedVersion = $this->config->getAppValue('files_encryption', 'installed_version', '-1'); |
|
64 | + $this->appManager = $appManager; |
|
65 | + } |
|
66 | + |
|
67 | + public function finalCleanUp() { |
|
68 | + $this->view->deleteAll('files_encryption/public_keys'); |
|
69 | + $this->updateFileCache(); |
|
70 | + $this->config->deleteAppValue('files_encryption', 'installed_version'); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * update file cache, copy unencrypted_size to the 'size' column |
|
75 | + */ |
|
76 | + private function updateFileCache() { |
|
77 | + // make sure that we don't update the file cache multiple times |
|
78 | + // only update during the first run |
|
79 | + if ($this->installedVersion !== '-1') { |
|
80 | + $query = $this->connection->getQueryBuilder(); |
|
81 | + $query->update('filecache') |
|
82 | + ->set('size', 'unencrypted_size') |
|
83 | + ->where($query->expr()->eq('encrypted', $query->createParameter('encrypted'))) |
|
84 | + ->setParameter('encrypted', 1); |
|
85 | + $query->execute(); |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * iterate through users and reorganize the folder structure |
|
91 | + */ |
|
92 | + public function reorganizeFolderStructure() { |
|
93 | + $this->reorganizeSystemFolderStructure(); |
|
94 | + |
|
95 | + $limit = 500; |
|
96 | + $offset = 0; |
|
97 | + do { |
|
98 | + $users = \OCP\User::getUsers('', $limit, $offset); |
|
99 | + foreach ($users as $user) { |
|
100 | + $this->reorganizeFolderStructureForUser($user); |
|
101 | + } |
|
102 | + $offset += $limit; |
|
103 | + } while (count($users) >= $limit); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * reorganize system wide folder structure |
|
108 | + */ |
|
109 | + public function reorganizeSystemFolderStructure() { |
|
110 | + |
|
111 | + $this->createPathForKeys('/files_encryption'); |
|
112 | + |
|
113 | + // backup system wide folders |
|
114 | + $this->backupSystemWideKeys(); |
|
115 | + |
|
116 | + // rename system wide mount point |
|
117 | + $this->renameFileKeys('', '/files_encryption/keys'); |
|
118 | + |
|
119 | + // rename system private keys |
|
120 | + $this->renameSystemPrivateKeys(); |
|
121 | + |
|
122 | + $storage = $this->view->getMount('')->getStorage(); |
|
123 | + $storage->getScanner()->scan('files_encryption'); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * reorganize folder structure for user |
|
129 | + * |
|
130 | + * @param string $user |
|
131 | + */ |
|
132 | + public function reorganizeFolderStructureForUser($user) { |
|
133 | + // backup all keys |
|
134 | + \OC_Util::tearDownFS(); |
|
135 | + \OC_Util::setupFS($user); |
|
136 | + if ($this->backupUserKeys($user)) { |
|
137 | + // rename users private key |
|
138 | + $this->renameUsersPrivateKey($user); |
|
139 | + $this->renameUsersPublicKey($user); |
|
140 | + // rename file keys |
|
141 | + $path = '/files_encryption/keys'; |
|
142 | + $this->renameFileKeys($user, $path); |
|
143 | + $trashPath = '/files_trashbin/keys'; |
|
144 | + if ($this->appManager->isEnabledForUser('files_trashbin') && $this->view->is_dir($user . '/' . $trashPath)) { |
|
145 | + $this->renameFileKeys($user, $trashPath, true); |
|
146 | + $this->view->deleteAll($trashPath); |
|
147 | + } |
|
148 | + // delete old folders |
|
149 | + $this->deleteOldKeys($user); |
|
150 | + $this->view->getMount('/' . $user)->getStorage()->getScanner()->scan('files_encryption'); |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * update database |
|
156 | + */ |
|
157 | + public function updateDB() { |
|
158 | + |
|
159 | + // make sure that we don't update the file cache multiple times |
|
160 | + // only update during the first run |
|
161 | + if ($this->installedVersion === '-1') { |
|
162 | + return; |
|
163 | + } |
|
164 | + |
|
165 | + // delete left-over from old encryption which is no longer needed |
|
166 | + $this->config->deleteAppValue('files_encryption', 'ocsid'); |
|
167 | + $this->config->deleteAppValue('files_encryption', 'types'); |
|
168 | + $this->config->deleteAppValue('files_encryption', 'enabled'); |
|
169 | + |
|
170 | + $oldAppValues = $this->connection->getQueryBuilder(); |
|
171 | + $oldAppValues->select('*') |
|
172 | + ->from('appconfig') |
|
173 | + ->where($oldAppValues->expr()->eq('appid', $oldAppValues->createParameter('appid'))) |
|
174 | + ->setParameter('appid', 'files_encryption'); |
|
175 | + $appSettings = $oldAppValues->execute(); |
|
176 | + |
|
177 | + while ($row = $appSettings->fetch()) { |
|
178 | + // 'installed_version' gets deleted at the end of the migration process |
|
179 | + if ($row['configkey'] !== 'installed_version' ) { |
|
180 | + $this->config->setAppValue('encryption', $row['configkey'], $row['configvalue']); |
|
181 | + $this->config->deleteAppValue('files_encryption', $row['configkey']); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + $oldPreferences = $this->connection->getQueryBuilder(); |
|
186 | + $oldPreferences->select('*') |
|
187 | + ->from('preferences') |
|
188 | + ->where($oldPreferences->expr()->eq('appid', $oldPreferences->createParameter('appid'))) |
|
189 | + ->setParameter('appid', 'files_encryption'); |
|
190 | + $preferenceSettings = $oldPreferences->execute(); |
|
191 | + |
|
192 | + while ($row = $preferenceSettings->fetch()) { |
|
193 | + $this->config->setUserValue($row['userid'], 'encryption', $row['configkey'], $row['configvalue']); |
|
194 | + $this->config->deleteUserValue($row['userid'], 'files_encryption', $row['configkey']); |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * create backup of system-wide keys |
|
200 | + */ |
|
201 | + private function backupSystemWideKeys() { |
|
202 | + $backupDir = 'encryption_migration_backup_' . date("Y-m-d_H-i-s"); |
|
203 | + $this->view->mkdir($backupDir); |
|
204 | + $this->view->copy('files_encryption', $backupDir . '/files_encryption'); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * create backup of user specific keys |
|
209 | + * |
|
210 | + * @param string $user |
|
211 | + * @return bool |
|
212 | + */ |
|
213 | + private function backupUserKeys($user) { |
|
214 | + $encryptionDir = $user . '/files_encryption'; |
|
215 | + if ($this->view->is_dir($encryptionDir)) { |
|
216 | + $backupDir = $user . '/encryption_migration_backup_' . date("Y-m-d_H-i-s"); |
|
217 | + $this->view->mkdir($backupDir); |
|
218 | + $this->view->copy($encryptionDir, $backupDir); |
|
219 | + return true; |
|
220 | + } |
|
221 | + return false; |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * rename system-wide private keys |
|
226 | + */ |
|
227 | + private function renameSystemPrivateKeys() { |
|
228 | + $dh = $this->view->opendir('files_encryption'); |
|
229 | + $this->createPathForKeys('/files_encryption/' . $this->moduleId ); |
|
230 | + if (is_resource($dh)) { |
|
231 | + while (($privateKey = readdir($dh)) !== false) { |
|
232 | + if (!\OC\Files\Filesystem::isIgnoredDir($privateKey) ) { |
|
233 | + if (!$this->view->is_dir('/files_encryption/' . $privateKey)) { |
|
234 | + $this->view->rename('files_encryption/' . $privateKey, 'files_encryption/' . $this->moduleId . '/' . $privateKey); |
|
235 | + $this->renameSystemPublicKey($privateKey); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + closedir($dh); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * rename system wide public key |
|
245 | + * |
|
246 | + * @param string $privateKey private key for which we want to rename the corresponding public key |
|
247 | + */ |
|
248 | + private function renameSystemPublicKey($privateKey) { |
|
249 | + $publicKey = substr($privateKey,0 , strrpos($privateKey, '.privateKey')) . '.publicKey'; |
|
250 | + $this->view->rename('files_encryption/public_keys/' . $publicKey, 'files_encryption/' . $this->moduleId . '/' . $publicKey); |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * rename user-specific private keys |
|
255 | + * |
|
256 | + * @param string $user |
|
257 | + */ |
|
258 | + private function renameUsersPrivateKey($user) { |
|
259 | + $oldPrivateKey = $user . '/files_encryption/' . $user . '.privateKey'; |
|
260 | + $newPrivateKey = $user . '/files_encryption/' . $this->moduleId . '/' . $user . '.privateKey'; |
|
261 | + if ($this->view->file_exists($oldPrivateKey)) { |
|
262 | + $this->createPathForKeys(dirname($newPrivateKey)); |
|
263 | + $this->view->rename($oldPrivateKey, $newPrivateKey); |
|
264 | + } |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * rename user-specific public keys |
|
269 | + * |
|
270 | + * @param string $user |
|
271 | + */ |
|
272 | + private function renameUsersPublicKey($user) { |
|
273 | + $oldPublicKey = '/files_encryption/public_keys/' . $user . '.publicKey'; |
|
274 | + $newPublicKey = $user . '/files_encryption/' . $this->moduleId . '/' . $user . '.publicKey'; |
|
275 | + if ($this->view->file_exists($oldPublicKey)) { |
|
276 | + $this->createPathForKeys(dirname($newPublicKey)); |
|
277 | + $this->view->rename($oldPublicKey, $newPublicKey); |
|
278 | + } |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * rename file keys |
|
283 | + * |
|
284 | + * @param string $user |
|
285 | + * @param string $path |
|
286 | + * @param bool $trash |
|
287 | + */ |
|
288 | + private function renameFileKeys($user, $path, $trash = false) { |
|
289 | + |
|
290 | + if ($this->view->is_dir($user . '/' . $path) === false) { |
|
291 | + $this->logger->info('Skip dir /' . $user . '/' . $path . ': does not exist'); |
|
292 | + return; |
|
293 | + } |
|
294 | + |
|
295 | + $dh = $this->view->opendir($user . '/' . $path); |
|
296 | + |
|
297 | + if (is_resource($dh)) { |
|
298 | + while (($file = readdir($dh)) !== false) { |
|
299 | + if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
|
300 | + if ($this->view->is_dir($user . '/' . $path . '/' . $file)) { |
|
301 | + $this->renameFileKeys($user, $path . '/' . $file, $trash); |
|
302 | + } else { |
|
303 | + $target = $this->getTargetDir($user, $path, $file, $trash); |
|
304 | + if ($target !== false) { |
|
305 | + $this->createPathForKeys(dirname($target)); |
|
306 | + $this->view->rename($user . '/' . $path . '/' . $file, $target); |
|
307 | + } else { |
|
308 | + $this->logger->warning( |
|
309 | + 'did not move key "' . $file |
|
310 | + . '" could not find the corresponding file in /data/' . $user . '/files.' |
|
311 | + . 'Most likely the key was already moved in a previous migration run and is already on the right place.'); |
|
312 | + } |
|
313 | + } |
|
314 | + } |
|
315 | + } |
|
316 | + closedir($dh); |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * get system mount points |
|
322 | + * wrap static method so that it can be mocked for testing |
|
323 | + * |
|
324 | + * @internal |
|
325 | + * @return array |
|
326 | + */ |
|
327 | + protected function getSystemMountPoints() { |
|
328 | + return \OC_Mount_Config::getSystemMountPoints(); |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * generate target directory |
|
333 | + * |
|
334 | + * @param string $user |
|
335 | + * @param string $keyPath |
|
336 | + * @param string $filename |
|
337 | + * @param bool $trash |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + private function getTargetDir($user, $keyPath, $filename, $trash) { |
|
341 | + if ($trash) { |
|
342 | + $filePath = substr($keyPath, strlen('/files_trashbin/keys/')); |
|
343 | + $targetDir = $user . '/files_encryption/keys/files_trashbin/' . $filePath . '/' . $this->moduleId . '/' . $filename; |
|
344 | + } else { |
|
345 | + $filePath = substr($keyPath, strlen('/files_encryption/keys/')); |
|
346 | + $targetDir = $user . '/files_encryption/keys/files/' . $filePath . '/' . $this->moduleId . '/' . $filename; |
|
347 | + } |
|
348 | + |
|
349 | + if ($user === '') { |
|
350 | + // for system wide mounts we need to check if the mount point really exists |
|
351 | + $normalized = \OC\Files\Filesystem::normalizePath($filePath); |
|
352 | + $systemMountPoints = $this->getSystemMountPoints(); |
|
353 | + foreach ($systemMountPoints as $mountPoint) { |
|
354 | + $normalizedMountPoint = \OC\Files\Filesystem::normalizePath($mountPoint['mountpoint']) . '/'; |
|
355 | + if (strpos($normalized, $normalizedMountPoint) === 0) |
|
356 | + return $targetDir; |
|
357 | + } |
|
358 | + } else if ($trash === false && $this->view->file_exists('/' . $user. '/files/' . $filePath)) { |
|
359 | + return $targetDir; |
|
360 | + } else if ($trash === true && $this->view->file_exists('/' . $user. '/files_trashbin/' . $filePath)) { |
|
361 | + return $targetDir; |
|
362 | + } |
|
363 | + |
|
364 | + return false; |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * delete old keys |
|
369 | + * |
|
370 | + * @param string $user |
|
371 | + */ |
|
372 | + private function deleteOldKeys($user) { |
|
373 | + $this->view->deleteAll($user . '/files_encryption/keyfiles'); |
|
374 | + $this->view->deleteAll($user . '/files_encryption/share-keys'); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * create directories for the keys recursively |
|
379 | + * |
|
380 | + * @param string $path |
|
381 | + */ |
|
382 | + private function createPathForKeys($path) { |
|
383 | + if (!$this->view->file_exists($path)) { |
|
384 | + $sub_dirs = explode('/', $path); |
|
385 | + $dir = ''; |
|
386 | + foreach ($sub_dirs as $sub_dir) { |
|
387 | + $dir .= '/' . $sub_dir; |
|
388 | + if (!$this->view->is_dir($dir)) { |
|
389 | + $this->view->mkdir($dir); |
|
390 | + } |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | 394 | } |
@@ -141,13 +141,13 @@ discard block |
||
141 | 141 | $path = '/files_encryption/keys'; |
142 | 142 | $this->renameFileKeys($user, $path); |
143 | 143 | $trashPath = '/files_trashbin/keys'; |
144 | - if ($this->appManager->isEnabledForUser('files_trashbin') && $this->view->is_dir($user . '/' . $trashPath)) { |
|
144 | + if ($this->appManager->isEnabledForUser('files_trashbin') && $this->view->is_dir($user.'/'.$trashPath)) { |
|
145 | 145 | $this->renameFileKeys($user, $trashPath, true); |
146 | 146 | $this->view->deleteAll($trashPath); |
147 | 147 | } |
148 | 148 | // delete old folders |
149 | 149 | $this->deleteOldKeys($user); |
150 | - $this->view->getMount('/' . $user)->getStorage()->getScanner()->scan('files_encryption'); |
|
150 | + $this->view->getMount('/'.$user)->getStorage()->getScanner()->scan('files_encryption'); |
|
151 | 151 | } |
152 | 152 | } |
153 | 153 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | while ($row = $appSettings->fetch()) { |
178 | 178 | // 'installed_version' gets deleted at the end of the migration process |
179 | - if ($row['configkey'] !== 'installed_version' ) { |
|
179 | + if ($row['configkey'] !== 'installed_version') { |
|
180 | 180 | $this->config->setAppValue('encryption', $row['configkey'], $row['configvalue']); |
181 | 181 | $this->config->deleteAppValue('files_encryption', $row['configkey']); |
182 | 182 | } |
@@ -199,9 +199,9 @@ discard block |
||
199 | 199 | * create backup of system-wide keys |
200 | 200 | */ |
201 | 201 | private function backupSystemWideKeys() { |
202 | - $backupDir = 'encryption_migration_backup_' . date("Y-m-d_H-i-s"); |
|
202 | + $backupDir = 'encryption_migration_backup_'.date("Y-m-d_H-i-s"); |
|
203 | 203 | $this->view->mkdir($backupDir); |
204 | - $this->view->copy('files_encryption', $backupDir . '/files_encryption'); |
|
204 | + $this->view->copy('files_encryption', $backupDir.'/files_encryption'); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -211,9 +211,9 @@ discard block |
||
211 | 211 | * @return bool |
212 | 212 | */ |
213 | 213 | private function backupUserKeys($user) { |
214 | - $encryptionDir = $user . '/files_encryption'; |
|
214 | + $encryptionDir = $user.'/files_encryption'; |
|
215 | 215 | if ($this->view->is_dir($encryptionDir)) { |
216 | - $backupDir = $user . '/encryption_migration_backup_' . date("Y-m-d_H-i-s"); |
|
216 | + $backupDir = $user.'/encryption_migration_backup_'.date("Y-m-d_H-i-s"); |
|
217 | 217 | $this->view->mkdir($backupDir); |
218 | 218 | $this->view->copy($encryptionDir, $backupDir); |
219 | 219 | return true; |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | */ |
227 | 227 | private function renameSystemPrivateKeys() { |
228 | 228 | $dh = $this->view->opendir('files_encryption'); |
229 | - $this->createPathForKeys('/files_encryption/' . $this->moduleId ); |
|
229 | + $this->createPathForKeys('/files_encryption/'.$this->moduleId); |
|
230 | 230 | if (is_resource($dh)) { |
231 | 231 | while (($privateKey = readdir($dh)) !== false) { |
232 | - if (!\OC\Files\Filesystem::isIgnoredDir($privateKey) ) { |
|
233 | - if (!$this->view->is_dir('/files_encryption/' . $privateKey)) { |
|
234 | - $this->view->rename('files_encryption/' . $privateKey, 'files_encryption/' . $this->moduleId . '/' . $privateKey); |
|
232 | + if (!\OC\Files\Filesystem::isIgnoredDir($privateKey)) { |
|
233 | + if (!$this->view->is_dir('/files_encryption/'.$privateKey)) { |
|
234 | + $this->view->rename('files_encryption/'.$privateKey, 'files_encryption/'.$this->moduleId.'/'.$privateKey); |
|
235 | 235 | $this->renameSystemPublicKey($privateKey); |
236 | 236 | } |
237 | 237 | } |
@@ -246,8 +246,8 @@ discard block |
||
246 | 246 | * @param string $privateKey private key for which we want to rename the corresponding public key |
247 | 247 | */ |
248 | 248 | private function renameSystemPublicKey($privateKey) { |
249 | - $publicKey = substr($privateKey,0 , strrpos($privateKey, '.privateKey')) . '.publicKey'; |
|
250 | - $this->view->rename('files_encryption/public_keys/' . $publicKey, 'files_encryption/' . $this->moduleId . '/' . $publicKey); |
|
249 | + $publicKey = substr($privateKey, 0, strrpos($privateKey, '.privateKey')).'.publicKey'; |
|
250 | + $this->view->rename('files_encryption/public_keys/'.$publicKey, 'files_encryption/'.$this->moduleId.'/'.$publicKey); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | /** |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | * @param string $user |
257 | 257 | */ |
258 | 258 | private function renameUsersPrivateKey($user) { |
259 | - $oldPrivateKey = $user . '/files_encryption/' . $user . '.privateKey'; |
|
260 | - $newPrivateKey = $user . '/files_encryption/' . $this->moduleId . '/' . $user . '.privateKey'; |
|
259 | + $oldPrivateKey = $user.'/files_encryption/'.$user.'.privateKey'; |
|
260 | + $newPrivateKey = $user.'/files_encryption/'.$this->moduleId.'/'.$user.'.privateKey'; |
|
261 | 261 | if ($this->view->file_exists($oldPrivateKey)) { |
262 | 262 | $this->createPathForKeys(dirname($newPrivateKey)); |
263 | 263 | $this->view->rename($oldPrivateKey, $newPrivateKey); |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | * @param string $user |
271 | 271 | */ |
272 | 272 | private function renameUsersPublicKey($user) { |
273 | - $oldPublicKey = '/files_encryption/public_keys/' . $user . '.publicKey'; |
|
274 | - $newPublicKey = $user . '/files_encryption/' . $this->moduleId . '/' . $user . '.publicKey'; |
|
273 | + $oldPublicKey = '/files_encryption/public_keys/'.$user.'.publicKey'; |
|
274 | + $newPublicKey = $user.'/files_encryption/'.$this->moduleId.'/'.$user.'.publicKey'; |
|
275 | 275 | if ($this->view->file_exists($oldPublicKey)) { |
276 | 276 | $this->createPathForKeys(dirname($newPublicKey)); |
277 | 277 | $this->view->rename($oldPublicKey, $newPublicKey); |
@@ -287,27 +287,27 @@ discard block |
||
287 | 287 | */ |
288 | 288 | private function renameFileKeys($user, $path, $trash = false) { |
289 | 289 | |
290 | - if ($this->view->is_dir($user . '/' . $path) === false) { |
|
291 | - $this->logger->info('Skip dir /' . $user . '/' . $path . ': does not exist'); |
|
290 | + if ($this->view->is_dir($user.'/'.$path) === false) { |
|
291 | + $this->logger->info('Skip dir /'.$user.'/'.$path.': does not exist'); |
|
292 | 292 | return; |
293 | 293 | } |
294 | 294 | |
295 | - $dh = $this->view->opendir($user . '/' . $path); |
|
295 | + $dh = $this->view->opendir($user.'/'.$path); |
|
296 | 296 | |
297 | 297 | if (is_resource($dh)) { |
298 | 298 | while (($file = readdir($dh)) !== false) { |
299 | 299 | if (!\OC\Files\Filesystem::isIgnoredDir($file)) { |
300 | - if ($this->view->is_dir($user . '/' . $path . '/' . $file)) { |
|
301 | - $this->renameFileKeys($user, $path . '/' . $file, $trash); |
|
300 | + if ($this->view->is_dir($user.'/'.$path.'/'.$file)) { |
|
301 | + $this->renameFileKeys($user, $path.'/'.$file, $trash); |
|
302 | 302 | } else { |
303 | 303 | $target = $this->getTargetDir($user, $path, $file, $trash); |
304 | 304 | if ($target !== false) { |
305 | 305 | $this->createPathForKeys(dirname($target)); |
306 | - $this->view->rename($user . '/' . $path . '/' . $file, $target); |
|
306 | + $this->view->rename($user.'/'.$path.'/'.$file, $target); |
|
307 | 307 | } else { |
308 | 308 | $this->logger->warning( |
309 | - 'did not move key "' . $file |
|
310 | - . '" could not find the corresponding file in /data/' . $user . '/files.' |
|
309 | + 'did not move key "'.$file |
|
310 | + . '" could not find the corresponding file in /data/'.$user.'/files.' |
|
311 | 311 | . 'Most likely the key was already moved in a previous migration run and is already on the right place.'); |
312 | 312 | } |
313 | 313 | } |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | private function getTargetDir($user, $keyPath, $filename, $trash) { |
341 | 341 | if ($trash) { |
342 | 342 | $filePath = substr($keyPath, strlen('/files_trashbin/keys/')); |
343 | - $targetDir = $user . '/files_encryption/keys/files_trashbin/' . $filePath . '/' . $this->moduleId . '/' . $filename; |
|
343 | + $targetDir = $user.'/files_encryption/keys/files_trashbin/'.$filePath.'/'.$this->moduleId.'/'.$filename; |
|
344 | 344 | } else { |
345 | 345 | $filePath = substr($keyPath, strlen('/files_encryption/keys/')); |
346 | - $targetDir = $user . '/files_encryption/keys/files/' . $filePath . '/' . $this->moduleId . '/' . $filename; |
|
346 | + $targetDir = $user.'/files_encryption/keys/files/'.$filePath.'/'.$this->moduleId.'/'.$filename; |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | if ($user === '') { |
@@ -351,13 +351,13 @@ discard block |
||
351 | 351 | $normalized = \OC\Files\Filesystem::normalizePath($filePath); |
352 | 352 | $systemMountPoints = $this->getSystemMountPoints(); |
353 | 353 | foreach ($systemMountPoints as $mountPoint) { |
354 | - $normalizedMountPoint = \OC\Files\Filesystem::normalizePath($mountPoint['mountpoint']) . '/'; |
|
354 | + $normalizedMountPoint = \OC\Files\Filesystem::normalizePath($mountPoint['mountpoint']).'/'; |
|
355 | 355 | if (strpos($normalized, $normalizedMountPoint) === 0) |
356 | 356 | return $targetDir; |
357 | 357 | } |
358 | - } else if ($trash === false && $this->view->file_exists('/' . $user. '/files/' . $filePath)) { |
|
358 | + } else if ($trash === false && $this->view->file_exists('/'.$user.'/files/'.$filePath)) { |
|
359 | 359 | return $targetDir; |
360 | - } else if ($trash === true && $this->view->file_exists('/' . $user. '/files_trashbin/' . $filePath)) { |
|
360 | + } else if ($trash === true && $this->view->file_exists('/'.$user.'/files_trashbin/'.$filePath)) { |
|
361 | 361 | return $targetDir; |
362 | 362 | } |
363 | 363 | |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | * @param string $user |
371 | 371 | */ |
372 | 372 | private function deleteOldKeys($user) { |
373 | - $this->view->deleteAll($user . '/files_encryption/keyfiles'); |
|
374 | - $this->view->deleteAll($user . '/files_encryption/share-keys'); |
|
373 | + $this->view->deleteAll($user.'/files_encryption/keyfiles'); |
|
374 | + $this->view->deleteAll($user.'/files_encryption/share-keys'); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | /** |
@@ -384,7 +384,7 @@ discard block |
||
384 | 384 | $sub_dirs = explode('/', $path); |
385 | 385 | $dir = ''; |
386 | 386 | foreach ($sub_dirs as $sub_dir) { |
387 | - $dir .= '/' . $sub_dir; |
|
387 | + $dir .= '/'.$sub_dir; |
|
388 | 388 | if (!$this->view->is_dir($dir)) { |
389 | 389 | $this->view->mkdir($dir); |
390 | 390 | } |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * @return bool |
164 | 164 | */ |
165 | 165 | public function userHasFiles($uid) { |
166 | - return $this->files->file_exists($uid . '/files'); |
|
166 | + return $this->files->file_exists($uid.'/files'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | if (count($parts) > 1) { |
180 | 180 | $owner = $parts[1]; |
181 | 181 | if ($this->userManager->userExists($owner) === false) { |
182 | - throw new \BadMethodCallException('Unknown user: ' . |
|
182 | + throw new \BadMethodCallException('Unknown user: '. |
|
183 | 183 | 'method expects path to a user folder relative to the data folder'); |
184 | 184 | } |
185 | 185 |
@@ -36,167 +36,167 @@ |
||
36 | 36 | use OCP\PreConditionNotMetException; |
37 | 37 | |
38 | 38 | class Util { |
39 | - /** |
|
40 | - * @var View |
|
41 | - */ |
|
42 | - private $files; |
|
43 | - /** |
|
44 | - * @var Crypt |
|
45 | - */ |
|
46 | - private $crypt; |
|
47 | - /** |
|
48 | - * @var ILogger |
|
49 | - */ |
|
50 | - private $logger; |
|
51 | - /** |
|
52 | - * @var bool|IUser |
|
53 | - */ |
|
54 | - private $user; |
|
55 | - /** |
|
56 | - * @var IConfig |
|
57 | - */ |
|
58 | - private $config; |
|
59 | - /** |
|
60 | - * @var IUserManager |
|
61 | - */ |
|
62 | - private $userManager; |
|
63 | - |
|
64 | - /** |
|
65 | - * Util constructor. |
|
66 | - * |
|
67 | - * @param View $files |
|
68 | - * @param Crypt $crypt |
|
69 | - * @param ILogger $logger |
|
70 | - * @param IUserSession $userSession |
|
71 | - * @param IConfig $config |
|
72 | - * @param IUserManager $userManager |
|
73 | - */ |
|
74 | - public function __construct(View $files, |
|
75 | - Crypt $crypt, |
|
76 | - ILogger $logger, |
|
77 | - IUserSession $userSession, |
|
78 | - IConfig $config, |
|
79 | - IUserManager $userManager |
|
80 | - ) { |
|
81 | - $this->files = $files; |
|
82 | - $this->crypt = $crypt; |
|
83 | - $this->logger = $logger; |
|
84 | - $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false; |
|
85 | - $this->config = $config; |
|
86 | - $this->userManager = $userManager; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * check if recovery key is enabled for user |
|
91 | - * |
|
92 | - * @param string $uid |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public function isRecoveryEnabledForUser($uid) { |
|
96 | - $recoveryMode = $this->config->getUserValue($uid, |
|
97 | - 'encryption', |
|
98 | - 'recoveryEnabled', |
|
99 | - '0'); |
|
100 | - |
|
101 | - return ($recoveryMode === '1'); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * check if the home storage should be encrypted |
|
106 | - * |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - public function shouldEncryptHomeStorage() { |
|
110 | - $encryptHomeStorage = $this->config->getAppValue( |
|
111 | - 'encryption', |
|
112 | - 'encryptHomeStorage', |
|
113 | - '1' |
|
114 | - ); |
|
115 | - |
|
116 | - return ($encryptHomeStorage === '1'); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * set the home storage encryption on/off |
|
121 | - * |
|
122 | - * @param bool $encryptHomeStorage |
|
123 | - */ |
|
124 | - public function setEncryptHomeStorage($encryptHomeStorage) { |
|
125 | - $value = $encryptHomeStorage ? '1' : '0'; |
|
126 | - $this->config->setAppValue( |
|
127 | - 'encryption', |
|
128 | - 'encryptHomeStorage', |
|
129 | - $value |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * check if master key is enabled |
|
135 | - * |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function isMasterKeyEnabled() { |
|
139 | - $userMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', '1'); |
|
140 | - return ($userMasterKey === '1'); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @param $enabled |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - public function setRecoveryForUser($enabled) { |
|
148 | - $value = $enabled ? '1' : '0'; |
|
149 | - |
|
150 | - try { |
|
151 | - $this->config->setUserValue($this->user->getUID(), |
|
152 | - 'encryption', |
|
153 | - 'recoveryEnabled', |
|
154 | - $value); |
|
155 | - return true; |
|
156 | - } catch (PreConditionNotMetException $e) { |
|
157 | - return false; |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @param string $uid |
|
163 | - * @return bool |
|
164 | - */ |
|
165 | - public function userHasFiles($uid) { |
|
166 | - return $this->files->file_exists($uid . '/files'); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * get owner from give path, path relative to data/ expected |
|
171 | - * |
|
172 | - * @param string $path relative to data/ |
|
173 | - * @return string |
|
174 | - * @throws \BadMethodCallException |
|
175 | - */ |
|
176 | - public function getOwner($path) { |
|
177 | - $owner = ''; |
|
178 | - $parts = explode('/', $path, 3); |
|
179 | - if (count($parts) > 1) { |
|
180 | - $owner = $parts[1]; |
|
181 | - if ($this->userManager->userExists($owner) === false) { |
|
182 | - throw new \BadMethodCallException('Unknown user: ' . |
|
183 | - 'method expects path to a user folder relative to the data folder'); |
|
184 | - } |
|
185 | - |
|
186 | - } |
|
187 | - |
|
188 | - return $owner; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * get storage of path |
|
193 | - * |
|
194 | - * @param string $path |
|
195 | - * @return \OC\Files\Storage\Storage |
|
196 | - */ |
|
197 | - public function getStorage($path) { |
|
198 | - $storage = $this->files->getMount($path)->getStorage(); |
|
199 | - return $storage; |
|
200 | - } |
|
39 | + /** |
|
40 | + * @var View |
|
41 | + */ |
|
42 | + private $files; |
|
43 | + /** |
|
44 | + * @var Crypt |
|
45 | + */ |
|
46 | + private $crypt; |
|
47 | + /** |
|
48 | + * @var ILogger |
|
49 | + */ |
|
50 | + private $logger; |
|
51 | + /** |
|
52 | + * @var bool|IUser |
|
53 | + */ |
|
54 | + private $user; |
|
55 | + /** |
|
56 | + * @var IConfig |
|
57 | + */ |
|
58 | + private $config; |
|
59 | + /** |
|
60 | + * @var IUserManager |
|
61 | + */ |
|
62 | + private $userManager; |
|
63 | + |
|
64 | + /** |
|
65 | + * Util constructor. |
|
66 | + * |
|
67 | + * @param View $files |
|
68 | + * @param Crypt $crypt |
|
69 | + * @param ILogger $logger |
|
70 | + * @param IUserSession $userSession |
|
71 | + * @param IConfig $config |
|
72 | + * @param IUserManager $userManager |
|
73 | + */ |
|
74 | + public function __construct(View $files, |
|
75 | + Crypt $crypt, |
|
76 | + ILogger $logger, |
|
77 | + IUserSession $userSession, |
|
78 | + IConfig $config, |
|
79 | + IUserManager $userManager |
|
80 | + ) { |
|
81 | + $this->files = $files; |
|
82 | + $this->crypt = $crypt; |
|
83 | + $this->logger = $logger; |
|
84 | + $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser() : false; |
|
85 | + $this->config = $config; |
|
86 | + $this->userManager = $userManager; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * check if recovery key is enabled for user |
|
91 | + * |
|
92 | + * @param string $uid |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public function isRecoveryEnabledForUser($uid) { |
|
96 | + $recoveryMode = $this->config->getUserValue($uid, |
|
97 | + 'encryption', |
|
98 | + 'recoveryEnabled', |
|
99 | + '0'); |
|
100 | + |
|
101 | + return ($recoveryMode === '1'); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * check if the home storage should be encrypted |
|
106 | + * |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + public function shouldEncryptHomeStorage() { |
|
110 | + $encryptHomeStorage = $this->config->getAppValue( |
|
111 | + 'encryption', |
|
112 | + 'encryptHomeStorage', |
|
113 | + '1' |
|
114 | + ); |
|
115 | + |
|
116 | + return ($encryptHomeStorage === '1'); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * set the home storage encryption on/off |
|
121 | + * |
|
122 | + * @param bool $encryptHomeStorage |
|
123 | + */ |
|
124 | + public function setEncryptHomeStorage($encryptHomeStorage) { |
|
125 | + $value = $encryptHomeStorage ? '1' : '0'; |
|
126 | + $this->config->setAppValue( |
|
127 | + 'encryption', |
|
128 | + 'encryptHomeStorage', |
|
129 | + $value |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * check if master key is enabled |
|
135 | + * |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function isMasterKeyEnabled() { |
|
139 | + $userMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', '1'); |
|
140 | + return ($userMasterKey === '1'); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @param $enabled |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + public function setRecoveryForUser($enabled) { |
|
148 | + $value = $enabled ? '1' : '0'; |
|
149 | + |
|
150 | + try { |
|
151 | + $this->config->setUserValue($this->user->getUID(), |
|
152 | + 'encryption', |
|
153 | + 'recoveryEnabled', |
|
154 | + $value); |
|
155 | + return true; |
|
156 | + } catch (PreConditionNotMetException $e) { |
|
157 | + return false; |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @param string $uid |
|
163 | + * @return bool |
|
164 | + */ |
|
165 | + public function userHasFiles($uid) { |
|
166 | + return $this->files->file_exists($uid . '/files'); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * get owner from give path, path relative to data/ expected |
|
171 | + * |
|
172 | + * @param string $path relative to data/ |
|
173 | + * @return string |
|
174 | + * @throws \BadMethodCallException |
|
175 | + */ |
|
176 | + public function getOwner($path) { |
|
177 | + $owner = ''; |
|
178 | + $parts = explode('/', $path, 3); |
|
179 | + if (count($parts) > 1) { |
|
180 | + $owner = $parts[1]; |
|
181 | + if ($this->userManager->userExists($owner) === false) { |
|
182 | + throw new \BadMethodCallException('Unknown user: ' . |
|
183 | + 'method expects path to a user folder relative to the data folder'); |
|
184 | + } |
|
185 | + |
|
186 | + } |
|
187 | + |
|
188 | + return $owner; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * get storage of path |
|
193 | + * |
|
194 | + * @param string $path |
|
195 | + * @return \OC\Files\Storage\Storage |
|
196 | + */ |
|
197 | + public function getStorage($path) { |
|
198 | + $storage = $this->files->getMount($path)->getStorage(); |
|
199 | + return $storage; |
|
200 | + } |
|
201 | 201 | |
202 | 202 | } |
@@ -32,58 +32,58 @@ |
||
32 | 32 | use OCP\IUserSession; |
33 | 33 | |
34 | 34 | class Setup { |
35 | - /** |
|
36 | - * @var Crypt |
|
37 | - */ |
|
38 | - private $crypt; |
|
39 | - /** |
|
40 | - * @var KeyManager |
|
41 | - */ |
|
42 | - private $keyManager; |
|
43 | - /** |
|
44 | - * @var ILogger |
|
45 | - */ |
|
46 | - private $logger; |
|
47 | - /** |
|
48 | - * @var bool|string |
|
49 | - */ |
|
50 | - private $user; |
|
35 | + /** |
|
36 | + * @var Crypt |
|
37 | + */ |
|
38 | + private $crypt; |
|
39 | + /** |
|
40 | + * @var KeyManager |
|
41 | + */ |
|
42 | + private $keyManager; |
|
43 | + /** |
|
44 | + * @var ILogger |
|
45 | + */ |
|
46 | + private $logger; |
|
47 | + /** |
|
48 | + * @var bool|string |
|
49 | + */ |
|
50 | + private $user; |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @param ILogger $logger |
|
55 | - * @param IUserSession $userSession |
|
56 | - * @param Crypt $crypt |
|
57 | - * @param KeyManager $keyManager |
|
58 | - */ |
|
59 | - public function __construct(ILogger $logger, |
|
60 | - IUserSession $userSession, |
|
61 | - Crypt $crypt, |
|
62 | - KeyManager $keyManager) { |
|
63 | - $this->logger = $logger; |
|
64 | - $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false; |
|
65 | - $this->crypt = $crypt; |
|
66 | - $this->keyManager = $keyManager; |
|
67 | - } |
|
53 | + /** |
|
54 | + * @param ILogger $logger |
|
55 | + * @param IUserSession $userSession |
|
56 | + * @param Crypt $crypt |
|
57 | + * @param KeyManager $keyManager |
|
58 | + */ |
|
59 | + public function __construct(ILogger $logger, |
|
60 | + IUserSession $userSession, |
|
61 | + Crypt $crypt, |
|
62 | + KeyManager $keyManager) { |
|
63 | + $this->logger = $logger; |
|
64 | + $this->user = $userSession && $userSession->isLoggedIn() ? $userSession->getUser()->getUID() : false; |
|
65 | + $this->crypt = $crypt; |
|
66 | + $this->keyManager = $keyManager; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * @param string $uid user id |
|
71 | - * @param string $password user password |
|
72 | - * @return bool |
|
73 | - */ |
|
74 | - public function setupUser($uid, $password) { |
|
75 | - if (!$this->keyManager->userHasKeys($uid)) { |
|
76 | - return $this->keyManager->storeKeyPair($uid, $password, |
|
77 | - $this->crypt->createKeyPair()); |
|
78 | - } |
|
79 | - return true; |
|
80 | - } |
|
69 | + /** |
|
70 | + * @param string $uid user id |
|
71 | + * @param string $password user password |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | + public function setupUser($uid, $password) { |
|
75 | + if (!$this->keyManager->userHasKeys($uid)) { |
|
76 | + return $this->keyManager->storeKeyPair($uid, $password, |
|
77 | + $this->crypt->createKeyPair()); |
|
78 | + } |
|
79 | + return true; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * make sure that all system keys exists |
|
84 | - */ |
|
85 | - public function setupSystem() { |
|
86 | - $this->keyManager->validateShareKey(); |
|
87 | - $this->keyManager->validateMasterKey(); |
|
88 | - } |
|
82 | + /** |
|
83 | + * make sure that all system keys exists |
|
84 | + */ |
|
85 | + public function setupSystem() { |
|
86 | + $this->keyManager->validateShareKey(); |
|
87 | + $this->keyManager->validateMasterKey(); |
|
88 | + } |
|
89 | 89 | } |
@@ -38,129 +38,129 @@ |
||
38 | 38 | |
39 | 39 | class SettingsController extends Controller { |
40 | 40 | |
41 | - /** @var IL10N */ |
|
42 | - private $l; |
|
43 | - |
|
44 | - /** @var IUserManager */ |
|
45 | - private $userManager; |
|
46 | - |
|
47 | - /** @var IUserSession */ |
|
48 | - private $userSession; |
|
49 | - |
|
50 | - /** @var KeyManager */ |
|
51 | - private $keyManager; |
|
52 | - |
|
53 | - /** @var Crypt */ |
|
54 | - private $crypt; |
|
55 | - |
|
56 | - /** @var Session */ |
|
57 | - private $session; |
|
58 | - |
|
59 | - /** @var ISession */ |
|
60 | - private $ocSession; |
|
61 | - |
|
62 | - /** @var Util */ |
|
63 | - private $util; |
|
64 | - |
|
65 | - /** |
|
66 | - * @param string $AppName |
|
67 | - * @param IRequest $request |
|
68 | - * @param IL10N $l10n |
|
69 | - * @param IUserManager $userManager |
|
70 | - * @param IUserSession $userSession |
|
71 | - * @param KeyManager $keyManager |
|
72 | - * @param Crypt $crypt |
|
73 | - * @param Session $session |
|
74 | - * @param ISession $ocSession |
|
75 | - * @param Util $util |
|
76 | - */ |
|
77 | - public function __construct($AppName, |
|
78 | - IRequest $request, |
|
79 | - IL10N $l10n, |
|
80 | - IUserManager $userManager, |
|
81 | - IUserSession $userSession, |
|
82 | - KeyManager $keyManager, |
|
83 | - Crypt $crypt, |
|
84 | - Session $session, |
|
85 | - ISession $ocSession, |
|
86 | - Util $util |
|
41 | + /** @var IL10N */ |
|
42 | + private $l; |
|
43 | + |
|
44 | + /** @var IUserManager */ |
|
45 | + private $userManager; |
|
46 | + |
|
47 | + /** @var IUserSession */ |
|
48 | + private $userSession; |
|
49 | + |
|
50 | + /** @var KeyManager */ |
|
51 | + private $keyManager; |
|
52 | + |
|
53 | + /** @var Crypt */ |
|
54 | + private $crypt; |
|
55 | + |
|
56 | + /** @var Session */ |
|
57 | + private $session; |
|
58 | + |
|
59 | + /** @var ISession */ |
|
60 | + private $ocSession; |
|
61 | + |
|
62 | + /** @var Util */ |
|
63 | + private $util; |
|
64 | + |
|
65 | + /** |
|
66 | + * @param string $AppName |
|
67 | + * @param IRequest $request |
|
68 | + * @param IL10N $l10n |
|
69 | + * @param IUserManager $userManager |
|
70 | + * @param IUserSession $userSession |
|
71 | + * @param KeyManager $keyManager |
|
72 | + * @param Crypt $crypt |
|
73 | + * @param Session $session |
|
74 | + * @param ISession $ocSession |
|
75 | + * @param Util $util |
|
76 | + */ |
|
77 | + public function __construct($AppName, |
|
78 | + IRequest $request, |
|
79 | + IL10N $l10n, |
|
80 | + IUserManager $userManager, |
|
81 | + IUserSession $userSession, |
|
82 | + KeyManager $keyManager, |
|
83 | + Crypt $crypt, |
|
84 | + Session $session, |
|
85 | + ISession $ocSession, |
|
86 | + Util $util |
|
87 | 87 | ) { |
88 | - parent::__construct($AppName, $request); |
|
89 | - $this->l = $l10n; |
|
90 | - $this->userSession = $userSession; |
|
91 | - $this->userManager = $userManager; |
|
92 | - $this->keyManager = $keyManager; |
|
93 | - $this->crypt = $crypt; |
|
94 | - $this->session = $session; |
|
95 | - $this->ocSession = $ocSession; |
|
96 | - $this->util = $util; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @NoAdminRequired |
|
102 | - * @UseSession |
|
103 | - * |
|
104 | - * @param string $oldPassword |
|
105 | - * @param string $newPassword |
|
106 | - * @return DataResponse |
|
107 | - */ |
|
108 | - public function updatePrivateKeyPassword($oldPassword, $newPassword) { |
|
109 | - $result = false; |
|
110 | - $uid = $this->userSession->getUser()->getUID(); |
|
111 | - $errorMessage = $this->l->t('Could not update the private key password.'); |
|
112 | - |
|
113 | - //check if password is correct |
|
114 | - $passwordCorrect = $this->userManager->checkPassword($uid, $newPassword); |
|
115 | - if ($passwordCorrect === false) { |
|
116 | - // if check with uid fails we need to check the password with the login name |
|
117 | - // e.g. in the ldap case. For local user we need to check the password with |
|
118 | - // the uid because in this case the login name is case insensitive |
|
119 | - $loginName = $this->ocSession->get('loginname'); |
|
120 | - $passwordCorrect = $this->userManager->checkPassword($loginName, $newPassword); |
|
121 | - } |
|
122 | - |
|
123 | - if ($passwordCorrect !== false) { |
|
124 | - $encryptedKey = $this->keyManager->getPrivateKey($uid); |
|
125 | - $decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword, $uid); |
|
126 | - |
|
127 | - if ($decryptedKey) { |
|
128 | - $encryptedKey = $this->crypt->encryptPrivateKey($decryptedKey, $newPassword, $uid); |
|
129 | - $header = $this->crypt->generateHeader(); |
|
130 | - if ($encryptedKey) { |
|
131 | - $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); |
|
132 | - $this->session->setPrivateKey($decryptedKey); |
|
133 | - $result = true; |
|
134 | - } |
|
135 | - } else { |
|
136 | - $errorMessage = $this->l->t('The old password was not correct, please try again.'); |
|
137 | - } |
|
138 | - } else { |
|
139 | - $errorMessage = $this->l->t('The current log-in password was not correct, please try again.'); |
|
140 | - } |
|
141 | - |
|
142 | - if ($result === true) { |
|
143 | - $this->session->setStatus(Session::INIT_SUCCESSFUL); |
|
144 | - return new DataResponse( |
|
145 | - ['message' => (string) $this->l->t('Private key password successfully updated.')] |
|
146 | - ); |
|
147 | - } else { |
|
148 | - return new DataResponse( |
|
149 | - ['message' => (string) $errorMessage], |
|
150 | - Http::STATUS_BAD_REQUEST |
|
151 | - ); |
|
152 | - } |
|
153 | - |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @UseSession |
|
158 | - * |
|
159 | - * @param bool $encryptHomeStorage |
|
160 | - * @return DataResponse |
|
161 | - */ |
|
162 | - public function setEncryptHomeStorage($encryptHomeStorage) { |
|
163 | - $this->util->setEncryptHomeStorage($encryptHomeStorage); |
|
164 | - return new DataResponse(); |
|
165 | - } |
|
88 | + parent::__construct($AppName, $request); |
|
89 | + $this->l = $l10n; |
|
90 | + $this->userSession = $userSession; |
|
91 | + $this->userManager = $userManager; |
|
92 | + $this->keyManager = $keyManager; |
|
93 | + $this->crypt = $crypt; |
|
94 | + $this->session = $session; |
|
95 | + $this->ocSession = $ocSession; |
|
96 | + $this->util = $util; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @NoAdminRequired |
|
102 | + * @UseSession |
|
103 | + * |
|
104 | + * @param string $oldPassword |
|
105 | + * @param string $newPassword |
|
106 | + * @return DataResponse |
|
107 | + */ |
|
108 | + public function updatePrivateKeyPassword($oldPassword, $newPassword) { |
|
109 | + $result = false; |
|
110 | + $uid = $this->userSession->getUser()->getUID(); |
|
111 | + $errorMessage = $this->l->t('Could not update the private key password.'); |
|
112 | + |
|
113 | + //check if password is correct |
|
114 | + $passwordCorrect = $this->userManager->checkPassword($uid, $newPassword); |
|
115 | + if ($passwordCorrect === false) { |
|
116 | + // if check with uid fails we need to check the password with the login name |
|
117 | + // e.g. in the ldap case. For local user we need to check the password with |
|
118 | + // the uid because in this case the login name is case insensitive |
|
119 | + $loginName = $this->ocSession->get('loginname'); |
|
120 | + $passwordCorrect = $this->userManager->checkPassword($loginName, $newPassword); |
|
121 | + } |
|
122 | + |
|
123 | + if ($passwordCorrect !== false) { |
|
124 | + $encryptedKey = $this->keyManager->getPrivateKey($uid); |
|
125 | + $decryptedKey = $this->crypt->decryptPrivateKey($encryptedKey, $oldPassword, $uid); |
|
126 | + |
|
127 | + if ($decryptedKey) { |
|
128 | + $encryptedKey = $this->crypt->encryptPrivateKey($decryptedKey, $newPassword, $uid); |
|
129 | + $header = $this->crypt->generateHeader(); |
|
130 | + if ($encryptedKey) { |
|
131 | + $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); |
|
132 | + $this->session->setPrivateKey($decryptedKey); |
|
133 | + $result = true; |
|
134 | + } |
|
135 | + } else { |
|
136 | + $errorMessage = $this->l->t('The old password was not correct, please try again.'); |
|
137 | + } |
|
138 | + } else { |
|
139 | + $errorMessage = $this->l->t('The current log-in password was not correct, please try again.'); |
|
140 | + } |
|
141 | + |
|
142 | + if ($result === true) { |
|
143 | + $this->session->setStatus(Session::INIT_SUCCESSFUL); |
|
144 | + return new DataResponse( |
|
145 | + ['message' => (string) $this->l->t('Private key password successfully updated.')] |
|
146 | + ); |
|
147 | + } else { |
|
148 | + return new DataResponse( |
|
149 | + ['message' => (string) $errorMessage], |
|
150 | + Http::STATUS_BAD_REQUEST |
|
151 | + ); |
|
152 | + } |
|
153 | + |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @UseSession |
|
158 | + * |
|
159 | + * @param bool $encryptHomeStorage |
|
160 | + * @return DataResponse |
|
161 | + */ |
|
162 | + public function setEncryptHomeStorage($encryptHomeStorage) { |
|
163 | + $this->util->setEncryptHomeStorage($encryptHomeStorage); |
|
164 | + return new DataResponse(); |
|
165 | + } |
|
166 | 166 | } |
@@ -128,7 +128,7 @@ |
||
128 | 128 | $encryptedKey = $this->crypt->encryptPrivateKey($decryptedKey, $newPassword, $uid); |
129 | 129 | $header = $this->crypt->generateHeader(); |
130 | 130 | if ($encryptedKey) { |
131 | - $this->keyManager->setPrivateKey($uid, $header . $encryptedKey); |
|
131 | + $this->keyManager->setPrivateKey($uid, $header.$encryptedKey); |
|
132 | 132 | $this->session->setPrivateKey($decryptedKey); |
133 | 133 | $result = true; |
134 | 134 | } |