13
13
14
14
namespace Minishlink \WebPush ;
15
15
16
+ use Base64Url \Base64Url ;
16
17
use Jose \Component \Core \AlgorithmManager ;
17
18
use Jose \Component \Core \JWK ;
18
19
use Jose \Component \KeyManagement \JWKFactory ;
19
20
use Jose \Component \Signature \Algorithm \ES256 ;
20
21
use Jose \Component \Signature \JWSBuilder ;
21
22
use Jose \Component \Signature \Serializer \CompactSerializer ;
22
- use ParagonIE \ConstantTime \Base64UrlSafe ;
23
23
24
24
class VAPID
25
25
{
@@ -54,14 +54,14 @@ public static function validate(array $vapid): array
54
54
throw new \ErrorException ('Failed to convert VAPID public key from hexadecimal to binary ' );
55
55
}
56
56
$ vapid ['publicKey ' ] = base64_encode ($ binaryPublicKey );
57
- $ vapid ['privateKey ' ] = base64_encode (str_pad (Base64UrlSafe:: decodeNoPadding ($ jwk ->get ('d ' )), 2 * self ::PRIVATE_KEY_LENGTH , '0 ' , STR_PAD_LEFT ));
57
+ $ vapid ['privateKey ' ] = base64_encode (str_pad (Base64Url:: decode ($ jwk ->get ('d ' )), 2 * self ::PRIVATE_KEY_LENGTH , '0 ' , STR_PAD_LEFT ));
58
58
}
59
59
60
60
if (!isset ($ vapid ['publicKey ' ])) {
61
61
throw new \ErrorException ('[VAPID] You must provide a public key. ' );
62
62
}
63
63
64
- $ publicKey = Base64UrlSafe:: decodeNoPadding ($ vapid ['publicKey ' ]);
64
+ $ publicKey = Base64Url:: decode ($ vapid ['publicKey ' ]);
65
65
66
66
if (Utils::safeStrlen ($ publicKey ) !== self ::PUBLIC_KEY_LENGTH ) {
67
67
throw new \ErrorException ('[VAPID] Public key should be 65 bytes long when decoded. ' );
@@ -71,7 +71,7 @@ public static function validate(array $vapid): array
71
71
throw new \ErrorException ('[VAPID] You must provide a private key. ' );
72
72
}
73
73
74
- $ privateKey = Base64UrlSafe:: decodeNoPadding ($ vapid ['privateKey ' ]);
74
+ $ privateKey = Base64Url:: decode ($ vapid ['privateKey ' ]);
75
75
76
76
if (Utils::safeStrlen ($ privateKey ) !== self ::PRIVATE_KEY_LENGTH ) {
77
77
throw new \ErrorException ('[VAPID] Private key should be 32 bytes long when decoded. ' );
@@ -122,9 +122,9 @@ public static function getVapidHeaders(string $audience, string $subject, string
122
122
$ jwk = new JWK ([
123
123
'kty ' => 'EC ' ,
124
124
'crv ' => 'P-256 ' ,
125
- 'x ' => Base64UrlSafe:: encodeUnpadded ($ x ),
126
- 'y ' => Base64UrlSafe:: encodeUnpadded ($ y ),
127
- 'd ' => Base64UrlSafe:: encodeUnpadded ($ privateKey ),
125
+ 'x ' => Base64Url:: encode ($ x ),
126
+ 'y ' => Base64Url:: encode ($ y ),
127
+ 'd ' => Base64Url:: encode ($ privateKey ),
128
128
]);
129
129
130
130
$ jwsCompactSerializer = new CompactSerializer ();
@@ -136,7 +136,7 @@ public static function getVapidHeaders(string $audience, string $subject, string
136
136
->build ();
137
137
138
138
$ jwt = $ jwsCompactSerializer ->serialize ($ jws , 0 );
139
- $ encodedPublicKey = Base64UrlSafe:: encodeUnpadded ($ publicKey );
139
+ $ encodedPublicKey = Base64Url:: encode ($ publicKey );
140
140
141
141
if ($ contentEncoding === "aesgcm " ) {
142
142
return [
@@ -169,14 +169,14 @@ public static function createVapidKeys(): array
169
169
throw new \ErrorException ('Failed to convert VAPID public key from hexadecimal to binary ' );
170
170
}
171
171
172
- $ binaryPrivateKey = hex2bin (str_pad (bin2hex (Base64UrlSafe:: decodeNoPadding ($ jwk ->get ('d ' ))), 2 * self ::PRIVATE_KEY_LENGTH , '0 ' , STR_PAD_LEFT ));
172
+ $ binaryPrivateKey = hex2bin (str_pad (bin2hex (Base64Url:: decode ($ jwk ->get ('d ' ))), 2 * self ::PRIVATE_KEY_LENGTH , '0 ' , STR_PAD_LEFT ));
173
173
if (!$ binaryPrivateKey ) {
174
174
throw new \ErrorException ('Failed to convert VAPID private key from hexadecimal to binary ' );
175
175
}
176
176
177
177
return [
178
- 'publicKey ' => Base64UrlSafe:: encodeUnpadded ($ binaryPublicKey ),
179
- 'privateKey ' => Base64UrlSafe:: encodeUnpadded ($ binaryPrivateKey ),
178
+ 'publicKey ' => Base64Url:: encode ($ binaryPublicKey ),
179
+ 'privateKey ' => Base64Url:: encode ($ binaryPrivateKey ),
180
180
];
181
181
}
182
182
}
0 commit comments