Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@
composer.phar
composer.lock
vendor

### PHPUnit ###
# Covers PHPUnit
# Reference: https://phpunit.de/

# Generated files
.phpunit.result.cache
.phpunit.cache

# PHPUnit
/app/phpunit.xml
/phpunit.xml

# Build data
/build/
11 changes: 7 additions & 4 deletions src/Eher/OAuth/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

namespace Eher\OAuth;

class Consumer {
class Consumer
{
public $key;
public $secret;
public $callback_url;

function __construct($key, $secret, $callback_url=NULL) {
function __construct($key, $secret, $callback_url = NULL)
{
$this->key = $key;
$this->secret = $secret;
$this->callback_url = $callback_url;
}

function __toString() {
function __toString()
{
return "Consumer[key=$this->key,secret=$this->secret]";
}
}

30 changes: 21 additions & 9 deletions src/Eher/OAuth/RsaSha1.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
* specification.
* - Chapter 9.3 ("RSA-SHA1")
*/
abstract class RsaSha1 extends SignatureMethod {
public function get_name() {
abstract class RsaSha1 extends SignatureMethod
{
public function get_name()
{
return "RSA-SHA1";
}

Expand All @@ -29,7 +31,8 @@ protected abstract function fetch_public_cert(&$request);
// Either way should return a string representation of the certificate
protected abstract function fetch_private_cert(&$request);

public function build_signature($request, $consumer, $token) {
public function build_signature($request, $consumer, $token)
{
$base_string = $request->get_signature_base_string();
$request->base_string = $base_string;

Expand All @@ -40,15 +43,20 @@ public function build_signature($request, $consumer, $token) {
$privatekeyid = openssl_get_privatekey($cert);

// Sign using the key
$ok = openssl_sign($base_string, $signature, $privatekeyid);
openssl_sign($base_string, $signature, $privatekeyid);

// Release the key resource
openssl_free_key($privatekeyid);
if (PHP_MAJOR_VERSION < 8) {
// Release the key resource
openssl_free_key($privatekeyid);
} else {
unset($privatekeyid);
}

return base64_encode($signature);
}

public function check_signature($request, $consumer, $token, $signature) {
public function check_signature($request, $consumer, $token, $signature)
{
$decoded_sig = base64_decode($signature);

$base_string = $request->get_signature_base_string();
Expand All @@ -62,8 +70,12 @@ public function check_signature($request, $consumer, $token, $signature) {
// Check the computed signature against the one passed in the query
$ok = openssl_verify($base_string, $decoded_sig, $publickeyid);

// Release the key resource
openssl_free_key($publickeyid);
if (PHP_MAJOR_VERSION < 8) {
// Release the key resource
openssl_free_key($publickeyid);
} else {
unset($privatekeyid);
}

return $ok == 1;
}
Expand Down