Completed
Push — master ( eba447...1a7516 )
by Blizzz
18:31
created
apps/dav/lib/Connector/Sabre/Auth.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -170,12 +170,12 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	private function requiresCSRFCheck() {
172 172
 		// GET requires no check at all
173
-		if($this->request->getMethod() === 'GET') {
173
+		if ($this->request->getMethod() === 'GET') {
174 174
 			return false;
175 175
 		}
176 176
 
177 177
 		// Official Nextcloud clients require no checks
178
-		if($this->request->isUserAgent([
178
+		if ($this->request->isUserAgent([
179 179
 			IRequest::USER_AGENT_CLIENT_DESKTOP,
180 180
 			IRequest::USER_AGENT_CLIENT_ANDROID,
181 181
 			IRequest::USER_AGENT_CLIENT_IOS,
@@ -184,17 +184,17 @@  discard block
 block discarded – undo
184 184
 		}
185 185
 
186 186
 		// If not logged-in no check is required
187
-		if(!$this->userSession->isLoggedIn()) {
187
+		if (!$this->userSession->isLoggedIn()) {
188 188
 			return false;
189 189
 		}
190 190
 
191 191
 		// POST always requires a check
192
-		if($this->request->getMethod() === 'POST') {
192
+		if ($this->request->getMethod() === 'POST') {
193 193
 			return true;
194 194
 		}
195 195
 
196 196
 		// If logged-in AND DAV authenticated no check is required
197
-		if($this->userSession->isLoggedIn() &&
197
+		if ($this->userSession->isLoggedIn() &&
198 198
 			$this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199 199
 			return false;
200 200
 		}
@@ -211,10 +211,10 @@  discard block
 block discarded – undo
211 211
 	private function auth(RequestInterface $request, ResponseInterface $response) {
212 212
 		$forcedLogout = false;
213 213
 
214
-		if(!$this->request->passesCSRFCheck() &&
214
+		if (!$this->request->passesCSRFCheck() &&
215 215
 			$this->requiresCSRFCheck()) {
216 216
 			// In case of a fail with POST we need to recheck the credentials
217
-			if($this->request->getMethod() === 'POST') {
217
+			if ($this->request->getMethod() === 'POST') {
218 218
 				$forcedLogout = true;
219 219
 			} else {
220 220
 				$response->setStatus(401);
@@ -222,10 +222,10 @@  discard block
 block discarded – undo
222 222
 			}
223 223
 		}
224 224
 
225
-		if($forcedLogout) {
225
+		if ($forcedLogout) {
226 226
 			$this->userSession->logout();
227 227
 		} else {
228
-			if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
228
+			if ($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
229 229
 				throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
230 230
 			}
231 231
 			if (\OC_User::handleApacheAuth() ||
@@ -238,19 +238,19 @@  discard block
 block discarded – undo
238 238
 				\OC_Util::setupFS($user);
239 239
 				$this->currentUser = $user;
240 240
 				$this->session->close();
241
-				return [true, $this->principalPrefix . $user];
241
+				return [true, $this->principalPrefix.$user];
242 242
 			}
243 243
 		}
244 244
 
245 245
 		if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
246 246
 			// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
247
-			$response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
247
+			$response->addHeader('WWW-Authenticate', 'DummyBasic realm="'.$this->realm.'"');
248 248
 			$response->setStatus(401);
249 249
 			throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
250 250
 		}
251 251
 
252 252
 		$data = parent::check($request, $response);
253
-		if($data[0] === true) {
253
+		if ($data[0] === true) {
254 254
 			$startPos = strrpos($data[1], '/') + 1;
255 255
 			$user = $this->userSession->getUser()->getUID();
256 256
 			$data[1] = substr_replace($data[1], $user, $startPos);
Please login to merge, or discard this patch.
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -49,212 +49,212 @@
 block discarded – undo
49 49
 class Auth extends AbstractBasic {
50 50
 
51 51
 
52
-	const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
52
+    const DAV_AUTHENTICATED = 'AUTHENTICATED_TO_DAV_BACKEND';
53 53
 
54
-	/** @var ISession */
55
-	private $session;
56
-	/** @var Session */
57
-	private $userSession;
58
-	/** @var IRequest */
59
-	private $request;
60
-	/** @var string */
61
-	private $currentUser;
62
-	/** @var Manager */
63
-	private $twoFactorManager;
64
-	/** @var Throttler */
65
-	private $throttler;
54
+    /** @var ISession */
55
+    private $session;
56
+    /** @var Session */
57
+    private $userSession;
58
+    /** @var IRequest */
59
+    private $request;
60
+    /** @var string */
61
+    private $currentUser;
62
+    /** @var Manager */
63
+    private $twoFactorManager;
64
+    /** @var Throttler */
65
+    private $throttler;
66 66
 
67
-	/**
68
-	 * @param ISession $session
69
-	 * @param Session $userSession
70
-	 * @param IRequest $request
71
-	 * @param Manager $twoFactorManager
72
-	 * @param Throttler $throttler
73
-	 * @param string $principalPrefix
74
-	 */
75
-	public function __construct(ISession $session,
76
-								Session $userSession,
77
-								IRequest $request,
78
-								Manager $twoFactorManager,
79
-								Throttler $throttler,
80
-								$principalPrefix = 'principals/users/') {
81
-		$this->session = $session;
82
-		$this->userSession = $userSession;
83
-		$this->twoFactorManager = $twoFactorManager;
84
-		$this->request = $request;
85
-		$this->throttler = $throttler;
86
-		$this->principalPrefix = $principalPrefix;
67
+    /**
68
+     * @param ISession $session
69
+     * @param Session $userSession
70
+     * @param IRequest $request
71
+     * @param Manager $twoFactorManager
72
+     * @param Throttler $throttler
73
+     * @param string $principalPrefix
74
+     */
75
+    public function __construct(ISession $session,
76
+                                Session $userSession,
77
+                                IRequest $request,
78
+                                Manager $twoFactorManager,
79
+                                Throttler $throttler,
80
+                                $principalPrefix = 'principals/users/') {
81
+        $this->session = $session;
82
+        $this->userSession = $userSession;
83
+        $this->twoFactorManager = $twoFactorManager;
84
+        $this->request = $request;
85
+        $this->throttler = $throttler;
86
+        $this->principalPrefix = $principalPrefix;
87 87
 
88
-		// setup realm
89
-		$defaults = new \OCP\Defaults();
90
-		$this->realm = $defaults->getName();
91
-	}
88
+        // setup realm
89
+        $defaults = new \OCP\Defaults();
90
+        $this->realm = $defaults->getName();
91
+    }
92 92
 
93
-	/**
94
-	 * Whether the user has initially authenticated via DAV
95
-	 *
96
-	 * This is required for WebDAV clients that resent the cookies even when the
97
-	 * account was changed.
98
-	 *
99
-	 * @see https://github.com/owncloud/core/issues/13245
100
-	 *
101
-	 * @param string $username
102
-	 * @return bool
103
-	 */
104
-	public function isDavAuthenticated($username) {
105
-		return !is_null($this->session->get(self::DAV_AUTHENTICATED)) &&
106
-		$this->session->get(self::DAV_AUTHENTICATED) === $username;
107
-	}
93
+    /**
94
+     * Whether the user has initially authenticated via DAV
95
+     *
96
+     * This is required for WebDAV clients that resent the cookies even when the
97
+     * account was changed.
98
+     *
99
+     * @see https://github.com/owncloud/core/issues/13245
100
+     *
101
+     * @param string $username
102
+     * @return bool
103
+     */
104
+    public function isDavAuthenticated($username) {
105
+        return !is_null($this->session->get(self::DAV_AUTHENTICATED)) &&
106
+        $this->session->get(self::DAV_AUTHENTICATED) === $username;
107
+    }
108 108
 
109
-	/**
110
-	 * Validates a username and password
111
-	 *
112
-	 * This method should return true or false depending on if login
113
-	 * succeeded.
114
-	 *
115
-	 * @param string $username
116
-	 * @param string $password
117
-	 * @return bool
118
-	 * @throws PasswordLoginForbidden
119
-	 */
120
-	protected function validateUserPass($username, $password) {
121
-		if ($this->userSession->isLoggedIn() &&
122
-			$this->isDavAuthenticated($this->userSession->getUser()->getUID())
123
-		) {
124
-			\OC_Util::setupFS($this->userSession->getUser()->getUID());
125
-			$this->session->close();
126
-			return true;
127
-		} else {
128
-			\OC_Util::setupFS(); //login hooks may need early access to the filesystem
129
-			try {
130
-				if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) {
131
-					\OC_Util::setupFS($this->userSession->getUser()->getUID());
132
-					$this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
133
-					$this->session->close();
134
-					return true;
135
-				} else {
136
-					$this->session->close();
137
-					return false;
138
-				}
139
-			} catch (PasswordLoginForbiddenException $ex) {
140
-				$this->session->close();
141
-				throw new PasswordLoginForbidden();
142
-			}
143
-		}
144
-	}
109
+    /**
110
+     * Validates a username and password
111
+     *
112
+     * This method should return true or false depending on if login
113
+     * succeeded.
114
+     *
115
+     * @param string $username
116
+     * @param string $password
117
+     * @return bool
118
+     * @throws PasswordLoginForbidden
119
+     */
120
+    protected function validateUserPass($username, $password) {
121
+        if ($this->userSession->isLoggedIn() &&
122
+            $this->isDavAuthenticated($this->userSession->getUser()->getUID())
123
+        ) {
124
+            \OC_Util::setupFS($this->userSession->getUser()->getUID());
125
+            $this->session->close();
126
+            return true;
127
+        } else {
128
+            \OC_Util::setupFS(); //login hooks may need early access to the filesystem
129
+            try {
130
+                if ($this->userSession->logClientIn($username, $password, $this->request, $this->throttler)) {
131
+                    \OC_Util::setupFS($this->userSession->getUser()->getUID());
132
+                    $this->session->set(self::DAV_AUTHENTICATED, $this->userSession->getUser()->getUID());
133
+                    $this->session->close();
134
+                    return true;
135
+                } else {
136
+                    $this->session->close();
137
+                    return false;
138
+                }
139
+            } catch (PasswordLoginForbiddenException $ex) {
140
+                $this->session->close();
141
+                throw new PasswordLoginForbidden();
142
+            }
143
+        }
144
+    }
145 145
 
146
-	/**
147
-	 * @param RequestInterface $request
148
-	 * @param ResponseInterface $response
149
-	 * @return array
150
-	 * @throws NotAuthenticated
151
-	 * @throws ServiceUnavailable
152
-	 */
153
-	function check(RequestInterface $request, ResponseInterface $response) {
154
-		try {
155
-			return $this->auth($request, $response);
156
-		} catch (NotAuthenticated $e) {
157
-			throw $e;
158
-		} catch (Exception $e) {
159
-			$class = get_class($e);
160
-			$msg = $e->getMessage();
161
-			\OC::$server->getLogger()->logException($e);
162
-			throw new ServiceUnavailable("$class: $msg");
163
-		}
164
-	}
146
+    /**
147
+     * @param RequestInterface $request
148
+     * @param ResponseInterface $response
149
+     * @return array
150
+     * @throws NotAuthenticated
151
+     * @throws ServiceUnavailable
152
+     */
153
+    function check(RequestInterface $request, ResponseInterface $response) {
154
+        try {
155
+            return $this->auth($request, $response);
156
+        } catch (NotAuthenticated $e) {
157
+            throw $e;
158
+        } catch (Exception $e) {
159
+            $class = get_class($e);
160
+            $msg = $e->getMessage();
161
+            \OC::$server->getLogger()->logException($e);
162
+            throw new ServiceUnavailable("$class: $msg");
163
+        }
164
+    }
165 165
 
166
-	/**
167
-	 * Checks whether a CSRF check is required on the request
168
-	 *
169
-	 * @return bool
170
-	 */
171
-	private function requiresCSRFCheck() {
172
-		// GET requires no check at all
173
-		if($this->request->getMethod() === 'GET') {
174
-			return false;
175
-		}
166
+    /**
167
+     * Checks whether a CSRF check is required on the request
168
+     *
169
+     * @return bool
170
+     */
171
+    private function requiresCSRFCheck() {
172
+        // GET requires no check at all
173
+        if($this->request->getMethod() === 'GET') {
174
+            return false;
175
+        }
176 176
 
177
-		// Official Nextcloud clients require no checks
178
-		if($this->request->isUserAgent([
179
-			IRequest::USER_AGENT_CLIENT_DESKTOP,
180
-			IRequest::USER_AGENT_CLIENT_ANDROID,
181
-			IRequest::USER_AGENT_CLIENT_IOS,
182
-		])) {
183
-			return false;
184
-		}
177
+        // Official Nextcloud clients require no checks
178
+        if($this->request->isUserAgent([
179
+            IRequest::USER_AGENT_CLIENT_DESKTOP,
180
+            IRequest::USER_AGENT_CLIENT_ANDROID,
181
+            IRequest::USER_AGENT_CLIENT_IOS,
182
+        ])) {
183
+            return false;
184
+        }
185 185
 
186
-		// If not logged-in no check is required
187
-		if(!$this->userSession->isLoggedIn()) {
188
-			return false;
189
-		}
186
+        // If not logged-in no check is required
187
+        if(!$this->userSession->isLoggedIn()) {
188
+            return false;
189
+        }
190 190
 
191
-		// POST always requires a check
192
-		if($this->request->getMethod() === 'POST') {
193
-			return true;
194
-		}
191
+        // POST always requires a check
192
+        if($this->request->getMethod() === 'POST') {
193
+            return true;
194
+        }
195 195
 
196
-		// If logged-in AND DAV authenticated no check is required
197
-		if($this->userSession->isLoggedIn() &&
198
-			$this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199
-			return false;
200
-		}
196
+        // If logged-in AND DAV authenticated no check is required
197
+        if($this->userSession->isLoggedIn() &&
198
+            $this->isDavAuthenticated($this->userSession->getUser()->getUID())) {
199
+            return false;
200
+        }
201 201
 
202
-		return true;
203
-	}
202
+        return true;
203
+    }
204 204
 
205
-	/**
206
-	 * @param RequestInterface $request
207
-	 * @param ResponseInterface $response
208
-	 * @return array
209
-	 * @throws NotAuthenticated
210
-	 */
211
-	private function auth(RequestInterface $request, ResponseInterface $response) {
212
-		$forcedLogout = false;
205
+    /**
206
+     * @param RequestInterface $request
207
+     * @param ResponseInterface $response
208
+     * @return array
209
+     * @throws NotAuthenticated
210
+     */
211
+    private function auth(RequestInterface $request, ResponseInterface $response) {
212
+        $forcedLogout = false;
213 213
 
214
-		if(!$this->request->passesCSRFCheck() &&
215
-			$this->requiresCSRFCheck()) {
216
-			// In case of a fail with POST we need to recheck the credentials
217
-			if($this->request->getMethod() === 'POST') {
218
-				$forcedLogout = true;
219
-			} else {
220
-				$response->setStatus(401);
221
-				throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.');
222
-			}
223
-		}
214
+        if(!$this->request->passesCSRFCheck() &&
215
+            $this->requiresCSRFCheck()) {
216
+            // In case of a fail with POST we need to recheck the credentials
217
+            if($this->request->getMethod() === 'POST') {
218
+                $forcedLogout = true;
219
+            } else {
220
+                $response->setStatus(401);
221
+                throw new \Sabre\DAV\Exception\NotAuthenticated('CSRF check not passed.');
222
+            }
223
+        }
224 224
 
225
-		if($forcedLogout) {
226
-			$this->userSession->logout();
227
-		} else {
228
-			if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
229
-				throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
230
-			}
231
-			if (\OC_User::handleApacheAuth() ||
232
-				//Fix for broken webdav clients
233
-				($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
234
-				//Well behaved clients that only send the cookie are allowed
235
-				($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null)
236
-			) {
237
-				$user = $this->userSession->getUser()->getUID();
238
-				\OC_Util::setupFS($user);
239
-				$this->currentUser = $user;
240
-				$this->session->close();
241
-				return [true, $this->principalPrefix . $user];
242
-			}
243
-		}
225
+        if($forcedLogout) {
226
+            $this->userSession->logout();
227
+        } else {
228
+            if($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
229
+                throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
230
+            }
231
+            if (\OC_User::handleApacheAuth() ||
232
+                //Fix for broken webdav clients
233
+                ($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED))) ||
234
+                //Well behaved clients that only send the cookie are allowed
235
+                ($this->userSession->isLoggedIn() && $this->session->get(self::DAV_AUTHENTICATED) === $this->userSession->getUser()->getUID() && $request->getHeader('Authorization') === null)
236
+            ) {
237
+                $user = $this->userSession->getUser()->getUID();
238
+                \OC_Util::setupFS($user);
239
+                $this->currentUser = $user;
240
+                $this->session->close();
241
+                return [true, $this->principalPrefix . $user];
242
+            }
243
+        }
244 244
 
245
-		if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
246
-			// do not re-authenticate over ajax, use dummy auth name to prevent browser popup
247
-			$response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
248
-			$response->setStatus(401);
249
-			throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
250
-		}
245
+        if (!$this->userSession->isLoggedIn() && in_array('XMLHttpRequest', explode(',', $request->getHeader('X-Requested-With')))) {
246
+            // do not re-authenticate over ajax, use dummy auth name to prevent browser popup
247
+            $response->addHeader('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"');
248
+            $response->setStatus(401);
249
+            throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls');
250
+        }
251 251
 
252
-		$data = parent::check($request, $response);
253
-		if($data[0] === true) {
254
-			$startPos = strrpos($data[1], '/') + 1;
255
-			$user = $this->userSession->getUser()->getUID();
256
-			$data[1] = substr_replace($data[1], $user, $startPos);
257
-		}
258
-		return $data;
259
-	}
252
+        $data = parent::check($request, $response);
253
+        if($data[0] === true) {
254
+            $startPos = strrpos($data[1], '/') + 1;
255
+            $user = $this->userSession->getUser()->getUID();
256
+            $data[1] = substr_replace($data[1], $user, $startPos);
257
+        }
258
+        return $data;
259
+    }
260 260
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/BearerAuth.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	private function setupUserFs($userId) {
56 56
 		\OC_Util::setupFS($userId);
57 57
 		$this->session->close();
58
-		return $this->principalPrefix . $userId;
58
+		return $this->principalPrefix.$userId;
59 59
 	}
60 60
 
61 61
 	/**
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
 	public function validateBearerToken($bearerToken) {
65 65
 		\OC_Util::setupFS();
66 66
 
67
-		if(!$this->userSession->isLoggedIn()) {
67
+		if (!$this->userSession->isLoggedIn()) {
68 68
 			$this->userSession->tryTokenLogin($this->request);
69 69
 		}
70
-		if($this->userSession->isLoggedIn()) {
70
+		if ($this->userSession->isLoggedIn()) {
71 71
 			return $this->setupUserFs($this->userSession->getUser()->getUID());
72 72
 		}
73 73
 
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -29,66 +29,66 @@
 block discarded – undo
29 29
 use Sabre\HTTP\ResponseInterface;
30 30
 
31 31
 class BearerAuth extends AbstractBearer {
32
-	/** @var IUserSession */
33
-	private $userSession;
34
-	/** @var ISession */
35
-	private $session;
36
-	/** @var IRequest */
37
-	private $request;
38
-	/** @var string */
39
-	private $principalPrefix;
32
+    /** @var IUserSession */
33
+    private $userSession;
34
+    /** @var ISession */
35
+    private $session;
36
+    /** @var IRequest */
37
+    private $request;
38
+    /** @var string */
39
+    private $principalPrefix;
40 40
 
41
-	/**
42
-	 * @param IUserSession $userSession
43
-	 * @param ISession $session
44
-	 * @param string $principalPrefix
45
-	 * @param IRequest $request
46
-	 */
47
-	public function __construct(IUserSession $userSession,
48
-								ISession $session,
49
-								IRequest $request,
50
-								$principalPrefix = 'principals/users/') {
51
-		$this->userSession = $userSession;
52
-		$this->session = $session;
53
-		$this->request = $request;
54
-		$this->principalPrefix = $principalPrefix;
41
+    /**
42
+     * @param IUserSession $userSession
43
+     * @param ISession $session
44
+     * @param string $principalPrefix
45
+     * @param IRequest $request
46
+     */
47
+    public function __construct(IUserSession $userSession,
48
+                                ISession $session,
49
+                                IRequest $request,
50
+                                $principalPrefix = 'principals/users/') {
51
+        $this->userSession = $userSession;
52
+        $this->session = $session;
53
+        $this->request = $request;
54
+        $this->principalPrefix = $principalPrefix;
55 55
 
56
-		// setup realm
57
-		$defaults = new \OCP\Defaults();
58
-		$this->realm = $defaults->getName();
59
-	}
56
+        // setup realm
57
+        $defaults = new \OCP\Defaults();
58
+        $this->realm = $defaults->getName();
59
+    }
60 60
 
61
-	private function setupUserFs($userId) {
62
-		\OC_Util::setupFS($userId);
63
-		$this->session->close();
64
-		return $this->principalPrefix . $userId;
65
-	}
61
+    private function setupUserFs($userId) {
62
+        \OC_Util::setupFS($userId);
63
+        $this->session->close();
64
+        return $this->principalPrefix . $userId;
65
+    }
66 66
 
67
-	/**
68
-	 * {@inheritdoc}
69
-	 */
70
-	public function validateBearerToken($bearerToken) {
71
-		\OC_Util::setupFS();
67
+    /**
68
+     * {@inheritdoc}
69
+     */
70
+    public function validateBearerToken($bearerToken) {
71
+        \OC_Util::setupFS();
72 72
 
73
-		if(!$this->userSession->isLoggedIn()) {
74
-			$this->userSession->tryTokenLogin($this->request);
75
-		}
76
-		if($this->userSession->isLoggedIn()) {
77
-			return $this->setupUserFs($this->userSession->getUser()->getUID());
78
-		}
73
+        if(!$this->userSession->isLoggedIn()) {
74
+            $this->userSession->tryTokenLogin($this->request);
75
+        }
76
+        if($this->userSession->isLoggedIn()) {
77
+            return $this->setupUserFs($this->userSession->getUser()->getUID());
78
+        }
79 79
 
80
-		return false;
81
-	}
80
+        return false;
81
+    }
82 82
 
83
-	/**
84
-	 * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
85
-	 * header which some DAV clients can't handle. Thus we override this function
86
-	 * and make it simply return a 401.
87
-	 *
88
-	 * @param RequestInterface $request
89
-	 * @param ResponseInterface $response
90
-	 */
91
-	public function challenge(RequestInterface $request, ResponseInterface $response) {
92
-		$response->setStatus(401);
93
-	}
83
+    /**
84
+     * \Sabre\DAV\Auth\Backend\AbstractBearer::challenge sets an WWW-Authenticate
85
+     * header which some DAV clients can't handle. Thus we override this function
86
+     * and make it simply return a 401.
87
+     *
88
+     * @param RequestInterface $request
89
+     * @param ResponseInterface $response
90
+     */
91
+    public function challenge(RequestInterface $request, ResponseInterface $response) {
92
+        $response->setStatus(401);
93
+    }
94 94
 }
Please login to merge, or discard this patch.
lib/private/Settings/Personal/Additional.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -29,31 +29,31 @@
 block discarded – undo
29 29
 
30 30
 class Additional implements ISettings {
31 31
 
32
-	/**
33
-	 * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
34
-	 * @since 9.1
35
-	 */
36
-	public function getForm() {
37
-		return new TemplateResponse('settings', 'settings/empty');
38
-	}
32
+    /**
33
+     * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
34
+     * @since 9.1
35
+     */
36
+    public function getForm() {
37
+        return new TemplateResponse('settings', 'settings/empty');
38
+    }
39 39
 
40
-	/**
41
-	 * @return string the section ID, e.g. 'sharing'
42
-	 * @since 9.1
43
-	 */
44
-	public function getSection() {
45
-		return 'additional';
46
-	}
40
+    /**
41
+     * @return string the section ID, e.g. 'sharing'
42
+     * @since 9.1
43
+     */
44
+    public function getSection() {
45
+        return 'additional';
46
+    }
47 47
 
48
-	/**
49
-	 * @return int whether the form should be rather on the top or bottom of
50
-	 * the admin section. The forms are arranged in ascending order of the
51
-	 * priority values. It is required to return a value between 0 and 100.
52
-	 *
53
-	 * E.g.: 70
54
-	 * @since 9.1
55
-	 */
56
-	public function getPriority() {
57
-		return '5';
58
-	}
48
+    /**
49
+     * @return int whether the form should be rather on the top or bottom of
50
+     * the admin section. The forms are arranged in ascending order of the
51
+     * priority values. It is required to return a value between 0 and 100.
52
+     *
53
+     * E.g.: 70
54
+     * @since 9.1
55
+     */
56
+    public function getPriority() {
57
+        return '5';
58
+    }
59 59
 }
Please login to merge, or discard this patch.
lib/private/GlobalScale/Config.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -27,45 +27,45 @@
 block discarded – undo
27 27
 
28 28
 class Config implements \OCP\GlobalScale\IConfig {
29 29
 
30
-	/** @var IConfig */
31
-	private $config;
30
+    /** @var IConfig */
31
+    private $config;
32 32
 
33
-	/**
34
-	 * Config constructor.
35
-	 *
36
-	 * @param IConfig $config
37
-	 */
38
-	public function __construct(IConfig $config) {
39
-		$this->config = $config;
40
-	}
33
+    /**
34
+     * Config constructor.
35
+     *
36
+     * @param IConfig $config
37
+     */
38
+    public function __construct(IConfig $config) {
39
+        $this->config = $config;
40
+    }
41 41
 
42
-	/**
43
-	 * check if global scale is enabled
44
-	 *
45
-	 * @since 12.0.1
46
-	 * @return bool
47
-	 */
48
-	public function isGlobalScaleEnabled() {
49
-		$enabled = $this->config->getSystemValue('gs.enabled', false);
50
-		return $enabled !== false;
51
-	}
42
+    /**
43
+     * check if global scale is enabled
44
+     *
45
+     * @since 12.0.1
46
+     * @return bool
47
+     */
48
+    public function isGlobalScaleEnabled() {
49
+        $enabled = $this->config->getSystemValue('gs.enabled', false);
50
+        return $enabled !== false;
51
+    }
52 52
 
53
-	/**
54
-	 * check if federation should only be used internally in a global scale setup
55
-	 *
56
-	 * @since 12.0.1
57
-	 * @return bool
58
-	 */
59
-	public function onlyInternalFederation() {
60
-		// if global scale is disabled federation works always globally
61
-		$gsEnabled = $this->isGlobalScaleEnabled();
62
-		if ($gsEnabled === false) {
63
-			return false;
64
-		}
53
+    /**
54
+     * check if federation should only be used internally in a global scale setup
55
+     *
56
+     * @since 12.0.1
57
+     * @return bool
58
+     */
59
+    public function onlyInternalFederation() {
60
+        // if global scale is disabled federation works always globally
61
+        $gsEnabled = $this->isGlobalScaleEnabled();
62
+        if ($gsEnabled === false) {
63
+            return false;
64
+        }
65 65
 
66
-		$enabled = $this->config->getSystemValue('gs.federation', 'internal');
66
+        $enabled = $this->config->getSystemValue('gs.federation', 'internal');
67 67
 
68
-		return $enabled === 'internal';
69
-	}
68
+        return $enabled === 'internal';
69
+    }
70 70
 
71 71
 }
Please login to merge, or discard this patch.
lib/public/GlobalScale/IConfig.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -32,20 +32,20 @@
 block discarded – undo
32 32
  */
33 33
 interface IConfig {
34 34
 
35
-	/**
36
-	 * check if global scale is enabled
37
-	 *
38
-	 * @since 12.0.1
39
-	 * @return bool
40
-	 */
41
-	public function isGlobalScaleEnabled();
35
+    /**
36
+     * check if global scale is enabled
37
+     *
38
+     * @since 12.0.1
39
+     * @return bool
40
+     */
41
+    public function isGlobalScaleEnabled();
42 42
 
43
-	/**
44
-	 * check if federation should only be used internally in a global scale setup
45
-	 *
46
-	 * @since 12.0.1
47
-	 * @return bool
48
-	 */
49
-	public function onlyInternalFederation();
43
+    /**
44
+     * check if federation should only be used internally in a global scale setup
45
+     *
46
+     * @since 12.0.1
47
+     * @return bool
48
+     */
49
+    public function onlyInternalFederation();
50 50
 
51 51
 }
Please login to merge, or discard this patch.
lib/public/Encryption/IEncryptionModule.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -35,161 +35,161 @@
 block discarded – undo
35 35
  */
36 36
 interface IEncryptionModule {
37 37
 
38
-	/**
39
-	 * @return string defining the technical unique id
40
-	 * @since 8.1.0
41
-	 */
42
-	public function getId();
43
-
44
-	/**
45
-	 * In comparison to getKey() this function returns a human readable (maybe translated) name
46
-	 *
47
-	 * @return string
48
-	 * @since 8.1.0
49
-	 */
50
-	public function getDisplayName();
51
-
52
-	/**
53
-	 * start receiving chunks from a file. This is the place where you can
54
-	 * perform some initial step before starting encrypting/decrypting the
55
-	 * chunks
56
-	 *
57
-	 * @param string $path to the file
58
-	 * @param string $user who read/write the file (null for public access)
59
-	 * @param string $mode php stream open mode
60
-	 * @param array $header contains the header data read from the file
61
-	 * @param array $accessList who has access to the file contains the key 'users' and 'public'
62
-	 *
63
-	 * $return array $header contain data as key-value pairs which should be
64
-	 *                       written to the header, in case of a write operation
65
-	 *                       or if no additional data is needed return a empty array
66
-	 * @since 8.1.0
67
-	 */
68
-	public function begin($path, $user, $mode, array $header, array $accessList);
69
-
70
-	/**
71
-	 * last chunk received. This is the place where you can perform some final
72
-	 * operation and return some remaining data if something is left in your
73
-	 * buffer.
74
-	 *
75
-	 * @param string $path to the file
76
-	 * @param string $position id of the last block (looks like "<Number>end")
77
-	 *
78
-	 * @return string remained data which should be written to the file in case
79
-	 *                of a write operation
80
-	 *
81
-	 * @since 8.1.0
82
-	 * @since 9.0.0 parameter $position added
83
-	 */
84
-	public function end($path, $position);
85
-
86
-	/**
87
-	 * encrypt data
88
-	 *
89
-	 * @param string $data you want to encrypt
90
-	 * @param string $position position of the block we want to encrypt (starts with '0')
91
-	 *
92
-	 * @return mixed encrypted data
93
-	 *
94
-	 * @since 8.1.0
95
-	 * @since 9.0.0 parameter $position added
96
-	 */
97
-	public function encrypt($data, $position);
98
-
99
-	/**
100
-	 * decrypt data
101
-	 *
102
-	 * @param string $data you want to decrypt
103
-	 * @param string $position position of the block we want to decrypt
104
-	 *
105
-	 * @return mixed decrypted data
106
-	 *
107
-	 * @since 8.1.0
108
-	 * @since 9.0.0 parameter $position added
109
-	 */
110
-	public function decrypt($data, $position);
111
-
112
-	/**
113
-	 * update encrypted file, e.g. give additional users access to the file
114
-	 *
115
-	 * @param string $path path to the file which should be updated
116
-	 * @param string $uid of the user who performs the operation
117
-	 * @param array $accessList who has access to the file contains the key 'users' and 'public'
118
-	 * @return boolean
119
-	 * @since 8.1.0
120
-	 */
121
-	public function update($path, $uid, array $accessList);
122
-
123
-	/**
124
-	 * should the file be encrypted or not
125
-	 *
126
-	 * @param string $path
127
-	 * @return boolean
128
-	 * @since 8.1.0
129
-	 */
130
-	public function shouldEncrypt($path);
131
-
132
-	/**
133
-	 * get size of the unencrypted payload per block.
134
-	 * ownCloud read/write files with a block size of 8192 byte
135
-	 *
136
-	 * @param bool $signed
137
-	 * @return int
138
-	 * @since 8.1.0 optional parameter $signed was added in 9.0.0
139
-	 */
140
-	public function getUnencryptedBlockSize($signed = false);
141
-
142
-	/**
143
-	 * check if the encryption module is able to read the file,
144
-	 * e.g. if all encryption keys exists
145
-	 *
146
-	 * @param string $path
147
-	 * @param string $uid user for whom we want to check if he can read the file
148
-	 * @return boolean
149
-	 * @since 8.1.0
150
-	 */
151
-	public function isReadable($path, $uid);
152
-
153
-	/**
154
-	 * Initial encryption of all files
155
-	 *
156
-	 * @param InputInterface $input
157
-	 * @param OutputInterface $output write some status information to the terminal during encryption
158
-	 * @since 8.2.0
159
-	 */
160
-	public function encryptAll(InputInterface $input, OutputInterface $output);
161
-
162
-	/**
163
-	 * prepare encryption module to decrypt all files
164
-	 *
165
-	 * @param InputInterface $input
166
-	 * @param OutputInterface $output write some status information to the terminal during encryption
167
-	 * @param $user (optional) for which the files should be decrypted, default = all users
168
-	 * @return bool return false on failure or if it isn't supported by the module
169
-	 * @since 8.2.0
170
-	 */
171
-	public function prepareDecryptAll(InputInterface $input, OutputInterface $output, $user = '');
172
-
173
-	/**
174
-	 * Check if the module is ready to be used by that specific user.
175
-	 * In case a module is not ready - because e.g. key pairs have not been generated
176
-	 * upon login this method can return false before any operation starts and might
177
-	 * cause issues during operations.
178
-	 *
179
-	 * @param string $user
180
-	 * @return boolean
181
-	 * @since 9.1.0
182
-	 */
183
-	public function isReadyForUser($user);
184
-
185
-	/**
186
-	 * Does the encryption module needs a detailed list of users with access to the file?
187
-	 * For example if the encryption module uses per-user encryption keys and needs to know
188
-	 * the users with access to the file to encrypt/decrypt it.
189
-	 *
190
-	 * @since 13.0.0
191
-	 * @return bool
192
-	 */
193
-	public function needDetailedAccessList();
38
+    /**
39
+     * @return string defining the technical unique id
40
+     * @since 8.1.0
41
+     */
42
+    public function getId();
43
+
44
+    /**
45
+     * In comparison to getKey() this function returns a human readable (maybe translated) name
46
+     *
47
+     * @return string
48
+     * @since 8.1.0
49
+     */
50
+    public function getDisplayName();
51
+
52
+    /**
53
+     * start receiving chunks from a file. This is the place where you can
54
+     * perform some initial step before starting encrypting/decrypting the
55
+     * chunks
56
+     *
57
+     * @param string $path to the file
58
+     * @param string $user who read/write the file (null for public access)
59
+     * @param string $mode php stream open mode
60
+     * @param array $header contains the header data read from the file
61
+     * @param array $accessList who has access to the file contains the key 'users' and 'public'
62
+     *
63
+     * $return array $header contain data as key-value pairs which should be
64
+     *                       written to the header, in case of a write operation
65
+     *                       or if no additional data is needed return a empty array
66
+     * @since 8.1.0
67
+     */
68
+    public function begin($path, $user, $mode, array $header, array $accessList);
69
+
70
+    /**
71
+     * last chunk received. This is the place where you can perform some final
72
+     * operation and return some remaining data if something is left in your
73
+     * buffer.
74
+     *
75
+     * @param string $path to the file
76
+     * @param string $position id of the last block (looks like "<Number>end")
77
+     *
78
+     * @return string remained data which should be written to the file in case
79
+     *                of a write operation
80
+     *
81
+     * @since 8.1.0
82
+     * @since 9.0.0 parameter $position added
83
+     */
84
+    public function end($path, $position);
85
+
86
+    /**
87
+     * encrypt data
88
+     *
89
+     * @param string $data you want to encrypt
90
+     * @param string $position position of the block we want to encrypt (starts with '0')
91
+     *
92
+     * @return mixed encrypted data
93
+     *
94
+     * @since 8.1.0
95
+     * @since 9.0.0 parameter $position added
96
+     */
97
+    public function encrypt($data, $position);
98
+
99
+    /**
100
+     * decrypt data
101
+     *
102
+     * @param string $data you want to decrypt
103
+     * @param string $position position of the block we want to decrypt
104
+     *
105
+     * @return mixed decrypted data
106
+     *
107
+     * @since 8.1.0
108
+     * @since 9.0.0 parameter $position added
109
+     */
110
+    public function decrypt($data, $position);
111
+
112
+    /**
113
+     * update encrypted file, e.g. give additional users access to the file
114
+     *
115
+     * @param string $path path to the file which should be updated
116
+     * @param string $uid of the user who performs the operation
117
+     * @param array $accessList who has access to the file contains the key 'users' and 'public'
118
+     * @return boolean
119
+     * @since 8.1.0
120
+     */
121
+    public function update($path, $uid, array $accessList);
122
+
123
+    /**
124
+     * should the file be encrypted or not
125
+     *
126
+     * @param string $path
127
+     * @return boolean
128
+     * @since 8.1.0
129
+     */
130
+    public function shouldEncrypt($path);
131
+
132
+    /**
133
+     * get size of the unencrypted payload per block.
134
+     * ownCloud read/write files with a block size of 8192 byte
135
+     *
136
+     * @param bool $signed
137
+     * @return int
138
+     * @since 8.1.0 optional parameter $signed was added in 9.0.0
139
+     */
140
+    public function getUnencryptedBlockSize($signed = false);
141
+
142
+    /**
143
+     * check if the encryption module is able to read the file,
144
+     * e.g. if all encryption keys exists
145
+     *
146
+     * @param string $path
147
+     * @param string $uid user for whom we want to check if he can read the file
148
+     * @return boolean
149
+     * @since 8.1.0
150
+     */
151
+    public function isReadable($path, $uid);
152
+
153
+    /**
154
+     * Initial encryption of all files
155
+     *
156
+     * @param InputInterface $input
157
+     * @param OutputInterface $output write some status information to the terminal during encryption
158
+     * @since 8.2.0
159
+     */
160
+    public function encryptAll(InputInterface $input, OutputInterface $output);
161
+
162
+    /**
163
+     * prepare encryption module to decrypt all files
164
+     *
165
+     * @param InputInterface $input
166
+     * @param OutputInterface $output write some status information to the terminal during encryption
167
+     * @param $user (optional) for which the files should be decrypted, default = all users
168
+     * @return bool return false on failure or if it isn't supported by the module
169
+     * @since 8.2.0
170
+     */
171
+    public function prepareDecryptAll(InputInterface $input, OutputInterface $output, $user = '');
172
+
173
+    /**
174
+     * Check if the module is ready to be used by that specific user.
175
+     * In case a module is not ready - because e.g. key pairs have not been generated
176
+     * upon login this method can return false before any operation starts and might
177
+     * cause issues during operations.
178
+     *
179
+     * @param string $user
180
+     * @return boolean
181
+     * @since 9.1.0
182
+     */
183
+    public function isReadyForUser($user);
184
+
185
+    /**
186
+     * Does the encryption module needs a detailed list of users with access to the file?
187
+     * For example if the encryption module uses per-user encryption keys and needs to know
188
+     * the users with access to the file to encrypt/decrypt it.
189
+     *
190
+     * @since 13.0.0
191
+     * @return bool
192
+     */
193
+    public function needDetailedAccessList();
194 194
 
195 195
 }
Please login to merge, or discard this patch.
apps/encryption/templates/settings-admin.php 2 patches
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,10 +9,13 @@  discard block
 block discarded – undo
9 9
 	<h3><?php p($l->t("Default encryption module")); ?></h3>
10 10
 	<?php if(!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
11 11
 		<?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?>
12
-	<?php else: ?>
12
+	<?php else {
13
+    : ?>
13 14
 		<p id="encryptHomeStorageSetting">
14 15
 			<input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage"
15
-				   value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); ?> />
16
+				   value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"');
17
+}
18
+?> />
16 19
 			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br>
17 20
 			<em><?php p( $l->t( "Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted" ) ); ?></em>
18 21
 		</p>
@@ -42,7 +45,10 @@  discard block
 block discarded – undo
42 45
 			</p>
43 46
 			<br/><br/>
44 47
 
45
-			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
48
+			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') {
49
+    print_unescaped('class="hidden"');
50
+}
51
+?>>
46 52
 				<?php p($l->t("Change recovery key password:")); ?>
47 53
 				<span class="msg"></span>
48 54
 				<br/>
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -7,17 +7,17 @@  discard block
 block discarded – undo
7 7
 ?>
8 8
 <form id="ocDefaultEncryptionModule" class="sub-section">
9 9
 	<h3><?php p($l->t("Default encryption module")); ?></h3>
10
-	<?php if(!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
10
+	<?php if (!$_["initStatus"] && $_['masterKeyEnabled'] === false): ?>
11 11
 		<?php p($l->t("Encryption app is enabled but your keys are not initialized, please log-out and log-in again")); ?>
12 12
 	<?php else: ?>
13 13
 		<p id="encryptHomeStorageSetting">
14 14
 			<input type="checkbox" class="checkbox" name="encrypt_home_storage" id="encryptHomeStorage"
15 15
 				   value="1" <?php if ($_['encryptHomeStorage']) print_unescaped('checked="checked"'); ?> />
16
-			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage'));?></label></br>
17
-			<em><?php p( $l->t( "Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted" ) ); ?></em>
16
+			<label for="encryptHomeStorage"><?php p($l->t('Encrypt the home storage')); ?></label></br>
17
+			<em><?php p($l->t("Enabling this option encrypts all files stored on the main storage, otherwise only files on external storage will be encrypted")); ?></em>
18 18
 		</p>
19 19
 		<br />
20
-		<?php if($_['masterKeyEnabled'] === false): ?>
20
+		<?php if ($_['masterKeyEnabled'] === false): ?>
21 21
 			<p id="encryptionSetRecoveryKey">
22 22
 				<?php $_["recoveryEnabled"] === '0' ?  p($l->t("Enable recovery key")) : p($l->t("Disable recovery key")); ?>
23 23
 				<span class="msg"></span>
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 			</p>
43 43
 			<br/><br/>
44 44
 
45
-			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"');?>>
45
+			<p name="changeRecoveryPasswordBlock" id="encryptionChangeRecoveryKey" <?php if ($_['recoveryEnabled'] === '0') print_unescaped('class="hidden"'); ?>>
46 46
 				<?php p($l->t("Change recovery key password:")); ?>
47 47
 				<span class="msg"></span>
48 48
 				<br/>
Please login to merge, or discard this patch.
apps/encryption/lib/Migration/SetMasterKeyStatus.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -35,43 +35,43 @@
 block discarded – undo
35 35
 class SetMasterKeyStatus implements IRepairStep {
36 36
 
37 37
 
38
-	/** @var  IConfig */
39
-	private $config;
38
+    /** @var  IConfig */
39
+    private $config;
40 40
 
41 41
 
42
-	public function __construct(IConfig $config) {
43
-		$this->config = $config;
44
-	}
42
+    public function __construct(IConfig $config) {
43
+        $this->config = $config;
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the step's name
48
-	 *
49
-	 * @return string
50
-	 * @since 9.1.0
51
-	 */
52
-	public function getName() {
53
-		return 'Write default encryption module configuration to the database';
54
-	}
46
+    /**
47
+     * Returns the step's name
48
+     *
49
+     * @return string
50
+     * @since 9.1.0
51
+     */
52
+    public function getName() {
53
+        return 'Write default encryption module configuration to the database';
54
+    }
55 55
 
56
-	/**
57
-	 * @param IOutput $output
58
-	 */
59
-	public function run(IOutput $output) {
60
-		if (!$this->shouldRun()) {
61
-			return;
62
-		}
56
+    /**
57
+     * @param IOutput $output
58
+     */
59
+    public function run(IOutput $output) {
60
+        if (!$this->shouldRun()) {
61
+            return;
62
+        }
63 63
 
64
-		// if no config for the master key is set we set it explicitly to '0' in
65
-		// order not to break old installations because the default changed to '1'.
66
-		$configAlreadySet = $this->config->getAppValue('encryption', 'useMasterKey', false);
67
-		if ($configAlreadySet === false) {
68
-			$this->config->setAppValue('encryption', 'useMasterKey', '0');
69
-		}
70
-	}
64
+        // if no config for the master key is set we set it explicitly to '0' in
65
+        // order not to break old installations because the default changed to '1'.
66
+        $configAlreadySet = $this->config->getAppValue('encryption', 'useMasterKey', false);
67
+        if ($configAlreadySet === false) {
68
+            $this->config->setAppValue('encryption', 'useMasterKey', '0');
69
+        }
70
+    }
71 71
 
72
-	protected function shouldRun() {
73
-		$appVersion = $this->config->getAppValue('encryption', 'installed_version', '0.0.0');
74
-		return version_compare($appVersion, '2.0.0', '<');
75
-	}
72
+    protected function shouldRun() {
73
+        $appVersion = $this->config->getAppValue('encryption', 'installed_version', '0.0.0');
74
+        return version_compare($appVersion, '2.0.0', '<');
75
+    }
76 76
 
77 77
 }
Please login to merge, or discard this patch.
apps/encryption/lib/Command/DisableMasterKey.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -33,57 +33,57 @@
 block discarded – undo
33 33
 
34 34
 class DisableMasterKey extends Command {
35 35
 
36
-	/** @var Util */
37
-	protected $util;
38
-
39
-	/** @var IConfig */
40
-	protected $config;
41
-
42
-	/** @var  QuestionHelper */
43
-	protected $questionHelper;
44
-
45
-	/**
46
-	 * @param Util $util
47
-	 * @param IConfig $config
48
-	 * @param QuestionHelper $questionHelper
49
-	 */
50
-	public function __construct(Util $util,
51
-								IConfig $config,
52
-								QuestionHelper $questionHelper) {
53
-
54
-		$this->util = $util;
55
-		$this->config = $config;
56
-		$this->questionHelper = $questionHelper;
57
-		parent::__construct();
58
-	}
59
-
60
-	protected function configure() {
61
-		$this
62
-			->setName('encryption:disable-master-key')
63
-			->setDescription('Disable the master key and use per-user keys instead. Only available for fresh installations with no existing encrypted data! There is no way to enable it again.');
64
-	}
65
-
66
-	protected function execute(InputInterface $input, OutputInterface $output) {
67
-
68
-		$isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
69
-
70
-		if(!$isMasterKeyEnabled) {
71
-			$output->writeln('Master key already disabled');
72
-		} else {
73
-			$question = new ConfirmationQuestion(
74
-				'Warning: Only perform this operation for a fresh installations with no existing encrypted data! '
75
-				. 'There is no way to enable the master key again. '
76
-				. 'We strongly recommend to keep the master key, it provides significant performance improvements '
77
-				. 'and is easier to handle for both, users and administrators. '
78
-				. 'Do you really want to switch to per-user keys? (y/n) ', false);
79
-			if ($this->questionHelper->ask($input, $output, $question)) {
80
-				$this->config->setAppValue('encryption', 'useMasterKey', '0');
81
-				$output->writeln('Master key successfully disabled.');
82
-			} else {
83
-				$output->writeln('aborted.');
84
-			}
85
-		}
86
-
87
-	}
36
+    /** @var Util */
37
+    protected $util;
38
+
39
+    /** @var IConfig */
40
+    protected $config;
41
+
42
+    /** @var  QuestionHelper */
43
+    protected $questionHelper;
44
+
45
+    /**
46
+     * @param Util $util
47
+     * @param IConfig $config
48
+     * @param QuestionHelper $questionHelper
49
+     */
50
+    public function __construct(Util $util,
51
+                                IConfig $config,
52
+                                QuestionHelper $questionHelper) {
53
+
54
+        $this->util = $util;
55
+        $this->config = $config;
56
+        $this->questionHelper = $questionHelper;
57
+        parent::__construct();
58
+    }
59
+
60
+    protected function configure() {
61
+        $this
62
+            ->setName('encryption:disable-master-key')
63
+            ->setDescription('Disable the master key and use per-user keys instead. Only available for fresh installations with no existing encrypted data! There is no way to enable it again.');
64
+    }
65
+
66
+    protected function execute(InputInterface $input, OutputInterface $output) {
67
+
68
+        $isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
69
+
70
+        if(!$isMasterKeyEnabled) {
71
+            $output->writeln('Master key already disabled');
72
+        } else {
73
+            $question = new ConfirmationQuestion(
74
+                'Warning: Only perform this operation for a fresh installations with no existing encrypted data! '
75
+                . 'There is no way to enable the master key again. '
76
+                . 'We strongly recommend to keep the master key, it provides significant performance improvements '
77
+                . 'and is easier to handle for both, users and administrators. '
78
+                . 'Do you really want to switch to per-user keys? (y/n) ', false);
79
+            if ($this->questionHelper->ask($input, $output, $question)) {
80
+                $this->config->setAppValue('encryption', 'useMasterKey', '0');
81
+                $output->writeln('Master key successfully disabled.');
82
+            } else {
83
+                $output->writeln('aborted.');
84
+            }
85
+        }
86
+
87
+    }
88 88
 
89 89
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 
68 68
 		$isMasterKeyEnabled = $this->util->isMasterKeyEnabled();
69 69
 
70
-		if(!$isMasterKeyEnabled) {
70
+		if (!$isMasterKeyEnabled) {
71 71
 			$output->writeln('Master key already disabled');
72 72
 		} else {
73 73
 			$question = new ConfirmationQuestion(
Please login to merge, or discard this patch.