Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 50... Línea 50...
50
     * @throws UnexpectedValueException     Provided JWK Set was invalid
50
     * @throws UnexpectedValueException     Provided JWK Set was invalid
51
     * @throws DomainException              OpenSSL failure
51
     * @throws DomainException              OpenSSL failure
52
     *
52
     *
53
     * @uses parseKey
53
     * @uses parseKey
54
     */
54
     */
55
    public static function parseKeySet(array $jwks, string $defaultAlg = null): array
55
    public static function parseKeySet(array $jwks, ?string $defaultAlg = null): array
56
    {
56
    {
57
        $keys = [];
57
        $keys = [];
Línea 58... Línea 58...
58
 
58
 
59
        if (!isset($jwks['keys'])) {
59
        if (!isset($jwks['keys'])) {
Línea 91... Línea 91...
91
     * @throws UnexpectedValueException     Provided JWK was invalid
91
     * @throws UnexpectedValueException     Provided JWK was invalid
92
     * @throws DomainException              OpenSSL failure
92
     * @throws DomainException              OpenSSL failure
93
     *
93
     *
94
     * @uses createPemFromModulusAndExponent
94
     * @uses createPemFromModulusAndExponent
95
     */
95
     */
96
    public static function parseKey(array $jwk, string $defaultAlg = null): ?Key
96
    public static function parseKey(array $jwk, ?string $defaultAlg = null): ?Key
97
    {
97
    {
98
        if (empty($jwk)) {
98
        if (empty($jwk)) {
99
            throw new InvalidArgumentException('JWK must not be empty');
99
            throw new InvalidArgumentException('JWK must not be empty');
100
        }
100
        }
Línea 170... Línea 170...
170
                }
170
                }
Línea 171... Línea 171...
171
 
171
 
172
                // This library works internally with EdDSA keys (Ed25519) encoded in standard base64.
172
                // This library works internally with EdDSA keys (Ed25519) encoded in standard base64.
173
                $publicKey = JWT::convertBase64urlToBase64($jwk['x']);
173
                $publicKey = JWT::convertBase64urlToBase64($jwk['x']);
-
 
174
                return new Key($publicKey, $jwk['alg']);
-
 
175
            case 'oct':
-
 
176
                if (!isset($jwk['k'])) {
-
 
177
                    throw new UnexpectedValueException('k not set');
-
 
178
                }
-
 
179
 
174
                return new Key($publicKey, $jwk['alg']);
180
                return new Key(JWT::urlsafeB64Decode($jwk['k']), $jwk['alg']);
175
            default:
181
            default:
176
                break;
182
                break;
Línea 177... Línea 183...
177
        }
183
        }
Línea 210... Línea 216...
210
                    . JWT::urlsafeB64Decode($x)
216
                    . JWT::urlsafeB64Decode($x)
211
                    . JWT::urlsafeB64Decode($y)
217
                    . JWT::urlsafeB64Decode($y)
212
                )
218
                )
213
            );
219
            );
Línea 214... Línea 220...
214
 
220
 
215
        return sprintf(
221
        return \sprintf(
216
            "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
222
            "-----BEGIN PUBLIC KEY-----\n%s\n-----END PUBLIC KEY-----\n",
217
            wordwrap(base64_encode($pem), 64, "\n", true)
223
            wordwrap(base64_encode($pem), 64, "\n", true)
218
        );
224
        );