kelvinmo/simplejwt

Importing RSA Key produces warnings

ecolinet opened this issue · 1 comments

Description

I'm trying to import an RSA key generated with openssl genrsa -out private_key.pem 2048.

I'm using the following syntax :

$key = new SimpleJWT\Keys\RSAKey(file_get_contents('keys/dipli_privkey.pem'), 'pem');

When I add it to a KeySet I get a lot of warnings, like Undefined array key "e".

In the RSAKey code that, when the Key is read in format pem :

  • a search is done for BEGIN PUBLIC KEY,
  • if it fails an other one for BEGIN RSA PRIVATE KEY,
  • and if it fails the error is not reported and the class is created whitout the required fields.

Steps to reproduce

  1. Private key generation

openssl genrsa -out private_key.pem 2048

  1. Load the RSAKey and put it in a KeySet
require_once 'vendor/autoload.php';

$set = new SimpleJWT\Keys\KeySet();

$key = new SimpleJWT\Keys\RSAKey(file_get_contents('private_key.pem'), 'pem');
$set->add($key, true);

Expected behaviour

The key is loaded or an exception is thrown.

Environment

  • Version v0.8.0
  • Server OS: Windows 10

Backtrace

Fatal error: Uncaught RuntimeException: Undefined array key "e" in C:\Applications\Projets\firebase-jwt\firebase-jwt\simplejwt_basic.php on line 3

I've created PR #174 which should fix the issue. Please let me know if there are further problems