@@ -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'); |
@@ -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 | * |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | */ |
118 | 118 | private function cleanExpired(): void { |
119 | 119 | try { |
120 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `expire` < ? AND NOT `expire` = 0"); |
|
120 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `expire` < ? AND NOT `expire` = 0"); |
|
121 | 121 | $sth->execute(array(time())); |
122 | - $deletedRows=$sth->rowCount(); |
|
122 | + $deletedRows = $sth->rowCount(); |
|
123 | 123 | $this->logger->notice( |
124 | 124 | sprintf("Deleted %d expired keys", $deletedRows) |
125 | 125 | ); |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | /** |
136 | 136 | * @see Tiqr_StateStorage_StateStorageInterface::setValue() |
137 | 137 | */ |
138 | - public function setValue(string $key, $value, int $expire=0): void |
|
138 | + public function setValue(string $key, $value, int $expire = 0): void |
|
139 | 139 | { |
140 | 140 | if (empty($key)) { |
141 | 141 | throw new InvalidArgumentException('Empty key not allowed'); |
142 | 142 | } |
143 | - if (((float) rand() /(float) getrandmax()) < $this->cleanupProbability) { |
|
143 | + if (((float) rand() / (float) getrandmax()) < $this->cleanupProbability) { |
|
144 | 144 | $this->cleanExpired(); |
145 | 145 | } |
146 | 146 | // REPLACE INTO is mysql dialect. Supported by sqlite as well. |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | // $expire == 0 means never expire |
155 | 155 | if ($expire != 0) { |
156 | - $expire+=time(); // Store unix timestamp after which the key expires |
|
156 | + $expire += time(); // Store unix timestamp after which the key expires |
|
157 | 157 | } |
158 | 158 | try { |
159 | 159 | $sth->execute(array(serialize($value), $expire, $key)); |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | throw new InvalidArgumentException('Empty key not allowed'); |
177 | 177 | } |
178 | 178 | try { |
179 | - $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
|
179 | + $sth = $this->handle->prepare("DELETE FROM ".$this->tablename." WHERE `key` = ?"); |
|
180 | 180 | $sth->execute(array($key)); |
181 | 181 | } |
182 | 182 | catch (Exception $e) { |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | try { |
209 | - $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
209 | + $sth = $this->handle->prepare('SELECT `value` FROM '.$this->tablename.' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
|
210 | 210 | $sth->execute(array($key, time())); |
211 | 211 | } |
212 | 212 | catch (Exception $e) { |
@@ -220,9 +220,9 @@ discard block |
||
220 | 220 | if (false === $result) { |
221 | 221 | // Occurs normally |
222 | 222 | $this->logger->info(sprintf('getValue: Key "%s" not found in PDO StateStorage', $key)); |
223 | - return NULL; // Key not found |
|
223 | + return NULL; // Key not found |
|
224 | 224 | } |
225 | - $result=unserialize($result, array('allowed_classes' => false)); |
|
225 | + $result = unserialize($result, array('allowed_classes' => false)); |
|
226 | 226 | if (false === $result) { |
227 | 227 | throw new RuntimeException(sprintf('getValue: unserialize error for key "%s" in PDO StateStorage', $key)); |
228 | 228 | } |
@@ -123,8 +123,7 @@ discard block |
||
123 | 123 | $this->logger->notice( |
124 | 124 | sprintf("Deleted %d expired keys", $deletedRows) |
125 | 125 | ); |
126 | - } |
|
127 | - catch (Exception $e) { |
|
126 | + } catch (Exception $e) { |
|
128 | 127 | $this->logger->error( |
129 | 128 | sprintf("Deleting expired keys failed: %s", $e->getMessage()), |
130 | 129 | array('exception', $e) |
@@ -157,8 +156,7 @@ discard block |
||
157 | 156 | } |
158 | 157 | try { |
159 | 158 | $sth->execute(array(serialize($value), $expire, $key)); |
160 | - } |
|
161 | - catch (Exception $e) { |
|
159 | + } catch (Exception $e) { |
|
162 | 160 | $this->logger->error( |
163 | 161 | sprintf('Unable to store key "%s" in PDO StateStorage', $key), |
164 | 162 | array('exception' => $e) |
@@ -178,8 +176,7 @@ discard block |
||
178 | 176 | try { |
179 | 177 | $sth = $this->handle->prepare("DELETE FROM " . $this->tablename . " WHERE `key` = ?"); |
180 | 178 | $sth->execute(array($key)); |
181 | - } |
|
182 | - catch (Exception $e) { |
|
179 | + } catch (Exception $e) { |
|
183 | 180 | $this->logger->error( |
184 | 181 | sprintf('Error deleting key "%s" from PDO StateStorage', $key), |
185 | 182 | array('exception' => $e) |
@@ -208,8 +205,7 @@ discard block |
||
208 | 205 | try { |
209 | 206 | $sth = $this->handle->prepare('SELECT `value` FROM ' . $this->tablename . ' WHERE `key` = ? AND (`expire` >= ? OR `expire` = 0)'); |
210 | 207 | $sth->execute(array($key, time())); |
211 | - } |
|
212 | - catch (Exception $e) { |
|
208 | + } catch (Exception $e) { |
|
213 | 209 | $this->logger->error( |
214 | 210 | sprintf('Error getting value for key "%s" from PDO StateStorage', $key), |
215 | 211 | array('exception' => $e) |
@@ -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 | } |