From d60493ee45ead1f26c3aaf8d7d13146f038f080e Mon Sep 17 00:00:00 2001 From: weetmuts Date: Fri, 15 Mar 2019 15:06:45 +0100 Subject: [PATCH] Added warning when T1 telegram is encrypted and no key was supplied. --- README.md | 2 +- simulations/simulation_c1.txt | 2 +- simulations/simulation_t1.txt | 2 +- src/main.cc | 2 +- src/meter_apator162.cc | 3 +++ src/meter_iperl.cc | 3 +++ src/meter_multical302.cc | 3 +++ src/meter_omnipower.cc | 3 +++ src/meter_qcaloric.cc | 3 +++ src/meter_supercom587.cc | 3 +++ src/wmbus.cc | 20 ++++++++++++++++---- src/wmbus.h | 8 +++++++- 12 files changed, 45 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2bb9623..114cd89 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ Supported heat cost allocator: Qundis Q caloric (qcaloric) Work in progress: -Water meter Apator wt-wmbus-16-2 (apator162) +Water meter Apator at-wmbus-16-2 (apator162) Heat meter Kamstrup Multical 302 (multical302) Electricity meter Kamstrup Omnipower (omnipower) ``` diff --git a/simulations/simulation_c1.txt b/simulations/simulation_c1.txt index 995db30..fcdeddc 100644 --- a/simulations/simulation_c1.txt +++ b/simulations/simulation_c1.txt @@ -25,7 +25,7 @@ telegram=|25442D2C785634121b048D2093E13CBA20|0000790000000000000000000000000000| # Test Omnipower C1 telegrams -telegram=|1E442D2C0771941501027A|B300108504833B08340500| +telegram=|1E442D2C0771941501027AB3001080|04833B08340500| {"media":"electricity","meter":"omnipower","name":"MyElectricity","id":"15947107","total_kwh":341.000000,"current_kw":"0.000000","timestamp":"1111-11-11T11:11:11Z"} # Test QCaloric C1 telegrams diff --git a/simulations/simulation_t1.txt b/simulations/simulation_t1.txt index f364667..7045f17 100644 --- a/simulations/simulation_t1.txt +++ b/simulations/simulation_t1.txt @@ -8,7 +8,7 @@ telegram=|A244EE4D111111113C077AAC000000|0C1389490000426CE1F14C130000000082046C2 # Test iPerl T1 telegram, after decryption, its got 2f2f markers. -telegram=|1E44AE4C9956341268077A36001005|2F2F0413181E0000023B00002F2F2F2F| +telegram=|1E44AE4C9956341268077A36001000|2F2F0413181E0000023B00002F2F2F2F| {"media":"water","meter":"iperl","name":"MoreWater","id":"12345699","total_m3":7.704000,"max_flow_m3h":0.000000,"timestamp":"1111-11-11T11:11:11Z"} # Test iPerl T1 telegram not encrypted, no 2f2f markers. diff --git a/src/main.cc b/src/main.cc index dafc4c3..89c5c9e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -100,7 +100,7 @@ Supported heat cost allocator: Qundis Q caloric (qcaloric) Work in progress: -Water meter Apator at-wmbus-16-2 +Water meter Apator at-wmbus-16-2 (apator162) Heat meter Kamstrup Multical 302 (multical302) Electricity meter Kamstrup Omnipower (omnipower) )MANUAL"; diff --git a/src/meter_apator162.cc b/src/meter_apator162.cc index 2150422..0047a49 100644 --- a/src/meter_apator162.cc +++ b/src/meter_apator162.cc @@ -107,6 +107,9 @@ void MeterApator162::handleTelegram(Telegram *t) t->a_field_version); } + if (t->isEncrypted() && !useAes()) { + warning("(apator162) warning: telegram is encrypted but no key supplied!\n"); + } if (useAes()) { vector aeskey = key(); decryptMode5_AES_CBC(t, aeskey); diff --git a/src/meter_iperl.cc b/src/meter_iperl.cc index b106dbf..7f296cb 100644 --- a/src/meter_iperl.cc +++ b/src/meter_iperl.cc @@ -109,6 +109,9 @@ void MeterIperl::handleTelegram(Telegram *t) t->a_field_version); } + if (t->isEncrypted() && !useAes()) { + warning("(iperl) warning: telegram is encrypted but no key supplied!\n"); + } if (useAes()) { vector aeskey = key(); decryptMode5_AES_CBC(t, aeskey); diff --git a/src/meter_multical302.cc b/src/meter_multical302.cc index ff663cb..d3a309b 100644 --- a/src/meter_multical302.cc +++ b/src/meter_multical302.cc @@ -84,6 +84,9 @@ void MeterMultical302::handleTelegram(Telegram *t) { t->a_field_address[0], t->a_field_address[1], t->a_field_address[2], t->a_field_address[3]); + if (t->isEncrypted() && !useAes()) { + warning("(multical302) warning: telegram is encrypted but no key supplied!\n"); + } if (useAes()) { vector aeskey = key(); decryptMode1_AES_CTR(t, aeskey); diff --git a/src/meter_omnipower.cc b/src/meter_omnipower.cc index 65775c3..a07ae54 100644 --- a/src/meter_omnipower.cc +++ b/src/meter_omnipower.cc @@ -83,6 +83,9 @@ void MeterOmnipower::handleTelegram(Telegram *t) { manufacturerFlag(t->m_field).c_str(), t->a_field_version); } + if (t->isEncrypted() && !useAes()) { + warning("(omnipower) warning: telegram is encrypted but no key supplied!\n"); + } if (useAes()) { vector aeskey = key(); decryptMode5_AES_CBC(t, aeskey); diff --git a/src/meter_qcaloric.cc b/src/meter_qcaloric.cc index 8d3c18f..fdbc9bd 100644 --- a/src/meter_qcaloric.cc +++ b/src/meter_qcaloric.cc @@ -98,6 +98,9 @@ void MeterQCaloric::handleTelegram(Telegram *t) { manufacturerFlag(t->m_field).c_str(), t->a_field_version); } + if (t->isEncrypted() && !useAes()) { + warning("(qcaloric) warning: telegram is encrypted but no key supplied!\n"); + } if (useAes()) { vector aeskey = key(); decryptMode5_AES_CBC(t, aeskey); diff --git a/src/meter_supercom587.cc b/src/meter_supercom587.cc index 9bcfe52..a3c350e 100644 --- a/src/meter_supercom587.cc +++ b/src/meter_supercom587.cc @@ -107,6 +107,9 @@ void MeterSupercom587::handleTelegram(Telegram *t) t->a_field_version); } + if (t->isEncrypted() && !useAes()) { + warning("(supercom587) warning: telegram is encrypted but no key supplied!\n"); + } if (useAes()) { vector aeskey = key(); decryptMode5_AES_CBC(t, aeskey); diff --git a/src/wmbus.cc b/src/wmbus.cc index 18cb36d..d518c1e 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -351,7 +351,7 @@ void Telegram::addMoreExplanation(int pos, const char* fmt, ...) for (auto& p : explanations) { if (p.first == pos) { if (p.second[0] == '*') { - warning("(wmbus) warning! already added more explanations to offset %d!\n"); + debug("(wmbus) warning: already added more explanations to offset %d!\n"); } p.second = string("* ")+p.second+buf; found = true; @@ -359,7 +359,7 @@ void Telegram::addMoreExplanation(int pos, const char* fmt, ...) } if (!found) { - warning("(wmbus) warning! cannot find offset %d to add more explanation \"%s\"\n", pos, buf); + debug("(wmbus) warning: cannot find offset %d to add more explanation \"%s\"\n", pos, buf); } } @@ -403,8 +403,20 @@ void Telegram::parse(vector &frame) addExplanation(bytes, 1, "%02x acc", acc); status = frame[12]; addExplanation(bytes, 1, "%02x status ()", status); - configuration = frame[13]<<8 | frame[14]; - addExplanation(bytes, 2, "%02x%02x configuration ()", frame[13], frame[14]); + config_field = frame[13]<<8 | frame[14]; + string config_info = ""; + if (config_field & 0x0f) { + config_info += "encrypted "; + is_encrypted_ = true; + } + if ((config_field & 0x0f) == 0 || (config_field & 0x0f) == 0x05) { + if ((config_field & 0x0f) == 0x05) config_info += "AES_CBC "; + if (config_field & 0x80) config_info += "bidirectional "; + if (config_field & 0x40) config_info += "accessibility "; + if (config_field & 0x20) config_info += "synchronous "; + } + if (config_info.length() > 0) config_info.pop_back(); + addExplanation(bytes, 2, "%02x%02x config (%s)", frame[13], frame[14], config_info.c_str()); header_size = 4; } else if (ci_field == 0x8d || ci_field == 0x8c) { diff --git a/src/wmbus.h b/src/wmbus.h index f346c8c..5ff40f4 100644 --- a/src/wmbus.h +++ b/src/wmbus.h @@ -79,7 +79,7 @@ struct Telegram { // When ci_field==0x7a then there are 4 extra header bytes, short data header int acc {}; // 1 byte int status {}; // 1 byte - int configuration {}; // 2 bytes + int config_field {}; // 2 bytes // When ci_field==0x8d then there are 8 extra header bytes (ELL header) int cc_field {}; // 1 byte @@ -105,6 +105,12 @@ struct Telegram { void addExplanation(vector::iterator &bytes, int len, const char* fmt, ...); void addMoreExplanation(int pos, const char* fmt, ...); void explainParse(string intro, int from); + + bool isEncrypted() { return is_encrypted_; } + +private: + + bool is_encrypted_ {}; }; struct WMBus {