Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curve encryption does not encode or decode "command" flag #696

Closed
jagori opened this issue Mar 14, 2019 · 6 comments
Closed

Curve encryption does not encode or decode "command" flag #696

jagori opened this issue Mar 14, 2019 · 6 comments

Comments

@jagori
Copy link
Contributor

jagori commented Mar 14, 2019

I am working on a project using jeromq v0.5.0 as the REQ side of a REQ-REP communication. The symptom is that the connection heartbeating added in v0.5.0 works when Curve is disabled, but not when it is enabled.

This seems to be related to flags: in zmq.io.mechanism.curve.CurveServerMechanism and CurveClientMechanism, there are encode and decode methods called by zmq.io.StreamEngine. These four methods set or read the 0x1/MORE flag but no others. This means that ping/pong messages, which use the 0x2/COMMAND flag, don't read or set that flag and the message gets treated as data instead.

Between two Java endpoints, the flag is never set in the data that goes over the socket. Between Java and C, it depends on the message source: when the Java side is the source, the command flag is not set when sending so the receiver raises an alarm and drops the message. When the C side is the source, the flag is present in the encoded message as received but not passed onto the decoded message, so the StreamEngine doesn't recognize it as a command and drops the message.

I was able to get it working between two Java endpoints, as well as between Java and C, by adding code to those four methods to read or set the 0x2/COMMAND flag similarly to the 0x1/MORE flag that's already there. I'm not familiar enough with the other flags to know if this is the right way to address the issue or if there's more to it, but it does get heartbeats working.

@fredoboulo
Copy link
Contributor

Oops, that was forgotten. Thanks for catching that!

Libzmq seems to agree with you: https://github.com/zeromq/libzmq/blob/master/src/curve_mechanism_base.cpp#L63
https://github.com/zeromq/libzmq/blob/master/src/curve_mechanism_base.cpp#L162

Could you make a PR for that?

@trevorbernard
Copy link
Member

trevorbernard commented Mar 18, 2019

I was looking into this issue I just noticed that JeroMQ isn't following spec... e.g.
https://github.com/zeromq/libzmq/blob/master/src/curve_mechanism_base.cpp#L89
https://github.com/zeromq/jeromq/blob/master/src/main/java/zmq/io/mechanism/curve/CurveServerMechanism.java#L155

The commands aren't prefixed with the size of the command. I don't see how this would work cross implementations.

https://rfc.zeromq.org/spec:26/CURVEZMQ/

@jagori
Copy link
Contributor Author

jagori commented Mar 18, 2019

I'm not sure what to make of that. I see the difference you're pointing out, but I can confirm that with the command flag added as per the commit above, my jeromq endpoint was able to successfully respond to heartbeat pings from an endpoint using libzmq.

@fredoboulo
Copy link
Contributor

The commands are prefixed by the length. It's done in Msgs class.

@trevorbernard
Copy link
Member

The appendData and Msgs.put methods are poorly named. I can see that being a source of hard to track down bugs

@fredoboulo
Copy link
Contributor

Everyone is free to propose a PR!
It's in internal classes of the project, so there should not be any side effects for the users.

fredoboulo added a commit to fredoboulo/jeromq that referenced this issue Mar 19, 2019
Solution: create a new method in Msg to allow put short string prefixed
with length.

Fixes zeromq#696
fredoboulo added a commit to fredoboulo/jeromq that referenced this issue Mar 19, 2019
Solution: create a new method in Msg to allow put short string prefixed
with length.

Fixes zeromq#696
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants