mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-02-01 07:19:24 +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:
parent
50a399e682
commit
1312835102
@ -1443,13 +1443,20 @@ sub decodePayload($$) {
|
|||||||
sub decrypt($) {
|
sub decrypt($) {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $encrypted = shift;
|
my $encrypted = shift;
|
||||||
|
my $padding = 2;
|
||||||
|
|
||||||
# see 4.2.5.3, page 26
|
# see 4.2.5.3, page 26
|
||||||
my $initVector = substr($self->{msg},2,8);
|
my $initVector = substr($self->{msg},2,8);
|
||||||
for (1..8) {
|
for (1..8) {
|
||||||
$initVector .= pack('C',$self->{access_no});
|
$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);
|
return $cipher->decrypt($encrypted, $self->{aeskey}, $initVector);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1817,6 +1824,7 @@ sub decodeApplicationLayer($) {
|
|||||||
|
|
||||||
if ($self->{aeskey}) {
|
if ($self->{aeskey}) {
|
||||||
if ($hasCBC) {
|
if ($hasCBC) {
|
||||||
|
#printf("encrypted payload %s\n", unpack("H*", substr($applicationlayer,$offset)));
|
||||||
$payload = $self->decrypt(substr($applicationlayer,$offset));
|
$payload = $self->decrypt(substr($applicationlayer,$offset));
|
||||||
#printf("decrypted payload %s\n", unpack("H*", $payload));
|
#printf("decrypted payload %s\n", unpack("H*", $payload));
|
||||||
if (unpack('n', $payload) == 0x2f2f) {
|
if (unpack('n', $payload) == 0x2f2f) {
|
||||||
|
Loading…
Reference in New Issue
Block a user