很多服務(wù)在做驗證的時候都會用到SharedAccessSignature,例如Azure Service Bus, Azure IoT Hub等。今天趟了回大坑,這里分享出來,希望對你有所幫助。
SharedAccessSignature的格式如下:
SharedAccessSignature sig={signature-string}&se={expiry}&skn={policyName}&sr={URL-encoded-resourceURI}
因此,憑直覺針對不同的服務(wù)只要正確指定policyname,resourceURI 就可以計算出相應(yīng)的SAS。但實際上,對于不同的服務(wù),他們對如何利用秘鑰生成signature會存在細微的差別。如果沒有注意到這個細微的差別,會讓你抓狂兩小時。
下面拿Azure Service Bus和Azure IoT Hub進行舉例,如果后續(xù)我碰到Azure 其他服務(wù)有類似的問題。我會更新此文。
首先是Azure IoT Hub, 針對如何生成signature 官方文檔說明如下:
{signature} :An HMAC-SHA256 signature string of the form: {URL-encoded-resourceURI} + "\n" + expiry. Important: The key is decoded from base64 and used as key to perform the HMAC-SHA256 computation.
再來看Azure Service Bus 的官方文檔說明:
The signature for the SAS token is computed using the HMAC-SHA256 hash of a string-to-sign with the PrimaryKey property of an authorization rule.
延伸閱讀
- ssh框架 2016-09-30
- 阿里移動安全 [無線安全]玩轉(zhuǎn)無線電——不安全的藍牙鎖 2017-07-26
- 消息隊列NetMQ 原理分析4-Socket、Session、Option和Pipe 2024-03-26
- Selective Search for Object Recognition 論文筆記【圖片目標分割】 2017-07-26
- 詞向量-LRWE模型-更好地識別反義詞同義詞 2017-07-26
- 從棧不平衡問題 理解 calling convention 2017-07-26
- php imagemagick 處理 圖片剪切、壓縮、合并、插入文本、背景色透明 2017-07-26
- Swift實現(xiàn)JSON轉(zhuǎn)Model - HandyJSON使用講解 2017-07-26
- 阿里移動安全 Android端惡意鎖屏勒索應(yīng)用分析 2017-07-26
- 集合結(jié)合數(shù)據(jù)結(jié)構(gòu)來看看(二) 2017-07-26