ILIAS  release_8 Revision v8.24
Firebase\JWT\JWT Class Reference
+ Collaboration diagram for Firebase\JWT\JWT:

Static Public Member Functions

static decode (string $jwt, $keyOrKeyArray, stdClass &$headers=null)
 Decodes a JWT string into a PHP object. More...
 
static encode (array $payload, $key, string $alg, string $keyId=null, array $head=null)
 Converts and signs a PHP array into a JWT string. More...
 
static sign (string $msg, $key, string $alg)
 Sign a string with a given key and algorithm. More...
 
static jsonDecode (string $input)
 Decode a JSON string into a PHP object. More...
 
static jsonEncode (array $input)
 Encode a PHP array into a JSON string. More...
 
static urlsafeB64Decode (string $input)
 Decode a string with URL-safe Base64. More...
 
static convertBase64UrlToBase64 (string $input)
 Convert a string in the base64url (URL-safe Base64) encoding to standard base64. More...
 
static urlsafeB64Encode (string $input)
 Encode a string with URL-safe Base64. More...
 
static constantTimeEquals (string $left, string $right)
 

Static Public Attributes

static int $leeway = 0
 
static int $timestamp = null
 
static array $supported_algs
 

Static Private Member Functions

static verify (string $msg, string $signature, $keyMaterial, string $alg)
 Verify a signature with the message, key and method. More...
 
static getKey ( $keyOrKeyArray, ?string $kid)
 Determine if an algorithm has been provided for each Key. More...
 
static handleJsonError (int $errno)
 Helper method to create a JSON error. More...
 
static safeStrlen (string $str)
 Get the number of bytes in cryptographic strings. More...
 
static signatureToDER (string $sig)
 Convert an ECDSA signature to an ASN.1 DER sequence. More...
 
static encodeDER (int $type, string $value)
 Encodes a value into a DER object. More...
 
static signatureFromDER (string $der, int $keySize)
 Encodes signature from a DER object. More...
 
static readDER (string $der, int $offset=0)
 Reads binary DER-encoded data and decodes into a single object. More...
 

Private Attributes

const ASN1_INTEGER = 0x02
 
const ASN1_SEQUENCE = 0x10
 
const ASN1_BIT_STRING = 0x03
 

Detailed Description

Definition at line 28 of file JWT.php.

Member Function Documentation

◆ constantTimeEquals()

static Firebase\JWT\JWT::constantTimeEquals ( string  $left,
string  $right 
)
static
Parameters
string$leftThe string of known length to compare against
string$rightThe user-supplied string
Returns
bool

Definition at line 489 of file JWT.php.

489 : bool
490 {
491 if (\function_exists('hash_equals')) {
492 return \hash_equals($left, $right);
493 }
494 $len = \min(self::safeStrlen($left), self::safeStrlen($right));
495
496 $status = 0;
497 for ($i = 0; $i < $len; $i++) {
498 $status |= (\ord($left[$i]) ^ \ord($right[$i]));
499 }
500 $status |= (self::safeStrlen($left) ^ self::safeStrlen($right));
501
502 return ($status === 0);
503 }
static safeStrlen(string $str)
Get the number of bytes in cryptographic strings.
Definition: JWT.php:537
$i
Definition: metadata.php:41

References $i.

◆ convertBase64UrlToBase64()

static Firebase\JWT\JWT::convertBase64UrlToBase64 ( string  $input)
static

Convert a string in the base64url (URL-safe Base64) encoding to standard base64.

Parameters
string$inputA Base64 encoded string with URL-safe characters (-_ and no padding)
Returns
string A Base64 encoded string with standard characters (+/) and padding (=), when needed.
See also
https://www.rfc-editor.org/rfc/rfc4648

Definition at line 427 of file JWT.php.

427 : string
428 {
429 $remainder = \strlen($input) % 4;
430 if ($remainder) {
431 $padlen = 4 - $remainder;
432 $input .= \str_repeat('=', $padlen);
433 }
434 return \strtr($input, '-_', '+/');
435 }

◆ decode()

static Firebase\JWT\JWT::decode ( string  $jwt,
  $keyOrKeyArray,
stdClass &  $headers = null 
)
static

Decodes a JWT string into a PHP object.

Parameters
string$jwtThe JWT
Key|ArrayAccess<string,Key>|array<string,Key>$keyOrKeyArray The Key or associative array of key IDs (kid) to Key objects. If the algorithm used is asymmetric, this is the public key. Each Key object contains an algorithm and matching key. Supported algorithms are 'ES384','ES256', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384' and 'RS512'.
stdClass$headersOptional. Populates stdClass with headers.
Returns
stdClass The JWT's payload as a PHP object
Exceptions
InvalidArgumentExceptionProvided key/key-array was empty or malformed
DomainExceptionProvided JWT is malformed
UnexpectedValueExceptionProvided JWT was invalid
SignatureInvalidExceptionProvided JWT was invalid because the signature verification failed
BeforeValidExceptionProvided JWT is trying to be used before it's eligible as defined by 'nbf'
BeforeValidExceptionProvided JWT is trying to be used before it's been created as defined by 'iat'
ExpiredExceptionProvided JWT has since expired, as defined by the 'exp' claim

@uses jsonDecode @uses urlsafeB64Decode

Definition at line 96 of file JWT.php.

100 : stdClass {
101 // Validate JWT
102 $timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp;
103
104 if (empty($keyOrKeyArray)) {
105 throw new InvalidArgumentException('Key may not be empty');
106 }
107 $tks = \explode('.', $jwt);
108 if (\count($tks) !== 3) {
109 throw new UnexpectedValueException('Wrong number of segments');
110 }
111 list($headb64, $bodyb64, $cryptob64) = $tks;
112 $headerRaw = static::urlsafeB64Decode($headb64);
113 if (null === ($header = static::jsonDecode($headerRaw))) {
114 throw new UnexpectedValueException('Invalid header encoding');
115 }
116 if ($headers !== null) {
117 $headers = $header;
118 }
119 $payloadRaw = static::urlsafeB64Decode($bodyb64);
120 if (null === ($payload = static::jsonDecode($payloadRaw))) {
121 throw new UnexpectedValueException('Invalid claims encoding');
122 }
123 if (\is_array($payload)) {
124 // prevent PHP Fatal Error in edge-cases when payload is empty array
126 }
127 if (!$payload instanceof stdClass) {
128 throw new UnexpectedValueException('Payload must be a JSON object');
129 }
130 $sig = static::urlsafeB64Decode($cryptob64);
131 if (empty($header->alg)) {
132 throw new UnexpectedValueException('Empty algorithm');
133 }
134 if (empty(static::$supported_algs[$header->alg])) {
135 throw new UnexpectedValueException('Algorithm not supported');
136 }
137
138 $key = self::getKey($keyOrKeyArray, property_exists($header, 'kid') ? $header->kid : null);
139
140 // Check the algorithm
141 if (!self::constantTimeEquals($key->getAlgorithm(), $header->alg)) {
142 // See issue #351
143 throw new UnexpectedValueException('Incorrect key for this algorithm');
144 }
145 if (\in_array($header->alg, ['ES256', 'ES256K', 'ES384'], true)) {
146 // OpenSSL expects an ASN.1 DER sequence for ES256/ES256K/ES384 signatures
147 $sig = self::signatureToDER($sig);
148 }
149 if (!self::verify("{$headb64}.{$bodyb64}", $sig, $key->getKeyMaterial(), $header->alg)) {
150 throw new SignatureInvalidException('Signature verification failed');
151 }
152
153 // Check the nbf if it is defined. This is the time that the
154 // token can actually be used. If it's not yet that time, abort.
155 if (isset($payload->nbf) && floor($payload->nbf) > ($timestamp + static::$leeway)) {
156 $ex = new BeforeValidException(
157 'Cannot handle token with nbf prior to ' . \date(DateTime::ISO8601, (int) $payload->nbf)
158 );
159 $ex->setPayload($payload);
160 throw $ex;
161 }
162
163 // Check that this token has been created before 'now'. This prevents
164 // using tokens that have been created for later use (and haven't
165 // correctly used the nbf claim).
166 if (!isset($payload->nbf) && isset($payload->iat) && floor($payload->iat) > ($timestamp + static::$leeway)) {
167 $ex = new BeforeValidException(
168 'Cannot handle token with iat prior to ' . \date(DateTime::ISO8601, (int) $payload->iat)
169 );
170 $ex->setPayload($payload);
171 throw $ex;
172 }
173
174 // Check if this token has expired.
175 if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) {
176 $ex = new ExpiredException('Expired token');
177 $ex->setPayload($payload);
178 throw $ex;
179 }
180
181 return $payload;
182 }
foreach($mandatory_scripts as $file) $timestamp
Definition: buildRTE.php:70
static signatureToDER(string $sig)
Convert an ECDSA signature to an ASN.1 DER sequence.
Definition: JWT.php:551
static int $timestamp
Definition: JWT.php:50
static getKey( $keyOrKeyArray, ?string $kid)
Determine if an algorithm has been provided for each Key.
Definition: JWT.php:460
if(count($parts) !=3) $payload
Definition: ltitoken.php:70
ClientInterface $jwt
JWT object, if any.
Definition: System.php:165
string $key
Consumer key/client ID value.
Definition: System.php:193

Referenced by ilObjLTIConsumerGUI\saveContentSelection(), and ILIAS\LTI\ToolProvider\Jwt\FirebaseClient\verify().

+ Here is the caller graph for this function:

◆ encode()

static Firebase\JWT\JWT::encode ( array  $payload,
  $key,
string  $alg,
string  $keyId = null,
array  $head = null 
)
static

Converts and signs a PHP array into a JWT string.

Parameters
array<mixed>$payload PHP array
string | resource | OpenSSLAsymmetricKey | OpenSSLCertificate$keyThe secret key.
string$algSupported algorithms are 'ES384','ES256', 'ES256K', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
string$keyId
array<string,string>$head An array with header elements to attach
Returns
string A signed JWT

@uses jsonEncode @uses urlsafeB64Encode

Definition at line 199 of file JWT.php.

205 : string {
206 $header = ['typ' => 'JWT', 'alg' => $alg];
207 if ($keyId !== null) {
208 $header['kid'] = $keyId;
209 }
210 if (isset($head) && \is_array($head)) {
211 $header = \array_merge($head, $header);
212 }
213 $segments = [];
214 $segments[] = static::urlsafeB64Encode((string) static::jsonEncode($header));
215 $segments[] = static::urlsafeB64Encode((string) static::jsonEncode($payload));
216 $signing_input = \implode('.', $segments);
217
218 $signature = static::sign($signing_input, $key, $alg);
219 $segments[] = static::urlsafeB64Encode($signature);
220
221 return \implode('.', $segments);
222 }

Referenced by ilObjLTIConsumer\LTISignJWT().

+ Here is the caller graph for this function:

◆ encodeDER()

static Firebase\JWT\JWT::encodeDER ( int  $type,
string  $value 
)
staticprivate

Encodes a value into a DER object.

Parameters
int$typeDER tag
string$valuethe value to encode
Returns
string the encoded object

Definition at line 585 of file JWT.php.

585 : string
586 {
587 $tag_header = 0;
588 if ($type === self::ASN1_SEQUENCE) {
589 $tag_header |= 0x20;
590 }
591
592 // Type
593 $der = \chr($tag_header | $type);
594
595 // Length
596 $der .= \chr(\strlen($value));
597
598 return $der . $value;
599 }
$type

References $type.

◆ getKey()

static Firebase\JWT\JWT::getKey (   $keyOrKeyArray,
?string  $kid 
)
staticprivate

Determine if an algorithm has been provided for each Key.

Parameters
Key|ArrayAccess<string,Key>|array<string,Key>$keyOrKeyArray
string | null$kid
Exceptions
UnexpectedValueException
Returns
Key

Definition at line 460 of file JWT.php.

463 : Key {
464 if ($keyOrKeyArray instanceof Key) {
465 return $keyOrKeyArray;
466 }
467
468 if (empty($kid) && $kid !== '0') {
469 throw new UnexpectedValueException('"kid" empty, unable to lookup correct key');
470 }
471
472 if ($keyOrKeyArray instanceof CachedKeySet) {
473 // Skip "isset" check, as this will automatically refresh if not set
474 return $keyOrKeyArray[$kid];
475 }
476
477 if (!isset($keyOrKeyArray[$kid])) {
478 throw new UnexpectedValueException('"kid" invalid, unable to lookup correct key');
479 }
480
481 return $keyOrKeyArray[$kid];
482 }
string $kid
Key ID.
Definition: System.php:88

◆ handleJsonError()

static Firebase\JWT\JWT::handleJsonError ( int  $errno)
staticprivate

Helper method to create a JSON error.

Parameters
int$errnoAn error number from json_last_error()
Exceptions
DomainException
Returns
void

Definition at line 514 of file JWT.php.

514 : void
515 {
516 $messages = [
517 JSON_ERROR_DEPTH => 'Maximum stack depth exceeded',
518 JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON',
519 JSON_ERROR_CTRL_CHAR => 'Unexpected control character found',
520 JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON',
521 JSON_ERROR_UTF8 => 'Malformed UTF-8 characters' //PHP >= 5.3.3
522 ];
523 throw new DomainException(
524 isset($messages[$errno])
525 ? $messages[$errno]
526 : 'Unknown JSON error: ' . $errno
527 );
528 }
$messages
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: xapiexit.php:22

References $messages.

◆ jsonDecode()

static Firebase\JWT\JWT::jsonDecode ( string  $input)
static

Decode a JSON string into a PHP object.

Parameters
string$inputJSON string
Returns
mixed The decoded JSON string
Exceptions
DomainExceptionProvided string was invalid JSON

Definition at line 363 of file JWT.php.

364 {
365 $obj = \json_decode($input, false, 512, JSON_BIGINT_AS_STRING);
366
367 if ($errno = \json_last_error()) {
368 self::handleJsonError($errno);
369 } elseif ($obj === null && $input !== 'null') {
370 throw new DomainException('Null result with non-null input');
371 }
372 return $obj;
373 }
static handleJsonError(int $errno)
Helper method to create a JSON error.
Definition: JWT.php:514

◆ jsonEncode()

static Firebase\JWT\JWT::jsonEncode ( array  $input)
static

Encode a PHP array into a JSON string.

Parameters
array<mixed>$input A PHP array
Returns
string JSON representation of the PHP array
Exceptions
DomainExceptionProvided object could not be encoded to valid JSON

Definition at line 384 of file JWT.php.

384 : string
385 {
386 if (PHP_VERSION_ID >= 50400) {
387 $json = \json_encode($input, \JSON_UNESCAPED_SLASHES);
388 } else {
389 // PHP 5.3 only
390 $json = \json_encode($input);
391 }
392 if ($errno = \json_last_error()) {
393 self::handleJsonError($errno);
394 } elseif ($json === 'null') {
395 throw new DomainException('Null result with non-null input');
396 }
397 if ($json === false) {
398 throw new DomainException('Provided object could not be encoded to valid JSON');
399 }
400 return $json;
401 }

◆ readDER()

static Firebase\JWT\JWT::readDER ( string  $der,
int  $offset = 0 
)
staticprivate

Reads binary DER-encoded data and decodes into a single object.

Parameters
string$derthe binary data in DER format
int$offsetthe offset of the data stream containing the object to decode
Returns
array{int, string|null} the new offset and the decoded object

Definition at line 637 of file JWT.php.

637 : array
638 {
639 $pos = $offset;
640 $size = \strlen($der);
641 $constructed = (\ord($der[$pos]) >> 5) & 0x01;
642 $type = \ord($der[$pos++]) & 0x1f;
643
644 // Length
645 $len = \ord($der[$pos++]);
646 if ($len & 0x80) {
647 $n = $len & 0x1f;
648 $len = 0;
649 while ($n-- && $pos < $size) {
650 $len = ($len << 8) | \ord($der[$pos++]);
651 }
652 }
653
654 // Value
655 if ($type === self::ASN1_BIT_STRING) {
656 $pos++; // Skip the first contents octet (padding indicator)
657 $data = \substr($der, $pos, $len - 1);
658 $pos += $len - 1;
659 } elseif (!$constructed) {
660 $data = \substr($der, $pos, $len);
661 $pos += $len;
662 } else {
663 $data = null;
664 }
665
666 return [$pos, $data];
667 }

References $data, and $type.

◆ safeStrlen()

static Firebase\JWT\JWT::safeStrlen ( string  $str)
staticprivate

Get the number of bytes in cryptographic strings.

Parameters
string$str
Returns
int

Definition at line 537 of file JWT.php.

537 : int
538 {
539 if (\function_exists('mb_strlen')) {
540 return \mb_strlen($str, '8bit');
541 }
542 return \strlen($str);
543 }

◆ sign()

static Firebase\JWT\JWT::sign ( string  $msg,
  $key,
string  $alg 
)
static

Sign a string with a given key and algorithm.

Parameters
string$msgThe message to sign
string | resource | OpenSSLAsymmetricKey | OpenSSLCertificate$keyThe secret key.
string$algSupported algorithms are 'EdDSA', 'ES384', 'ES256', 'ES256K', 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
Returns
string An encrypted message
Exceptions
DomainExceptionUnsupported algorithm or bad key was specified

Definition at line 236 of file JWT.php.

240 : string {
241 if (empty(static::$supported_algs[$alg])) {
242 throw new DomainException('Algorithm not supported');
243 }
244 list($function, $algorithm) = static::$supported_algs[$alg];
245 switch ($function) {
246 case 'hash_hmac':
247 if (!\is_string($key)) {
248 throw new InvalidArgumentException('key must be a string when using hmac');
249 }
250 return \hash_hmac($algorithm, $msg, $key, true);
251 case 'openssl':
252 $signature = '';
253 $success = \openssl_sign($msg, $signature, $key, $algorithm); // @phpstan-ignore-line
254 if (!$success) {
255 throw new DomainException('OpenSSL unable to sign data');
256 }
257 if ($alg === 'ES256' || $alg === 'ES256K') {
258 $signature = self::signatureFromDER($signature, 256);
259 } elseif ($alg === 'ES384') {
260 $signature = self::signatureFromDER($signature, 384);
261 }
262 return $signature;
263 case 'sodium_crypto':
264 if (!\function_exists('sodium_crypto_sign_detached')) {
265 throw new DomainException('libsodium is not available');
266 }
267 if (!\is_string($key)) {
268 throw new InvalidArgumentException('key must be a string when using EdDSA');
269 }
270 try {
271 // The last non-empty line is used as the key.
272 $lines = array_filter(explode("\n", $key));
273 $key = base64_decode((string) end($lines));
274 if (\strlen($key) === 0) {
275 throw new DomainException('Key cannot be empty string');
276 }
277 return sodium_crypto_sign_detached($msg, $key);
278 } catch (Exception $e) {
279 throw new DomainException($e->getMessage(), 0, $e);
280 }
281 }
282
283 throw new DomainException('Algorithm not supported');
284 }
static signatureFromDER(string $der, int $keySize)
Encodes signature from a DER object.
Definition: JWT.php:609

◆ signatureFromDER()

static Firebase\JWT\JWT::signatureFromDER ( string  $der,
int  $keySize 
)
staticprivate

Encodes signature from a DER object.

Parameters
string$derbinary signature in DER format
int$keySizethe number of bits in the key
Returns
string the signature

Definition at line 609 of file JWT.php.

609 : string
610 {
611 // OpenSSL returns the ECDSA signatures as a binary ASN.1 DER SEQUENCE
612 list($offset, $_) = self::readDER($der);
613 list($offset, $r) = self::readDER($der, $offset);
614 list($offset, $s) = self::readDER($der, $offset);
615
616 // Convert r-value and s-value from signed two's compliment to unsigned
617 // big-endian integers
618 $r = \ltrim($r, "\x00");
619 $s = \ltrim($s, "\x00");
620
621 // Pad out r and s so that they are $keySize bits long
622 $r = \str_pad($r, $keySize / 8, "\x00", STR_PAD_LEFT);
623 $s = \str_pad($s, $keySize / 8, "\x00", STR_PAD_LEFT);
624
625 return $r . $s;
626 }
static readDER(string $der, int $offset=0)
Reads binary DER-encoded data and decodes into a single object.
Definition: JWT.php:637

◆ signatureToDER()

static Firebase\JWT\JWT::signatureToDER ( string  $sig)
staticprivate

Convert an ECDSA signature to an ASN.1 DER sequence.

Parameters
string$sigThe ECDSA signature to convert
Returns
string The encoded DER object

Definition at line 551 of file JWT.php.

551 : string
552 {
553 // Separate the signature into r-value and s-value
554 $length = max(1, (int) (\strlen($sig) / 2));
555 list($r, $s) = \str_split($sig, $length);
556
557 // Trim leading zeros
558 $r = \ltrim($r, "\x00");
559 $s = \ltrim($s, "\x00");
560
561 // Convert r-value and s-value from unsigned big-endian integers to
562 // signed two's complement
563 if (\ord($r[0]) > 0x7f) {
564 $r = "\x00" . $r;
565 }
566 if (\ord($s[0]) > 0x7f) {
567 $s = "\x00" . $s;
568 }
569
570 return self::encodeDER(
571 self::ASN1_SEQUENCE,
572 self::encodeDER(self::ASN1_INTEGER, $r) .
573 self::encodeDER(self::ASN1_INTEGER, $s)
574 );
575 }
static encodeDER(int $type, string $value)
Encodes a value into a DER object.
Definition: JWT.php:585

◆ urlsafeB64Decode()

static Firebase\JWT\JWT::urlsafeB64Decode ( string  $input)
static

Decode a string with URL-safe Base64.

Parameters
string$inputA Base64 encoded string
Returns
string A decoded string
Exceptions
InvalidArgumentExceptioninvalid base64 characters

Definition at line 412 of file JWT.php.

412 : string
413 {
414 return \base64_decode(self::convertBase64UrlToBase64($input));
415 }

Referenced by Firebase\JWT\JWK\createPemFromCrvAndXYCoordinates(), and ILIAS\LTI\ToolProvider\Jwt\FirebaseClient\load().

+ Here is the caller graph for this function:

◆ urlsafeB64Encode()

static Firebase\JWT\JWT::urlsafeB64Encode ( string  $input)
static

Encode a string with URL-safe Base64.

Parameters
string$inputThe string you want encoded
Returns
string The base64 encode of what you passed in

Definition at line 444 of file JWT.php.

444 : string
445 {
446 return \str_replace('=', '', \strtr(\base64_encode($input), '+/', '-_'));
447 }

Referenced by ILIAS\LTI\ToolProvider\Jwt\FirebaseClient\getJWKS().

+ Here is the caller graph for this function:

◆ verify()

static Firebase\JWT\JWT::verify ( string  $msg,
string  $signature,
  $keyMaterial,
string  $alg 
)
staticprivate

Verify a signature with the message, key and method.

Not all methods are symmetric, so we must have a separate verify and sign method.

Parameters
string$msgThe original message (header and body)
string$signatureThe original signature
string | resource | OpenSSLAsymmetricKey | OpenSSLCertificate$keyMaterialFor Ed*, ES*, HS*, a string key works. for RS*, must be an instance of OpenSSLAsymmetricKey
string$algThe algorithm
Returns
bool
Exceptions
DomainExceptionInvalid Algorithm, bad key, or OpenSSL failure

Definition at line 299 of file JWT.php.

304 : bool {
305 if (empty(static::$supported_algs[$alg])) {
306 throw new DomainException('Algorithm not supported');
307 }
308
309 list($function, $algorithm) = static::$supported_algs[$alg];
310 switch ($function) {
311 case 'openssl':
312 $success = \openssl_verify($msg, $signature, $keyMaterial, $algorithm); // @phpstan-ignore-line
313 if ($success === 1) {
314 return true;
315 }
316 if ($success === 0) {
317 return false;
318 }
319 // returns 1 on success, 0 on failure, -1 on error.
320 throw new DomainException(
321 'OpenSSL error: ' . \openssl_error_string()
322 );
323 case 'sodium_crypto':
324 if (!\function_exists('sodium_crypto_sign_verify_detached')) {
325 throw new DomainException('libsodium is not available');
326 }
327 if (!\is_string($keyMaterial)) {
328 throw new InvalidArgumentException('key must be a string when using EdDSA');
329 }
330 try {
331 // The last non-empty line is used as the key.
332 $lines = array_filter(explode("\n", $keyMaterial));
333 $key = base64_decode((string) end($lines));
334 if (\strlen($key) === 0) {
335 throw new DomainException('Key cannot be empty string');
336 }
337 if (\strlen($signature) === 0) {
338 throw new DomainException('Signature cannot be empty string');
339 }
340 return sodium_crypto_sign_verify_detached($signature, $msg, $key);
341 } catch (Exception $e) {
342 throw new DomainException($e->getMessage(), 0, $e);
343 }
344 case 'hash_hmac':
345 default:
346 if (!\is_string($keyMaterial)) {
347 throw new InvalidArgumentException('key must be a string when using hmac');
348 }
349 $hash = \hash_hmac($algorithm, $msg, $keyMaterial, true);
350 return self::constantTimeEquals($hash, $signature);
351 }
352 }
static constantTimeEquals(string $left, string $right)
Definition: JWT.php:489

Field Documentation

◆ $leeway

int Firebase\JWT\JWT::$leeway = 0
static

Definition at line 41 of file JWT.php.

Referenced by ILIAS\LTI\ToolProvider\Jwt\FirebaseClient\verify().

◆ $supported_algs

array Firebase\JWT\JWT::$supported_algs
static
Initial value:
= [
'ES384' => ['openssl', 'SHA384'],
'ES256' => ['openssl', 'SHA256'],
'ES256K' => ['openssl', 'SHA256'],
'HS256' => ['hash_hmac', 'SHA256'],
'HS384' => ['hash_hmac', 'SHA384'],
'HS512' => ['hash_hmac', 'SHA512'],
'RS256' => ['openssl', 'SHA256'],
'RS384' => ['openssl', 'SHA384'],
'RS512' => ['openssl', 'SHA512'],
'EdDSA' => ['sodium_crypto', 'EdDSA'],
]

Definition at line 55 of file JWT.php.

◆ $timestamp

int Firebase\JWT\JWT::$timestamp = null
static

Definition at line 50 of file JWT.php.

◆ ASN1_BIT_STRING

const Firebase\JWT\JWT::ASN1_BIT_STRING = 0x03
private

Definition at line 32 of file JWT.php.

◆ ASN1_INTEGER

const Firebase\JWT\JWT::ASN1_INTEGER = 0x02
private

Definition at line 30 of file JWT.php.

◆ ASN1_SEQUENCE

const Firebase\JWT\JWT::ASN1_SEQUENCE = 0x10
private

Definition at line 31 of file JWT.php.


The documentation for this class was generated from the following file: