u9n / dlms-cosem

A Python library for DLMS/COSEM
Other
79 stars 39 forks source link

Get rid of cryptography dependency? #54

Closed astrand closed 2 years ago

astrand commented 2 years ago

As I understand it, European HAN energy meters (both according to Swedish, Norwegian, and Dutch standard) typically does not use encryption. Is it possible in any easy way to get rid of the cryptography dependency? This one in turn depends on quite a lot of other packages.

Krolken commented 2 years ago

No they are usually open, but some do use encryption if I remember correctly.

I really don't want to remove cryptography. It is an integral part in communicating using DLMS/COSEM. The P1 port companion standard is just a subset in the functionalities needed to fully communication with meters on the utility operator level, which is where our focus is. To have encryption as an extra would just lead to problems.

And I don't think there is a way in setup.py to define in extra_requires that a package should not be included.

´´´ pip install dlms-cosem[no-crypto]


would be a OK command but I don't know how that would be implemented.

If you are in control of your build environment I would just uninstall the packages you don't want after installing dlms-cosem.
astrand commented 2 years ago

Thanks for the rapid feedback. We are in control of the build environment (Yocto), and right now the package is actually built with "pip install --no-deps", so at that level, the dependency is not a problem. However, when trying "from dlms_cosem.protocol import xdlms" we get a traceback about missing cryptography module. For now, we are patching dlms_cosem/protocol/xdlms/init.py in order to solve this, but always nice to avoid patching.

We could consider shipping the cryptography module as well, but it does have a very long list o dependencies:

Depends: libc6 (>= 2.30), libcrypto1.1 (>= 1.1.1g), libpython3.7m1.0 (>= 3.7.7), libssl1.1 (>= 1.1.1g), python3-asn1crypto, python3-cffi, python3-idna, python3-numbers, python3-setuptools, python3-six, python3-threading

Some of these also requires other packages, for example a 5.8 MB large "cpp" package is required by python3-pycparser.

Krolken commented 2 years ago

OK. That error is because the xdlms packade will have the GeneralGlobalCipher APDU that imports dlms.security that has the deps.

Are you working from my example at: https://hanporten.se/norska/protokollet/ ?

You can just import directly from the file instead. That might solve it.

from dlms_cosem.protocol.xdlms.data_notification import DataNotification
Krolken commented 2 years ago

I'm closing this. If there is anything else just open it again.