@@ -55,10 +55,11 @@ public override void ExecuteCmdlet()
55
55
{
56
56
LocalResourceIdentifier identifier = new LocalResourceIdentifier ( AuthorizationRuleId ) ;
57
57
string resourceUri = string . Empty , strPolicyName = string . Empty , sakey = string . Empty ;
58
+ DateTime EpochTime = new DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , 0 , DateTimeKind . Utc ) ;
58
59
59
60
PSListKeysAttributes listkeys ;
60
61
if ( identifier . ParentResource1 != null && AuthorizationRuleId . Contains ( "topics" ) )
61
- {
62
+ {
62
63
listkeys = Client . GetTopicKey ( identifier . ResourceGroupName , identifier . ParentResource , identifier . ParentResource1 , identifier . ResourceName ) ;
63
64
}
64
65
else if ( identifier . ParentResource1 != null && AuthorizationRuleId . Contains ( "queues" ) )
@@ -94,13 +95,24 @@ public override void ExecuteCmdlet()
94
95
}
95
96
}
96
97
97
- string stringToSign = StartTime . HasValue ? StartTime . ToString ( ) + "\n " + System . Web . HttpUtility . UrlEncode ( resourceUri ) + "\n " + ExpiryTime . ToString ( ) : System . Web . HttpUtility . UrlEncode ( resourceUri ) + "\n " + ExpiryTime . ToString ( ) ;
98
+ var encodedResourceUri = System . Web . HttpUtility . UrlEncode ( resourceUri ) ;
99
+ var expiry = Convert . ToInt64 ( ExpiryTime . Value . Subtract ( EpochTime ) . TotalSeconds , CultureInfo . InvariantCulture ) ;
100
+ var stringToSign = StartTime == null ? "" : Convert . ToInt64 ( StartTime . Value . Subtract ( EpochTime ) . TotalSeconds , CultureInfo . InvariantCulture ) + "\n " ;
101
+ stringToSign = stringToSign + encodedResourceUri + "\n " + expiry ;
102
+
98
103
HMACSHA256 hmac = new HMACSHA256 ( System . Text . Encoding . UTF8 . GetBytes ( sakey ) ) ;
99
104
var signature = Convert . ToBase64String ( hmac . ComputeHash ( Encoding . UTF8 . GetBytes ( stringToSign ) ) ) ;
100
- string sasToken = String . Format ( CultureInfo . InvariantCulture , "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}" , HttpUtility . UrlEncode ( resourceUri ) , HttpUtility . UrlEncode ( signature ) , ExpiryTime , KeyType ) ;
105
+
106
+ string sasToken = String . Format ( CultureInfo . InvariantCulture ,
107
+ "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}" ,
108
+ HttpUtility . UrlEncode ( resourceUri ) ,
109
+ HttpUtility . UrlEncode ( signature ) ,
110
+ ExpiryTime ,
111
+ KeyType ) ;
112
+
101
113
PSSharedAccessSignatureAttributes psSastoken = new PSSharedAccessSignatureAttributes ( sasToken ) ;
102
- WriteObject ( psSastoken , true ) ;
103
114
115
+ WriteObject ( psSastoken , true ) ;
104
116
}
105
117
catch ( Management . ServiceBus . Models . ErrorResponseException ex )
106
118
{
0 commit comments