Skip to content

Commit 3bbb1c7

Browse files
authored
Merge pull request #10408 from apraovjr/fix-SASToken-dateformat
Fix SAS Token date format
2 parents 5d466aa + f2fe70b commit 3bbb1c7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/EventHub/EventHub/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fix for issue 10301 : Fix the SAS Token date format
2122

2223
## Version 1.4.0
2324
* Fixed miscellaneous typos across module

src/EventHub/EventHub/Cmdlets/AuthorizationRule/NewAzureEventhubAuthorizationRuleSASToken.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public override void ExecuteCmdlet()
5555
{
5656
LocalResourceIdentifier identifier = new LocalResourceIdentifier(AuthorizationRuleId);
5757
string resourceUri = string.Empty, strPolicyName = string.Empty, sakey = string.Empty;
58+
DateTime EpochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
5859

5960
PSListKeysAttributes listkeys;
6061
if (identifier.ParentResource1 != null)
@@ -90,10 +91,12 @@ public override void ExecuteCmdlet()
9091
}
9192
}
9293

93-
string stringToSign = StartTime.HasValue ? StartTime.ToString() + "\n" + System.Web.HttpUtility.UrlEncode(resourceUri) + "\n" + ExpiryTime.ToString() : System.Web.HttpUtility.UrlEncode(resourceUri) + "\n" + ExpiryTime.ToString();
94+
TimeSpan secondsFromBaseTime = ExpiryTime.Value.Subtract(EpochTime);
95+
long seconds = Convert.ToInt64(secondsFromBaseTime.TotalSeconds, CultureInfo.InvariantCulture);
96+
string stringToSign = StartTime.HasValue ? StartTime.ToString() + "\n" + System.Web.HttpUtility.UrlEncode(resourceUri) + "\n" + seconds : System.Web.HttpUtility.UrlEncode(resourceUri) + "\n" + seconds;
9497
HMACSHA256 hmac = new HMACSHA256(System.Text.Encoding.UTF8.GetBytes(sakey));
9598
var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign)));
96-
string sasToken = String.Format(CultureInfo.InvariantCulture, "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}", HttpUtility.UrlEncode(resourceUri), HttpUtility.UrlEncode(signature), ExpiryTime, KeyType);
99+
string sasToken = String.Format(CultureInfo.InvariantCulture, "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}", HttpUtility.UrlEncode(resourceUri), HttpUtility.UrlEncode(signature), seconds, KeyType);
97100
PSSharedAccessSignatureAttributes psSastoken = new PSSharedAccessSignatureAttributes(sasToken);
98101
WriteObject(psSastoken, true);
99102

0 commit comments

Comments
 (0)