2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-02-01 01:09:47 +00:00

WMBus: error correction for AES descryption (no padding if data length is multiple of block size)

git-svn-id: https://svn.fhem.de/fhem/trunk@17777 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
kaihs 2018-11-18 15:44:03 +00:00
parent 50a399e682
commit 1312835102

View File

@ -1443,13 +1443,20 @@ sub decodePayload($$) {
sub decrypt($) {
my $self = shift;
my $encrypted = shift;
my $padding = 2;
# see 4.2.5.3, page 26
my $initVector = substr($self->{msg},2,8);
for (1..8) {
$initVector .= pack('C',$self->{access_no});
}
my $cipher = Crypt::Mode::CBC->new('AES', 2);
if (length($encrypted)%16 == 0) {
# no padding if data length is multiple of blocksize
$padding = 0;
} else {
$padding = 2;
}
my $cipher = Crypt::Mode::CBC->new('AES', $padding);
return $cipher->decrypt($encrypted, $self->{aeskey}, $initVector);
}
@ -1817,6 +1824,7 @@ sub decodeApplicationLayer($) {
if ($self->{aeskey}) {
if ($hasCBC) {
#printf("encrypted payload %s\n", unpack("H*", substr($applicationlayer,$offset)));
$payload = $self->decrypt(substr($applicationlayer,$offset));
#printf("decrypted payload %s\n", unpack("H*", $payload));
if (unpack('n', $payload) == 0x2f2f) {