2016-08-02 36 views
6

Pracuję nad połączeniem aplikacji ColdFusion 2016 z Microsoft Azure blob storage i wydaje się, że nie można uzyskać poprawności uwierzytelnienia.Uwierzytelnianie Microsoft Azure nie powiodło się i ColdFusion

Oto błąd Otrzymuję:

<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 Serwer nie może uwierzytelnić prośbę. Upewnij się, że wartość nagłówka autoryzacji została poprawnie utworzona, w tym podpis . Długość zawartości: 419 Content-Type: application/xml Server: Microsoft-HTTPAPI/2.0 x-ms-request-id: 9aed89ad-0001-00b8-6fd8-ecc48c000000 Data: wt., 02 sierpnia 2016 16:07:42 GMT Connection: close

Oto mój kod do listy plamy w pojemniku:

<!--- 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> 

błąd sugeruje złą datę. Jako test skopiowałem datownik i datę pokazane w odpowiedzi na błąd i ponownie uruchomiłem mój program - ten sam błąd. Spędziłem sporo czasu, próbując samodzielnie to zbadać, ale po prostu nie poczyniłem żadnych postępów w tej sprawie. Wypróbowałem także Fiddlera, ale oczywiście mam ten sam błąd.

Czy ktoś widzi, jaki może być problem? Wszelkie pomysły będą mile widziane ...

Sharon

+0

(Edytuj) Funkcja replace() może być częścią problemu. Zazwyczaj żądania HTTP * only * wykorzystują 'chr (10)' dla nowych linii. Więc chyba, że ​​API wyraźnie poleci ci użycie zarówno 'chr (13)' i 'chr (10)', tj. CR & LF, które mogą być przyczyną problemu. Spróbuj użyć tylko 'chr (10)' -. – Leigh

+0

Jak tu obliczasz zmienną 'tmp': '? –

+0

@Leigh, po pierwsze, dziękuję za poprawienie formatowania mojego komunikatu o błędzie! Ponadto usunąłem #chr (13) # i nadal otrzymuję ten sam błąd. – SharonG

Odpowiedz

5

Chciałem podzielić się moją ostateczną, program roboczy w ColdFusion 2016:

<!--- 
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" /> 

Wielkie dzięki! Sharon