From cbde82bdfc2452504c77b77bdd42ffff709abc53 Mon Sep 17 00:00:00 2001 From: Xavier Date: Thu, 27 Jun 2019 22:12:57 +0200 Subject: [PATCH] Fix HMAC verif --- lemonldap-ng-common/lib/Lemonldap/NG/Common/Crypto.pm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Crypto.pm b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Crypto.pm index 2202b8817..553838434 100644 --- a/lemonldap-ng-common/lib/Lemonldap/NG/Common/Crypto.pm +++ b/lemonldap-ng-common/lib/Lemonldap/NG/Common/Crypto.pm @@ -82,7 +82,8 @@ sub encrypt { eval { $data = encode_base64( - $iv . $hmac . $self->_getCipher->set_iv($iv)->encrypt($data), '' ); + $iv . $self->_getCipher->set_iv($iv)->encrypt( $hmac . $data ), + '' ); }; if ($@) { $msg = "Crypt::Rijndael error : $@"; @@ -108,14 +109,15 @@ sub decrypt { $data = decode_base64($data); my $iv; $iv = bytes::substr( $data, 0, 16 ); - my $hmac = bytes::substr( $data, 16, 16 ); - $data = bytes::substr( $data, 32 ); + $data = bytes::substr( $data, 16 ); eval { $data = $self->_getCipher->set_iv($iv)->decrypt($data); }; if ($@) { $msg = "Crypt::Rijndael error : $@"; return undef; } + my $hmac = bytes::substr( $data, 0, 16 ); + $data = bytes::substr( $data, 16 ); if ( md5($data) ne $hmac ) { $msg = "Bad MAC"; return undef;