Skip to content

Commit

Permalink
HMAC-SHA-256 signature, alphanum keys allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Sep 3, 2020
1 parent debaff6 commit 47c08b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.3.2

- Alphanumeric secret keys are now allowed.
- Signature is now crypted using HMAC-SHA-256 instead of the deprecated SHA-1 algorithm.

# 1.3.1

- Email management fixes
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.3.1</version>
<version>1.3.2</version>
<authors>
<author>
<name>Franck Allimant</name>
Expand Down
31 changes: 16 additions & 15 deletions Payzen/PayzenApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,11 +870,6 @@ function setRedirectEnabled($enabled)
*/
function setCertificate($key, $mode)
{
// Check format
if (!preg_match('#\d{16}#', $key)) {
return false;
}

if ($mode == 'TEST') {
$this->keyTest = $key;
} elseif ($mode == 'PRODUCTION') {
Expand Down Expand Up @@ -1015,18 +1010,24 @@ function _generateSignatureFromFields($fields = null, $hashed = true)
* @access public
* @static
*/
function sign($parameters, $key, $hashed = true)
function sign($params, $key, $hashed = true)
{
$signContent = "";
ksort($parameters);
foreach ($parameters as $name => $value) {
if (substr($name, 0, 5) == 'vads_') {
$signContent .= $value . '+';
$contenu_signature = "";

ksort($params);

foreach ($params as $nom => $valeur) {
//Récupération des champs vads_
if (substr($nom, 0, 5) === 'vads_') {
//Concaténation avec le séparateur "+"
$contenu_signature .= $valeur."+";
}
}
$signContent .= $key;
$sign = $hashed ? sha1($signContent) : $signContent;
return $sign;

$contenu_signature .= $key;

//Encodage base64 de la chaine chiffrée avec l'algorithme HMAC-SHA-256
return base64_encode(hash_hmac('sha256', $contenu_signature, $key, true));
}

// **************************************
Expand Down Expand Up @@ -1206,4 +1207,4 @@ function uncharm($potentiallyMagicallyQuotedData)
}
return $sane;
}
}
}

0 comments on commit 47c08b4

Please sign in to comment.