File tree 3 files changed +26
-7
lines changed 3 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -119,7 +119,10 @@ protected function getContent()
119
119
}
120
120
121
121
/**
122
- * @throws \InvalidArgumentException
122
+ * @throws \InvalidArgumentException Has CURL error message and the CURL error
123
+ * number as exception code.
124
+ * Throws exception with error number 0
125
+ * if the error is not related to CURL.
123
126
*
124
127
* @return string
125
128
*/
@@ -137,9 +140,25 @@ private function downloadContent()
137
140
$ ch = curl_init ();
138
141
curl_setopt_array ($ ch , $ params );
139
142
$ content = curl_exec ($ ch );
140
- curl_close ($ ch );
141
143
142
- Assertion::false (false === $ content , 'Unable to get content. ' );
144
+ try {
145
+ Assertion::false (false === $ content , 'Failed to load JWK contents: ' );
146
+ } catch (\Assert \AssertionFailedException $ e ) {
147
+ $ curlError = curl_error ($ ch );
148
+ $ curlErrorNumber = curl_errno ($ ch );
149
+
150
+ throw new \InvalidArgumentException (
151
+ $ e ->getMessage ().$ curlError ,
152
+ $ curlErrorNumber
153
+ );
154
+ } catch (\Exception $ e ) {
155
+ throw new \InvalidArgumentException (
156
+ 'Failed to load JWK contents: ' .$ e ->getMessage (),
157
+ 0
158
+ );
159
+ } finally {
160
+ curl_close ($ ch );
161
+ }
143
162
144
163
return $ content ;
145
164
}
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ final class JKUJWKSet extends DownloadedJWKSet
24
24
public function getKeys ()
25
25
{
26
26
$ content = json_decode ($ this ->getContent (), true );
27
- Assertion::isArray ($ content , 'Invalid content. ' );
28
- Assertion::keyExists ($ content , 'keys ' , 'Invalid content. ' );
27
+ Assertion::isArray ($ content , 'Invalid JWK content. ' );
28
+ Assertion::keyExists ($ content , 'keys ' , 'Invalid JWKSet content. ' );
29
29
30
30
return (new JWKSet ($ content ))->getKeys ();
31
31
}
Original file line number Diff line number Diff line change @@ -25,11 +25,11 @@ final class X5UJWKSet extends DownloadedJWKSet
25
25
public function getKeys ()
26
26
{
27
27
$ content = json_decode ($ this ->getContent (), true );
28
- Assertion::isArray ($ content , 'Invalid content. ' );
28
+ Assertion::isArray ($ content , 'Invalid JWK content. ' );
29
29
$ jwkset = new JWKSet ();
30
30
foreach ($ content as $ kid => $ cert ) {
31
31
$ jwk = KeyConverter::loadKeyFromCertificate ($ cert );
32
- Assertion::notEmpty ($ jwk , 'Invalid content. ' );
32
+ Assertion::notEmpty ($ jwk , 'Invalid JWKSet content. ' );
33
33
if (is_string ($ kid )) {
34
34
$ jwk ['kid ' ] = $ kid ;
35
35
}
You can’t perform that action at this time.
0 commit comments