@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | $options = $this->getOptions(); |
24 | 24 | if (isset($options['apns.proxy_host_url'])) { |
25 | 25 | // Override CURL options to connect to a HTTP/1.1 to HTTP/2 proxy |
26 | - $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'] . '/3/device/' . $this->getAddress(); |
|
26 | + $curl_options[CURLOPT_URL] = $options['apns.proxy_host_url'].'/3/device/'.$this->getAddress(); |
|
27 | 27 | $curl_options[CURLOPT_PORT] = $options['apns.proxy_host_port'] ?? 443; |
28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
30 | - $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
30 | + $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
|
31 | 31 | } |
32 | 32 | else { |
33 | 33 | $version_info = curl_version(); |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | |
39 | 39 | // Get the UID from the client certificate we use for authentication, this |
40 | 40 | // is set to the bundle ID. |
41 | - $options=$this->getOptions(); |
|
41 | + $options = $this->getOptions(); |
|
42 | 42 | $cert_filename = $options['apns.certificate']; |
43 | 43 | $cert_file_contents = file_get_contents($cert_filename); |
44 | 44 | if (false === $cert_file_contents) { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
50 | - $cert=openssl_x509_parse( $cert_file_contents ); |
|
50 | + $cert = openssl_x509_parse($cert_file_contents); |
|
51 | 51 | if (false === $cert) { |
52 | 52 | throw new RuntimeException('Error parsing APNS client certificate'); |
53 | 53 | } |
@@ -72,42 +72,42 @@ discard block |
||
72 | 72 | $authProvider = AuthProvider\Certificate::create($authProviderOptions); |
73 | 73 | |
74 | 74 | // Create the push message |
75 | - $alert=Alert::create(); |
|
75 | + $alert = Alert::create(); |
|
76 | 76 | $alert->setBody($this->getText()); |
77 | 77 | // Note: It is possible to specify a title and a subtitle: $alert->setTitle() && $alert->setSubtitle() |
78 | 78 | // The tiqr service currently does not implement this. |
79 | - $payload=Payload::create()->setAlert($alert); |
|
79 | + $payload = Payload::create()->setAlert($alert); |
|
80 | 80 | $payload->setSound('default'); |
81 | 81 | foreach ($this->getCustomProperties() as $name => $value) { |
82 | 82 | $payload->setCustomValue($name, $value); |
83 | 83 | } |
84 | 84 | $this->logger->debug(sprintf('JSON Payload: %s', $payload->toJson())); |
85 | - $notification=new Notification($payload, $this->getAddress()); |
|
85 | + $notification = new Notification($payload, $this->getAddress()); |
|
86 | 86 | // Set expiration to 30 seconds from now, same as Message_APNS |
87 | 87 | $now = new DateTime(); |
88 | - $expirationInstant=$now->add(new DateInterval('PT30S')); |
|
88 | + $expirationInstant = $now->add(new DateInterval('PT30S')); |
|
89 | 89 | $notification->setExpirationAt($expirationInstant); |
90 | 90 | |
91 | 91 | // Send the push message |
92 | 92 | $client = new Client($authProvider, $options['apns.environment'] == 'production', $curl_options); |
93 | 93 | $client->addNotification($notification); |
94 | - $responses=$client->push(); |
|
95 | - if ( sizeof($responses) != 1) { |
|
96 | - $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses)) ); |
|
94 | + $responses = $client->push(); |
|
95 | + if (sizeof($responses) != 1) { |
|
96 | + $this->logger->warning(sprintf('Unexpected number responses. Expected 1, got %d', sizeof($responses))); |
|
97 | 97 | if (sizeof($responses) == 0) { |
98 | 98 | $this->logger->warning('Could not determine whether the notification was sent'); |
99 | 99 | return; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | /** @var \Pushok\Response $response */ |
103 | - $response = reset($responses); // Get first response from the array |
|
104 | - $deviceToken=$response->getDeviceToken() ?? ''; |
|
103 | + $response = reset($responses); // Get first response from the array |
|
104 | + $deviceToken = $response->getDeviceToken() ?? ''; |
|
105 | 105 | // A canonical UUID that is the unique ID for the notification. E.g. 123e4567-e89b-12d3-a456-4266554400a0 |
106 | - $apnsId=$response->getApnsId() ?? ''; |
|
106 | + $apnsId = $response->getApnsId() ?? ''; |
|
107 | 107 | // Status code. E.g. 200 (Success), 410 (The device token is no longer active for the topic.) |
108 | - $statusCode=$response->getStatusCode(); |
|
108 | + $statusCode = $response->getStatusCode(); |
|
109 | 109 | $this->logger->info(sprintf('Got response with ApnsId "%s", status %s for deviceToken "%s"', $apnsId, $statusCode, $deviceToken)); |
110 | - if ( strcasecmp($deviceToken, $this->getAddress()) ) { |
|
110 | + if (strcasecmp($deviceToken, $this->getAddress())) { |
|
111 | 111 | $this->logger->warning(sprintf('Unexpected deviceToken in response. Expected: "%s"; got: "%s"', $this->getAddress(), $deviceToken)); |
112 | 112 | } |
113 | 113 | if ($statusCode == 200) { |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - $reasonPhrase=$response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | - $errorReason=$response->getErrorReason(); // E.g. Unregistered |
|
120 | - $errorDescription=$response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
118 | + $reasonPhrase = $response->getReasonPhrase(); // E.g. The device token is no longer active for the topic. |
|
119 | + $errorReason = $response->getErrorReason(); // E.g. Unregistered |
|
120 | + $errorDescription = $response->getErrorDescription(); // E.g. The device token is inactive for the specified topic. |
|
121 | 121 | |
122 | 122 | $this->logger->error(sprintf('Error sending APNS2 push notification. APNS ID: "%s"; deviceToken: "%s"; Error: "%s" "%s" "%s"', $apnsId, $deviceToken, $reasonPhrase, $errorReason, $errorDescription)); |
123 | 123 | throw new RuntimeException( |
@@ -28,8 +28,7 @@ |
||
28 | 28 | // Use HTTP/1.1 instead of HTTP/2 |
29 | 29 | $curl_options[CURLOPT_HTTP_VERSION] = CURL_HTTP_VERSION_1_1; |
30 | 30 | $this->logger->notice(sprintf('Using HTTP/1.1 CURL Proxy URL: "%s" and port "%s"', $curl_options[CURLOPT_URL], $curl_options[CURLOPT_URL])); |
31 | - } |
|
32 | - else { |
|
31 | + } else { |
|
33 | 32 | $version_info = curl_version(); |
34 | 33 | if ($version_info['features'] & CURL_VERSION_HTTP2 == 0) { |
35 | 34 | throw new RuntimeException('APNS2 requires HTTP/2 support in curl'); |
@@ -80,8 +80,7 @@ discard block |
||
80 | 80 | $sth = $this->handle->prepare('SELECT `key` FROM ' . $this->tablename . ' WHERE `key` = ?'); |
81 | 81 | $sth->execute(array($key)); |
82 | 82 | return $sth->fetchColumn() !== false; |
83 | - } |
|
84 | - catch (Exception $e) { |
|
83 | + } catch (Exception $e) { |
|
85 | 84 | $this->logger->error( |
86 | 85 | sprintf('Error checking for key "%s" in PDO StateStorage', $key), |
87 | 86 | array('exception' => $e) |
@@ -103,8 +102,7 @@ discard block |
||
103 | 102 | $this->logger->notice( |
104 | 103 | sprintf("Deleted %d expired keys", $deletedRows) |
105 | 104 | ); |
106 | - } |
|
107 | - catch (Exception $e) { |
|
105 | + } catch (Exception $e) { |
|
108 | 106 | $this->logger->error( |
109 | 107 | sprintf("Deleting expired keys failed: %s", $e->getMessage()), |
110 | 108 | array('exception', $e) |
@@ -134,8 +132,7 @@ discard block |
||
134 | 132 | } |
135 | 133 | try { |
136 | 134 | $sth->execute(array(serialize($value), $expire, $key)); |
137 | - } |
|
138 | - catch (Exception $e) { |
|
135 | + } catch (Exception $e) { |
|
139 | 136 | $this->logger->error( |
140 | 137 | sprintf('Unable to store key "%s" in PDO StateStorage', $key), |
141 | 138 | array('exception' => $e) |
@@ -155,8 +152,7 @@ discard block |
||
155 | 152 | try { |
156 | 153 | $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
157 | 154 | $sth->execute(array($key)); |
158 | - } |
|
159 | - catch (Exception $e) { |
|
155 | + } catch (Exception $e) { |
|
160 | 156 | $this->logger->error( |
161 | 157 | sprintf('Error deleting key "%s" from PDO StateStorage', $key), |
162 | 158 | array('exception' => $e) |
@@ -185,8 +181,7 @@ discard block |
||
185 | 181 | try { |
186 | 182 | $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
187 | 183 | $sth->execute(array($key, time())); |
188 | - } |
|
189 | - catch (Exception $e) { |
|
184 | + } catch (Exception $e) { |
|
190 | 185 | $this->logger->error( |
191 | 186 | sprintf('Error getting value for key "%s" from PDO StateStorage', $key), |
192 | 187 | array('exception' => $e) |
@@ -59,7 +59,6 @@ |
||
59 | 59 | ); |
60 | 60 | |
61 | 61 | CREATE INDEX IF NOT EXISTS index_tiqrstate_expire ON tiqrstate (expire); |
62 | - |
|
63 | 62 | * @see Tiqr_StateStorage::getStorage() |
64 | 63 | * @see Tiqr_StateStorage_StateStorageInterface |
65 | 64 | * |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | throw new InvalidArgumentException('Empty key not allowed'); |
122 | 122 | } |
123 | 123 | try { |
124 | - $sth = $this->handle->prepare('SELECT `key` FROM ' . $this->tablename . ' WHERE `key` = ?'); |
|
124 | + $sth = $this->handle->prepare('SELECT `key` FROM '.$this->tablename.' WHERE `key` = ?'); |
|
125 | 125 | $sth->execute(array($key)); |
126 | 126 | return $sth->fetchColumn() !== false; |
127 | 127 | } |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | */ |
142 | 142 | private function cleanExpired(): void { |
143 | 143 | try { |
144 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `expire` < ? AND NOT `expire` = 0"); |
|
144 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0"); |
|
145 | 145 | $sth->execute(array(time())); |
146 | - $deletedRows=$sth->rowCount(); |
|
146 | + $deletedRows = $sth->rowCount(); |
|
147 | 147 | $this->logger->notice( |
148 | 148 | sprintf("Deleted %d expired keys", $deletedRows) |
149 | 149 | ); |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | /** |
160 | 160 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
161 | 161 | */ |
162 | - public function setValue(string $key, $value, int $expire=0): void |
|
162 | + public function setValue(string $key, $value, int $expire = 0): void |
|
163 | 163 | { |
164 | 164 | if (empty($key)) { |
165 | 165 | throw new InvalidArgumentException('Empty key not allowed'); |
166 | 166 | } |
167 | - if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) { |
|
167 | + if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) { |
|
168 | 168 | $this->cleanExpired(); |
169 | 169 | } |
170 | 170 | if ($this->keyExists($key)) { |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | } |
175 | 175 | // $expire == 0 means never expire |
176 | 176 | if ($expire != 0) { |
177 | - $expire+=time(); // Store unix timestamp after which the key expires |
|
177 | + $expire += time(); // Store unix timestamp after which the key expires |
|
178 | 178 | } |
179 | 179 | try { |
180 | 180 | $sth->execute(array(serialize($value), $expire, $key)); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | throw new InvalidArgumentException('Empty key not allowed'); |
198 | 198 | } |
199 | 199 | try { |
200 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
|
200 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?"); |
|
201 | 201 | $sth->execute(array($key)); |
202 | 202 | } |
203 | 203 | catch (Exception $e) { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | try { |
230 | - $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
230 | + $sth = $this->handle->prepare('SELECT `value` FROM '.$this->tablename.' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
231 | 231 | $sth->execute(array($key, time())); |
232 | 232 | } |
233 | 233 | catch (Exception $e) { |
@@ -241,9 +241,9 @@ discard block |
||
241 | 241 | if (false === $result) { |
242 | 242 | // Occurs normally |
243 | 243 | $this->logger->info(sprintf('getValue: Key "%s" not found in PDO StateStorage', $key)); |
244 | - return NULL; // Key not found |
|
244 | + return NULL; // Key not found |
|
245 | 245 | } |
246 | - $result=unserialize($result, array('allowed_classes' => false)); |
|
246 | + $result = unserialize($result, array('allowed_classes' => false)); |
|
247 | 247 | if (false === $result) { |
248 | 248 | throw new RuntimeException(sprintf('getValue: unserialize error for key "%s" in PDO StateStorage', $key)); |
249 | 249 | } |
@@ -74,7 +74,7 @@ |
||
74 | 74 | $password = $options['password']; |
75 | 75 | |
76 | 76 | try { |
77 | - $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) ); |
|
77 | + $handle = new PDO($dsn, $userName, $password, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)); |
|
78 | 78 | } catch (PDOException $e) { |
79 | 79 | $logger->error( |
80 | 80 | sprintf('Unable to establish a PDO connection. Error message from PDO: %s', $e->getMessage()) |
@@ -97,7 +97,7 @@ |
||
97 | 97 | * ), |
98 | 98 | * ) |
99 | 99 | * ); |
100 | - * |
|
100 | + * |
|
101 | 101 | * |
102 | 102 | * @return Tiqr_UserSecretStorage_Interface |
103 | 103 | * @throws RuntimeException If an unknown type is requested. |
@@ -39,10 +39,10 @@ |
||
39 | 39 | * @return Tiqr_OcraService_Interface |
40 | 40 | * @throws Exception An exception if an unknown orca service type is requested. |
41 | 41 | */ |
42 | - public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger=null) |
|
42 | + public static function getOcraService(string $type = "tiqr", array $options = array(), LoggerInterface $logger = null) |
|
43 | 43 | { |
44 | 44 | if (!$logger) |
45 | - $logger=new \Psr\Log\NullLogger(); |
|
45 | + $logger = new \Psr\Log\NullLogger(); |
|
46 | 46 | |
47 | 47 | switch ($type) { |
48 | 48 | case "tiqr": |
@@ -41,8 +41,9 @@ |
||
41 | 41 | */ |
42 | 42 | public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger=null) |
43 | 43 | { |
44 | - if (!$logger) |
|
45 | - $logger=new \Psr\Log\NullLogger(); |
|
44 | + if (!$logger) { |
|
45 | + $logger=new \Psr\Log\NullLogger(); |
|
46 | + } |
|
46 | 47 | |
47 | 48 | switch ($type) { |
48 | 49 | case "tiqr": |
@@ -35,7 +35,7 @@ |
||
35 | 35 | $this->logger = $logger; |
36 | 36 | |
37 | 37 | // Set the OCRA suite |
38 | - $this->_ocraSuite = $config['ocra.suite'] ?? 'OCRA-1:HOTP-SHA1-6:QH10-S'; // Use tiqr server default suite |
|
38 | + $this->_ocraSuite = $config['ocra.suite'] ?? 'OCRA-1:HOTP-SHA1-6:QH10-S'; // Use tiqr server default suite |
|
39 | 39 | $this->_ocraParser = new OATH_OCRAParser($this->_ocraSuite); |
40 | 40 | } |
41 | 41 |
@@ -40,10 +40,10 @@ |
||
40 | 40 | * @param LoggerInterface $logger |
41 | 41 | * @throws Exception An exception if an unknown storage is requested. |
42 | 42 | */ |
43 | - public static function getStorage(string $type="dummy", Array $options=array(), LoggerInterface $logger=null) |
|
43 | + public static function getStorage(string $type = "dummy", Array $options = array(), LoggerInterface $logger = null) |
|
44 | 44 | { |
45 | 45 | if (!$logger) |
46 | - $logger=new \Psr\Log\NullLogger(); |
|
46 | + $logger = new \Psr\Log\NullLogger(); |
|
47 | 47 | |
48 | 48 | switch ($type) { |
49 | 49 | case "dummy": |
@@ -42,8 +42,9 @@ |
||
42 | 42 | */ |
43 | 43 | public static function getStorage(string $type="dummy", Array $options=array(), LoggerInterface $logger=null) |
44 | 44 | { |
45 | - if (!$logger) |
|
46 | - $logger=new \Psr\Log\NullLogger(); |
|
45 | + if (!$logger) { |
|
46 | + $logger=new \Psr\Log\NullLogger(); |
|
47 | + } |
|
47 | 48 | |
48 | 49 | switch ($type) { |
49 | 50 | case "dummy": |
@@ -54,7 +54,7 @@ |
||
54 | 54 | if ($prefix === $this->encryption->get_type()) { |
55 | 55 | // Decrypt the secret if it is prefixed with the current encryption type |
56 | 56 | // Remove the encryption type prefix before decrypting |
57 | - return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) ); |
|
57 | + return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) ); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Check the decryption array for the encryption type to see if there is an encryption |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | if ($prefix === $this->encryption->get_type()) { |
55 | 55 | // Decrypt the secret if it is prefixed with the current encryption type |
56 | 56 | // Remove the encryption type prefix before decrypting |
57 | - return $this->encryption->decrypt( substr($encryptedSecret, $pos+1) ); |
|
57 | + return $this->encryption->decrypt(substr($encryptedSecret, $pos + 1)); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | // Check the decryption array for the encryption type to see if there is an encryption |
61 | 61 | // instance defined for it. If so, use that to decrypt the secret. |
62 | 62 | if (isset($this->decryption[$prefix])) { |
63 | - return $this->decryption[$prefix]->decrypt( substr($encryptedSecret, $pos+1) ); |
|
63 | + return $this->decryption[$prefix]->decrypt(substr($encryptedSecret, $pos + 1)); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | $this->logger->error("Secret for user '$userId' is encrypted with unsupported encryption type '$prefix'"); |
@@ -77,6 +77,6 @@ discard block |
||
77 | 77 | { |
78 | 78 | $encryptedSecret = $this->encryption->encrypt($secret); |
79 | 79 | // Prefix the user secret with the encryption type |
80 | - $this->setUserSecret($userId, $this->encryption->get_type() . ':' . $encryptedSecret); |
|
80 | + $this->setUserSecret($userId, $this->encryption->get_type().':'.$encryptedSecret); |
|
81 | 81 | } |
82 | 82 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | * |
39 | 39 | * @return Tiqr_UserSecretStorage_Encryption_Interface |
40 | 40 | */ |
41 | - public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
41 | + public static function getEncryption(LoggerInterface $logger, string $type = "dummy", array $options = array()): Tiqr_UserSecretStorage_Encryption_Interface |
|
42 | 42 | { |
43 | 43 | $instance = null; |
44 | 44 | $logger->info(sprintf('Using "%s" as UserSecretStorage encryption type', $type)); |
@@ -160,7 +160,7 @@ |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Decrypts the given data. |
|
163 | + * Decrypts the given data. |
|
164 | 164 | * |
165 | 165 | * @param string $data Data to decrypt. |
166 | 166 | * @return string decrypted data |
@@ -48,22 +48,22 @@ discard block |
||
48 | 48 | */ |
49 | 49 | |
50 | 50 | private $_supportedCiphers = [ |
51 | - 'aes-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
52 | - 'aes-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
53 | - 'aes-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
54 | - 'aes-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
55 | - 'aes-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
56 | - 'aes-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
57 | - 'chacha20' => [ 'tag' => false, 'key' => 32 ], |
|
58 | - 'camellia-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
59 | - 'camellia-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
60 | - 'camellia-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
61 | - 'aria-128-cbc' => [ 'tag' => false, 'key' => 16 ], |
|
62 | - 'aria-128-gcm' => [ 'tag' => true, 'key' => 16 ], |
|
63 | - 'aria-192-cbc' => [ 'tag' => false, 'key' => 24 ], |
|
64 | - 'aria-192-gcm' => [ 'tag' => true, 'key' => 24 ], |
|
65 | - 'aria-256-cbc' => [ 'tag' => false, 'key' => 32 ], |
|
66 | - 'aria-256-gcm' => [ 'tag' => true, 'key' => 32 ], |
|
51 | + 'aes-128-cbc' => ['tag' => false, 'key' => 16], |
|
52 | + 'aes-128-gcm' => ['tag' => true, 'key' => 16], |
|
53 | + 'aes-192-cbc' => ['tag' => false, 'key' => 24], |
|
54 | + 'aes-192-gcm' => ['tag' => true, 'key' => 24], |
|
55 | + 'aes-256-cbc' => ['tag' => false, 'key' => 32], |
|
56 | + 'aes-256-gcm' => ['tag' => true, 'key' => 32], |
|
57 | + 'chacha20' => ['tag' => false, 'key' => 32], |
|
58 | + 'camellia-128-cbc' => ['tag' => false, 'key' => 16], |
|
59 | + 'camellia-192-cbc' => ['tag' => false, 'key' => 24], |
|
60 | + 'camellia-256-cbc' => ['tag' => false, 'key' => 32], |
|
61 | + 'aria-128-cbc' => ['tag' => false, 'key' => 16], |
|
62 | + 'aria-128-gcm' => ['tag' => true, 'key' => 16], |
|
63 | + 'aria-192-cbc' => ['tag' => false, 'key' => 24], |
|
64 | + 'aria-192-gcm' => ['tag' => true, 'key' => 24], |
|
65 | + 'aria-256-cbc' => ['tag' => false, 'key' => 32], |
|
66 | + 'aria-256-gcm' => ['tag' => true, 'key' => 32], |
|
67 | 67 | ]; |
68 | 68 | |
69 | 69 | /** |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | // A longer key is not a problem, but could indicate a configuration error |
137 | 137 | $key_length = $this->_supportedCiphers[$this->_cipher]['key']; |
138 | 138 | if (strlen($key) != $key_length) { |
139 | - throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got " . strlen($key) . " bytes"); |
|
139 | + throw new RuntimeException("Invalid length of key with key_id '{$this->_key_id}' used with cipher '{$this->_cipher}', expected {$key_length} bytes, got ".strlen($key)." bytes"); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // openssl_encrypt returns the ciphertext as a base64 encoded string, so we don't need to encode it again |
143 | 143 | // The tag is returned as a binary string, but only if the cipher requires a tag |
144 | - $tag=''; |
|
144 | + $tag = ''; |
|
145 | 145 | if ($this->_supportedCiphers[$this->_cipher]['tag']) { |
146 | 146 | $encrypted = openssl_encrypt($data, $this->_cipher, $key, 0, $iv, $tag, '', 16); |
147 | 147 | } else { |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $tag = $this->_supportedCiphers[$this->_cipher]['tag'] ? $tag : ''; |
154 | 154 | // Return the encoded ciphertext, including the IV, tag and cipher |
155 | 155 | // <cipher>:<key_id>:iv<>:<tag>:<ciphertext> |
156 | - $encoded = $this->_cipher . ":" . $this->_key_id . ":" . base64_encode($iv) . ":" . base64_encode($tag) . ":" . $encrypted; |
|
156 | + $encoded = $this->_cipher.":".$this->_key_id.":".base64_encode($iv).":".base64_encode($tag).":".$encrypted; |
|
157 | 157 | |
158 | 158 | return $encoded; |
159 | 159 | } |
@@ -192,19 +192,19 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | // IV |
195 | - $iv = base64_decode($split_data[2],true); |
|
195 | + $iv = base64_decode($split_data[2], true); |
|
196 | 196 | if ($iv === false) { |
197 | 197 | throw new RuntimeException("Error decoding IV"); |
198 | 198 | } |
199 | 199 | |
200 | 200 | // Tag |
201 | - $tag = base64_decode($split_data[3],true); |
|
201 | + $tag = base64_decode($split_data[3], true); |
|
202 | 202 | if ($tag === false) { |
203 | 203 | throw new RuntimeException("Error decoding tag"); |
204 | 204 | } |
205 | 205 | $ciphertext = $split_data[4]; |
206 | 206 | |
207 | - $plaintext=openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
207 | + $plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv, $tag); |
|
208 | 208 | if ($plaintext === false) { |
209 | 209 | throw new RuntimeException("Error decrypting data"); |
210 | 210 | } |