1

I'm trying to debug an wrong signature calculation when accessing Amazon S3 via JavaScript. AWS returns an XML document which includes:

 <StringToSignBytes>41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 35 30 34 32 35 54 31 36 32 33 30 36 5a 0a 32 30 31 35 30 34 32 35 2f 65 75 2d 77 65 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 35 33 32 62 61 65 37 62 39 35 66 65 61 62 36 38 66 38 65 32 31 65 39 66 33 62 33 64 61 66 32 34 32 66 63 34 64 35 38 65 34 37 39 61 37 39 37 65 38 33 34 36 62 34 30 38 34 33 39 61 30 37 34 65</StringToSignBytes>

I'm wondering how to read these bytes (I'm sitting over debugging for so long, I'm getting desperate I guess...).

Currently I'm playing around in Node, but with things like:

console.log(new Buffer([41 57 53 34]).toString("utf8")) 

I'm getting really nowhere.

Question:
Is there a way to convert these bytes into something which might help me understand or find out why my request failed.

Thanks

EDIT:
Tried Uint8Array, throw error (at least something):

function uintToString(uintArray) {
    var encodedString = String.fromCharCode.apply(null, uintArray),
        decodedString = decodeURIComponent(escape(atob(encodedString)));
    return decodedString;
}

var foo = "41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 35 30 34 32 35 54 31 36 32 33 30 36 5a 0a 32 30 31 35 30 34 32 35 2f 65 75 2d 77 65 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 35 33 32 62 61 65 37 62 39 35 66 65 61 62 36 38 66 38 65 32 31 65 39 66 33 62 33 64 61 66 32 34 32 66 63 34 64 35 38 65 34 37 39 61 37 39 37 65 38 33 34 36 62 34 30 38 34 33 39 61 30 37 34 65".split(" ");
xxx = new Uint8Array(foo);
uintToString(xxx);

// > string contains invalid character    
frequent
  • 27,643
  • 59
  • 181
  • 333
  • 1
    Like this? http://stackoverflow.com/questions/17191945/conversion-between-utf-8-arraybuffer-and-string –  Apr 25 '15 at 17:41
  • Probably. I'm poking on it... can you tell me how to pluck my string of bytes into a compatible "unitArray"? – frequent Apr 25 '15 at 17:50

1 Answers1

4

Try this

var s = "41 57 53 34 2d 48 4d 41 43 2d 53 48 41 32 35 36 0a 32 30 31 35 30 34 32 35 54 31 36 32 33 30 36 5a 0a 32 30 31 35 30 34 32 35 2f 65 75 2d 77 65 73 74 2d 31 2f 73 33 2f 61 77 73 34 5f 72 65 71 75 65 73 74 0a 35 33 32 62 61 65 37 62 39 35 66 65 61 62 36 38 66 38 65 32 31 65 39 66 33 62 33 64 61 66 32 34 32 66 63 34 64 35 38 65 34 37 39 61 37 39 37 65 38 33 34 36 62 34 30 38 34 33 39 61 30 37 34 65";
var array = s.split(" ").map(function(n) {
  return Number.parseInt(n, 16);
});
var message = String.fromCharCode.apply(null, array);
Tesseract
  • 8,049
  • 2
  • 20
  • 37
  • @frequent: Are the characters in the response guaranteed to be in the ASCII range? –  Apr 25 '15 at 18:37
  • @squint: I'd say yes, both are from AWS and will convert to whatever AWS calculated (so I can compare to what I have). Values are either request headers, date time or hashes, so should all be ASCII – frequent Apr 25 '15 at 18:56