Skip to content

Commit

Permalink
Fixed response sign verification in the GPWebPay driver using DIGEST1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibyx committed Feb 23, 2022
1 parent d47e6e3 commit 3ba69d5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### v0.23.1: 2022/02/23

Fixed signature verification in GPwebpay response.

### v0.23.0: 2022/02/11

GPwebpay driver fills `ORDERNUMBER` with the microtime (as int) because this value have to be always unique. For the
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The recommended way to install the library is to use [composer](http://getcompos

{
"require": {
"backbone/chaching": "0.23.0"
"backbone/chaching": "0.23.1"
}
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "backbone/chaching",
"type": "library",
"version": "0.23.0",
"version": "0.23.1",
"license": "MIT",
"description": "Universal payment library for banking services in Slovakia",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/Chaching/Chaching.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class Chaching
{
const VERSION = '0.22.1';
const VERSION = '0.23.1';

const CARDPAY = 'cardpay';
const SPOROPAY = 'sporopay';
Expand Down
23 changes: 16 additions & 7 deletions src/Chaching/Drivers/GPwebpay/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ public function __construct(Array $authorization, Array $attributes, Array $opti

$this->readonly_fields = [
'OPERATION', 'ORDERNUMBER', 'MERORDERNUM', 'MD', 'PRCODE',
'SRCODE', 'RESULTTEXT', 'DIGEST', 'DIGEST1'
'SRCODE', 'RESULTTEXT', 'DETAILS', 'USERPARAM1', 'ADDINFO',
'DIGEST', 'DIGEST1'
];

foreach ($this->readonly_fields as $field)
{
$this->fields[ $field ] = !empty($attributes[ $field ])
? $attributes[ $field ]
: NULL;
if(array_key_exists($field, $attributes))
{
$this->fields[ $field ] = $attributes[ $field ];
}
else
{
$this->fields[ $field ] = NULL;
}
}

$this->set_authorization($authorization);
Expand All @@ -54,11 +60,11 @@ public function __construct(Array $authorization, Array $attributes, Array $opti
*/
protected function validate()
{
if (!$this->verify($this->fields['DIGEST']))
if (!$this->verify($this->fields['DIGEST1']))
throw new \Chaching\Exceptions\InvalidResponseException(sprintf(
"Signature received as part of the response is incorrect (" .
"'%s'). If this persists contact the bank.",
$this->fields['DIGEST']
$this->fields['DIGEST1']
));

$this->variable_symbol = $this->fields['MERORDERNUM'] != NULL ? $this->fields['MERORDERNUM'] : $this->fields['ORDERNUMBER'];
Expand All @@ -73,10 +79,13 @@ protected function validate()
protected function verify($given_signature)
{
$signature_base = '';
$fields = array_slice($this->readonly_fields, 0, 7);
$fields = array_slice($this->readonly_fields, 0, 10);

foreach ($fields as $field)
{
if ($this->fields[ $field ] === NULL)
continue;

if (!empty($signature_base))
{
$signature_base .= '|';
Expand Down
4 changes: 2 additions & 2 deletions src/Chaching/Encryption/PemKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function verify($given_signature, $signature_base)
file_get_contents($this->authorization[ 1 ]['key'])
);

$signature = base64_encode($signature_base);
$result = openssl_verify($given_signature, $signature, $resource_id);
$given_signature = base64_decode($given_signature);
$result = openssl_verify($signature_base, $given_signature, $resource_id);

openssl_free_key($resource_id);

Expand Down

0 comments on commit 3ba69d5

Please sign in to comment.