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

Bugfixes #1157

Merged
merged 15 commits into from
Aug 8, 2017
Merged

Bugfixes #1157

merged 15 commits into from
Aug 8, 2017

Conversation

rrran
Copy link

@rrran rrran commented Aug 3, 2017

Lots of PHPDOC fixes
Some method visibility fixes
Method signature fixes
And more

@@ -3086,7 +3086,7 @@ public function getSupportedVersions()
* @return bool
* @access private
*/
private function disconnect_helper($reason)
protected function disconnect_helper($reason)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please explain this?

Copy link
Author

@rrran rrran Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SFTP class extends SSH2 and overrides method disconnect_helper($reason), also it calls parent's method:

protected function disconnect_helper($reason)
    {
        $this->pwd = false;
        parent::disconnect_helper($reason);
    }

Parent's method was declared as private, so could not be called outside the class.
I changed it's visibility to protected.
Also I have to change visibility of the successor's method.

@@ -652,7 +652,7 @@ class SSH2
* @see self::_get_channel_packet()
* @access private
*/
private $curTimeout;
protected $curTimeout;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please minimize these changes to those that are required, since the phpdoc changes are bug fixes. :)

Copy link
Member

@terrafrost terrafrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the only reason this is needed is because of the ASN1::decodeLength. I did grep -r decodeLength . and it looks like it's not actually being used. ASN1::encodeLength is being used but not ASN1::decodeLength.

It looks like decodeLength ceased being used when I refactored the PKCS1/8 plugins in the master branch to facilitate re-use. At that point they used ASN1.php instead of having their own independent pseudo implementation of ASN1.

Overall, I'm thinking it'd probably just be better if decodeLength() was deleted

@@ -2796,7 +2797,7 @@ public function setEndDate($date)
*/
if (strtolower($date) == 'lifetime') {
$temp = '99991231235959Z';
$temp = chr(ASN1::TYPE_GENERALIZED_TIME) . Functions::encodeLength(strlen($temp)) . $temp;
$temp = chr(ASN1::TYPE_GENERALIZED_TIME) . ASN1::encodeLength(strlen($temp)) . $temp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! I'll have to add a unit test for this

{
return $this->getExtensionHelper($id, $cert);
return $this->getExtensionHelper($id, $cert, $path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a unit test will need to be written for this too. This is only called with a third parameter by getRevokedCertificateExtension.

getExtensions (plural vs singular) probably ought to be updated similarly, as well, and then getRevokedCertificateExtensions updated to call getExtensions instead of getExtensionsHelper.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, spaces ought to be added before and after the = in the $path=null bit. PSR-1/2 do appear to discuss this but in areas where those standards do not provide clarity I'd say, as a general rule of thumb, the PEAR standards apply. Quoting https://pear.php.net/manual/en/standards.funcalls.php ,

As displayed above, there should be one space on either side of an equals sign used to assign the return value of a function to a variable.

idk how well the phpseclib codebase actually conforms to these standards but, anyway, I can take care of this when I merge.

Copy link
Member

@terrafrost terrafrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation behind this change?

edit: it doesn't seem like this comment is linked to the specific commit so I made a new comment from where the specific change I'm referring to is more clear.

@@ -80,7 +80,7 @@ public static function isValidEngine()
* @param string $class
* @return \phpseclib\Math\BigInteger\Engines\PHP
*/
protected static function powModHelper(PHP $x, PHP $e, PHP $n, $class)
public static function powModHelper(PHP $x, PHP $e, PHP $n, $class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the motivation behind this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File PHP.php
method:

protected function powModInner(PHP $e, PHP $n)
{
try {
$class = static::$modexpEngine;
return $class::powModHelper($this, $e, $n, static::class);
} catch (\Exception $err) {
return PHP\DefaultEngine::powModHelper($this, $e, $n, static::class);
}
}

As you can see here's a static call which can't be performed if the powModHelper method is not public

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Engines/PHP/Base extends Engines/PHP so visibility shouldn't be an issue. Indeed, if visibility were an issue then one would think that changing the visibility from protected to private wouldn't break any unit tests but it does:

https://travis-ci.org/terrafrost/phpseclib/jobs/261813738

@@ -60,7 +60,7 @@ public static function isValidEngine()
* @param string $class
* @return \phpseclib\Math\BigInteger\Engines\BCMath
*/
protected static function powModHelper(BCMath $x, BCMath $e, BCMath $n, $class)
public static function powModHelper(BCMath $x, BCMath $e, BCMath $n, $class)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made a similar change in f314f97#r131527744 . I don't understand the motivation for that change nor do I understand it for this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File PHP.php
method:

protected function powModInner(PHP $e, PHP $n)
{
try {
$class = static::$modexpEngine;
return $class::powModHelper($this, $e, $n, static::class);
} catch (\Exception $err) {
return PHP\DefaultEngine::powModHelper($this, $e, $n, static::class);
}
}

As you can see here's a static call which can't be performed if the powModHelper method is not public

@terrafrost
Copy link
Member

terrafrost commented Aug 5, 2017

The changes look good to me!

I guess I have a few things I need to do:

  1. Delete ASN1::decodeLength per Bugfixes #1157 (review)
  2. Write a unit test for X509::setEndDate per Bugfixes #1157 (comment)
  3. Write a unit test for X509::getRevokedCertificateExtension and make some changes in X509::getExtensions and getRevokedCertificateExtensions per Bugfixes #1157 (comment)
  4. There's a call to $this->disconnectHepler in SSH2.php - that should be changed to $this->disconnect_helper.

A few questions I have that it'd be cool if you could answer or do:

  1. Why did you change the visibility of powModHelper from protected to public in both the PHP and BCMath engines per f314f97#r131527744 and 6f36c49#r131527812?

Thanks!

* @access public
* @return mixed
*/
public function getExtension($id, $cert = null)
public function getExtension($id, $cert = null, $path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be $path = null. As is not all the calls to getExtension have a third parameter:

$issuerAltName = $this->getExtension('id-ce-subjectAltName', $issuer->currentCert);

Also, that's how it's defined with getExtensionHelper:

    private function getExtensionHelper($id, $cert = null, $path = null)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind this - it looks like you fixed this specific issue with eb21fb2

@terrafrost
Copy link
Member

The changes I mention that I'd do have been done here:

https://github.com/terrafrost/phpseclib/tree/pre-1157-changes

This branch has failing unit tests that you're changes should fix. Just LMK about the powModHelper thing and then I'll merge.

Thanks!

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

Successfully merging this pull request may close these issues.

None yet

3 participants