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

Fix #905 : la fonction mcrypt_cbc est obsolète. #913

Closed
wants to merge 1 commit into from

Conversation

nikrou
Copy link
Contributor

@nikrou nikrou commented Jan 14, 2020

No description provided.

@macintoshplus
Copy link
Member

Fix #905

@@ -5,7 +5,7 @@

$comptaFact = new Facture($bdd);

$ref = trim(mcrypt_cbc (MCRYPT_TripleDES, 'PaiementFactureAFUP_AFUP', base64_decode(str_replace(' ', '+', urldecode($_GET['ref']))), MCRYPT_DECRYPT, '@PaiFact'));
$ref = $comptaFact->decryptLink(str_replace(' ', '+', urldecode($_GET['ref'])));
Copy link
Member

Choose a reason for hiding this comment

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

Le fallback sur l'ancien chiffrement est nécessaire pour conserver le fonctionnement des liens existants

Suggested change
$ref = $comptaFact->decryptLink(str_replace(' ', '+', urldecode($_GET['ref'])));
$ref = $comptaFact->decryptLink(str_replace(' ', '+', urldecode($_GET['ref'])));
if ($ref === false) {
$ref = trim(mcrypt_cbc (MCRYPT_TripleDES, 'PaiementFactureAFUP_AFUP', base64_decode(str_replace(' ', '+', urldecode($_GET['ref']))), MCRYPT_DECRYPT, '@PaiFact'));
}

{
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->cipher));

return base64_encode(openssl_encrypt($data, $this->cipher, $this->key, 0, $iv) . '::' . $iv);
Copy link
Member

Choose a reason for hiding this comment

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

Utilisation de URLBase64 car la valeur est utilisée dans une URL.

Suggested change
return base64_encode(openssl_encrypt($data, $this->cipher, $this->key, 0, $iv) . '::' . $iv);
return str_replace(['+','/'] , ['-','_'], base64_encode(openssl_encrypt($data, $this->cipher, $this->key, 0, $iv) . '::' . $iv));


public function decryptLink($data)
{
list($encrypted_data, $iv) = explode('::', base64_decode($data));
Copy link
Member

Choose a reason for hiding this comment

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

Gestion des erreurs liées à base64_decode et l'absence du séparateur

Suggested change
list($encrypted_data, $iv) = explode('::', base64_decode($data));
$decoded = base64_decode(str_replace(['-', '_'], ['+', '/'],$data));
if ($decoded === false || strpos($decoded, '::') === false) {
return false;
}
list($encrypted_data, $iv) = explode('::', $decoded);

@@ -9,6 +9,9 @@

class Facture
{
private $cipher = 'aes-256-gcm';
Copy link
Member

Choose a reason for hiding this comment

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

L'algo aes-256-gcm demande l'ajout de l'argument tag pour le chiffrement et déchiffrement. Pour éviter sont utilisation, il est possible d'utiliser aes-256-cbc.

Suggested change
private $cipher = 'aes-256-gcm';
private $cipher = 'aes-256-cbc';

@agallou
Copy link
Member

agallou commented Nov 22, 2023

Cela a été traité dans cette PR #1356 je ferme donc celle. Merci pour l'alerte et la première version.

@agallou agallou closed this Nov 22, 2023
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.

3 participants