Azure / azure-sdk-for-rust

This repository is for active development of the *unofficial* Azure SDK for Rust. This repository is *not* supported by the Azure SDK team.
MIT License
692 stars 237 forks source link

Fix service bus queue SAS token generation #1518

Closed jltorresm closed 8 months ago

jltorresm commented 8 months ago

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:

https://github.com/Azure/azure-sdk-for-rust/blob/a32e4115d42b426a054ba29e5c1563b5a0526d6c/sdk/core/src/hmac.rs#L12

On the service_bus/queue_client side it is used like the following, which means it'll be decoded inside the hmac function. https://github.com/Azure/azure-sdk-for-rust/blob/a32e4115d42b426a054ba29e5c1563b5a0526d6c/sdk/messaging_servicebus/src/service_bus/mod.rs#L67

However, from the version before the merge, I gathered the key needs to be used verbatim as bytes: https://github.com/Azure/azure-sdk-for-rust/blob/346330b6b8448d1d14228ec225e038282a39e0ce/sdk/messaging_servicebus/src/service_bus/mod.rs#L67

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 commented 8 months ago

Thanks for the fix.