Skip to content

Commit d4d9de9

Browse files
committed
Queue User Delegation SAS (Azure#50347)
1 parent 71cb6ab commit d4d9de9

30 files changed

+1177
-31
lines changed

sdk/storage/Azure.Storage.Blobs/src/Azure.Storage.Blobs.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@
106106
<Compile Include="$(AzureStorageSharedSources)\StorageBearerTokenChallengeAuthorizationPolicy.cs" LinkBase="Shared" />
107107
<Compile Include="$(AzureStorageSharedSources)ISupportsTenantIdChallenges.cs" LinkBase="Shared" />
108108
<Compile Include="$(AzureStorageSharedSources)AzureSasCredentialSynchronousPolicy.cs" LinkBase="Shared" />
109+
<Compile Include="..\..\Azure.Storage.Common\src\Shared\SasQueryParametersExtensions.cs" Link="Shared\Sas\KeySasQueryParametersExtensions.cs" />
109110
</ItemGroup>
110111
</Project>

sdk/storage/Azure.Storage.Blobs/src/BlobServiceClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,12 +1611,12 @@ private async Task<Response<UserDelegationKey>> GetUserDelegationKeyInternal(
16111611

16121612
if (startsOn.HasValue && startsOn.Value.Offset != TimeSpan.Zero)
16131613
{
1614-
throw BlobErrors.InvalidDateTimeUtc(nameof(startsOn));
1614+
throw Errors.InvalidDateTimeUtc(nameof(startsOn));
16151615
}
16161616

16171617
if (expiresOn.Offset != TimeSpan.Zero)
16181618
{
1619-
throw BlobErrors.InvalidDateTimeUtc(nameof(expiresOn));
1619+
throw Errors.InvalidDateTimeUtc(nameof(expiresOn));
16201620
}
16211621

16221622
KeyInfo keyInfo = new KeyInfo(expiresOn.ToString(Constants.Iso8601Format, CultureInfo.InvariantCulture))

sdk/storage/Azure.Storage.Blobs/src/Sas/BlobSasBuilder.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ public BlobSasQueryParameters ToSasQueryParameters(UserDelegationKey userDelegat
463463

464464
stringToSign = ToStringToSign(userDelegationKey, accountName);
465465

466-
string signature = ComputeHMACSHA256(userDelegationKey.Value, stringToSign);
466+
string signature = SasExtensions.ComputeHMACSHA256(userDelegationKey.Value, stringToSign);
467467

468468
BlobSasQueryParameters p = new BlobSasQueryParameters(
469469
version: Version,
@@ -546,22 +546,6 @@ private static string GetCanonicalName(string account, string containerName, str
546546
? $"/blob/{account}/{containerName}/{blobName.Replace("\\", "/")}"
547547
: $"/blob/{account}/{containerName}";
548548

549-
/// <summary>
550-
/// ComputeHMACSHA256 generates a base-64 hash signature string for an
551-
/// HTTP request or for a SAS.
552-
/// </summary>
553-
/// <param name="userDelegationKeyValue">
554-
/// A <see cref="UserDelegationKey.Value"/> used to sign with a key
555-
/// representing AD credentials.
556-
/// </param>
557-
/// <param name="message">The message to sign.</param>
558-
/// <returns>The signed message.</returns>
559-
private static string ComputeHMACSHA256(string userDelegationKeyValue, string message) =>
560-
Convert.ToBase64String(
561-
new HMACSHA256(
562-
Convert.FromBase64String(userDelegationKeyValue))
563-
.ComputeHash(Encoding.UTF8.GetBytes(message)));
564-
565549
/// <summary>
566550
/// Ensure the <see cref="BlobSasBuilder"/>'s properties are in a
567551
/// consistent state.

sdk/storage/Azure.Storage.Blobs/src/Shared/BlobErrors.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ public static InvalidOperationException BlobOrContainerMissing(string leaseClien
2020
string blobContainerClient) =>
2121
new InvalidOperationException($"{leaseClient} requires either a {blobBaseClient} or {blobContainerClient}");
2222

23-
public static ArgumentException InvalidDateTimeUtc(string dateTime) =>
24-
new ArgumentException($"{dateTime} must be UTC");
25-
2623
internal static void VerifyHttpsCustomerProvidedKey(Uri uri, CustomerProvidedKey? customerProvidedKey)
2724
{
2825
if (customerProvidedKey.HasValue && !string.Equals(uri.Scheme, Constants.Https, StringComparison.OrdinalIgnoreCase))

sdk/storage/Azure.Storage.Common/src/Shared/Constants.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ internal static class Constants
2525
/// Gets the default service version to use when building shared access
2626
/// signatures.
2727
/// </summary>
28-
public const string DefaultSasVersion = "2026-02-06";
28+
// TODO fix this
29+
public const string DefaultSasVersion = "2025-07-05";
2930

3031
/// <summary>
3132
/// Max download range size while requesting a transactional hash.
@@ -435,6 +436,8 @@ internal static class Queue
435436
public const string UriSubDomain = "queue";
436437

437438
public const string QueueTraitsMetadata = "metadata";
439+
440+
public const string Name = "Queue";
438441
}
439442

440443
/// <summary>
@@ -631,6 +634,7 @@ internal static class Resource
631634
public const string File = "f";
632635
public const string Share = "s";
633636
public const string Directory = "d";
637+
public const string Queue = "q";
634638
}
635639

636640
internal static class AccountServices

sdk/storage/Azure.Storage.Common/src/Shared/Errors.Clients.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public static ArgumentOutOfRangeException MustBeGreaterThanValueOrEqualToOtherVa
3535
long value1)
3636
=> new ArgumentOutOfRangeException(paramName, $"Value must be greater than {value0} or equal to {value1}");
3737

38+
public static ArgumentException InvalidDateTimeUtc(string dateTime) =>
39+
new ArgumentException($"{dateTime} must be UTC");
40+
3841
public static ArgumentException StreamMustBeReadable(string paramName)
3942
=> new ArgumentException("Stream must be readable", paramName);
4043

sdk/storage/Azure.Storage.Common/src/Shared/SasExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.Net;
88
using System.Runtime.CompilerServices;
9+
using System.Security.Cryptography;
910
using System.Text;
1011

1112
namespace Azure.Storage.Sas
@@ -238,5 +239,21 @@ internal static string ValidateAndSanitizeRawPermissions(string permissions,
238239

239240
return stringBuilder.ToString();
240241
}
242+
243+
/// <summary>
244+
/// ComputeHMACSHA256 generates a base-64 hash signature string for an
245+
/// HTTP request or for a SAS.
246+
/// </summary>
247+
/// <param name="userDelegationKeyValue">
248+
/// A UserDelegationKey.Value used to sign with a key
249+
/// representing AD credentials.
250+
/// </param>
251+
/// <param name="message">The message to sign.</param>
252+
/// <returns>The signed message.</returns>
253+
internal static string ComputeHMACSHA256(string userDelegationKeyValue, string message) =>
254+
Convert.ToBase64String(
255+
new HMACSHA256(
256+
Convert.FromBase64String(userDelegationKeyValue))
257+
.ComputeHash(Encoding.UTF8.GetBytes(message)));
241258
}
242259
}

sdk/storage/Azure.Storage.Blobs/src/Sas/SasQueryParametersExtensions.cs renamed to sdk/storage/Azure.Storage.Common/src/Shared/SasQueryParametersExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ internal static void ParseKeyProperties(
2626
BlobSasQueryParameters
2727
#elif DataLakeSDK
2828
DataLakeSasQueryParameters
29+
#elif QueueSDK
30+
QueueSasQueryParameters
2931
#endif
3032
parameters,
3133
IDictionary<string, string> values)

sdk/storage/Azure.Storage.Files.DataLake/src/Azure.Storage.Files.DataLake.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<Compile Include="$(AzureCoreSharedSources)XmlWriterExtensions.cs" LinkBase="SharedCore" />
3737
</ItemGroup>
3838
<ItemGroup>
39-
<Compile Include="..\..\Azure.Storage.Blobs\src\Sas\SasQueryParametersExtensions.cs" Link="Shared\Sas\KeySasQueryParametersExtensions.cs" />
39+
<Compile Include="..\..\Azure.Storage.Common\src\Shared\SasQueryParametersExtensions.cs" Link="Shared\Sas\KeySasQueryParametersExtensions.cs" />
4040
<Compile Include="$(AzureStorageSharedSources)AggregatingProgressIncrementer.cs" LinkBase="Shared" />
4141
<Compile Include="$(AzureStorageSharedSources)BufferExtensions.cs" LinkBase="Shared" />
4242
<Compile Include="$(AzureStorageSharedSources)ChecksumCalculatingStream.cs" LinkBase="Shared" />

sdk/storage/Azure.Storage.Queues/src/Azure.Storage.Queues.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,7 @@
7373
<Compile Include="$(AzureStorageSharedSources)ISupportsTenantIdChallenges.cs" LinkBase="Shared" />
7474
<Compile Include="$(AzureStorageSharedSources)AzureSasCredentialSynchronousPolicy.cs" LinkBase="Shared" />
7575
<Compile Include="$(AzureStorageSharedSources)SyncAsyncEventHandlerExtensions.cs" LinkBase="Shared" />
76+
<Compile Include="$(AzureStorageSharedSources)UserDelegationKeyProperties.cs" LinkBase="Shared" />
77+
<Compile Include="..\..\Azure.Storage.Common\src\Shared\SasQueryParametersExtensions.cs" Link="Shared\Sas\KeySasQueryParametersExtensions.cs" />
7678
</ItemGroup>
7779
</Project>

0 commit comments

Comments
 (0)