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

RSA-based and SHA-256-involving signature methods #194

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rpuch
Copy link

@rpuch rpuch commented Jun 8, 2017

  • added support for the following signature methods: RSA-SHA1, RSA-SHA256, HMAC-SHA256 (the third and second methods are non-standard extensions)

RSA-SHA1 is a standard signature method defined by OAuth 1.0a. It is nice to have it implemented.

As for RSA-SHA256, it is non-standard, but now, when SHA1 is compromised in practice, RSA-SHA1 does not seem to provide enough security. Hence RSA-SHA256 may be useful for clients and servers that will to use asymmetric signatures and not suffer from a weak signature algorithm.

HMAC-SHA1 does not seem to be compromised, but HMAC-SHA256 (again, a non-standard signature method) support was added for completeness.

- added support for the following signature methods: RSA-SHA1, RSA-SHA256, HMAC-SHA256 (the third and second methods are non-standard extensions)
tmhOAuth.php Outdated
* @return binary signature
*/
private function sign_with_rsa($algorithm) {
openssl_sign($this->request_settings['basestring'], $signature, $this->config['private_key_pem'], $algorithm);
Copy link
Owner

Choose a reason for hiding this comment

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

thinking this might need a function_exists check on openssl_sign.

Copy link
Author

Choose a reason for hiding this comment

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

Added a check for whether 'openssl_sign' function exists. If not, an exception is thrown.

tmhOAuth.php Outdated
$signature = $this->sign_with_rsa('sha1');
break;
case 'RSA-SHA256':
$signature = $this->sign_with_rsa('sha256');
Copy link
Owner

Choose a reason for hiding this comment

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

i know 'sha256' is supported but what about using OPENSSL_ALGO_SHA256 instead?

Copy link
Author

Choose a reason for hiding this comment

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

Replaced 'sha256' with OPENSSL_ALGO_SHA256

tmhOAuth.php Outdated
$signature = $this->sign_with_hmac('sha256');
break;
case 'RSA-SHA1':
$signature = $this->sign_with_rsa('sha1');
Copy link
Owner

Choose a reason for hiding this comment

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

i know 'sha1' is supported but what about using OPENSSL_ALGO_SHA1 instead?

Copy link
Author

Choose a reason for hiding this comment

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

Replaced 'sha1' with OPENSSL_ALGO_SHA1

tmhOAuth.php Outdated
@@ -45,6 +45,9 @@ public function reconfigure($config=array()) {
'token' => '',
'secret' => '',

// RSA private key (for RSA-SHA1 and RSA-SHA256 methods)
'private_key_pem' => '',
Copy link
Owner

Choose a reason for hiding this comment

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

openssl_sign is a messy function as it overloads the types that can be used for the key and algorithm variables.
it's possible to send a resource instead of a string as the private_key_pem but the implementation you are using assumes it's string. wanna call that out in the comment - that if used this is expecting a string representation of a private key and not a file resource?

Copy link
Author

Choose a reason for hiding this comment

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

A clarifying comment added

tmhOAuth.php Outdated
* @return binary signature
*/
private function sign_with_rsa($algorithm) {
openssl_sign($this->request_settings['basestring'], $signature, $this->config['private_key_pem'], $algorithm);
Copy link
Owner

Choose a reason for hiding this comment

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

thanks for contributing this, love it. just a couple of thoughts on improvements before a pull it in.
also - wanna bump the version number (0.8.5) and date?

Copy link
Author

Choose a reason for hiding this comment

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

Bumped version and date

@rpuch
Copy link
Author

rpuch commented Jun 9, 2017

Thanks for your review! I'm currently working on implementing the changes you suggested.

@rpuch
Copy link
Author

rpuch commented Jun 9, 2017

I've made the changes you suggested. Also, openssl_sign error handling is added. Could you please review this change specifically? I'm not very familiar with Openssl extension in PHP.

@rpuch
Copy link
Author

rpuch commented Jun 23, 2017

Hi Matt! Is there anything missing from my side on this pull request?

@rpuch
Copy link
Author

rpuch commented Jun 21, 2020

@themattharris just bumping

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.

2 participants