简体   繁体   中英

AWS signature problems with IE

i'm currently working on file upload directly to S3. The user should have the ability to drag a file/files to a defined part of the site. Then a request to my server starts and generates signatures for the uploaded file/files

At first i request valid signatures which are calculated from the server. The generated signature(s) looks like this:

 [
  {
  "success_action_status":"<status>successful</status>",
  "formAction":"http://[mybucket].s3.amazonaws.com",
  "Policy":"ew0KICJleHBpcmF0aW9uIjoiMjAxMy0xMi0xMVQwODoxMjo1Ni4wMDBaIiwN\nCiAiY29uZGl0aW9ucyI6DQogWw0KICB7DQogICAiYnVja2V0IjoiaHJ3b3Jr\ncy1kb2N1bWVudHMtZGV2ZWxvcG1lbnQtc2ltIg0KICB9LA0KICB7DQogICAi\nYWNsIjoiYnVja2V0LW93bmVyLWZ1bGwtY29udHJvbCINCiAgfSwNCiAgWyAi\nc3RhcnRzLXdpdGgiLCIka2V5IiwiIl0sDQogIFsgInN0YXJ0cy13aXRoIiwi\nJENvbnRlbnQtVHlwZSIsIiJdLA0KICB7DQogICAic3VjY2Vzc19hY3Rpb25f\nc3RhdHVzIjoiPHN0YXR1cz5zdWNjZXNzZnVsPC9zdGF0dXM+Ig0KICB9DQog\nXQ0KfQ0K",
  "signature":"z8vyDsAYzfFTW6bzrwMUrh/34Uc=",
  "doumentId":"6X7TP57L8S8",
  "acl":"bucket-owner-full-control",
  "Content-Type":"application/pdf",
  "AWSAccessKeyId":"AKIAIK67BLP7RUKG354A",
  "key":"14250053/6X7TP57L8S8.pdf"
  }
 ]

After this i start to upload the file to s3 using xmlhtttprequest. Here i recently ran into the problem that success_action_redirect doesn't work with such requests, therefore you have to use the success_action_status. After i recieve the success_action_status message after uploading, i have to notify my server that, the upload of the currently uploaded file was successful with a last request.

The problem i have is: This works very well in Chrome, Opera and Firefox. But it fails with IE 10. I can also drag the file to the document-part for uploading and the request to my server is called (and appended to the file-object). In the console i then see a CORS preflight request with a 200 response. So this also works. After this, at the begin of uploading the files Internet Explorer 10 gets stuck and recieves a 403 from amazon aws

 <?xml version="1.0" encoding="UTF-8"?>
 <Error>
  <Code>SignatureDoesNotMatch</Code>
  <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
  <StringToSignBytes>65 77 30 4b 49 43 4a 6c 65 48 42 70 63 6d 46 30 61 57 39 75 49 6a 6f 69 4d 6a 41 78 4d 79 30 78 4d 69 30 78 4d 56 51 77 4f 44 6f 78 4d 6a 6f 31 4e 69 34 77 4d 44 42 61 49 69 77 4e 0a 43 69 41 69 59 32 39 75 5a 47 6c 30 61 57 39 75 63 79 49 36 44 51 6f 67 57 77 30 4b 49 43 42 37 44 51 6f 67 49 43 41 69 59 6e 56 6a 61 32 56 30 49 6a 6f 69 61 48 4a 33 62 33 4a 72 0a 63 79 31 6b 62 32 4e 31 62 57 56 75 64 48 4d 74 5a 47 56 32 5a 57 78 76 63 47 31 6c 62 6e 51 74 63 32 6c 74 49 67 30 4b 49 43 42 39 4c 41 30 4b 49 43 42 37 44 51 6f 67 49 43 41 69 0a 59 57 4e 73 49 6a 6f 69 59 6e 56 6a 61 32 56 30 4c 57 39 33 62 6d 56 79 4c 57 5a 31 62 47 77 74 59 32 39 75 64 48 4a 76 62 43 49 4e 43 69 41 67 66 53 77 4e 43 69 41 67 57 79 41 69 0a 63 33 52 68 63 6e 52 7a 4c 58 64 70 64 47 67 69 4c 43 49 6b 61 32 56 35 49 69 77 69 49 6c 30 73 44 51 6f 67 49 46 73 67 49 6e 4e 30 59 58 4a 30 63 79 31 33 61 58 52 6f 49 69 77 69 0a 4a 45 4e 76 62 6e 52 6c 62 6e 51 74 56 48 6c 77 5a 53 49 73 49 69 4a 64 4c 41 30 4b 49 43 42 37 44 51 6f 67 49 43 41 69 63 33 56 6a 59 32 56 7a 63 31 39 68 59 33 52 70 62 32 35 66 0a 63 33 52 68 64 48 56 7a 49 6a 6f 69 50 48 4e 30 59 58 52 31 63 7a 35 7a 64 57 4e 6a 5a 58 4e 7a 5a 6e 56 73 50 43 39 7a 64 47 46 30 64 58 4d 2b 49 67 30 4b 49 43 42 39 44 51 6f 67 0a 58 51 30 4b 66 51 30 4b</StringToSignBytes>
  <RequestId>92D4E69C75687EB6</RequestId>
  <HostId>27jK6m/fqwKxHIj77uVNP+WNjnIGGIP+tIGrRYwHD1MwDmf3kz5saN7a7KL5e1fA</HostId>
  <SignatureProvided>z8vyDsAYzfFTW6bzrwMUrh/34Uc=</SignatureProvided>
  <StringToSign>ew0KICJleHBpcmF0aW9uIjoiMjAxMy0xMi0xMVQwODoxMjo1Ni4wMDBaIiwN
   CiAiY29uZGl0aW9ucyI6DQogWw0KICB7DQogICAiYnVja2V0IjoiaHJ3b3Jr
   cy1kb2N1bWVudHMtZGV2ZWxvcG1lbnQtc2ltIg0KICB9LA0KICB7DQogICAi
   YWNsIjoiYnVja2V0LW93bmVyLWZ1bGwtY29udHJvbCINCiAgfSwNCiAgWyAi
   c3RhcnRzLXdpdGgiLCIka2V5IiwiIl0sDQogIFsgInN0YXJ0cy13aXRoIiwi
   JENvbnRlbnQtVHlwZSIsIiJdLA0KICB7DQogICAic3VjY2Vzc19hY3Rpb25f
   c3RhdHVzIjoiPHN0YXR1cz5zdWNjZXNzZnVsPC9zdGF0dXM+Ig0KICB9DQog
   XQ0KfQ0K</StringToSign>
  <AWSAccessKeyId>AKIAIK67BLP7RUKG354A</AWSAccessKeyId>
 </Error>

I'm wondering why this works perfectly in firefox and chrome, but fails in Internet Explorer. Because of creating the signature on my server and is in both cases (Chrome/IE) the "same" response, the signature should match.

Has anybody an idea why IE fails and chrome/firefox works perfectly? I can also post my requests and responses from amazon if needed.

After refacturing the whole ajax-call without using FormData (using How to send multipart/form-data form content by ajax (no jquery)? ) the error was present too, using fiddler2 there were no differences in the request. But, at last i've found the bug, using fiddler and the hex-output.

Firefox and Chrome replace the "\\n" in the json response to "\\r\\n", Internet Explorer not. replacing by default the "\\n" with "\\r\\n" worked and wsa the solution. Now it works fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM