Skip to content

feat: let the application decorate the outbound Logon - #354

Open
fraVlaca wants to merge 1 commit into
Validus-Risk-Management:mainfrom
fraVlaca:feat/logon-decorator
Open

fraVlaca wants to merge 1 commit into
Validus-Risk-Management:mainfrom
fraVlaca:feat/logon-decorator

Conversation

@fraVlaca

Copy link
Copy Markdown

Problem

Some FIX venues authenticate in the Logon itself: the initiator must add credentials such as Username(553) and Password(554), or an HMAC signature over header fields (for example SendingTime, MsgSeqNum, SenderCompID and TargetCompID) carried in RawDataLength(95)/RawData(96). The signature depends on the final MsgSeqNum and SendingTime, so it can only be computed once the engine has built the Logon. Today the Logon is built from configuration alone and there is no hook to add these fields.

Change

  • Application::decorate_logon(&self, logon: &mut Message) -> Result<(), LogonDecorationError>, a synchronous method with a default that leaves the Logon unchanged, so existing applications are unaffected.
  • It is called for every outbound Logon after the standard header fields (34/49/52/56) and the Logon's own fields are set, and before the message is encoded, persisted and sent.
  • Returning an error refuses the Logon: nothing is persisted or sent and no sequence number is consumed, so a Logon that cannot be signed (for example because a credential is unavailable) is never sent without its credentials. The session then behaves as if the counterparty had not answered: logon timeout, then reconnect. The error surfaces as SendError::LogonRefused / an internal LogonRefused send error.
  • Internally, generate_message is split into build_message (header plus body, unencoded) and the encode step, and SessionCtx::prepare_logon shares the increment-then-persist tail with prepare_message. Sequence-number and store semantics are unchanged for every other message.

Tests

  • test_logon_is_decorated_by_application: the decorator reads the header's MsgSeqNum and adds Password(554); the counterparty receives the decorated Logon and the session becomes active.
  • test_logon_refused_by_application_is_not_sent: a refusing decorator leaves the session in AwaitingLogon with the next sender sequence number still 1, and the counterparty is disconnected at the logon timeout without ever receiving a message.

The fake application gains a logon_decorator_fn builder option for these tests.

I could not build this workspace locally, so I am relying on CI for the compile, clippy and test run.

Note on logging

The writer logs every outbound message at debug level, so credentials added by a decorator appear in debug logs. We redact Password, Username and RawData in our own deployment; if you would like that upstream, I am happy to follow up with a separate PR for a configurable list of tags to mask in message logging.

This contribution is offered under the project's MIT licence.

Add Application::decorate_logon, called for every outbound Logon after the
standard header fields and the Logon's own fields are set, and before the
message is encoded, persisted and sent. Counterparties that authenticate in
the Logon (Username/Password, or a signature over the header fields in
RawData) can add those fields here.

An error refuses the Logon: nothing is persisted or sent and no sequence
number is consumed, so a Logon that cannot be authenticated is never sent
without its credentials.
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

Successfully merging this pull request may close these issues.

1 participant