我正在努力将ColdFusion 2016应用程序连接到Microsoft Azure blob storage,似乎无法正确验证身份。
以下是我收到的错误:
<Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. RequestId:9aed89ad-0001-00b8-6fd8-ecc48c000000 Time:2016-08-02T16:07:42.9046123Z</Message><AuthenticationErrorDetail>The Date header in the request is incorrect.</AuthenticationErrorDetail></Error>
HTTP / 1.1 403服务器无法验证请求。确保 正确形成授权标头的值,包括 签名。内容长度:419内容类型:application / xml服务器: Microsoft-HTTPAPI / 2.0 x-ms-request-id: 9aed89ad-0001-00b8-6fd8-ecc48c000000日期:星期二,2016年8月2日16:07:42 GMT连接:关闭
这是我在容器中列出blob的代码:
<!--- The key is copied directly from the Azure portal interface. --->
<cfset theKey = "fxIciOymaQ2OAcc1g2M...BwQRxNPtEzmwHAyx6J6pw==" />
<cfset requestMethod = "GET" />
<cfset utcDate = dateConvert("local2UTC",now()) />
<cfset xmsDate = dateFormat(utcDate,"ddd, d mmm yyyy") & " " & timeFormat(utcDate,"HH:mm:ss") & " GMT" />
<cfset xmsVersion = "2015-12-11" />
<cfset canonicalizedHeaders = "x-ms-date:#xmsDate#\nx-ms-version:#xmsVersion#\n" />
<cfset canonicalizedResource = "/coldfusion/slao\ncomp:list\ninclude:metadata,snapshots,uncommittedblobs\nrestype:container\n" />
<cfset stringToSign = "#requestMethod#\n\n\n\n\n\n\n\n\n\n\n\n#canonicalizedHeaders##canonicalizedResource#" />
<cfset x = replace(stringToSign,"\n","#chr(13)##chr(10)#","all") />
<cfset y = hmac(x,tmp,"HmacSHA256","utf-8") />
<cfset requestSignature = toBase64(binaryDecode(y,"hex")) />
<cfhttp method="#requestMethod#" url="https://coldfusion.blob.core.windows.net/slao?restype=container&comp=list&include=snapshots&include=metadata&include=uncommittedblobs" result="requestResult">
<cfhttpparam type="header" name="Authorization" value="SharedKey coldfusion:#requestSignature#">
<cfhttpparam type="header" name="x-ms-date" value="#xmsDate#">
<cfhttpparam type="header" name="x-ms-version" value="#xmsVersion#">
</cfhttp>
错误表明日期不好。作为测试,我复制了错误响应中显示的日期和时间戳并重新运行我的程序 - 同样的错误。我花了很多时间尝试自己研究这个,但我没有在这方面取得任何进展。我也尝试过Fiddler,当然,我也遇到了同样的错误。
有谁看到问题可能是什么?任何想法将不胜感激......
沙龙
答案 0 :(得分:5)
我想在2016年ColdFusion上分享我的最终工作计划:
<!---
Copied directly from portal.azure for this storage account.
The copied value is in base64 format.
--->
<cfset theKey = "fxIciOymaQ2OAcc1g2M...BwQRxNPtEzmwHAyx6J6pw==" />
<!---
Explicitly decode the base64 key into binary, so that hmac()
does not use the supplied "encoding", ie utf-8 to decode it
(because that produces the wrong result).
--->
<cfset binaryKey = binaryDecode(theKey, "base64")>
<cfset requestMethod = "GET" />
<cfset utcDate = dateConvert("local2UTC",now()) />
<cfset xmsDate = dateFormat(utcDate,"ddd, dd mmm yyyy") & " " & timeFormat(utcDate,"HH:mm:ss") & " GMT" />
<cfset xmsVersion = "2015-12-11" />
<cfset canonicalizedHeaders = "x-ms-date:#xmsDate#\nx-ms-version:#xmsVersion#\n" />
<cfset canonicalizedResource = "/coldfusion/slao\ncomp:list\ninclude:metadata,snapshots,uncommittedblobs\nrestype:container" />
<cfset stringToSign = "#requestMethod#\n\n\n\n\n\n\n\n\n\n\n\n#canonicalizedHeaders##canonicalizedResource#" />
<cfset x = replace(stringToSign,"\n","#chr(10)#","all") />
<cfset y = hmac(x,binaryKey,"HmacSHA256","utf-8") />
<cfset requestSignature = toBase64(binaryDecode(y,"hex")) />
<cfhttp method="#requestMethod#" url="https://coldfusion.blob.core.windows.net/slao?restype=container&comp=list&include=snapshots&include=metadata&include=uncommittedblobs" result="requestResult">
<cfhttpparam type="header" name="Authorization" value="SharedKey coldfusion:#requestSignature#">
<cfhttpparam type="header" name="x-ms-date" value="#xmsDate#">
<cfhttpparam type="header" name="x-ms-version" value="#xmsVersion#">
</cfhttp>
<cfdump var="#requestResult#" expand="yes" />
非常感谢! 沙龙