Skip to content

Commit 91b0ab8

Browse files
authored
Update AESGCM dep and don't check php version anymore (#77)
1 parent 7246088 commit 91b0ab8

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"mdanter/ecc": "^0.4.0",
1818
"lib-openssl": "*",
1919
"spomky-labs/base64url": "^1.0",
20-
"spomky-labs/php-aes-gcm": "^1.0",
20+
"spomky-labs/php-aes-gcm": "^1.2",
2121
"spomky-labs/jose": "^6.0",
2222
"guzzlehttp/guzzle": "^6.2"
2323
},

src/Encryption.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ public static function padPayload($payload, $maxLengthToPad)
3838
* @param string $payload With padding
3939
* @param string $userPublicKey Base 64 encoded (MIME or URL-safe)
4040
* @param string $userAuthToken Base 64 encoded (MIME or URL-safe)
41-
* @param bool $nativeEncryption Use OpenSSL (>PHP7.1)
4241
*
4342
* @return array
4443
*/
45-
public static function encrypt($payload, $userPublicKey, $userAuthToken, $nativeEncryption)
44+
public static function encrypt($payload, $userPublicKey, $userAuthToken)
4645
{
4746
$userPublicKey = Base64Url::decode($userPublicKey);
4847
$userAuthToken = Base64Url::decode($userAuthToken);
@@ -86,11 +85,7 @@ public static function encrypt($payload, $userPublicKey, $userAuthToken, $native
8685

8786
// encrypt
8887
// "The additional data passed to each invocation of AEAD_AES_128_GCM is a zero-length octet sequence."
89-
if (!$nativeEncryption) {
90-
list($encryptedText, $tag) = \AESGCM\AESGCM::encrypt($contentEncryptionKey, $nonce, $payload, '');
91-
} else {
92-
$encryptedText = openssl_encrypt($payload, 'aes-128-gcm', $contentEncryptionKey, OPENSSL_RAW_DATA, $nonce, $tag); // base 64 encoded
93-
}
88+
list($encryptedText, $tag) = \AESGCM\AESGCM::encrypt($contentEncryptionKey, $nonce, $payload, '');
9489

9590
// return values in url safe base64
9691
return array(

src/WebPush.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class WebPush
3535
/** @var int Automatic padding of payloads, if disabled, trade security for bandwidth */
3636
private $automaticPadding = Encryption::MAX_COMPATIBILITY_PAYLOAD_LENGTH;
3737

38-
/** @var bool */
39-
private $nativePayloadEncryptionSupport;
40-
4138
/**
4239
* WebPush constructor.
4340
*
@@ -60,8 +57,6 @@ public function __construct(array $auth = array(), $defaultOptions = array(), $t
6057
$clientOptions['timeout'] = $timeout;
6158
}
6259
$this->client = new Client($clientOptions);
63-
64-
$this->nativePayloadEncryptionSupport = version_compare(phpversion(), '7.1', '>=');
6560
}
6661

6762
/**
@@ -188,7 +183,7 @@ private function prepare(array $notifications)
188183
$auth = $notification->getAuth($this->auth);
189184

190185
if (isset($payload) && isset($userPublicKey) && isset($userAuthToken)) {
191-
$encrypted = Encryption::encrypt($payload, $userPublicKey, $userAuthToken, $this->nativePayloadEncryptionSupport);
186+
$encrypted = Encryption::encrypt($payload, $userPublicKey, $userAuthToken);
192187

193188
$headers = array(
194189
'Content-Length' => Utils::safeStrlen($encrypted['cipherText']),

0 commit comments

Comments
 (0)