Definition at line 21 of file JWK.php.
◆ createPemFromCrvAndXYCoordinates()
static Firebase\JWT\JWK::createPemFromCrvAndXYCoordinates |
( |
string |
$crv, |
|
|
string |
$x, |
|
|
string |
$y |
|
) |
| |
|
staticprivate |
Converts the EC JWK values to pem format.
- Parameters
-
string | $crv | The EC curve (only P-256 & P-384 is supported) |
string | $x | The EC x-coordinate |
string | $y | The EC y-coordinate |
- Returns
- string
Definition at line 191 of file JWK.php.
References Firebase\JWT\JWT\urlsafeB64Decode().
199 self::ASN1_OBJECT_IDENTIFIER,
200 self::encodeOID(self::OID)
203 self::ASN1_OBJECT_IDENTIFIER,
204 self::encodeOID(self::EC_CURVES[$crv])
208 self::ASN1_BIT_STRING,
209 \chr(0x00) . \chr(0x04)
216 "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
217 wordwrap(base64_encode($pem), 64,
"\n",
true)
static urlsafeB64Decode(string $input)
Decode a string with URL-safe Base64.
◆ createPemFromModulusAndExponent()
static Firebase\JWT\JWK::createPemFromModulusAndExponent |
( |
string |
$n, |
|
|
string |
$e |
|
) |
| |
|
staticprivate |
Create a public key represented in PEM format from RSA modulus and exponent information.
- Parameters
-
string | $n | The RSA modulus encoded in Base64 |
string | $e | The RSA exponent encoded in Base64 |
- Returns
- string The RSA public key represented in PEM format
encodeLength
Definition at line 231 of file JWK.php.
References Firebase\JWT\JWT\urlsafeB64Decode().
238 $modulus = \pack(
'Ca*a*', 2, self::encodeLength(\strlen($mod)), $mod);
239 $publicExponent = \pack(
'Ca*a*', 2, self::encodeLength(\strlen($exp)), $exp);
241 $rsaPublicKey = \pack(
244 self::encodeLength(\strlen($modulus) + \strlen($publicExponent)),
250 $rsaOID = \pack(
'H*',
'300d06092a864886f70d0101010500');
251 $rsaPublicKey = \chr(0) . $rsaPublicKey;
252 $rsaPublicKey = \chr(3) . self::encodeLength(\strlen($rsaPublicKey)) . $rsaPublicKey;
254 $rsaPublicKey = \pack(
257 self::encodeLength(\strlen($rsaOID . $rsaPublicKey)),
258 $rsaOID . $rsaPublicKey
261 return "-----BEGIN PUBLIC KEY-----\r\n" .
262 \chunk_split(\base64_encode($rsaPublicKey), 64) .
263 '-----END PUBLIC KEY-----';
static urlsafeB64Decode(string $input)
Decode a string with URL-safe Base64.
◆ encodeDER()
static Firebase\JWT\JWK::encodeDER |
( |
int |
$type, |
|
|
string |
$value |
|
) |
| |
|
staticprivate |
Encodes a value into a DER object.
Also defined in Firebase
- Parameters
-
int | $type | DER tag |
string | $value | the value to encode |
- Returns
- string the encoded object
Definition at line 294 of file JWK.php.
297 if (
$type === self::ASN1_SEQUENCE) {
302 $der = \chr($tag_header |
$type);
305 $der .= \chr(\strlen($value));
307 return $der . $value;
◆ encodeLength()
static Firebase\JWT\JWK::encodeLength |
( |
int |
$length | ) |
|
|
staticprivate |
DER-encode the length.
DER supports lengths up to (2**8)**127, however, we'll only support lengths up to (2**8)**4. See X.690 paragraph 8.1.3 for more information.
- Parameters
-
- Returns
- string
Definition at line 275 of file JWK.php.
277 if ($length <= 0x7F) {
278 return \chr($length);
281 $temp = \ltrim(\pack(
'N', $length), \chr(0));
283 return \pack(
'Ca*', 0x80 | \strlen($temp), $temp);
◆ encodeOID()
static Firebase\JWT\JWK::encodeOID |
( |
string |
$oid | ) |
|
|
staticprivate |
Encodes a string into a DER-encoded OID.
- Parameters
-
- Returns
- string the binary DER-encoded OID
Definition at line 316 of file JWK.php.
References ILIAS\Repository\int().
318 $octets = explode(
'.', $oid);
321 $first = (
int) array_shift($octets);
322 $second = (
int) array_shift($octets);
323 $oid = \chr($first * 40 + $second);
326 foreach ($octets as $octet) {
334 $bin .= \chr(0x80 | ($octet & 0x7f));
337 $bin[0] = $bin[0] & \chr(0x7f);
340 if (pack(
'V', 65534) == pack(
'L', 65534)) {
341 $oid .= strrev($bin);
◆ parseKey()
static Firebase\JWT\JWK::parseKey |
( |
array |
$jwk, |
|
|
string |
$defaultAlg = null |
|
) |
| |
|
static |
Parse a JWK key.
- Parameters
-
| array<mixed> | $jwk An individual JWK |
string | $defaultAlg | The algorithm for the Key object if "alg" is not set in the JSON Web Key Set |
- Returns
- Key The key object for the JWK
- Exceptions
-
InvalidArgumentException | Provided JWK is empty |
UnexpectedValueException | Provided JWK was invalid |
DomainException | OpenSSL failure |
createPemFromModulusAndExponent
Definition at line 96 of file JWK.php.
Referenced by Firebase\JWT\CachedKeySet\offsetGet(), and ILIAS\LTI\ToolProvider\Jwt\FirebaseClient\parseKeySet().
102 if (!isset($jwk[
'kty'])) {
106 if (!isset($jwk[
'alg'])) {
107 if (\is_null($defaultAlg)) {
114 $jwk[
'alg'] = $defaultAlg;
117 switch ($jwk[
'kty']) {
119 if (!empty($jwk[
'd'])) {
122 if (!isset($jwk[
'n']) || !isset($jwk[
'e'])) {
126 $pem = self::createPemFromModulusAndExponent($jwk[
'n'], $jwk[
'e']);
127 $publicKey = \openssl_pkey_get_public($pem);
128 if (
false === $publicKey) {
130 'OpenSSL error: ' . \openssl_error_string()
133 return new Key($publicKey, $jwk[
'alg']);
135 if (isset($jwk[
'd'])) {
140 if (empty($jwk[
'crv'])) {
144 if (!isset(self::EC_CURVES[$jwk[
'crv']])) {
148 if (empty($jwk[
'x']) || empty($jwk[
'y'])) {
152 $publicKey = self::createPemFromCrvAndXYCoordinates($jwk[
'crv'], $jwk[
'x'], $jwk[
'y']);
153 return new Key($publicKey, $jwk[
'alg']);
155 if (isset($jwk[
'd'])) {
160 if (!isset($jwk[
'crv'])) {
164 if (empty(self::OKP_SUBTYPES[$jwk[
'crv']])) {
165 throw new DomainException(
'Unrecognised or unsupported OKP key subtype');
168 if (empty($jwk[
'x'])) {
173 $publicKey = JWT::convertBase64urlToBase64($jwk[
'x']);
174 return new Key($publicKey, $jwk[
'alg']);
◆ parseKeySet()
const const static Firebase\JWT\JWK::parseKeySet |
( |
array |
$jwks, |
|
|
string |
$defaultAlg = null |
|
) |
| |
|
static |
Parse a set of JWK keys.
- Parameters
-
| array<mixed> | $jwks The JSON Web Key Set as an associative array |
string | $defaultAlg | The algorithm for the Key object if "alg" is not set in the JSON Web Key Set |
- Returns
- array<string, Key> An associative array of key IDs (kid) to Key objects
- Exceptions
-
InvalidArgumentException | Provided JWK Set is empty |
UnexpectedValueException | Provided JWK Set was invalid |
DomainException | OpenSSL failure |
parseKey
Definition at line 55 of file JWK.php.
References ILIAS\LTI\ToolProvider\$key, $keys, and ILIAS\LTI\ToolProvider\$kid.
Referenced by ilObjLTIConsumerGUI\saveContentSelection().
59 if (!isset($jwks[
'keys'])) {
63 if (empty($jwks[
'keys'])) {
67 foreach ($jwks[
'keys'] as $k => $v) {
68 $kid = isset($v[
'kid']) ? $v[
'kid'] : $k;
69 if (
$key = self::parseKey($v, $defaultAlg)) {
74 if (0 === \count(
$keys)) {
◆ ASN1_BIT_STRING
const Firebase\JWT\JWK::ASN1_BIT_STRING = 0x03 |
|
private |
◆ ASN1_OBJECT_IDENTIFIER
const Firebase\JWT\JWK::ASN1_OBJECT_IDENTIFIER = 0x06 |
|
private |
◆ ASN1_SEQUENCE
const Firebase\JWT\JWK::ASN1_SEQUENCE = 0x10 |
|
private |
◆ EC_CURVES
const Firebase\JWT\JWK::EC_CURVES |
|
private |
Initial value:= [
'P-256' => '1.2.840.10045.3.1.7'
Definition at line 27 of file JWK.php.
◆ OID
const Firebase\JWT\JWK::OID = '1.2.840.10045.2.1' |
|
private |
◆ OKP_SUBTYPES
const const Firebase\JWT\JWK::OKP_SUBTYPES |
|
private |
Initial value:
Definition at line 36 of file JWK.php.
The documentation for this class was generated from the following file: