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

Clients should accept messages secured by an expired SecurityToken #404

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

svanharmelen
Copy link
Contributor

@svanharmelen svanharmelen commented Nov 9, 2024

I encountered a bug where an incoming message would fail with an invalid signature error. After quite some debugging I noticed this only occurred when the message was received just a few milliseconds after a security channel renewal.

After careful inspection it turned out that the message was still encrypted (which is according to spec) with the remote keys of the old security channel, but the client tried to decrypt and validate the message with the renewed keys.

According to the specs clients should accept messages secured by an expired SecurityToken for up to 25 % of the token lifetime (see https://reference.opcfoundation.org/Core/Part4/v105/docs/5.5.2 for more details), so I added a bit of logic to store the last 5 used remote keys and choose which one to use based on the token ID in the security header.

After making these changes and testing again against the same OPC UA server the issue did not occur again (while it occurred multiple times per hour before this fix was implemented) so this seems like a nice little improvement making the package a little bit more complaint.

Copy link
Contributor

@einarmo einarmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clearly something we need, but I'm not entirely sold on the approach, see comments.

lib/src/core/comms/secure_channel.rs Outdated Show resolved Hide resolved
lib/src/core/comms/secure_channel.rs Outdated Show resolved Hide resolved
@svanharmelen
Copy link
Contributor Author

svanharmelen commented Nov 12, 2024

Updated the PR... It maybe just a little bit more involved, but it follows the spec for 100% this way.

Note that I removed the token_has_expired method as it contained a bug (used the lifetime as seconds instead of milliseconds) and wasn't used by any of the client or server code.

@svanharmelen svanharmelen force-pushed the fix/channel-renewals branch 3 times, most recently from db60783 to e0ea0ee Compare November 12, 2024 11:11
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.

2 participants