@@ -42,232 +42,232 @@ |
||
| 42 | 42 | use OCP\HintException; |
| 43 | 43 | |
| 44 | 44 | class ExceptionSerializer { |
| 45 | - public const methodsWithSensitiveParameters = [ |
|
| 46 | - // Session/User |
|
| 47 | - 'completeLogin', |
|
| 48 | - 'login', |
|
| 49 | - 'checkPassword', |
|
| 50 | - 'checkPasswordNoLogging', |
|
| 51 | - 'loginWithPassword', |
|
| 52 | - 'updatePrivateKeyPassword', |
|
| 53 | - 'validateUserPass', |
|
| 54 | - 'loginWithToken', |
|
| 55 | - '{closure}', |
|
| 56 | - 'createSessionToken', |
|
| 45 | + public const methodsWithSensitiveParameters = [ |
|
| 46 | + // Session/User |
|
| 47 | + 'completeLogin', |
|
| 48 | + 'login', |
|
| 49 | + 'checkPassword', |
|
| 50 | + 'checkPasswordNoLogging', |
|
| 51 | + 'loginWithPassword', |
|
| 52 | + 'updatePrivateKeyPassword', |
|
| 53 | + 'validateUserPass', |
|
| 54 | + 'loginWithToken', |
|
| 55 | + '{closure}', |
|
| 56 | + 'createSessionToken', |
|
| 57 | 57 | |
| 58 | - // Provisioning |
|
| 59 | - 'addUser', |
|
| 58 | + // Provisioning |
|
| 59 | + 'addUser', |
|
| 60 | 60 | |
| 61 | - // TokenProvider |
|
| 62 | - 'getToken', |
|
| 63 | - 'isTokenPassword', |
|
| 64 | - 'getPassword', |
|
| 65 | - 'decryptPassword', |
|
| 66 | - 'logClientIn', |
|
| 67 | - 'generateToken', |
|
| 68 | - 'validateToken', |
|
| 61 | + // TokenProvider |
|
| 62 | + 'getToken', |
|
| 63 | + 'isTokenPassword', |
|
| 64 | + 'getPassword', |
|
| 65 | + 'decryptPassword', |
|
| 66 | + 'logClientIn', |
|
| 67 | + 'generateToken', |
|
| 68 | + 'validateToken', |
|
| 69 | 69 | |
| 70 | - // TwoFactorAuth |
|
| 71 | - 'solveChallenge', |
|
| 72 | - 'verifyChallenge', |
|
| 70 | + // TwoFactorAuth |
|
| 71 | + 'solveChallenge', |
|
| 72 | + 'verifyChallenge', |
|
| 73 | 73 | |
| 74 | - // ICrypto |
|
| 75 | - 'calculateHMAC', |
|
| 76 | - 'encrypt', |
|
| 77 | - 'decrypt', |
|
| 74 | + // ICrypto |
|
| 75 | + 'calculateHMAC', |
|
| 76 | + 'encrypt', |
|
| 77 | + 'decrypt', |
|
| 78 | 78 | |
| 79 | - // LoginController |
|
| 80 | - 'tryLogin', |
|
| 81 | - 'confirmPassword', |
|
| 79 | + // LoginController |
|
| 80 | + 'tryLogin', |
|
| 81 | + 'confirmPassword', |
|
| 82 | 82 | |
| 83 | - // LDAP |
|
| 84 | - 'bind', |
|
| 85 | - 'areCredentialsValid', |
|
| 86 | - 'invokeLDAPMethod', |
|
| 83 | + // LDAP |
|
| 84 | + 'bind', |
|
| 85 | + 'areCredentialsValid', |
|
| 86 | + 'invokeLDAPMethod', |
|
| 87 | 87 | |
| 88 | - // Encryption |
|
| 89 | - 'storeKeyPair', |
|
| 90 | - 'setupUser', |
|
| 91 | - 'checkSignature', |
|
| 88 | + // Encryption |
|
| 89 | + 'storeKeyPair', |
|
| 90 | + 'setupUser', |
|
| 91 | + 'checkSignature', |
|
| 92 | 92 | |
| 93 | - // files_external: OCA\Files_External\MountConfig |
|
| 94 | - 'getBackendStatus', |
|
| 93 | + // files_external: OCA\Files_External\MountConfig |
|
| 94 | + 'getBackendStatus', |
|
| 95 | 95 | |
| 96 | - // files_external: UserStoragesController |
|
| 97 | - 'update', |
|
| 96 | + // files_external: UserStoragesController |
|
| 97 | + 'update', |
|
| 98 | 98 | |
| 99 | - // Preview providers, don't log big data strings |
|
| 100 | - 'imagecreatefromstring', |
|
| 101 | - ]; |
|
| 99 | + // Preview providers, don't log big data strings |
|
| 100 | + 'imagecreatefromstring', |
|
| 101 | + ]; |
|
| 102 | 102 | |
| 103 | - /** @var SystemConfig */ |
|
| 104 | - private $systemConfig; |
|
| 103 | + /** @var SystemConfig */ |
|
| 104 | + private $systemConfig; |
|
| 105 | 105 | |
| 106 | - public function __construct(SystemConfig $systemConfig) { |
|
| 107 | - $this->systemConfig = $systemConfig; |
|
| 108 | - } |
|
| 106 | + public function __construct(SystemConfig $systemConfig) { |
|
| 107 | + $this->systemConfig = $systemConfig; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - public const methodsWithSensitiveParametersByClass = [ |
|
| 111 | - SetupController::class => [ |
|
| 112 | - 'run', |
|
| 113 | - 'display', |
|
| 114 | - 'loadAutoConfig', |
|
| 115 | - ], |
|
| 116 | - Setup::class => [ |
|
| 117 | - 'install' |
|
| 118 | - ], |
|
| 119 | - Key::class => [ |
|
| 120 | - '__construct' |
|
| 121 | - ], |
|
| 122 | - \Redis::class => [ |
|
| 123 | - 'auth' |
|
| 124 | - ], |
|
| 125 | - \RedisCluster::class => [ |
|
| 126 | - '__construct' |
|
| 127 | - ], |
|
| 128 | - Crypt::class => [ |
|
| 129 | - 'symmetricEncryptFileContent', |
|
| 130 | - 'encrypt', |
|
| 131 | - 'generatePasswordHash', |
|
| 132 | - 'encryptPrivateKey', |
|
| 133 | - 'decryptPrivateKey', |
|
| 134 | - 'isValidPrivateKey', |
|
| 135 | - 'symmetricDecryptFileContent', |
|
| 136 | - 'checkSignature', |
|
| 137 | - 'createSignature', |
|
| 138 | - 'decrypt', |
|
| 139 | - 'multiKeyDecrypt', |
|
| 140 | - 'multiKeyEncrypt', |
|
| 141 | - ], |
|
| 142 | - RecoveryController::class => [ |
|
| 143 | - 'adminRecovery', |
|
| 144 | - 'changeRecoveryPassword' |
|
| 145 | - ], |
|
| 146 | - SettingsController::class => [ |
|
| 147 | - 'updatePrivateKeyPassword', |
|
| 148 | - ], |
|
| 149 | - Encryption::class => [ |
|
| 150 | - 'encrypt', |
|
| 151 | - 'decrypt', |
|
| 152 | - ], |
|
| 153 | - KeyManager::class => [ |
|
| 154 | - 'checkRecoveryPassword', |
|
| 155 | - 'storeKeyPair', |
|
| 156 | - 'setRecoveryKey', |
|
| 157 | - 'setPrivateKey', |
|
| 158 | - 'setFileKey', |
|
| 159 | - 'setAllFileKeys', |
|
| 160 | - ], |
|
| 161 | - Session::class => [ |
|
| 162 | - 'setPrivateKey', |
|
| 163 | - 'prepareDecryptAll', |
|
| 164 | - ], |
|
| 165 | - \OCA\Encryption\Users\Setup::class => [ |
|
| 166 | - 'setupUser', |
|
| 167 | - ], |
|
| 168 | - UserHooks::class => [ |
|
| 169 | - 'login', |
|
| 170 | - 'postCreateUser', |
|
| 171 | - 'postDeleteUser', |
|
| 172 | - 'prePasswordReset', |
|
| 173 | - 'postPasswordReset', |
|
| 174 | - 'preSetPassphrase', |
|
| 175 | - 'setPassphrase', |
|
| 176 | - ], |
|
| 177 | - ]; |
|
| 110 | + public const methodsWithSensitiveParametersByClass = [ |
|
| 111 | + SetupController::class => [ |
|
| 112 | + 'run', |
|
| 113 | + 'display', |
|
| 114 | + 'loadAutoConfig', |
|
| 115 | + ], |
|
| 116 | + Setup::class => [ |
|
| 117 | + 'install' |
|
| 118 | + ], |
|
| 119 | + Key::class => [ |
|
| 120 | + '__construct' |
|
| 121 | + ], |
|
| 122 | + \Redis::class => [ |
|
| 123 | + 'auth' |
|
| 124 | + ], |
|
| 125 | + \RedisCluster::class => [ |
|
| 126 | + '__construct' |
|
| 127 | + ], |
|
| 128 | + Crypt::class => [ |
|
| 129 | + 'symmetricEncryptFileContent', |
|
| 130 | + 'encrypt', |
|
| 131 | + 'generatePasswordHash', |
|
| 132 | + 'encryptPrivateKey', |
|
| 133 | + 'decryptPrivateKey', |
|
| 134 | + 'isValidPrivateKey', |
|
| 135 | + 'symmetricDecryptFileContent', |
|
| 136 | + 'checkSignature', |
|
| 137 | + 'createSignature', |
|
| 138 | + 'decrypt', |
|
| 139 | + 'multiKeyDecrypt', |
|
| 140 | + 'multiKeyEncrypt', |
|
| 141 | + ], |
|
| 142 | + RecoveryController::class => [ |
|
| 143 | + 'adminRecovery', |
|
| 144 | + 'changeRecoveryPassword' |
|
| 145 | + ], |
|
| 146 | + SettingsController::class => [ |
|
| 147 | + 'updatePrivateKeyPassword', |
|
| 148 | + ], |
|
| 149 | + Encryption::class => [ |
|
| 150 | + 'encrypt', |
|
| 151 | + 'decrypt', |
|
| 152 | + ], |
|
| 153 | + KeyManager::class => [ |
|
| 154 | + 'checkRecoveryPassword', |
|
| 155 | + 'storeKeyPair', |
|
| 156 | + 'setRecoveryKey', |
|
| 157 | + 'setPrivateKey', |
|
| 158 | + 'setFileKey', |
|
| 159 | + 'setAllFileKeys', |
|
| 160 | + ], |
|
| 161 | + Session::class => [ |
|
| 162 | + 'setPrivateKey', |
|
| 163 | + 'prepareDecryptAll', |
|
| 164 | + ], |
|
| 165 | + \OCA\Encryption\Users\Setup::class => [ |
|
| 166 | + 'setupUser', |
|
| 167 | + ], |
|
| 168 | + UserHooks::class => [ |
|
| 169 | + 'login', |
|
| 170 | + 'postCreateUser', |
|
| 171 | + 'postDeleteUser', |
|
| 172 | + 'prePasswordReset', |
|
| 173 | + 'postPasswordReset', |
|
| 174 | + 'preSetPassphrase', |
|
| 175 | + 'setPassphrase', |
|
| 176 | + ], |
|
| 177 | + ]; |
|
| 178 | 178 | |
| 179 | - private function editTrace(array &$sensitiveValues, array $traceLine): array { |
|
| 180 | - if (isset($traceLine['args'])) { |
|
| 181 | - $sensitiveValues = array_merge($sensitiveValues, $traceLine['args']); |
|
| 182 | - } |
|
| 183 | - $traceLine['args'] = ['*** sensitive parameters replaced ***']; |
|
| 184 | - return $traceLine; |
|
| 185 | - } |
|
| 179 | + private function editTrace(array &$sensitiveValues, array $traceLine): array { |
|
| 180 | + if (isset($traceLine['args'])) { |
|
| 181 | + $sensitiveValues = array_merge($sensitiveValues, $traceLine['args']); |
|
| 182 | + } |
|
| 183 | + $traceLine['args'] = ['*** sensitive parameters replaced ***']; |
|
| 184 | + return $traceLine; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - private function filterTrace(array $trace) { |
|
| 188 | - $sensitiveValues = []; |
|
| 189 | - $trace = array_map(function (array $traceLine) use (&$sensitiveValues) { |
|
| 190 | - $className = $traceLine['class'] ?? ''; |
|
| 191 | - if ($className && isset(self::methodsWithSensitiveParametersByClass[$className]) |
|
| 192 | - && in_array($traceLine['function'], self::methodsWithSensitiveParametersByClass[$className], true)) { |
|
| 193 | - return $this->editTrace($sensitiveValues, $traceLine); |
|
| 194 | - } |
|
| 195 | - foreach (self::methodsWithSensitiveParameters as $sensitiveMethod) { |
|
| 196 | - if (strpos($traceLine['function'], $sensitiveMethod) !== false) { |
|
| 197 | - return $this->editTrace($sensitiveValues, $traceLine); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - return $traceLine; |
|
| 201 | - }, $trace); |
|
| 202 | - return array_map(function (array $traceLine) use ($sensitiveValues) { |
|
| 203 | - if (isset($traceLine['args'])) { |
|
| 204 | - $traceLine['args'] = $this->removeValuesFromArgs($traceLine['args'], $sensitiveValues); |
|
| 205 | - } |
|
| 206 | - return $traceLine; |
|
| 207 | - }, $trace); |
|
| 208 | - } |
|
| 187 | + private function filterTrace(array $trace) { |
|
| 188 | + $sensitiveValues = []; |
|
| 189 | + $trace = array_map(function (array $traceLine) use (&$sensitiveValues) { |
|
| 190 | + $className = $traceLine['class'] ?? ''; |
|
| 191 | + if ($className && isset(self::methodsWithSensitiveParametersByClass[$className]) |
|
| 192 | + && in_array($traceLine['function'], self::methodsWithSensitiveParametersByClass[$className], true)) { |
|
| 193 | + return $this->editTrace($sensitiveValues, $traceLine); |
|
| 194 | + } |
|
| 195 | + foreach (self::methodsWithSensitiveParameters as $sensitiveMethod) { |
|
| 196 | + if (strpos($traceLine['function'], $sensitiveMethod) !== false) { |
|
| 197 | + return $this->editTrace($sensitiveValues, $traceLine); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + return $traceLine; |
|
| 201 | + }, $trace); |
|
| 202 | + return array_map(function (array $traceLine) use ($sensitiveValues) { |
|
| 203 | + if (isset($traceLine['args'])) { |
|
| 204 | + $traceLine['args'] = $this->removeValuesFromArgs($traceLine['args'], $sensitiveValues); |
|
| 205 | + } |
|
| 206 | + return $traceLine; |
|
| 207 | + }, $trace); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - private function removeValuesFromArgs($args, $values) { |
|
| 211 | - foreach ($args as &$arg) { |
|
| 212 | - if (in_array($arg, $values, true)) { |
|
| 213 | - $arg = '*** sensitive parameter replaced ***'; |
|
| 214 | - } elseif (is_array($arg)) { |
|
| 215 | - $arg = $this->removeValuesFromArgs($arg, $values); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - return $args; |
|
| 219 | - } |
|
| 210 | + private function removeValuesFromArgs($args, $values) { |
|
| 211 | + foreach ($args as &$arg) { |
|
| 212 | + if (in_array($arg, $values, true)) { |
|
| 213 | + $arg = '*** sensitive parameter replaced ***'; |
|
| 214 | + } elseif (is_array($arg)) { |
|
| 215 | + $arg = $this->removeValuesFromArgs($arg, $values); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + return $args; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - private function encodeTrace($trace) { |
|
| 222 | - $filteredTrace = $this->filterTrace($trace); |
|
| 223 | - return array_map(function (array $line) { |
|
| 224 | - if (isset($line['args'])) { |
|
| 225 | - $line['args'] = array_map([$this, 'encodeArg'], $line['args']); |
|
| 226 | - } |
|
| 227 | - return $line; |
|
| 228 | - }, $filteredTrace); |
|
| 229 | - } |
|
| 221 | + private function encodeTrace($trace) { |
|
| 222 | + $filteredTrace = $this->filterTrace($trace); |
|
| 223 | + return array_map(function (array $line) { |
|
| 224 | + if (isset($line['args'])) { |
|
| 225 | + $line['args'] = array_map([$this, 'encodeArg'], $line['args']); |
|
| 226 | + } |
|
| 227 | + return $line; |
|
| 228 | + }, $filteredTrace); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - private function encodeArg($arg) { |
|
| 232 | - if (is_object($arg)) { |
|
| 233 | - $data = get_object_vars($arg); |
|
| 234 | - $data['__class__'] = get_class($arg); |
|
| 235 | - return array_map([$this, 'encodeArg'], $data); |
|
| 236 | - } |
|
| 231 | + private function encodeArg($arg) { |
|
| 232 | + if (is_object($arg)) { |
|
| 233 | + $data = get_object_vars($arg); |
|
| 234 | + $data['__class__'] = get_class($arg); |
|
| 235 | + return array_map([$this, 'encodeArg'], $data); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - if (is_array($arg)) { |
|
| 239 | - // Only log the first 5 elements of an array unless we are on debug |
|
| 240 | - if ((int)$this->systemConfig->getValue('loglevel', 2) !== 0) { |
|
| 241 | - $elemCount = count($arg); |
|
| 242 | - if ($elemCount > 5) { |
|
| 243 | - $arg = array_slice($arg, 0, 5); |
|
| 244 | - $arg[] = 'And ' . ($elemCount - 5) . ' more entries, set log level to debug to see all entries'; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - return array_map([$this, 'encodeArg'], $arg); |
|
| 248 | - } |
|
| 238 | + if (is_array($arg)) { |
|
| 239 | + // Only log the first 5 elements of an array unless we are on debug |
|
| 240 | + if ((int)$this->systemConfig->getValue('loglevel', 2) !== 0) { |
|
| 241 | + $elemCount = count($arg); |
|
| 242 | + if ($elemCount > 5) { |
|
| 243 | + $arg = array_slice($arg, 0, 5); |
|
| 244 | + $arg[] = 'And ' . ($elemCount - 5) . ' more entries, set log level to debug to see all entries'; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + return array_map([$this, 'encodeArg'], $arg); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - return $arg; |
|
| 251 | - } |
|
| 250 | + return $arg; |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - public function serializeException(\Throwable $exception) { |
|
| 254 | - $data = [ |
|
| 255 | - 'Exception' => get_class($exception), |
|
| 256 | - 'Message' => $exception->getMessage(), |
|
| 257 | - 'Code' => $exception->getCode(), |
|
| 258 | - 'Trace' => $this->encodeTrace($exception->getTrace()), |
|
| 259 | - 'File' => $exception->getFile(), |
|
| 260 | - 'Line' => $exception->getLine(), |
|
| 261 | - ]; |
|
| 253 | + public function serializeException(\Throwable $exception) { |
|
| 254 | + $data = [ |
|
| 255 | + 'Exception' => get_class($exception), |
|
| 256 | + 'Message' => $exception->getMessage(), |
|
| 257 | + 'Code' => $exception->getCode(), |
|
| 258 | + 'Trace' => $this->encodeTrace($exception->getTrace()), |
|
| 259 | + 'File' => $exception->getFile(), |
|
| 260 | + 'Line' => $exception->getLine(), |
|
| 261 | + ]; |
|
| 262 | 262 | |
| 263 | - if ($exception instanceof HintException) { |
|
| 264 | - $data['Hint'] = $exception->getHint(); |
|
| 265 | - } |
|
| 263 | + if ($exception instanceof HintException) { |
|
| 264 | + $data['Hint'] = $exception->getHint(); |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - if ($exception->getPrevious()) { |
|
| 268 | - $data['Previous'] = $this->serializeException($exception->getPrevious()); |
|
| 269 | - } |
|
| 267 | + if ($exception->getPrevious()) { |
|
| 268 | + $data['Previous'] = $this->serializeException($exception->getPrevious()); |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - return $data; |
|
| 272 | - } |
|
| 271 | + return $data; |
|
| 272 | + } |
|
| 273 | 273 | } |