Comments (9)
As a temporary workaround you can do that in your own project with
composer require phpseclib/phpseclib:^2.0
from jose-php.
"require": {
"php": ">=5.6",
"phpseclib/phpseclib": ">=2.0.0"
},
in new ver phpseclib used NS as phpseclib3
need to limit ver phpseclib
from jose-php.
composer require phpseclib/phpseclib2_compat:~1.0
should also work. That'd let you use the phpseclib v2 API with phpseclib v3
from jose-php.
Limiting the version to v2
composer require phpseclib/phpseclib:~2.0
Also phpseclib2_compat did not work for me
$rsa = new RSA();
$rsa->_convertPublicKey($n, $e) // method not found
from jose-php.
@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).
from jose-php.
@terrafrost thanks for the tip however the issue is specific to this package.
inspect jose-php/src/JOSE/JWK.php
function toKey() {
... stuff
$pem_string = $rsa->_convertPublicKey($n, $e);
}
from jose-php.
I wrote an override class that addresses most of not all the compatibility issues. Note that it depends on Firebase\JWT
to facilitate what RSA::_convertPublicKey()
previously offered. And that some Reflection hackery was needed to regain access to now-protected properties.
<?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');
}
}
}
from jose-php.
Here is my PR to change to phpseclib 3, #45
from jose-php.
@nov any chance to merge the PR above and release a new version ?
from jose-php.
Related Issues (18)
- PS256/384/512 JWS test case signatures seem invalid HOT 1
- The library unconditionally adds JWE header as additional authenticated data HOT 2
- Consider removing composer.phar
- Broken phpseclib/phpseclib dependency HOT 3
- JWT Auth Guard for Laravel HOT 2
- Composer can't find gree/jose HOT 5
- Tag for PHP 5.4 HOT 1
- signature validation
- Master Key Encryption failed
- Any plans to implement claims verification and additional signature types? HOT 2
- Documentation suggestion
- JWS(Signing issue)
- installation HOT 3
- Please update code for php 8.1.5 HOT 1
- Latest phpseclib is not compatible with this code
- It's not possible to determine $public_key_or_secret by the 'kid' header value. HOT 2
- Doesn't support draft 7+ encryption requirements (A128CBC-HS256 and A256CBC-HS512) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jose-php.