From 4cd318cd3381aae011ce649d7590c165d907a7b5 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Fri, 15 Sep 2017 14:14:14 +0300 Subject: Testing WIP --- route53.sh | 94 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/route53.sh b/route53.sh index 07c33e4..b92c0c8 100755 --- a/route53.sh +++ b/route53.sh @@ -19,67 +19,87 @@ API_PATH="/2013-04-01/hostedzone/${HOSTED_ZONE_ID}/rrset/" # AWS_ACCESS_KEY_ID='' # AWS_SECRET_ACCESS_KEY='' AWS_REGION='us-east-1' -AWS_SERVICE='route53domains' - -request_body=" - - - - - - UPSERT - - ${RECORD_NAME} - ${RECORD_TYPE} - ${RECORD_TTL} - - - ${RECORD_VALUE} - - - - - - - -" - -fulldate=$(date -Iseconds) -shortdate=$(date +%Y%m%d) -signed_headers="host;z-amx-date" -canonical_request="POST\n${PATH}\n\nhost:route53.amazon.com\nx-amz-date:${fulldate}\n\n${signed_headers}\n$(hash "${request_body}")" +AWS_SERVICE='route53' hash() { msg=$1 - echo -n "$msg" | openssl dgst -sha256 | sed 's/^.* //' + echo -en "$msg" | openssl dgst -sha256 | sed 's/^.* //' } sign() { key=$1 msg=$2 - echo -n "$msg" | openssl dgst -sha256 -hmac "$key" | sed 's/^.* //' + echo -en "$msg" | openssl dgst -sha256 -hmac "$key" | sed 's/^.* //' } +request_body=" \ + \ + \ + \ + \ + UPSERT \ + \ + ${RECORD_NAME} \ + ${RECORD_TYPE} \ + ${RECORD_TTL} \ + \ + \ + ${RECORD_VALUE} \ + \ + \ + \ + \ + \ + \ +" + +#fulldate=$(date -Iseconds) +fulldate=$(date --utc +%Y%m%dT%H%M%SZ) +shortdate=$(date --utc +%Y%m%d) +signed_headers="host;x-amz-date" +request_hash=$(hash $request_body) +canonical_request="POST\n${API_PATH}\n\nhost:route53.amazon.com\nx-amz-date:${fulldate}\n\n${signed_headers}\n${request_hash}" + +echo "Canonical request:" +echo -e $canonical_request +echo +echo + getSignatureKey() { - # usage: getSignatureKey date region service - date_key=$(sign "AWS4${AWS_SECRET_ACCESS_KEY_ID}" "${shortdate}") + date_key=$(sign "AWS4${AWS_SECRET_ACCESS_KEY}" "${shortdate}") region_key=$(sign "$date_key" $AWS_REGION) service_key=$(sign "$region_key" $AWS_SERVICE) signing_key=$(sign "$service_key" aws4_request) echo -n "$signing_key" } +test() { + date_key=$(sign "AWS4wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY" "20150830") + region_key=$(sign "$date_key" "us-east-1") + service_key=$(sign "$region_key" "") + signing_key=$(sign "$service_key" aws4_request) + echo -n "$signing_key" +} + credential="${shortdate}/${AWS_REGION}/${AWS_SERVICE}/aws4_request" -sigmsg="AWS4-HMAC-SHA256\n${credential}\n$(hash "$(echo -e canonical_request)")" +sigmsg="AWS4-HMAC-SHA256\n${fulldate}\n${credential}\n$(hash $canonical_request)" sigkey=$(getSignatureKey) -signature=$(sign sigkey sigmsg) +echo $sigkey +echo $sigmsg +signature=$(sign $sigkey $sigmsg) + +authorization="AWS4-HMAC-SHA256 Credential=${AWS_ACCESS_KEY_ID}/${credential}, SignedHeaders=${signed_headers}, Signature=${signature}" -authorization="AWS4-HMAC-SHA256 Credential=${AWS_ACCESS_KEY_ID}/${credential},SignedHeaders=${signed_headers},Signature=${signature}" +echo 'Auth' +echo $authorization +echo +echo curl \ -X "POST" \ -H "host:route53.amazonaws.com" \ -H "x-amz-date:${fulldate}" \ -H "authorization:${authorization}}" \ - --data "$request_body" \ + -H "Content-Type:text/xml;charset=UTF-8" \ + -d "$request_body" \ "https://${ENDPOINT}${API_PATH}" -- cgit v1.3.1