11
11
12
12
namespace Minishlink \WebPush ;
13
13
14
+ use Base64Url \Base64Url ;
14
15
use Buzz \Browser ;
15
16
use Buzz \Client \AbstractClient ;
16
17
use Buzz \Client \MultiCurl ;
@@ -177,7 +178,7 @@ public function flush()
177
178
}
178
179
179
180
/**
180
- * @param string $userPublicKey base 64 encoded
181
+ * @param string $userPublicKey MIME base 64 encoded
181
182
* @param string $payload
182
183
*
183
184
* @return array
@@ -193,7 +194,7 @@ private function encrypt($userPublicKey, $payload)
193
194
// get local key pair
194
195
$ localPrivateKeyObject = $ curveGenerator ->createPrivateKey ();
195
196
$ localPublicKeyObject = $ localPrivateKeyObject ->getPublicKey ();
196
- $ localPublicKey = base64_encode ( hex2bin ($ keySerializer ->serialize ($ localPublicKeyObject ->getPoint () )));
197
+ $ localPublicKey = hex2bin ($ keySerializer ->serialize ($ localPublicKeyObject ->getPoint ()));
197
198
198
199
// get user public key object
199
200
$ userPublicKeyObject = new PublicKey ($ math , $ curveGenerator , $ keySerializer ->unserialize ($ curve , bin2hex (base64_decode ($ userPublicKey ))));
@@ -216,10 +217,11 @@ private function encrypt($userPublicKey, $payload)
216
217
$ cipherText = openssl_encrypt ($ payload , 'aes-128-gcm ' , $ encryptionKey , false , $ iv ); // base 64 encoded
217
218
}
218
219
220
+ // return values in url safe base64
219
221
return array (
220
- 'localPublicKey ' => $ localPublicKey ,
221
- 'salt ' => base64_encode ($ salt ),
222
- 'cipherText ' => base64_encode ($ cipherText ),
222
+ 'localPublicKey ' => Base64Url:: encode ( $ localPublicKey) ,
223
+ 'salt ' => Base64Url:: encode ($ salt ),
224
+ 'cipherText ' => Base64Url:: encode ($ cipherText ),
223
225
);
224
226
}
225
227
@@ -237,9 +239,9 @@ private function sendToStandardEndpoints(array $notifications)
237
239
$ headers = array (
238
240
'Content-Length ' => strlen ($ encrypted ['cipherText ' ]),
239
241
'Content-Type ' => 'application/octet-stream ' ,
240
- 'Content-Encoding ' => 'aesgcm-128 ' ,
242
+ 'Content-Encoding ' => 'aesgcm128 ' ,
241
243
'Encryption ' => 'keyid="p256dh";salt=" ' .$ encrypted ['salt ' ].'" ' ,
242
- 'Encryption -Key ' => 'keyid="p256dh";dh=" ' .$ encrypted ['localPublicKey ' ].'" ' ,
244
+ 'Crypto -Key ' => 'keyid="p256dh";dh=" ' .$ encrypted ['localPublicKey ' ].'" ' ,
243
245
'TTL ' => $ this ->TTL ,
244
246
);
245
247
0 commit comments