AWS API Dlang, hmac sha256 function.

Laeeth Isharc via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 8 22:53:10 PDT 2015


On Friday, 9 October 2015 at 04:04:57 UTC, holo wrote:

> 	r.dateString = 	client.addRequestHeader("Authoryzation:", 
> "AWS4-HMAC-SHA256" ~ " " ~ "Credential=" ~ accKey ~ "/" ~ 
> xamztime ~ "/" ~ zone ~ "/" ~ service ~ "/" ~ "aws4_request" ~ 
> ", " ~ "SignedHeaders=" ~ "content-type;host;x-amz-date" ~ ", " 
> ~ "Signature=" ~ signature);

authorisation ??? (Or maybe authorization) ie a typo (check other 
fields carefully too, just in case)



> 	auto url = service ~ ".amazonaws.com?" ~ 
> "Action=DescribeInstances&Version=2013-10-15";
> 	writeln(url);
> 	auto content = get(url, client);
> 	writeln(content);
> }
>
> Everything is compiling but im getting 400 (Bad Request):
>
>   [root at ultraxps aws]# ./header.d
>
> action=DescribeRegions&version=2013-10-15
>
> content-type: application/x-www-form-urlencoded; charset=utf-8
> host: ec2.amazonaws.com
> x-amz-date: 20151009T053800Z
>
>
> AWS4-HMAC-SHA256
> 20151009T053800Z
> 20151009/us-east-1/ec2/aws4_request
> 888595748692147ceafafcae3941ec0d83ac42c97641e4d954d7447a00c56270
>
> 69b1e4c5212cc6b485569fdfb43f7dde94413b36c50393c55d4810ced47f167b
>
> ec2.amazonaws.com?Action=DescribeRegions&Version=2013-10-15
> std.net.curl.CurlException@/usr/include/dlang/dmd/std/net/curl.d(824): HTTP request returned status code 400 (Bad Request)
> ----------------
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(pure @safe bool std.exception.enforce!(std.net.curl.CurlException, bool).enforce(bool, lazy const(char)[], immutable(char)[], ulong)+0x65) [0x5004bd]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(char[] std.net.curl._basicHTTP!(char)._basicHTTP(const(char)[], const(void)[], std.net.curl.HTTP)+0x1a2) [0x4fc0ba]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(char[] std.net.curl.get!(std.net.curl.HTTP, char).get(const(char)[], std.net.curl.HTTP)+0x6a) [0x4fbec2]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(_Dmain+0x840) [0x4f8f98]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x1f) [0x533eab]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x533e06]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x2b) [0x533e67]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x533e06]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(_d_run_main+0x1d2) [0x533d86]
> /tmp/.rdmd-0/rdmd-header.d-54C0A2BD6BD71C27D9AC7319D786A6F3/header(main+0x12) [0x52cb62]
> /usr/lib/libc.so.6(__libc_start_main+0xf0) [0x7f9c39f71610]
> [root at ultraxps aws]#
>
> What am i doing wrong? What is strange when when i do same with 
> curl its responding normally of course is not authenticated).
>
> [root at ultraxps aws]# curl 
> ec2.amazonaws.com?Action=DescribeInstances&Version=2013-10-15
> [1] 20390
> [root at ultraxps aws]# <?xml version="1.0" encoding="UTF-8"?>
> <Response><Errors><Error><Code>MissingParameter</Code><Message>The request must contain the parameter AWSAccessKeyId</Message></Error></Errors><RequestID>e1352781-c2b4-4e74-ade3-80d655efd0ac</RequestID></Response>




More information about the Digitalmars-d-learn mailing list