Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update validatePhpseclib() Method for phpseclib3 Compatibility #2

Open
samex opened this issue Sep 21, 2023 · 0 comments
Open

Update validatePhpseclib() Method for phpseclib3 Compatibility #2

samex opened this issue Sep 21, 2023 · 0 comments

Comments

@samex
Copy link

samex commented Sep 21, 2023

Hello,

I noticed that the validatePhpseclib() method in /Creativestyle/AmazonCheckout/Model/Debug.php is incompatible with the latest phpseclib3 version installed via Composer.

Current Code (Line 285) :

 public function validatePhpseclib()
    {
        try {
            if (class_exists('Crypt_RSA', false)) {
                $rsa = new Crypt_RSA();
            } elseif (class_exists('\phpseclib\Crypt\RSA', true)) {
                $rsa = new \phpseclib\Crypt\RSA();
            } else {
                return false;
            }

            $rsa->setHash(AmazonPayV2_Client::HASH_ALGORITHM);
            $rsa->setMGFHash(AmazonPayV2_Client::HASH_ALGORITHM);
            $rsa->setSaltLength(20);

            $rsa->loadKey($this->_getDummyPrivateKey());

            if (empty($rsa->modulus) || empty($rsa->exponent)) {
                return false;
            }

        } catch (Exception $e) {
            return false;
        }

        return true;
    }

Issue:

Instantiating the RSA class directly results in a fatal error since the class is abstract in phpseclib3.

Suggested Fix:

    public function validatePhpseclib()
    {
        try {
            if (class_exists('\phpseclib3\Crypt\PublicKeyLoader', true)) {
                $rsa = \phpseclib3\Crypt\PublicKeyLoader::load($this->_getDummyPrivateKey());
            } else {
                return false;
            }
    
            $privateKeyString = $rsa->toString('PKCS1');
            $publicKeyString = $rsa->getPublicKey()->toString('PKCS1');
            if (empty($privateKeyString) || empty($publicKeyString)) {
                return false;
            }
    
        } catch (\Exception $e) {
            return false;
        }
    
        return true;
    }

This update simplifies the validation and ensures compatibility with the newer phpseclib3.

Thank you for considering this change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant