fix: Trims SQN string passed to strictHex to make sure it doesn't have any non-printable characters #163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
strictHex
method is used to normalize SQN hex - it needs to be exactly 12-characters long in order to produce a 6-element byte slice.In some cases, the SQN hex returned by the UDR client contains a new line at the end of the valid SQN hex string. As a result,
strictHex
assumes that the string length is 13 characters and "normalizes" it by cutting of the first digit. This produces an invalid, 11-char long output, which causes authentication error:err encoding/hex: invalid byte: U+000A
.This PR addresses this problem by trimming all non-printable chars off the input string before
strictHex
assesses the length of the input.Some logs:
Initial state, sequenceNumber assigned to the subscriber is
0001863958fe
, UE authenticates for the first time:Authentication was successful, the SQN has been increased. So far, so good.
Now the gNB fails (CU and DU are restarted) and the UE needs to reattach:
UDM fetches the SQN hex from UDR:
0001863958ff
, but because it's returned with a new line at the end,strictHex
thinks it's 13-chars long. So it cuts one character and returns001863958ff
. New line gets trimmed as well, becausestrictHex
creates a slice. New SQN hex is 11-chars long, so it can't produce a 6-element byte slice. As a result we geterr encoding/hex: invalid byte: U+000A
.After applying a fix from this PR we get: