Passed
Push — master ( 350d02...42b98d )
by Joas
23:24 queued 09:28
created
themes/example/defaults.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 * @return string short footer
91 91
 	 */
92 92
 	public function getShortFooter() {
93
-		$footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
94
-			'<br/>' . $this->getSlogan();
93
+		$footer = '© '.date('Y').' <a href="'.$this->getBaseUrl().'" target="_blank">'.$this->getEntity().'</a>'.
94
+			'<br/>'.$this->getSlogan();
95 95
 
96 96
 		return $footer;
97 97
 	}
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @return string long footer
102 102
 	 */
103 103
 	public function getLongFooter() {
104
-		$footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
105
-			'<br/>' . $this->getSlogan();
104
+		$footer = '© '.date('Y').' <a href="'.$this->getBaseUrl().'" target="_blank">'.$this->getEntity().'</a>'.
105
+			'<br/>'.$this->getSlogan();
106 106
 
107 107
 		return $footer;
108 108
 	}
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @return string documentation link
113 113
 	 */
114 114
 	public function buildDocLinkToKey($key) {
115
-		return $this->getDocBaseUrl() . '/server/15/go.php?to=' . $key;
115
+		return $this->getDocBaseUrl().'/server/15/go.php?to='.$key;
116 116
 	}
117 117
 
118 118
 
Please login to merge, or discard this patch.
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -20,108 +20,108 @@
 block discarded – undo
20 20
 
21 21
 class OC_Theme {
22 22
 
23
-	/**
24
-	 * Returns the base URL
25
-	 * @return string URL
26
-	 */
27
-	public function getBaseUrl() {
28
-		return 'https://nextcloud.com';
29
-	}
30
-
31
-	/**
32
-	 * Returns the documentation URL
33
-	 * @return string URL
34
-	 */
35
-	public function getDocBaseUrl() {
36
-		return 'https://docs.nextcloud.com';
37
-	}
38
-
39
-	/**
40
-	 * Returns the title
41
-	 * @return string title
42
-	 */
43
-	public function getTitle() {
44
-		return 'Custom Cloud';
45
-	}
46
-
47
-	/**
48
-	 * Returns the short name of the software
49
-	 * @return string title
50
-	 */
51
-	public function getName() {
52
-		return 'Custom Cloud';
53
-	}
54
-
55
-	/**
56
-	 * Returns the short name of the software containing HTML strings
57
-	 * @return string title
58
-	 */
59
-	public function getHTMLName() {
60
-		return 'Custom Cloud';
61
-	}
62
-
63
-	/**
64
-	 * Returns entity (e.g. company name) - used for footer, copyright
65
-	 * @return string entity name
66
-	 */
67
-	public function getEntity() {
68
-		return 'Custom Cloud Co.';
69
-	}
70
-
71
-	/**
72
-	 * Returns slogan
73
-	 * @return string slogan
74
-	 */
75
-	public function getSlogan() {
76
-		return 'Your custom cloud, personalized for you!';
77
-	}
78
-
79
-	/**
80
-	 * Returns short version of the footer
81
-	 * @return string short footer
82
-	 */
83
-	public function getShortFooter() {
84
-		$footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
85
-			'<br/>' . $this->getSlogan();
86
-
87
-		return $footer;
88
-	}
89
-
90
-	/**
91
-	 * Returns long version of the footer
92
-	 * @return string long footer
93
-	 */
94
-	public function getLongFooter() {
95
-		$footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
96
-			'<br/>' . $this->getSlogan();
97
-
98
-		return $footer;
99
-	}
100
-
101
-	/**
102
-	 * Generate a documentation link for a given key
103
-	 * @return string documentation link
104
-	 */
105
-	public function buildDocLinkToKey($key) {
106
-		return $this->getDocBaseUrl() . '/server/15/go.php?to=' . $key;
107
-	}
108
-
109
-
110
-	/**
111
-	 * Returns mail header color
112
-	 * @return string
113
-	 */
114
-	public function getColorPrimary() {
115
-		return '#745bca';
116
-	}
117
-
118
-	/**
119
-	 * Returns variables to overload defaults from core/css/variables.scss
120
-	 * @return array
121
-	 */
122
-	public function getScssVariables() {
123
-		return [
124
-			'color-primary' => '#745bca'
125
-		];
126
-	}
23
+    /**
24
+     * Returns the base URL
25
+     * @return string URL
26
+     */
27
+    public function getBaseUrl() {
28
+        return 'https://nextcloud.com';
29
+    }
30
+
31
+    /**
32
+     * Returns the documentation URL
33
+     * @return string URL
34
+     */
35
+    public function getDocBaseUrl() {
36
+        return 'https://docs.nextcloud.com';
37
+    }
38
+
39
+    /**
40
+     * Returns the title
41
+     * @return string title
42
+     */
43
+    public function getTitle() {
44
+        return 'Custom Cloud';
45
+    }
46
+
47
+    /**
48
+     * Returns the short name of the software
49
+     * @return string title
50
+     */
51
+    public function getName() {
52
+        return 'Custom Cloud';
53
+    }
54
+
55
+    /**
56
+     * Returns the short name of the software containing HTML strings
57
+     * @return string title
58
+     */
59
+    public function getHTMLName() {
60
+        return 'Custom Cloud';
61
+    }
62
+
63
+    /**
64
+     * Returns entity (e.g. company name) - used for footer, copyright
65
+     * @return string entity name
66
+     */
67
+    public function getEntity() {
68
+        return 'Custom Cloud Co.';
69
+    }
70
+
71
+    /**
72
+     * Returns slogan
73
+     * @return string slogan
74
+     */
75
+    public function getSlogan() {
76
+        return 'Your custom cloud, personalized for you!';
77
+    }
78
+
79
+    /**
80
+     * Returns short version of the footer
81
+     * @return string short footer
82
+     */
83
+    public function getShortFooter() {
84
+        $footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
85
+            '<br/>' . $this->getSlogan();
86
+
87
+        return $footer;
88
+    }
89
+
90
+    /**
91
+     * Returns long version of the footer
92
+     * @return string long footer
93
+     */
94
+    public function getLongFooter() {
95
+        $footer = '© ' . date('Y') . ' <a href="' . $this->getBaseUrl() . '" target="_blank">' . $this->getEntity() . '</a>' .
96
+            '<br/>' . $this->getSlogan();
97
+
98
+        return $footer;
99
+    }
100
+
101
+    /**
102
+     * Generate a documentation link for a given key
103
+     * @return string documentation link
104
+     */
105
+    public function buildDocLinkToKey($key) {
106
+        return $this->getDocBaseUrl() . '/server/15/go.php?to=' . $key;
107
+    }
108
+
109
+
110
+    /**
111
+     * Returns mail header color
112
+     * @return string
113
+     */
114
+    public function getColorPrimary() {
115
+        return '#745bca';
116
+    }
117
+
118
+    /**
119
+     * Returns variables to overload defaults from core/css/variables.scss
120
+     * @return array
121
+     */
122
+    public function getScssVariables() {
123
+        return [
124
+            'color-primary' => '#745bca'
125
+        ];
126
+    }
127 127
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/ReloadExecutionMiddleware.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -35,34 +35,34 @@
 block discarded – undo
35 35
  * a reload but if the session variable is set we properly redirect to the login page.
36 36
  */
37 37
 class ReloadExecutionMiddleware extends Middleware {
38
-	/** @var ISession */
39
-	private $session;
40
-	/** @var IURLGenerator */
41
-	private $urlGenerator;
38
+    /** @var ISession */
39
+    private $session;
40
+    /** @var IURLGenerator */
41
+    private $urlGenerator;
42 42
 
43
-	public function __construct(ISession $session, IURLGenerator $urlGenerator) {
44
-		$this->session = $session;
45
-		$this->urlGenerator = $urlGenerator;
46
-	}
43
+    public function __construct(ISession $session, IURLGenerator $urlGenerator) {
44
+        $this->session = $session;
45
+        $this->urlGenerator = $urlGenerator;
46
+    }
47 47
 
48
-	public function beforeController($controller, $methodName) {
49
-		if ($this->session->exists('clearingExecutionContexts')) {
50
-			throw new ReloadExecutionException();
51
-		}
52
-	}
48
+    public function beforeController($controller, $methodName) {
49
+        if ($this->session->exists('clearingExecutionContexts')) {
50
+            throw new ReloadExecutionException();
51
+        }
52
+    }
53 53
 
54
-	public function afterException($controller, $methodName, \Exception $exception) {
55
-		if ($exception instanceof ReloadExecutionException) {
56
-			$this->session->remove('clearingExecutionContexts');
54
+    public function afterException($controller, $methodName, \Exception $exception) {
55
+        if ($exception instanceof ReloadExecutionException) {
56
+            $this->session->remove('clearingExecutionContexts');
57 57
 
58
-			return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute(
59
-				'core.login.showLoginForm',
60
-				['clear' => true] // this param the the code in login.js may be removed when the "Clear-Site-Data" is working in the browsers
61
-			));
62
-		}
58
+            return new RedirectResponse($this->urlGenerator->linkToRouteAbsolute(
59
+                'core.login.showLoginForm',
60
+                ['clear' => true] // this param the the code in login.js may be removed when the "Clear-Site-Data" is working in the browsers
61
+            ));
62
+        }
63 63
 
64
-		return parent::afterException($controller, $methodName, $exception);
65
-	}
64
+        return parent::afterException($controller, $methodName, $exception);
65
+    }
66 66
 
67 67
 
68 68
 }
Please login to merge, or discard this patch.
lib/public/IAvatarManager.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -34,24 +34,24 @@
 block discarded – undo
34 34
 
35 35
 interface IAvatarManager {
36 36
 
37
-	/**
38
-	 * return a user specific instance of \OCP\IAvatar
39
-	 * @see IAvatar
40
-	 * @param string $user the ownCloud user id
41
-	 * @return IAvatar
42
-	 * @throws \Exception In case the username is potentially dangerous
43
-	 * @throws \OCP\Files\NotFoundException In case there is no user folder yet
44
-	 * @since 6.0.0
45
-	 */
46
-	public function getAvatar(string $user) : IAvatar;
37
+    /**
38
+     * return a user specific instance of \OCP\IAvatar
39
+     * @see IAvatar
40
+     * @param string $user the ownCloud user id
41
+     * @return IAvatar
42
+     * @throws \Exception In case the username is potentially dangerous
43
+     * @throws \OCP\Files\NotFoundException In case there is no user folder yet
44
+     * @since 6.0.0
45
+     */
46
+    public function getAvatar(string $user) : IAvatar;
47 47
 
48
-	/**
49
-	 * Returns a guest user avatar instance.
50
-	 *
51
-	 * @param string $name The guest name, e.g. "Albert".
52
-	 * @return IAvatar
53
-	 * @since 16.0.0
54
-	 */
55
-	public function getGuestAvatar(string $name): IAvatar;
48
+    /**
49
+     * Returns a guest user avatar instance.
50
+     *
51
+     * @param string $name The guest name, e.g. "Albert".
52
+     * @return IAvatar
53
+     * @since 16.0.0
54
+     */
55
+    public function getGuestAvatar(string $name): IAvatar;
56 56
 
57 57
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Config/IConfigHandler.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -30,10 +30,10 @@
 block discarded – undo
30 30
  * @since 16.0.0
31 31
  */
32 32
 interface IConfigHandler {
33
-	/**
34
-	 * @param mixed $optionValue
35
-	 * @return mixed the same type as $optionValue
36
-	 * @since 16.0.0
37
-	 */
38
-	public function handle($optionValue);
33
+    /**
34
+     * @param mixed $optionValue
35
+     * @return mixed the same type as $optionValue
36
+     * @since 16.0.0
37
+     */
38
+    public function handle($optionValue);
39 39
 }
Please login to merge, or discard this patch.
apps/cloud_federation_api/lib/Capabilities.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,38 +28,38 @@
 block discarded – undo
28 28
 
29 29
 class Capabilities implements ICapability {
30 30
 
31
-	/** @var IURLGenerator */
32
-	private $urlGenerator;
31
+    /** @var IURLGenerator */
32
+    private $urlGenerator;
33 33
 
34
-	public function __construct(IURLGenerator $urlGenerator) {
35
-		$this->urlGenerator = $urlGenerator;
36
-	}
34
+    public function __construct(IURLGenerator $urlGenerator) {
35
+        $this->urlGenerator = $urlGenerator;
36
+    }
37 37
 
38
-	/**
39
-	 * Function an app uses to return the capabilities
40
-	 *
41
-	 * @return array Array containing the apps capabilities
42
-	 * @since 8.2.0
43
-	 */
44
-	public function getCapabilities() {
45
-		$url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
46
-		$capabilities = ['ocm' =>
47
-			[
48
-				'enabled' => true,
49
-				'apiVersion' => '1.0-proposal1',
50
-				'endPoint' => substr($url, 0, strrpos($url, '/')),
51
-				'resourceTypes' => [
52
-					[
53
-						'name' => 'file',
54
-						'shareTypes' => ['user', 'group'],
55
-						'protocols' => [
56
-							'webdav' => '/public.php/webdav/',
57
-						]
58
-					],
59
-				]
60
-			]
61
-		];
38
+    /**
39
+     * Function an app uses to return the capabilities
40
+     *
41
+     * @return array Array containing the apps capabilities
42
+     * @since 8.2.0
43
+     */
44
+    public function getCapabilities() {
45
+        $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare');
46
+        $capabilities = ['ocm' =>
47
+            [
48
+                'enabled' => true,
49
+                'apiVersion' => '1.0-proposal1',
50
+                'endPoint' => substr($url, 0, strrpos($url, '/')),
51
+                'resourceTypes' => [
52
+                    [
53
+                        'name' => 'file',
54
+                        'shareTypes' => ['user', 'group'],
55
+                        'protocols' => [
56
+                            'webdav' => '/public.php/webdav/',
57
+                        ]
58
+                    ],
59
+                ]
60
+            ]
61
+        ];
62 62
 
63
-		return $capabilities;
64
-	}
63
+        return $capabilities;
64
+    }
65 65
 }
Please login to merge, or discard this patch.
lib/private/Repair/NC16/AddClenupLoginFlowV2BackgroundJob.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -31,19 +31,19 @@
 block discarded – undo
31 31
 
32 32
 class AddClenupLoginFlowV2BackgroundJob implements IRepairStep {
33 33
 
34
-	/** @var IJobList */
35
-	private $jobList;
34
+    /** @var IJobList */
35
+    private $jobList;
36 36
 
37
-	public function __construct(IJobList $jobList) {
38
-		$this->jobList = $jobList;
39
-	}
37
+    public function __construct(IJobList $jobList) {
38
+        $this->jobList = $jobList;
39
+    }
40 40
 
41
-	public function getName(): string {
42
-		return 'Add background job to cleanup login flow v2 tokens';
43
-	}
41
+    public function getName(): string {
42
+        return 'Add background job to cleanup login flow v2 tokens';
43
+    }
44 44
 
45
-	public function run(IOutput $output) {
46
-		$this->jobList->add(CleanupLoginFlowV2::class);
47
-	}
45
+    public function run(IOutput $output) {
46
+        $this->jobList->add(CleanupLoginFlowV2::class);
47
+    }
48 48
 
49 49
 }
Please login to merge, or discard this patch.
core/Data/LoginFlowV2Credentials.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -25,47 +25,47 @@
 block discarded – undo
25 25
 namespace OC\Core\Data;
26 26
 
27 27
 class LoginFlowV2Credentials implements \JsonSerializable {
28
-	/** @var string */
29
-	private $server;
30
-	/** @var string */
31
-	private $loginName;
32
-	/** @var string */
33
-	private $appPassword;
28
+    /** @var string */
29
+    private $server;
30
+    /** @var string */
31
+    private $loginName;
32
+    /** @var string */
33
+    private $appPassword;
34 34
 
35
-	public function __construct(string $server, string $loginName, string $appPassword) {
36
-		$this->server = $server;
37
-		$this->loginName = $loginName;
38
-		$this->appPassword = $appPassword;
39
-	}
35
+    public function __construct(string $server, string $loginName, string $appPassword) {
36
+        $this->server = $server;
37
+        $this->loginName = $loginName;
38
+        $this->appPassword = $appPassword;
39
+    }
40 40
 
41
-	/**
42
-	 * @return string
43
-	 */
44
-	public function getServer(): string {
45
-		return $this->server;
46
-	}
41
+    /**
42
+     * @return string
43
+     */
44
+    public function getServer(): string {
45
+        return $this->server;
46
+    }
47 47
 
48
-	/**
49
-	 * @return string
50
-	 */
51
-	public function getLoginName(): string {
52
-		return $this->loginName;
53
-	}
48
+    /**
49
+     * @return string
50
+     */
51
+    public function getLoginName(): string {
52
+        return $this->loginName;
53
+    }
54 54
 
55
-	/**
56
-	 * @return string
57
-	 */
58
-	public function getAppPassword(): string {
59
-		return $this->appPassword;
60
-	}
55
+    /**
56
+     * @return string
57
+     */
58
+    public function getAppPassword(): string {
59
+        return $this->appPassword;
60
+    }
61 61
 
62
-	public function jsonSerialize(): array {
63
-		return [
64
-			'server' => $this->server,
65
-			'loginName' => $this->loginName,
66
-			'appPassword' => $this->appPassword,
67
-		];
68
-	}
62
+    public function jsonSerialize(): array {
63
+        return [
64
+            'server' => $this->server,
65
+            'loginName' => $this->loginName,
66
+            'appPassword' => $this->appPassword,
67
+        ];
68
+    }
69 69
 
70 70
 
71 71
 }
Please login to merge, or discard this patch.
core/Service/LoginFlowV2Service.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 
212 212
 	private function hashToken(string $token): string {
213 213
 		$secret = $this->config->getSystemValue('secret');
214
-		return hash('sha512', $token . $secret);
214
+		return hash('sha512', $token.$secret);
215 215
 	}
216 216
 
217 217
 	private function getKeyPair(): array {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		while ($error = openssl_error_string()) {
242 242
 			$errors[] = $error;
243 243
 		}
244
-		$this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
244
+		$this->logger->critical('Something is wrong with your openssl setup: '.implode(', ', $errors));
245 245
 	}
246 246
 
247 247
 	private function encryptPassword(string $password, string $publicKey): string {
Please login to merge, or discard this patch.
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -44,235 +44,235 @@
 block discarded – undo
44 44
 
45 45
 class LoginFlowV2Service {
46 46
 
47
-	/** @var LoginFlowV2Mapper */
48
-	private $mapper;
49
-	/** @var ISecureRandom */
50
-	private $random;
51
-	/** @var ITimeFactory */
52
-	private $time;
53
-	/** @var IConfig */
54
-	private $config;
55
-	/** @var ICrypto */
56
-	private $crypto;
57
-	/** @var ILogger */
58
-	private $logger;
59
-	/** @var IProvider */
60
-	private $tokenProvider;
61
-
62
-	public function __construct(LoginFlowV2Mapper $mapper,
63
-								ISecureRandom $random,
64
-								ITimeFactory $time,
65
-								IConfig $config,
66
-								ICrypto $crypto,
67
-								ILogger $logger,
68
-								IProvider $tokenProvider) {
69
-		$this->mapper = $mapper;
70
-		$this->random = $random;
71
-		$this->time = $time;
72
-		$this->config = $config;
73
-		$this->crypto = $crypto;
74
-		$this->logger = $logger;
75
-		$this->tokenProvider = $tokenProvider;
76
-	}
77
-
78
-	/**
79
-	 * @param string $pollToken
80
-	 * @return LoginFlowV2Credentials
81
-	 * @throws LoginFlowV2NotFoundException
82
-	 */
83
-	public function poll(string $pollToken): LoginFlowV2Credentials {
84
-		try {
85
-			$data = $this->mapper->getByPollToken($this->hashToken($pollToken));
86
-		} catch (DoesNotExistException $e) {
87
-			throw new LoginFlowV2NotFoundException('Invalid token');
88
-		}
89
-
90
-		$loginName = $data->getLoginName();
91
-		$server = $data->getServer();
92
-		$appPassword = $data->getAppPassword();
93
-
94
-		if ($loginName === null || $server === null || $appPassword === null) {
95
-			throw new LoginFlowV2NotFoundException('Token not yet ready');
96
-		}
97
-
98
-		// Remove the data from the DB
99
-		$this->mapper->delete($data);
100
-
101
-		try {
102
-			// Decrypt the apptoken
103
-			$privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken);
104
-			$appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey);
105
-		} catch (\Exception $e) {
106
-			throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted');
107
-		}
108
-
109
-		return new LoginFlowV2Credentials($server, $loginName, $appPassword);
110
-	}
111
-
112
-	/**
113
-	 * @param string $loginToken
114
-	 * @return LoginFlowV2
115
-	 * @throws LoginFlowV2NotFoundException
116
-	 */
117
-	public function getByLoginToken(string $loginToken): LoginFlowV2 {
118
-		try {
119
-			return $this->mapper->getByLoginToken($loginToken);
120
-		} catch (DoesNotExistException $e) {
121
-			throw new LoginFlowV2NotFoundException('Login token invalid');
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * @param string $loginToken
127
-	 * @return bool returns true if the start was successfull. False if not.
128
-	 */
129
-	public function startLoginFlow(string $loginToken): bool {
130
-		try {
131
-			$data = $this->mapper->getByLoginToken($loginToken);
132
-		} catch (DoesNotExistException $e) {
133
-			return false;
134
-		}
135
-
136
-		$data->setStarted(1);
137
-		$this->mapper->update($data);
138
-
139
-		return true;
140
-	}
141
-
142
-	/**
143
-	 * @param string $loginToken
144
-	 * @param string $sessionId
145
-	 * @param string $server
146
-	 * @param string $userId
147
-	 * @return bool true if the flow was successfully completed false otherwise
148
-	 */
149
-	public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool {
150
-		try {
151
-			$data = $this->mapper->getByLoginToken($loginToken);
152
-		} catch (DoesNotExistException $e) {
153
-			return false;
154
-		}
155
-
156
-		try {
157
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
158
-			$loginName = $sessionToken->getLoginName();
159
-			try {
160
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
161
-			} catch (PasswordlessTokenException $ex) {
162
-				$password = null;
163
-			}
164
-		} catch (InvalidTokenException $ex) {
165
-			return false;
166
-		}
167
-
168
-		$appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
169
-		$this->tokenProvider->generateToken(
170
-			$appPassword,
171
-			$userId,
172
-			$loginName,
173
-			$password,
174
-			$data->getClientName(),
175
-			IToken::PERMANENT_TOKEN,
176
-			IToken::DO_NOT_REMEMBER
177
-		);
178
-
179
-		$data->setLoginName($loginName);
180
-		$data->setServer($server);
181
-
182
-		// Properly encrypt
183
-		$data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
184
-
185
-		$this->mapper->update($data);
186
-		return true;
187
-	}
188
-
189
-	public function flowDoneWithAppPassword(string $loginToken, string $server, string $loginName, string $appPassword): bool {
190
-		try {
191
-			$data = $this->mapper->getByLoginToken($loginToken);
192
-		} catch (DoesNotExistException $e) {
193
-			return false;
194
-		}
195
-
196
-		$data->setLoginName($loginName);
197
-		$data->setServer($server);
198
-
199
-		// Properly encrypt
200
-		$data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
201
-
202
-		$this->mapper->update($data);
203
-		return true;
204
-	}
205
-
206
-	public function createTokens(string $userAgent): LoginFlowV2Tokens {
207
-		$flow = new LoginFlowV2();
208
-		$pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
209
-		$loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
210
-		$flow->setPollToken($this->hashToken($pollToken));
211
-		$flow->setLoginToken($loginToken);
212
-		$flow->setStarted(0);
213
-		$flow->setTimestamp($this->time->getTime());
214
-		$flow->setClientName($userAgent);
215
-
216
-		[$publicKey, $privateKey] = $this->getKeyPair();
217
-		$privateKey = $this->crypto->encrypt($privateKey, $pollToken);
218
-
219
-		$flow->setPublicKey($publicKey);
220
-		$flow->setPrivateKey($privateKey);
221
-
222
-		$this->mapper->insert($flow);
223
-
224
-		return new LoginFlowV2Tokens($loginToken, $pollToken);
225
-	}
226
-
227
-	private function hashToken(string $token): string {
228
-		$secret = $this->config->getSystemValue('secret');
229
-		return hash('sha512', $token . $secret);
230
-	}
231
-
232
-	private function getKeyPair(): array {
233
-		$config = array_merge([
234
-			'digest_alg' => 'sha512',
235
-			'private_key_bits' => 2048,
236
-		], $this->config->getSystemValue('openssl', []));
237
-
238
-		// Generate new key
239
-		$res = openssl_pkey_new($config);
240
-		if ($res === false) {
241
-			$this->logOpensslError();
242
-			throw new \RuntimeException('Could not initialize keys');
243
-		}
244
-
245
-		if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
246
-			$this->logOpensslError();
247
-			throw new \RuntimeException('OpenSSL reported a problem');
248
-		}
249
-
250
-		// Extract the public key from $res to $pubKey
251
-		$publicKey = openssl_pkey_get_details($res);
252
-		$publicKey = $publicKey['key'];
253
-
254
-		return [$publicKey, $privateKey];
255
-	}
256
-
257
-	private function logOpensslError(): void {
258
-		$errors = [];
259
-		while ($error = openssl_error_string()) {
260
-			$errors[] = $error;
261
-		}
262
-		$this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
263
-	}
264
-
265
-	private function encryptPassword(string $password, string $publicKey): string {
266
-		openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
267
-		$encryptedPassword = base64_encode($encryptedPassword);
268
-
269
-		return $encryptedPassword;
270
-	}
271
-
272
-	private function decryptPassword(string $encryptedPassword, string $privateKey): string {
273
-		$encryptedPassword = base64_decode($encryptedPassword);
274
-		openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
275
-
276
-		return $password;
277
-	}
47
+    /** @var LoginFlowV2Mapper */
48
+    private $mapper;
49
+    /** @var ISecureRandom */
50
+    private $random;
51
+    /** @var ITimeFactory */
52
+    private $time;
53
+    /** @var IConfig */
54
+    private $config;
55
+    /** @var ICrypto */
56
+    private $crypto;
57
+    /** @var ILogger */
58
+    private $logger;
59
+    /** @var IProvider */
60
+    private $tokenProvider;
61
+
62
+    public function __construct(LoginFlowV2Mapper $mapper,
63
+                                ISecureRandom $random,
64
+                                ITimeFactory $time,
65
+                                IConfig $config,
66
+                                ICrypto $crypto,
67
+                                ILogger $logger,
68
+                                IProvider $tokenProvider) {
69
+        $this->mapper = $mapper;
70
+        $this->random = $random;
71
+        $this->time = $time;
72
+        $this->config = $config;
73
+        $this->crypto = $crypto;
74
+        $this->logger = $logger;
75
+        $this->tokenProvider = $tokenProvider;
76
+    }
77
+
78
+    /**
79
+     * @param string $pollToken
80
+     * @return LoginFlowV2Credentials
81
+     * @throws LoginFlowV2NotFoundException
82
+     */
83
+    public function poll(string $pollToken): LoginFlowV2Credentials {
84
+        try {
85
+            $data = $this->mapper->getByPollToken($this->hashToken($pollToken));
86
+        } catch (DoesNotExistException $e) {
87
+            throw new LoginFlowV2NotFoundException('Invalid token');
88
+        }
89
+
90
+        $loginName = $data->getLoginName();
91
+        $server = $data->getServer();
92
+        $appPassword = $data->getAppPassword();
93
+
94
+        if ($loginName === null || $server === null || $appPassword === null) {
95
+            throw new LoginFlowV2NotFoundException('Token not yet ready');
96
+        }
97
+
98
+        // Remove the data from the DB
99
+        $this->mapper->delete($data);
100
+
101
+        try {
102
+            // Decrypt the apptoken
103
+            $privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken);
104
+            $appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey);
105
+        } catch (\Exception $e) {
106
+            throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted');
107
+        }
108
+
109
+        return new LoginFlowV2Credentials($server, $loginName, $appPassword);
110
+    }
111
+
112
+    /**
113
+     * @param string $loginToken
114
+     * @return LoginFlowV2
115
+     * @throws LoginFlowV2NotFoundException
116
+     */
117
+    public function getByLoginToken(string $loginToken): LoginFlowV2 {
118
+        try {
119
+            return $this->mapper->getByLoginToken($loginToken);
120
+        } catch (DoesNotExistException $e) {
121
+            throw new LoginFlowV2NotFoundException('Login token invalid');
122
+        }
123
+    }
124
+
125
+    /**
126
+     * @param string $loginToken
127
+     * @return bool returns true if the start was successfull. False if not.
128
+     */
129
+    public function startLoginFlow(string $loginToken): bool {
130
+        try {
131
+            $data = $this->mapper->getByLoginToken($loginToken);
132
+        } catch (DoesNotExistException $e) {
133
+            return false;
134
+        }
135
+
136
+        $data->setStarted(1);
137
+        $this->mapper->update($data);
138
+
139
+        return true;
140
+    }
141
+
142
+    /**
143
+     * @param string $loginToken
144
+     * @param string $sessionId
145
+     * @param string $server
146
+     * @param string $userId
147
+     * @return bool true if the flow was successfully completed false otherwise
148
+     */
149
+    public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool {
150
+        try {
151
+            $data = $this->mapper->getByLoginToken($loginToken);
152
+        } catch (DoesNotExistException $e) {
153
+            return false;
154
+        }
155
+
156
+        try {
157
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
158
+            $loginName = $sessionToken->getLoginName();
159
+            try {
160
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
161
+            } catch (PasswordlessTokenException $ex) {
162
+                $password = null;
163
+            }
164
+        } catch (InvalidTokenException $ex) {
165
+            return false;
166
+        }
167
+
168
+        $appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
169
+        $this->tokenProvider->generateToken(
170
+            $appPassword,
171
+            $userId,
172
+            $loginName,
173
+            $password,
174
+            $data->getClientName(),
175
+            IToken::PERMANENT_TOKEN,
176
+            IToken::DO_NOT_REMEMBER
177
+        );
178
+
179
+        $data->setLoginName($loginName);
180
+        $data->setServer($server);
181
+
182
+        // Properly encrypt
183
+        $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
184
+
185
+        $this->mapper->update($data);
186
+        return true;
187
+    }
188
+
189
+    public function flowDoneWithAppPassword(string $loginToken, string $server, string $loginName, string $appPassword): bool {
190
+        try {
191
+            $data = $this->mapper->getByLoginToken($loginToken);
192
+        } catch (DoesNotExistException $e) {
193
+            return false;
194
+        }
195
+
196
+        $data->setLoginName($loginName);
197
+        $data->setServer($server);
198
+
199
+        // Properly encrypt
200
+        $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
201
+
202
+        $this->mapper->update($data);
203
+        return true;
204
+    }
205
+
206
+    public function createTokens(string $userAgent): LoginFlowV2Tokens {
207
+        $flow = new LoginFlowV2();
208
+        $pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
209
+        $loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
210
+        $flow->setPollToken($this->hashToken($pollToken));
211
+        $flow->setLoginToken($loginToken);
212
+        $flow->setStarted(0);
213
+        $flow->setTimestamp($this->time->getTime());
214
+        $flow->setClientName($userAgent);
215
+
216
+        [$publicKey, $privateKey] = $this->getKeyPair();
217
+        $privateKey = $this->crypto->encrypt($privateKey, $pollToken);
218
+
219
+        $flow->setPublicKey($publicKey);
220
+        $flow->setPrivateKey($privateKey);
221
+
222
+        $this->mapper->insert($flow);
223
+
224
+        return new LoginFlowV2Tokens($loginToken, $pollToken);
225
+    }
226
+
227
+    private function hashToken(string $token): string {
228
+        $secret = $this->config->getSystemValue('secret');
229
+        return hash('sha512', $token . $secret);
230
+    }
231
+
232
+    private function getKeyPair(): array {
233
+        $config = array_merge([
234
+            'digest_alg' => 'sha512',
235
+            'private_key_bits' => 2048,
236
+        ], $this->config->getSystemValue('openssl', []));
237
+
238
+        // Generate new key
239
+        $res = openssl_pkey_new($config);
240
+        if ($res === false) {
241
+            $this->logOpensslError();
242
+            throw new \RuntimeException('Could not initialize keys');
243
+        }
244
+
245
+        if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
246
+            $this->logOpensslError();
247
+            throw new \RuntimeException('OpenSSL reported a problem');
248
+        }
249
+
250
+        // Extract the public key from $res to $pubKey
251
+        $publicKey = openssl_pkey_get_details($res);
252
+        $publicKey = $publicKey['key'];
253
+
254
+        return [$publicKey, $privateKey];
255
+    }
256
+
257
+    private function logOpensslError(): void {
258
+        $errors = [];
259
+        while ($error = openssl_error_string()) {
260
+            $errors[] = $error;
261
+        }
262
+        $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
263
+    }
264
+
265
+    private function encryptPassword(string $password, string $publicKey): string {
266
+        openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
267
+        $encryptedPassword = base64_encode($encryptedPassword);
268
+
269
+        return $encryptedPassword;
270
+    }
271
+
272
+    private function decryptPassword(string $encryptedPassword, string $privateKey): string {
273
+        $encryptedPassword = base64_decode($encryptedPassword);
274
+        openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
275
+
276
+        return $password;
277
+    }
278 278
 }
Please login to merge, or discard this patch.
core/Db/LoginFlowV2.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -49,37 +49,37 @@
 block discarded – undo
49 49
  * @method void setAppPassword(string $appPassword)
50 50
  */
51 51
 class LoginFlowV2 extends Entity {
52
-	/** @var int */
53
-	protected $timestamp;
54
-	/** @var int */
55
-	protected $started;
56
-	/** @var string */
57
-	protected $pollToken;
58
-	/** @var string */
59
-	protected $loginToken;
60
-	/** @var string */
61
-	protected $publicKey;
62
-	/** @var string */
63
-	protected $privateKey;
64
-	/** @var string */
65
-	protected $clientName;
66
-	/** @var string */
67
-	protected $loginName;
68
-	/** @var string */
69
-	protected $server;
70
-	/** @var string */
71
-	protected $appPassword;
52
+    /** @var int */
53
+    protected $timestamp;
54
+    /** @var int */
55
+    protected $started;
56
+    /** @var string */
57
+    protected $pollToken;
58
+    /** @var string */
59
+    protected $loginToken;
60
+    /** @var string */
61
+    protected $publicKey;
62
+    /** @var string */
63
+    protected $privateKey;
64
+    /** @var string */
65
+    protected $clientName;
66
+    /** @var string */
67
+    protected $loginName;
68
+    /** @var string */
69
+    protected $server;
70
+    /** @var string */
71
+    protected $appPassword;
72 72
 
73
-	public function __construct() {
74
-		$this->addType('timestamp', 'int');
75
-		$this->addType('started', 'int');
76
-		$this->addType('pollToken', 'string');
77
-		$this->addType('loginToken', 'string');
78
-		$this->addType('publicKey', 'string');
79
-		$this->addType('privateKey', 'string');
80
-		$this->addType('clientName', 'string');
81
-		$this->addType('loginName', 'string');
82
-		$this->addType('server', 'string');
83
-		$this->addType('appPassword', 'string');
84
-	}
73
+    public function __construct() {
74
+        $this->addType('timestamp', 'int');
75
+        $this->addType('started', 'int');
76
+        $this->addType('pollToken', 'string');
77
+        $this->addType('loginToken', 'string');
78
+        $this->addType('publicKey', 'string');
79
+        $this->addType('privateKey', 'string');
80
+        $this->addType('clientName', 'string');
81
+        $this->addType('loginName', 'string');
82
+        $this->addType('server', 'string');
83
+        $this->addType('appPassword', 'string');
84
+    }
85 85
 }
Please login to merge, or discard this patch.