Skip to content

Commit ececaa3

Browse files
committed
Re-adding phpseclib for better reliability
1 parent f58b94f commit ececaa3

File tree

4 files changed

+106
-15
lines changed

4 files changed

+106
-15
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"license": "MIT",
55
"require": {
66
"firebase/php-jwt": "~4.0",
7-
"guzzlehttp/guzzle": "~5.3"
7+
"guzzlehttp/guzzle": "~5.3",
8+
"phpseclib/phpseclib": "~2.0.4"
89
},
910
"require-dev": {
1011
"phpunit/phpunit": "~5.0"

composer.lock

Lines changed: 98 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BYUJWT.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Firebase\JWT\JWT;
2121
use GuzzleHttp\Client;
2222
use GuzzleHttp\Exception\RequestException;
23+
use phpseclib\File\X509;
2324

2425
/**
2526
* Provides helpful functions to retrieve a specified BYU
@@ -112,15 +113,12 @@ public function getPublicKey()
112113
return null;
113114
}
114115

115-
$keyResource = openssl_pkey_get_public(
116-
"-----BEGIN CERTIFICATE-----\n"
117-
. $jwks->keys[0]->x5c[0]
118-
. "\n-----END CERTIFICATE-----"
119-
);
120-
if (!$keyResource) {
116+
$X509 = new X509();
117+
if (!$X509->loadX509($jwks->keys[0]->x5c[0])) {
121118
return null;
122119
}
123-
$key = openssl_pkey_get_details($keyResource)['key'];
120+
121+
$key = (string)$X509->getPublicKey();
124122

125123
$this->setCache('publicKey', $key);
126124

tests/BYUJWTTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function testParsedClaims()
292292
public function testRealWellKnown()
293293
{
294294
//one "live" test to https://api.byu.edu
295-
$this->assertNotEmpty((new BYUJWT)->getWellKnown());
295+
$this->assertNotEmpty((new BYUJWT)->getPublicKey());
296296
}
297297

298298
protected function mockClient($responseTexts = [])

0 commit comments

Comments
 (0)