-
-
Notifications
You must be signed in to change notification settings - Fork 68
Changed version phpseclib 3 #42
Comments
"require": { |
As a temporary workaround you can do that in your own project with
|
|
Limiting the version to v2
Also phpseclib2_compat did not work for me
|
@nextofblake - the presence of the underscore means that that method is not an officially supported method. This can be traced back to the old PEAR coding standards. Quoting them, "Private class members are preceded by a single underscore". phpseclib 3 doesn't follow this convention but phpseclib 1/2 did. Anyway, I'd rewrite your code thusly: $rsa = new RSA;
$rsa->load([
'e' => new BigInteger('...'),
'n' => new BigInteger('...')
]); phpseclib 2 has supported this since the initial release of 2.0 (2.0.0). |
@terrafrost thanks for the tip however the issue is specific to this package.
|
I wrote an override class that addresses most of not all the compatibility issues. Note that it depends on <?php
namespace App\Overrides\JOSE;
use Error;
use JOSE_JWK;
use ReflectionClass;
use JOSE_URLSafeBase64;
use ReflectionException;
use phpseclib3\Crypt\RSA;
use UnexpectedValueException;
use phpseclib3\Crypt\RSA\PublicKey;
use Firebase\JWT\JWK as FirebaseJWK;
use phpseclib3\Crypt\PublicKeyLoader;
use JOSE_Exception_UnexpectedAlgorithm;
/**
* Override to cope with changes from phpseclib/phpseclib v2 to 3
*/
class JWK extends JOSE_JWK
{
/**
* @inheritDoc
* @throws ReflectionException
*/
public static function encode($key, $extra_components = [])
{
try {
return parent::encode($key, $extra_components);
} catch (JOSE_Exception_UnexpectedAlgorithm $error) {
//
}
if ($key instanceof RSA\PublicKey) {
$modulus = static::getProtectedProperty($key, 'modulus');
$exponent = static::getProtectedProperty($key, 'exponent');
$components = [
'kty' => 'RSA',
'e' => JOSE_URLSafeBase64::encode($key->publicExponent->toBytes()),
'n' => JOSE_URLSafeBase64::encode($modulus->toBytes())
];
if ($exponent != $key->publicExponent) {
$components = array_merge($components, ['d' => JOSE_URLSafeBase64::encode($exponent->toBytes())]);
}
return new static(array_merge($components, $extra_components));
}
throw new JOSE_Exception_UnexpectedAlgorithm('Unknown key type: '.get_class($key));
}
/**
* @param object $object
* @param string $propertyName
* @return mixed
* @throws ReflectionException
*/
protected static function getProtectedProperty(object $object, string $propertyName)
{
$reflectionClass = app(ReflectionClass::class, ['argument' => $object]);
$reflectionProperty = $reflectionClass->getProperty($propertyName);
if ($reflectionProperty->isPublic()) {
throw new UnexpectedValueException($reflectionClass->name."::$propertyName is public");
}
$reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($object);
}
/**
* @inheritDoc
*/
public static function decode($components)
{
$jwk = new static($components);
return $jwk->toKey();
}
/**
* @inheritDoc
*/
public function toKey()
{
try {
return parent::toKey();
} catch (Error $e) {
//
}
switch ($this->components['kty']) {
case 'RSA':
$pemResource = FirebaseJWK::parseKey($this->components);
$keyData = openssl_pkey_get_details($pemResource);
$keyString = $keyData['key'];
/** @var PublicKey $rsa */
$rsa = PublicKeyLoader::loadPublicKey($keyString);
return $rsa;
default:
throw new JOSE_Exception_UnexpectedAlgorithm('Unknown key type');
}
}
} |
Here is my PR to change to phpseclib 3, #45 |
@nov any chance to merge the PR above and release a new version ? |
Error: Class 'phpseclib\Crypt\RSA' not found in JOSE_JWK->toKey() (line 23 of \vendor\gree\jose\src\JOSE\JWK.php).
The text was updated successfully, but these errors were encountered: