Modify MQTT binding to add AES decryption?

I have received AES encrypted messages from a nodeMCU and I would like to get the decrypted message displayed on openHAB. How should I go about doing this? It would be possible to send the variables required for decrypting (iv and cipher) to the openhab subscriber and then modify the java code to add AES decryption and return the decrypted text to openhab right? How hard would it be? Where are the binding files located? Any existing solutions?

You can decrypt it in rules. I have used bouncy castle for decryption. I would use a language you know like python, java or similar.

Please be careful. Posting the same message over and over in rapid succession across lots of different threads looks a whole lot like a spam bot and is likely to get you heuristically banned. At the moment four of your posts have already been reported as spam. I’ve prevented your account from being blocked for now.

See the Developer Guide and Developer Appendix section of the official docs to get started. Developer Guide | openHAB

If it was an add-on (transformation), it could be used in different places. Sounds like a useful addition.

sorry, thanks a lot for your help

I have decrypted it and published locally using a nodejs script that is a mqtt client as well, but it would be nice if it was possible to directly decrypt on openhab. I know other languages but not java, although I think it wouldn’t be hard for this basic implementation right

I am new to openhab I am not sure what rules are…

In that case, you‘d better start reading the docs and get familiar with the openHAB concept, before fiddling around.

I read some of it…but wouldn’t it be better to modify the binding itself and change the payload value to the decrypted message instead of using rules?

Perhaps, but if you don’t even know what rules are, you are very likely to:

  • become incredibly frustrated trying to understand the binding code in the first place
  • break something in your attempt to modify the code and not understand why it broke
  • not understand that there might be a more appropriate way to implement it besides just adding it to the binding (see Jan’s post above mentioning it might more appropriately be implemented as a transformation)

Ahh I see, using transformations seems like a better idea…I’m really sorry to ask this but how should I go about doing that? I’ve read some of the documentation but how/where would I add the decrypting code for the transformation? Isn’t transformation like a format change? Thanks a lot

A decrypting transformation is not existing atm, it would need to be developed. Easiest and quickest start would be to create a rule for what you want.

And please, don‘t ask us to write that rule for you, that‘s not how this community works.

Read/learn about rules, search for examples and start writing it. If you have issues, post what you have done and we are happy to help.

And please, don‘t ask us to write that rule for you

I won’t, I was just asking about the general flow/concept/how things will work together. Could the transformation use a python or nodejs script to get the decrypted value? The rule would just call the transformation when message arrives right?

That‘s why I asked you to read and understand the docs.

A transformation like @J-N-K wrote is an installable addon developed in Java.

What you can do is write a rule in one of your preferred available languages or addons like node-js or HABapp automation, which takes the encrypted value of your item, decrypt it and update another item decrypted information as state value.

I just want to level set here. openHAB is not small. There is tens of thousands (hundreds perhaps?) of lines of code split across 44 separate repositories with a complex build and deployment system. And that doesn’t even include the many many third party libraries, frameworks, and such that OH runs on.

One does not simply come to openHAB and start creating/modifying add-ons without understanding basic openHAB concepts (and Java).

No one is saying you can’t do this eventually, but with your current knowledge and understanding level, you’re gonna have a hard time if you try to jump in right now.

Spend a little bit of time with the docs and your openHAB config. Build and configure some. Get a good feel for how the data flows from an end device through a Thing’s Channels and to an Item. Spend some time figuring out what you can do with an Item. Then dig into how to set up a development and build environment so you can code, compile and debug your new add-on, modifications to an existing add-on, or to the core.

Item, Thing, Channel, Link, Action, Transformation, Rule, Script, Condition, … these are all terms of art in openHAB. They are concepts and have a mean specific to openHAB. These all work together in specific ways and having even just a basic understanding of these concepts will be vital to your success if you want to try to create and add-on or modify an existing one. That’s why we keep mentioning going back to the docs.

It takes a big lift to write an OH add-on.

So what would it mean to have an AES Transformation? It means the development of a new add-on, written in Java, that takes in a string, decrypts that string, and outputs the decrypted string. So far so good. Once you have it as a transformation, you can use it :

  • as part of the configuration for Channels that support transformations (some add-ons even support chaining transformations so you could decrypt and then JSONPATH to extract a piece of data all on the one config line)
  • in the transform Profile which supports transforming the output from a Channel using any of the installed Transformation add-ons as the data passes from the Channel to the Item
  • in a rule with the transform Action
  • in the UI to transform the raw state of an Item to something more human friendly

The above is the sort of thing that you would get by reading the docs, at a minimum the concepts section and the getting started tutorial. If not there, from spending more time configuring and using openHAB.

2 Likes