Skip to content

Conversation

jltorresm
Copy link
Contributor

@jltorresm jltorresm commented Dec 17, 2023

The PR to standardize HMAC implementation (#1473) introduced an issue in generating service bus queue SAS tokens.

The standard implementation in azure_core::auth::hmac assumes the signing key is the base64::decoded of the key passed as an argument:

let key = base64::decode(key)?;

On the service_bus/queue_client side it is used like the following, which means it'll be decoded inside the hmac function.

let sig = hmac_sha256(&str_to_sign, signing_key)?;

However, from the version before the merge, I gathered the key needs to be used verbatim as bytes:

let sig = hmac::sign(signing_key, str_to_sign.as_bytes()); // shared access key

Tested this using this example and confirmed that the fix works. If this is not the direction / style of fix you want, I'd be happy to rework it to make it more suitable.

I also wanted to add a few unit tests for the SAS token generation but this would need a time-mocking library so I wanted to check before changing the code further.

@demoray
Copy link
Contributor

demoray commented Dec 18, 2023

Thanks for the fix.

@demoray demoray merged commit c999ef3 into Azure:main Dec 18, 2023
@jltorresm jltorresm deleted the jltorresm/sbq-sas branch December 19, 2023 11:23
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