From 7299fc696f5387aa88f0e483b293f06f5fc7042f Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Fri, 15 Sep 2017 00:03:26 +0300 Subject: Initial script dump, WIP --- README.md | 14 ++++++++++++ route53.sh | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 README.md create mode 100755 route53.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..6412205 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# route53-ddns + +A simple (b)ash script aimed for usage on LEDE/OpenWRT devices which enables sending DDNS updates to Route53 + +## Requirements + + - [curl](https://lede-project.org/packages/pkgdata/curl) + - [openssl-util](https://lede-project.org/packages/pkgdata/openssl-util) + +## Usage + +```bash +$ TBD +``` diff --git a/route53.sh b/route53.sh new file mode 100755 index 0000000..1d9c362 --- /dev/null +++ b/route53.sh @@ -0,0 +1,77 @@ +#!/bin/bash + +### route53.sh +### For use in LEDE / OpenWRT DDNS scenarios +### +### Requires: curl, openssl-util + +set -euo pipefail +IFS=$'\n\t' + +ENDPOINT="route53.amazonaws.com" +RECORD_TTL=300 +RECORD_NAME="" +RECORD_TYPE="A" +RECORD_VALUE="1.2.3.4" +HOSTED_ZONE_ID="" +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' + +date=`date +%Y%m%d` + +request_body=$(cat < + + + + + UPSERT + + ${RECORD_NAME} + ${RECORD_TYPE} + ${RECORD_TTL} + + + ${RECORD_VALUE} + + + + + + + +EOF +) + +canonical_request="POST\n${PATH}\n\nhost:route53.amazon.com\nx-amz-date:`date -Iseconds`\n\nhost;x-amz-date" + +sign() { + key=$1 + msg=$2 + echo -n $msg | openssl dgst -sha256 -hmac $key | sed 's/^.* //' +} + +getSignatureKey() { + # usage: getSignatureKey date region service + date_key=$(sign AWS4${AWS_SECRET_ACCESS_KEY_ID} ${date}) + 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 +} + +amzdate=`date -Iseconds` + +credential="${AWS_ACCESS_KEY_ID}/${date}/${AWS_REGION}/${AWS_SERVICE}/aws4_request" +signed_headers="host;x-amz-date" +signature="" +authorization="AWS4-HMAC-SHA256 Credential=${credential},SignedHeaders=${signed_headers},Signature=${signature}" + +curl \ + -H "x-amz-date=`date -Iseconds`" \ + -H "Authorization=${authorization}}" + "https://${ENDPOINT}" -- cgit v1.3.1