dnp3 icon indicating copy to clipboard operation
dnp3 copied to clipboard

Support for reading and writing zero-length OctetStrings

Open justinstenning opened this issue 1 year ago • 3 comments

We will be working on a migration from OpenDNP3 to stepfunc/dnp3 C# bindings soon. One of the customisations we had to make within OpenDNP3 was support for reading and writing OctetStrings, including zero-length ones.

We understand that zero-length OctetStrings is probably a non-standard implementation, so perhaps this could live behind some kind of enableNonStandardFeatures flag?

As discussed previously, our team are happy to help with implementation and can assist with testing C# bindings if required.

justinstenning avatar Dec 04 '24 23:12 justinstenning

I think that writing them could always be allowed in the master. There's a security issue with reading them. The encoding for a zero-length string is nothing but a header, e.g. you can say "this packets contains group 110 variation 0 start: 0 stop: 65535" and it only takes ~5 bytes to encode 65K values.... repeat this to fill an ASDU and it's like a ZIP bomb if the master makes a callback for each value:

https://www.cisa.gov/news-events/ics-advisories/icsa-14-149-01

It was kinda vague in the spec before I pointed out how problematic this is, then the committee "clarified" that 0-length strings weren't allowed b/c variation had always been reserved for requests to mean "send whatever your default variation is".

All of that said, I just think we need a configuration option to enable parsing 0-length strings on the master, and we can always allow writing them.

jadamcrain avatar Dec 04 '24 23:12 jadamcrain

@justinstenning I've begin working on this feature in #379.

On the parsing side of things, I have a global setting enabled them to be parsed in responses.

One thing I just realized is that if we always allow writing them, the decoder will by always need to be able to parse them... That's fine, I'm not concerned about the parsing of these objects if the stack is sending them, it's only parsing them during reception that we need to make this a feature that users opt into.

I'll do some more on this later in the week.

jadamcrain avatar Apr 30 '25 18:04 jadamcrain

In the latest commits, I made it so that decoding ASDU written by the library is always done liberally, i.e. allowing zero-length strings. This will make it so the decoding works regardless of the input parsers accept.

I think the only left to do now is to make it so that zero-length strings are constructible.

jadamcrain avatar May 01 '25 17:05 jadamcrain

The outstation can now transmit group 110/111 var 0, i.e. zero length strings can now be constructed.

There's no support for writing octet strings from the master or receiving written strings in the outstation, but there are no longer any parser limitations w.r.t to zero-length strings.

I will close this ticket as soon as #379 is merged and we can add another ticket for WRITE support on both sides.

jadamcrain avatar May 08 '25 17:05 jadamcrain

Completed in https://github.com/stepfunc/dnp3/pull/379

jadamcrain avatar May 08 '25 17:05 jadamcrain