Passed
Push — master ( 7d851f...e6959b )
by Robin
15:52 queued 12s
created
lib/private/Files/ObjectStore/SwiftV2CachingAuthService.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,11 +25,11 @@
 block discarded – undo
25 25
 use OpenStack\Identity\v2\Service;
26 26
 
27 27
 class SwiftV2CachingAuthService extends Service {
28
-	public function authenticate(array $options = []): array {
29
-		if (!empty($options['v2cachedToken'])) {
30
-			return [$options['v2cachedToken'], $options['v2serviceUrl']];
31
-		} else {
32
-			return parent::authenticate($options);
33
-		}
34
-	}
28
+    public function authenticate(array $options = []): array {
29
+        if (!empty($options['v2cachedToken'])) {
30
+            return [$options['v2cachedToken'], $options['v2serviceUrl']];
31
+        } else {
32
+            return parent::authenticate($options);
33
+        }
34
+    }
35 35
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Settings/Personal.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@
 block discarded – undo
28 28
 use OCP\Template;
29 29
 
30 30
 class Personal implements IPersonalProviderSettings {
31
-	public function getBody(): Template {
32
-		return new Template('twofactor_backupcodes', 'personal');
33
-	}
31
+    public function getBody(): Template {
32
+        return new Template('twofactor_backupcodes', 'personal');
33
+    }
34 34
 
35 35
 }
Please login to merge, or discard this patch.
apps/dav/lib/Provisioning/Apple/AppleProvisioningNode.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
 
53 53
 	public function setName($name) {
54
-		throw new Forbidden('Renaming ' . self::FILENAME . ' is forbidden');
54
+		throw new Forbidden('Renaming '.self::FILENAME.' is forbidden');
55 55
 	}
56 56
 
57 57
 	/**
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	 * @throws Forbidden
66 66
 	 */
67 67
 	public function delete() {
68
-		throw new Forbidden(self::FILENAME . ' may not be deleted.');
68
+		throw new Forbidden(self::FILENAME.' may not be deleted.');
69 69
 	}
70 70
 
71 71
 	/**
@@ -86,6 +86,6 @@  discard block
 block discarded – undo
86 86
 	 * @throws Forbidden
87 87
 	 */
88 88
 	public function propPatch(PropPatch $propPatch) {
89
-		throw new Forbidden(self::FILENAME . '\'s properties may not be altered.');
89
+		throw new Forbidden(self::FILENAME.'\'s properties may not be altered.');
90 90
 	}
91 91
 }
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -30,61 +30,61 @@
 block discarded – undo
30 30
 use Sabre\DAV\PropPatch;
31 31
 
32 32
 class AppleProvisioningNode implements INode, IProperties {
33
-	public const FILENAME = 'apple-provisioning.mobileconfig';
33
+    public const FILENAME = 'apple-provisioning.mobileconfig';
34 34
 
35
-	protected $timeFactory;
35
+    protected $timeFactory;
36 36
 
37
-	/**
38
-	 * @param ITimeFactory $timeFactory
39
-	 */
40
-	public function __construct(ITimeFactory $timeFactory) {
41
-		$this->timeFactory = $timeFactory;
42
-	}
37
+    /**
38
+     * @param ITimeFactory $timeFactory
39
+     */
40
+    public function __construct(ITimeFactory $timeFactory) {
41
+        $this->timeFactory = $timeFactory;
42
+    }
43 43
 
44
-	/**
45
-	 * @return string
46
-	 */
47
-	public function getName() {
48
-		return self::FILENAME;
49
-	}
44
+    /**
45
+     * @return string
46
+     */
47
+    public function getName() {
48
+        return self::FILENAME;
49
+    }
50 50
 
51 51
 
52
-	public function setName($name) {
53
-		throw new Forbidden('Renaming ' . self::FILENAME . ' is forbidden');
54
-	}
52
+    public function setName($name) {
53
+        throw new Forbidden('Renaming ' . self::FILENAME . ' is forbidden');
54
+    }
55 55
 
56
-	/**
57
-	 * @return null
58
-	 */
59
-	public function getLastModified() {
60
-		return null;
61
-	}
56
+    /**
57
+     * @return null
58
+     */
59
+    public function getLastModified() {
60
+        return null;
61
+    }
62 62
 
63
-	/**
64
-	 * @throws Forbidden
65
-	 */
66
-	public function delete() {
67
-		throw new Forbidden(self::FILENAME . ' may not be deleted.');
68
-	}
63
+    /**
64
+     * @throws Forbidden
65
+     */
66
+    public function delete() {
67
+        throw new Forbidden(self::FILENAME . ' may not be deleted.');
68
+    }
69 69
 
70
-	/**
71
-	 * @param array $properties
72
-	 * @return array
73
-	 */
74
-	public function getProperties($properties) {
75
-		$datetime = $this->timeFactory->getDateTime();
70
+    /**
71
+     * @param array $properties
72
+     * @return array
73
+     */
74
+    public function getProperties($properties) {
75
+        $datetime = $this->timeFactory->getDateTime();
76 76
 
77
-		return [
78
-			'{DAV:}getcontentlength' => 42,
79
-			'{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC2822),
80
-		];
81
-	}
77
+        return [
78
+            '{DAV:}getcontentlength' => 42,
79
+            '{DAV:}getlastmodified' => $datetime->format(\DateTimeInterface::RFC2822),
80
+        ];
81
+    }
82 82
 
83
-	/**
84
-	 * @param PropPatch $propPatch
85
-	 * @throws Forbidden
86
-	 */
87
-	public function propPatch(PropPatch $propPatch) {
88
-		throw new Forbidden(self::FILENAME . '\'s properties may not be altered.');
89
-	}
83
+    /**
84
+     * @param PropPatch $propPatch
85
+     * @throws Forbidden
86
+     */
87
+    public function propPatch(PropPatch $propPatch) {
88
+        throw new Forbidden(self::FILENAME . '\'s properties may not be altered.');
89
+    }
90 90
 }
Please login to merge, or discard this patch.
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.
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.
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   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -43,228 +43,228 @@
 block discarded – undo
43 43
 use Psr\Log\LoggerInterface;
44 44
 
45 45
 class LoginFlowV2Service {
46
-	private LoginFlowV2Mapper $mapper;
47
-	private ISecureRandom $random;
48
-	private ITimeFactory $time;
49
-	private IConfig $config;
50
-	private ICrypto $crypto;
51
-	private LoggerInterface $logger;
52
-	private IProvider $tokenProvider;
53
-
54
-	public function __construct(LoginFlowV2Mapper $mapper,
55
-								ISecureRandom $random,
56
-								ITimeFactory $time,
57
-								IConfig $config,
58
-								ICrypto $crypto,
59
-								LoggerInterface $logger,
60
-								IProvider $tokenProvider) {
61
-		$this->mapper = $mapper;
62
-		$this->random = $random;
63
-		$this->time = $time;
64
-		$this->config = $config;
65
-		$this->crypto = $crypto;
66
-		$this->logger = $logger;
67
-		$this->tokenProvider = $tokenProvider;
68
-	}
69
-
70
-	/**
71
-	 * @param string $pollToken
72
-	 * @return LoginFlowV2Credentials
73
-	 * @throws LoginFlowV2NotFoundException
74
-	 */
75
-	public function poll(string $pollToken): LoginFlowV2Credentials {
76
-		try {
77
-			$data = $this->mapper->getByPollToken($this->hashToken($pollToken));
78
-		} catch (DoesNotExistException $e) {
79
-			throw new LoginFlowV2NotFoundException('Invalid token');
80
-		}
81
-
82
-		$loginName = $data->getLoginName();
83
-		$server = $data->getServer();
84
-		$appPassword = $data->getAppPassword();
85
-
86
-		if ($loginName === null || $server === null || $appPassword === null) {
87
-			throw new LoginFlowV2NotFoundException('Token not yet ready');
88
-		}
89
-
90
-		// Remove the data from the DB
91
-		$this->mapper->delete($data);
92
-
93
-		try {
94
-			// Decrypt the apptoken
95
-			$privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken);
96
-			$appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey);
97
-		} catch (\Exception $e) {
98
-			throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted');
99
-		}
100
-
101
-		return new LoginFlowV2Credentials($server, $loginName, $appPassword);
102
-	}
103
-
104
-	/**
105
-	 * @param string $loginToken
106
-	 * @return LoginFlowV2
107
-	 * @throws LoginFlowV2NotFoundException
108
-	 */
109
-	public function getByLoginToken(string $loginToken): LoginFlowV2 {
110
-		try {
111
-			return $this->mapper->getByLoginToken($loginToken);
112
-		} catch (DoesNotExistException $e) {
113
-			throw new LoginFlowV2NotFoundException('Login token invalid');
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * @param string $loginToken
119
-	 * @return bool returns true if the start was successfull. False if not.
120
-	 */
121
-	public function startLoginFlow(string $loginToken): bool {
122
-		try {
123
-			$data = $this->mapper->getByLoginToken($loginToken);
124
-		} catch (DoesNotExistException $e) {
125
-			return false;
126
-		}
127
-
128
-		$data->setStarted(1);
129
-		$this->mapper->update($data);
130
-
131
-		return true;
132
-	}
133
-
134
-	/**
135
-	 * @param string $loginToken
136
-	 * @param string $sessionId
137
-	 * @param string $server
138
-	 * @param string $userId
139
-	 * @return bool true if the flow was successfully completed false otherwise
140
-	 */
141
-	public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool {
142
-		try {
143
-			$data = $this->mapper->getByLoginToken($loginToken);
144
-		} catch (DoesNotExistException $e) {
145
-			return false;
146
-		}
147
-
148
-		try {
149
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
150
-			$loginName = $sessionToken->getLoginName();
151
-			try {
152
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
153
-			} catch (PasswordlessTokenException $ex) {
154
-				$password = null;
155
-			}
156
-		} catch (InvalidTokenException $ex) {
157
-			return false;
158
-		}
159
-
160
-		$appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
161
-		$this->tokenProvider->generateToken(
162
-			$appPassword,
163
-			$userId,
164
-			$loginName,
165
-			$password,
166
-			$data->getClientName(),
167
-			IToken::PERMANENT_TOKEN,
168
-			IToken::DO_NOT_REMEMBER
169
-		);
170
-
171
-		$data->setLoginName($loginName);
172
-		$data->setServer($server);
173
-
174
-		// Properly encrypt
175
-		$data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
176
-
177
-		$this->mapper->update($data);
178
-		return true;
179
-	}
180
-
181
-	public function flowDoneWithAppPassword(string $loginToken, string $server, string $loginName, string $appPassword): bool {
182
-		try {
183
-			$data = $this->mapper->getByLoginToken($loginToken);
184
-		} catch (DoesNotExistException $e) {
185
-			return false;
186
-		}
187
-
188
-		$data->setLoginName($loginName);
189
-		$data->setServer($server);
190
-
191
-		// Properly encrypt
192
-		$data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
193
-
194
-		$this->mapper->update($data);
195
-		return true;
196
-	}
197
-
198
-	public function createTokens(string $userAgent): LoginFlowV2Tokens {
199
-		$flow = new LoginFlowV2();
200
-		$pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
201
-		$loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
202
-		$flow->setPollToken($this->hashToken($pollToken));
203
-		$flow->setLoginToken($loginToken);
204
-		$flow->setStarted(0);
205
-		$flow->setTimestamp($this->time->getTime());
206
-		$flow->setClientName($userAgent);
207
-
208
-		[$publicKey, $privateKey] = $this->getKeyPair();
209
-		$privateKey = $this->crypto->encrypt($privateKey, $pollToken);
210
-
211
-		$flow->setPublicKey($publicKey);
212
-		$flow->setPrivateKey($privateKey);
213
-
214
-		$this->mapper->insert($flow);
215
-
216
-		return new LoginFlowV2Tokens($loginToken, $pollToken);
217
-	}
218
-
219
-	private function hashToken(string $token): string {
220
-		$secret = $this->config->getSystemValue('secret');
221
-		return hash('sha512', $token . $secret);
222
-	}
223
-
224
-	private function getKeyPair(): array {
225
-		$config = array_merge([
226
-			'digest_alg' => 'sha512',
227
-			'private_key_bits' => 2048,
228
-		], $this->config->getSystemValue('openssl', []));
229
-
230
-		// Generate new key
231
-		$res = openssl_pkey_new($config);
232
-		if ($res === false) {
233
-			$this->logOpensslError();
234
-			throw new \RuntimeException('Could not initialize keys');
235
-		}
236
-
237
-		if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
238
-			$this->logOpensslError();
239
-			throw new \RuntimeException('OpenSSL reported a problem');
240
-		}
241
-
242
-		// Extract the public key from $res to $pubKey
243
-		$publicKey = openssl_pkey_get_details($res);
244
-		$publicKey = $publicKey['key'];
245
-
246
-		return [$publicKey, $privateKey];
247
-	}
248
-
249
-	private function logOpensslError(): void {
250
-		$errors = [];
251
-		while ($error = openssl_error_string()) {
252
-			$errors[] = $error;
253
-		}
254
-		$this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
255
-	}
256
-
257
-	private function encryptPassword(string $password, string $publicKey): string {
258
-		openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
259
-		$encryptedPassword = base64_encode($encryptedPassword);
260
-
261
-		return $encryptedPassword;
262
-	}
263
-
264
-	private function decryptPassword(string $encryptedPassword, string $privateKey): string {
265
-		$encryptedPassword = base64_decode($encryptedPassword);
266
-		openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
267
-
268
-		return $password;
269
-	}
46
+    private LoginFlowV2Mapper $mapper;
47
+    private ISecureRandom $random;
48
+    private ITimeFactory $time;
49
+    private IConfig $config;
50
+    private ICrypto $crypto;
51
+    private LoggerInterface $logger;
52
+    private IProvider $tokenProvider;
53
+
54
+    public function __construct(LoginFlowV2Mapper $mapper,
55
+                                ISecureRandom $random,
56
+                                ITimeFactory $time,
57
+                                IConfig $config,
58
+                                ICrypto $crypto,
59
+                                LoggerInterface $logger,
60
+                                IProvider $tokenProvider) {
61
+        $this->mapper = $mapper;
62
+        $this->random = $random;
63
+        $this->time = $time;
64
+        $this->config = $config;
65
+        $this->crypto = $crypto;
66
+        $this->logger = $logger;
67
+        $this->tokenProvider = $tokenProvider;
68
+    }
69
+
70
+    /**
71
+     * @param string $pollToken
72
+     * @return LoginFlowV2Credentials
73
+     * @throws LoginFlowV2NotFoundException
74
+     */
75
+    public function poll(string $pollToken): LoginFlowV2Credentials {
76
+        try {
77
+            $data = $this->mapper->getByPollToken($this->hashToken($pollToken));
78
+        } catch (DoesNotExistException $e) {
79
+            throw new LoginFlowV2NotFoundException('Invalid token');
80
+        }
81
+
82
+        $loginName = $data->getLoginName();
83
+        $server = $data->getServer();
84
+        $appPassword = $data->getAppPassword();
85
+
86
+        if ($loginName === null || $server === null || $appPassword === null) {
87
+            throw new LoginFlowV2NotFoundException('Token not yet ready');
88
+        }
89
+
90
+        // Remove the data from the DB
91
+        $this->mapper->delete($data);
92
+
93
+        try {
94
+            // Decrypt the apptoken
95
+            $privateKey = $this->crypto->decrypt($data->getPrivateKey(), $pollToken);
96
+            $appPassword = $this->decryptPassword($data->getAppPassword(), $privateKey);
97
+        } catch (\Exception $e) {
98
+            throw new LoginFlowV2NotFoundException('Apptoken could not be decrypted');
99
+        }
100
+
101
+        return new LoginFlowV2Credentials($server, $loginName, $appPassword);
102
+    }
103
+
104
+    /**
105
+     * @param string $loginToken
106
+     * @return LoginFlowV2
107
+     * @throws LoginFlowV2NotFoundException
108
+     */
109
+    public function getByLoginToken(string $loginToken): LoginFlowV2 {
110
+        try {
111
+            return $this->mapper->getByLoginToken($loginToken);
112
+        } catch (DoesNotExistException $e) {
113
+            throw new LoginFlowV2NotFoundException('Login token invalid');
114
+        }
115
+    }
116
+
117
+    /**
118
+     * @param string $loginToken
119
+     * @return bool returns true if the start was successfull. False if not.
120
+     */
121
+    public function startLoginFlow(string $loginToken): bool {
122
+        try {
123
+            $data = $this->mapper->getByLoginToken($loginToken);
124
+        } catch (DoesNotExistException $e) {
125
+            return false;
126
+        }
127
+
128
+        $data->setStarted(1);
129
+        $this->mapper->update($data);
130
+
131
+        return true;
132
+    }
133
+
134
+    /**
135
+     * @param string $loginToken
136
+     * @param string $sessionId
137
+     * @param string $server
138
+     * @param string $userId
139
+     * @return bool true if the flow was successfully completed false otherwise
140
+     */
141
+    public function flowDone(string $loginToken, string $sessionId, string $server, string $userId): bool {
142
+        try {
143
+            $data = $this->mapper->getByLoginToken($loginToken);
144
+        } catch (DoesNotExistException $e) {
145
+            return false;
146
+        }
147
+
148
+        try {
149
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
150
+            $loginName = $sessionToken->getLoginName();
151
+            try {
152
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
153
+            } catch (PasswordlessTokenException $ex) {
154
+                $password = null;
155
+            }
156
+        } catch (InvalidTokenException $ex) {
157
+            return false;
158
+        }
159
+
160
+        $appPassword = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
161
+        $this->tokenProvider->generateToken(
162
+            $appPassword,
163
+            $userId,
164
+            $loginName,
165
+            $password,
166
+            $data->getClientName(),
167
+            IToken::PERMANENT_TOKEN,
168
+            IToken::DO_NOT_REMEMBER
169
+        );
170
+
171
+        $data->setLoginName($loginName);
172
+        $data->setServer($server);
173
+
174
+        // Properly encrypt
175
+        $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
176
+
177
+        $this->mapper->update($data);
178
+        return true;
179
+    }
180
+
181
+    public function flowDoneWithAppPassword(string $loginToken, string $server, string $loginName, string $appPassword): bool {
182
+        try {
183
+            $data = $this->mapper->getByLoginToken($loginToken);
184
+        } catch (DoesNotExistException $e) {
185
+            return false;
186
+        }
187
+
188
+        $data->setLoginName($loginName);
189
+        $data->setServer($server);
190
+
191
+        // Properly encrypt
192
+        $data->setAppPassword($this->encryptPassword($appPassword, $data->getPublicKey()));
193
+
194
+        $this->mapper->update($data);
195
+        return true;
196
+    }
197
+
198
+    public function createTokens(string $userAgent): LoginFlowV2Tokens {
199
+        $flow = new LoginFlowV2();
200
+        $pollToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
201
+        $loginToken = $this->random->generate(128, ISecureRandom::CHAR_DIGITS.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER);
202
+        $flow->setPollToken($this->hashToken($pollToken));
203
+        $flow->setLoginToken($loginToken);
204
+        $flow->setStarted(0);
205
+        $flow->setTimestamp($this->time->getTime());
206
+        $flow->setClientName($userAgent);
207
+
208
+        [$publicKey, $privateKey] = $this->getKeyPair();
209
+        $privateKey = $this->crypto->encrypt($privateKey, $pollToken);
210
+
211
+        $flow->setPublicKey($publicKey);
212
+        $flow->setPrivateKey($privateKey);
213
+
214
+        $this->mapper->insert($flow);
215
+
216
+        return new LoginFlowV2Tokens($loginToken, $pollToken);
217
+    }
218
+
219
+    private function hashToken(string $token): string {
220
+        $secret = $this->config->getSystemValue('secret');
221
+        return hash('sha512', $token . $secret);
222
+    }
223
+
224
+    private function getKeyPair(): array {
225
+        $config = array_merge([
226
+            'digest_alg' => 'sha512',
227
+            'private_key_bits' => 2048,
228
+        ], $this->config->getSystemValue('openssl', []));
229
+
230
+        // Generate new key
231
+        $res = openssl_pkey_new($config);
232
+        if ($res === false) {
233
+            $this->logOpensslError();
234
+            throw new \RuntimeException('Could not initialize keys');
235
+        }
236
+
237
+        if (openssl_pkey_export($res, $privateKey, null, $config) === false) {
238
+            $this->logOpensslError();
239
+            throw new \RuntimeException('OpenSSL reported a problem');
240
+        }
241
+
242
+        // Extract the public key from $res to $pubKey
243
+        $publicKey = openssl_pkey_get_details($res);
244
+        $publicKey = $publicKey['key'];
245
+
246
+        return [$publicKey, $privateKey];
247
+    }
248
+
249
+    private function logOpensslError(): void {
250
+        $errors = [];
251
+        while ($error = openssl_error_string()) {
252
+            $errors[] = $error;
253
+        }
254
+        $this->logger->critical('Something is wrong with your openssl setup: ' . implode(', ', $errors));
255
+    }
256
+
257
+    private function encryptPassword(string $password, string $publicKey): string {
258
+        openssl_public_encrypt($password, $encryptedPassword, $publicKey, OPENSSL_PKCS1_OAEP_PADDING);
259
+        $encryptedPassword = base64_encode($encryptedPassword);
260
+
261
+        return $encryptedPassword;
262
+    }
263
+
264
+    private function decryptPassword(string $encryptedPassword, string $privateKey): string {
265
+        $encryptedPassword = base64_decode($encryptedPassword);
266
+        openssl_private_decrypt($encryptedPassword, $password, $privateKey, OPENSSL_PKCS1_OAEP_PADDING);
267
+
268
+        return $password;
269
+    }
270 270
 }
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.