You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

373 lines
12 KiB

7 years ago
7 years ago
6 years ago
7 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
8 years ago
Update dns_aws.sh Use `hostedzonesbyname` Route 53 API endpoint instead of `hostedzones` endpoint. The `hostedzones` endpoint returns all hosted zones for a given Route 53 account in groups of 100. For AWS Route 53 accounts with many domains, this could mean a large number of requests to the `hostedzones` endpoint as it progresses through each page of 100 results. This will often result in a "Rate exceeded" API error from Route 53. Instead of using `hostedzones` endpoint, we can use `hostedzonesbyname` and then filter by the specific domain we are looking for and ask for a `max-items` of 1. The while loop in _get_root() starts with a given domain and removes parts from the front of the given domain if no match is found. For example, when requesting a certificate for `test.www.domain.co.uk`, the while loop will check for Route 53 hosted zones for: 1st: test.www.domain.co.uk 2nd: www.domain.co.uk 3rd: domain.co.uk 4th: co.uk 5th: uk The first two checks will result in no matches, while the third check should be successful (if, of course, domain.co.uk is actually a hosted zone in the given AWS account). Now imagine that the given AWS account owns 2500 domains and, therefore, has 2500 hosted zones. Using the `hostedzones` endpoint would result in: 1st: 25 GET requests to the Route 53 API looking for a match to test.www.domain.co.uk 2nd: 25 GET requests to the Route 53 API looking for a match to www.domain.co.uk 3rd: 25 GET requests to the Route 53 API looking for a match to domain.co.uk 4th: 25 GET requests to the Route 53 API looking for a match to co.uk 5th: 25 GET requests to the Route 53 API looking for a match to uk This would far exceed the Route 53 limit of five requests per second. Using `hostedzonesbyname` results in a dramatic reduction in Route 53 API GET requests for AWS accounts with large numbers of hosted zones.
4 years ago
Update dns_aws.sh Use `hostedzonesbyname` Route 53 API endpoint instead of `hostedzones` endpoint. The `hostedzones` endpoint returns all hosted zones for a given Route 53 account in groups of 100. For AWS Route 53 accounts with many domains, this could mean a large number of requests to the `hostedzones` endpoint as it progresses through each page of 100 results. This will often result in a "Rate exceeded" API error from Route 53. Instead of using `hostedzones` endpoint, we can use `hostedzonesbyname` and then filter by the specific domain we are looking for and ask for a `max-items` of 1. The while loop in _get_root() starts with a given domain and removes parts from the front of the given domain if no match is found. For example, when requesting a certificate for `test.www.domain.co.uk`, the while loop will check for Route 53 hosted zones for: 1st: test.www.domain.co.uk 2nd: www.domain.co.uk 3rd: domain.co.uk 4th: co.uk 5th: uk The first two checks will result in no matches, while the third check should be successful (if, of course, domain.co.uk is actually a hosted zone in the given AWS account). Now imagine that the given AWS account owns 2500 domains and, therefore, has 2500 hosted zones. Using the `hostedzones` endpoint would result in: 1st: 25 GET requests to the Route 53 API looking for a match to test.www.domain.co.uk 2nd: 25 GET requests to the Route 53 API looking for a match to www.domain.co.uk 3rd: 25 GET requests to the Route 53 API looking for a match to domain.co.uk 4th: 25 GET requests to the Route 53 API looking for a match to co.uk 5th: 25 GET requests to the Route 53 API looking for a match to uk This would far exceed the Route 53 limit of five requests per second. Using `hostedzonesbyname` results in a dramatic reduction in Route 53 API GET requests for AWS accounts with large numbers of hosted zones.
4 years ago
Update dns_aws.sh Use `hostedzonesbyname` Route 53 API endpoint instead of `hostedzones` endpoint. The `hostedzones` endpoint returns all hosted zones for a given Route 53 account in groups of 100. For AWS Route 53 accounts with many domains, this could mean a large number of requests to the `hostedzones` endpoint as it progresses through each page of 100 results. This will often result in a "Rate exceeded" API error from Route 53. Instead of using `hostedzones` endpoint, we can use `hostedzonesbyname` and then filter by the specific domain we are looking for and ask for a `max-items` of 1. The while loop in _get_root() starts with a given domain and removes parts from the front of the given domain if no match is found. For example, when requesting a certificate for `test.www.domain.co.uk`, the while loop will check for Route 53 hosted zones for: 1st: test.www.domain.co.uk 2nd: www.domain.co.uk 3rd: domain.co.uk 4th: co.uk 5th: uk The first two checks will result in no matches, while the third check should be successful (if, of course, domain.co.uk is actually a hosted zone in the given AWS account). Now imagine that the given AWS account owns 2500 domains and, therefore, has 2500 hosted zones. Using the `hostedzones` endpoint would result in: 1st: 25 GET requests to the Route 53 API looking for a match to test.www.domain.co.uk 2nd: 25 GET requests to the Route 53 API looking for a match to www.domain.co.uk 3rd: 25 GET requests to the Route 53 API looking for a match to domain.co.uk 4th: 25 GET requests to the Route 53 API looking for a match to co.uk 5th: 25 GET requests to the Route 53 API looking for a match to uk This would far exceed the Route 53 limit of five requests per second. Using `hostedzonesbyname` results in a dramatic reduction in Route 53 API GET requests for AWS accounts with large numbers of hosted zones.
4 years ago
Update dns_aws.sh Use `hostedzonesbyname` Route 53 API endpoint instead of `hostedzones` endpoint. The `hostedzones` endpoint returns all hosted zones for a given Route 53 account in groups of 100. For AWS Route 53 accounts with many domains, this could mean a large number of requests to the `hostedzones` endpoint as it progresses through each page of 100 results. This will often result in a "Rate exceeded" API error from Route 53. Instead of using `hostedzones` endpoint, we can use `hostedzonesbyname` and then filter by the specific domain we are looking for and ask for a `max-items` of 1. The while loop in _get_root() starts with a given domain and removes parts from the front of the given domain if no match is found. For example, when requesting a certificate for `test.www.domain.co.uk`, the while loop will check for Route 53 hosted zones for: 1st: test.www.domain.co.uk 2nd: www.domain.co.uk 3rd: domain.co.uk 4th: co.uk 5th: uk The first two checks will result in no matches, while the third check should be successful (if, of course, domain.co.uk is actually a hosted zone in the given AWS account). Now imagine that the given AWS account owns 2500 domains and, therefore, has 2500 hosted zones. Using the `hostedzones` endpoint would result in: 1st: 25 GET requests to the Route 53 API looking for a match to test.www.domain.co.uk 2nd: 25 GET requests to the Route 53 API looking for a match to www.domain.co.uk 3rd: 25 GET requests to the Route 53 API looking for a match to domain.co.uk 4th: 25 GET requests to the Route 53 API looking for a match to co.uk 5th: 25 GET requests to the Route 53 API looking for a match to uk This would far exceed the Route 53 limit of five requests per second. Using `hostedzonesbyname` results in a dramatic reduction in Route 53 API GET requests for AWS accounts with large numbers of hosted zones.
4 years ago
Update dns_aws.sh Use `hostedzonesbyname` Route 53 API endpoint instead of `hostedzones` endpoint. The `hostedzones` endpoint returns all hosted zones for a given Route 53 account in groups of 100. For AWS Route 53 accounts with many domains, this could mean a large number of requests to the `hostedzones` endpoint as it progresses through each page of 100 results. This will often result in a "Rate exceeded" API error from Route 53. Instead of using `hostedzones` endpoint, we can use `hostedzonesbyname` and then filter by the specific domain we are looking for and ask for a `max-items` of 1. The while loop in _get_root() starts with a given domain and removes parts from the front of the given domain if no match is found. For example, when requesting a certificate for `test.www.domain.co.uk`, the while loop will check for Route 53 hosted zones for: 1st: test.www.domain.co.uk 2nd: www.domain.co.uk 3rd: domain.co.uk 4th: co.uk 5th: uk The first two checks will result in no matches, while the third check should be successful (if, of course, domain.co.uk is actually a hosted zone in the given AWS account). Now imagine that the given AWS account owns 2500 domains and, therefore, has 2500 hosted zones. Using the `hostedzones` endpoint would result in: 1st: 25 GET requests to the Route 53 API looking for a match to test.www.domain.co.uk 2nd: 25 GET requests to the Route 53 API looking for a match to www.domain.co.uk 3rd: 25 GET requests to the Route 53 API looking for a match to domain.co.uk 4th: 25 GET requests to the Route 53 API looking for a match to co.uk 5th: 25 GET requests to the Route 53 API looking for a match to uk This would far exceed the Route 53 limit of five requests per second. Using `hostedzonesbyname` results in a dramatic reduction in Route 53 API GET requests for AWS accounts with large numbers of hosted zones.
4 years ago
Update dns_aws.sh Use `hostedzonesbyname` Route 53 API endpoint instead of `hostedzones` endpoint. The `hostedzones` endpoint returns all hosted zones for a given Route 53 account in groups of 100. For AWS Route 53 accounts with many domains, this could mean a large number of requests to the `hostedzones` endpoint as it progresses through each page of 100 results. This will often result in a "Rate exceeded" API error from Route 53. Instead of using `hostedzones` endpoint, we can use `hostedzonesbyname` and then filter by the specific domain we are looking for and ask for a `max-items` of 1. The while loop in _get_root() starts with a given domain and removes parts from the front of the given domain if no match is found. For example, when requesting a certificate for `test.www.domain.co.uk`, the while loop will check for Route 53 hosted zones for: 1st: test.www.domain.co.uk 2nd: www.domain.co.uk 3rd: domain.co.uk 4th: co.uk 5th: uk The first two checks will result in no matches, while the third check should be successful (if, of course, domain.co.uk is actually a hosted zone in the given AWS account). Now imagine that the given AWS account owns 2500 domains and, therefore, has 2500 hosted zones. Using the `hostedzones` endpoint would result in: 1st: 25 GET requests to the Route 53 API looking for a match to test.www.domain.co.uk 2nd: 25 GET requests to the Route 53 API looking for a match to www.domain.co.uk 3rd: 25 GET requests to the Route 53 API looking for a match to domain.co.uk 4th: 25 GET requests to the Route 53 API looking for a match to co.uk 5th: 25 GET requests to the Route 53 API looking for a match to uk This would far exceed the Route 53 limit of five requests per second. Using `hostedzonesbyname` results in a dramatic reduction in Route 53 API GET requests for AWS accounts with large numbers of hosted zones.
4 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #!/usr/bin/env sh
  2. #
  3. #AWS_ACCESS_KEY_ID="sdfsdfsdfljlbjkljlkjsdfoiwje"
  4. #
  5. #AWS_SECRET_ACCESS_KEY="xxxxxxx"
  6. #This is the Amazon Route53 api wrapper for acme.sh
  7. #All `_sleep` commands are included to avoid Route53 throttling, see
  8. #https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/DNSLimitations.html#limits-api-requests
  9. AWS_HOST="route53.amazonaws.com"
  10. AWS_URL="https://$AWS_HOST"
  11. AWS_WIKI="https://github.com/acmesh-official/acme.sh/wiki/How-to-use-Amazon-Route53-API"
  12. ######## Public functions #####################
  13. #Usage: dns_myapi_add _acme-challenge.www.domain.com "XKrxpRBosdIKFzxW_CT3KLZNf6q0HG9i01zxXp5CPBs"
  14. dns_aws_add() {
  15. fulldomain=$1
  16. txtvalue=$2
  17. AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID:-$(_readaccountconf_mutable AWS_ACCESS_KEY_ID)}"
  18. AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY:-$(_readaccountconf_mutable AWS_SECRET_ACCESS_KEY)}"
  19. AWS_DNS_SLOWRATE="${AWS_DNS_SLOWRATE:-$(_readaccountconf_mutable AWS_DNS_SLOWRATE)}"
  20. if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
  21. _use_container_role || _use_instance_role
  22. fi
  23. if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
  24. AWS_ACCESS_KEY_ID=""
  25. AWS_SECRET_ACCESS_KEY=""
  26. _err "You haven't specifed the aws route53 api key id and and api key secret yet."
  27. _err "Please create your key and try again. see $(__green $AWS_WIKI)"
  28. return 1
  29. fi
  30. #save for future use, unless using a role which will be fetched as needed
  31. if [ -z "$_using_role" ]; then
  32. _saveaccountconf_mutable AWS_ACCESS_KEY_ID "$AWS_ACCESS_KEY_ID"
  33. _saveaccountconf_mutable AWS_SECRET_ACCESS_KEY "$AWS_SECRET_ACCESS_KEY"
  34. _saveaccountconf_mutable AWS_DNS_SLOWRATE "$AWS_DNS_SLOWRATE"
  35. fi
  36. _debug "First detect the root zone"
  37. if ! _get_root "$fulldomain"; then
  38. _err "invalid domain"
  39. _sleep 1
  40. return 1
  41. fi
  42. _debug _domain_id "$_domain_id"
  43. _debug _sub_domain "$_sub_domain"
  44. _debug _domain "$_domain"
  45. _info "Getting existing records for $fulldomain"
  46. if ! aws_rest GET "2013-04-01$_domain_id/rrset" "name=$fulldomain&type=TXT"; then
  47. _sleep 1
  48. return 1
  49. fi
  50. if _contains "$response" "<Name>$fulldomain.</Name>"; then
  51. _resource_record="$(echo "$response" | sed 's/<ResourceRecordSet>/"/g' | tr '"' "\n" | grep "<Name>$fulldomain.</Name>" | _egrep_o "<ResourceRecords.*</ResourceRecords>" | sed "s/<ResourceRecords>//" | sed "s#</ResourceRecords>##")"
  52. _debug "_resource_record" "$_resource_record"
  53. else
  54. _debug "single new add"
  55. fi
  56. if [ "$_resource_record" ] && _contains "$response" "$txtvalue"; then
  57. _info "The TXT record already exists. Skipping."
  58. _sleep 1
  59. return 0
  60. fi
  61. _debug "Adding records"
  62. _aws_tmpl_xml="<ChangeResourceRecordSetsRequest xmlns=\"https://route53.amazonaws.com/doc/2013-04-01/\"><ChangeBatch><Changes><Change><Action>UPSERT</Action><ResourceRecordSet><Name>$fulldomain</Name><Type>TXT</Type><TTL>300</TTL><ResourceRecords>$_resource_record<ResourceRecord><Value>\"$txtvalue\"</Value></ResourceRecord></ResourceRecords></ResourceRecordSet></Change></Changes></ChangeBatch></ChangeResourceRecordSetsRequest>"
  63. if aws_rest POST "2013-04-01$_domain_id/rrset/" "" "$_aws_tmpl_xml" && _contains "$response" "ChangeResourceRecordSetsResponse"; then
  64. _info "TXT record updated successfully."
  65. if [ -n "$AWS_DNS_SLOWRATE" ]; then
  66. _info "Slow rate activated: sleeping for $AWS_DNS_SLOWRATE seconds"
  67. _sleep "$AWS_DNS_SLOWRATE"
  68. else
  69. _sleep 1
  70. fi
  71. return 0
  72. fi
  73. _sleep 1
  74. return 1
  75. }
  76. #fulldomain txtvalue
  77. dns_aws_rm() {
  78. fulldomain=$1
  79. txtvalue=$2
  80. AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID:-$(_readaccountconf_mutable AWS_ACCESS_KEY_ID)}"
  81. AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY:-$(_readaccountconf_mutable AWS_SECRET_ACCESS_KEY)}"
  82. AWS_DNS_SLOWRATE="${AWS_DNS_SLOWRATE:-$(_readaccountconf_mutable AWS_DNS_SLOWRATE)}"
  83. if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
  84. _use_container_role || _use_instance_role
  85. fi
  86. _debug "First detect the root zone"
  87. if ! _get_root "$fulldomain"; then
  88. _err "invalid domain"
  89. _sleep 1
  90. return 1
  91. fi
  92. _debug _domain_id "$_domain_id"
  93. _debug _sub_domain "$_sub_domain"
  94. _debug _domain "$_domain"
  95. _info "Getting existing records for $fulldomain"
  96. if ! aws_rest GET "2013-04-01$_domain_id/rrset" "name=$fulldomain&type=TXT"; then
  97. _sleep 1
  98. return 1
  99. fi
  100. if _contains "$response" "<Name>$fulldomain.</Name>"; then
  101. _resource_record="$(echo "$response" | sed 's/<ResourceRecordSet>/"/g' | tr '"' "\n" | grep "<Name>$fulldomain.</Name>" | _egrep_o "<ResourceRecords.*</ResourceRecords>" | sed "s/<ResourceRecords>//" | sed "s#</ResourceRecords>##")"
  102. _debug "_resource_record" "$_resource_record"
  103. else
  104. _debug "no records exist, skip"
  105. _sleep 1
  106. return 0
  107. fi
  108. _aws_tmpl_xml="<ChangeResourceRecordSetsRequest xmlns=\"https://route53.amazonaws.com/doc/2013-04-01/\"><ChangeBatch><Changes><Change><Action>DELETE</Action><ResourceRecordSet><ResourceRecords>$_resource_record</ResourceRecords><Name>$fulldomain.</Name><Type>TXT</Type><TTL>300</TTL></ResourceRecordSet></Change></Changes></ChangeBatch></ChangeResourceRecordSetsRequest>"
  109. if aws_rest POST "2013-04-01$_domain_id/rrset/" "" "$_aws_tmpl_xml" && _contains "$response" "ChangeResourceRecordSetsResponse"; then
  110. _info "TXT record deleted successfully."
  111. if [ -n "$AWS_DNS_SLOWRATE" ]; then
  112. _info "Slow rate activated: sleeping for $AWS_DNS_SLOWRATE seconds"
  113. _sleep "$AWS_DNS_SLOWRATE"
  114. else
  115. _sleep 1
  116. fi
  117. return 0
  118. fi
  119. _sleep 1
  120. return 1
  121. }
  122. #################### Private functions below ##################################
  123. _get_root() {
  124. domain=$1
  125. # Start with field 2 since each domain starts with _acme-challenge
  126. # Example: _acme-challenge.www.domain.com
  127. field=2
  128. subdomain_part=1
  129. while true; do
  130. hostname=$(printf "%s" "$domain" | cut -d . -f $field-100)
  131. if [ -z "$hostname" ]
  132. then
  133. _debug "There are no more fields in the hostname to check"
  134. _err "No matching Route 53 hosted zones for: $domain"
  135. return 1
  136. fi
  137. _debug "Checking domain: $hostname"
  138. if aws_rest GET "2013-04-01/hostedzonesbyname" "dnsname=$hostname&maxitems=1"; then
  139. if _contains "$response" "<Name>$hostname.</Name>"; then
  140. hostedzone="$(echo "$response" | sed 's/<HostedZone>/#&/g' | tr '#' '\n' | _egrep_o "<HostedZone><Id>[^<]*<.Id><Name>$hostname.<.Name>.*<PrivateZone>false<.PrivateZone>.*<.HostedZone>")"
  141. _debug hostedzone "$hostedzone"
  142. if [ "$hostedzone" ]; then
  143. _domain_id=$(printf "%s\n" "$hostedzone" | _egrep_o "<Id>.*<.Id>" | head -n 1 | _egrep_o ">.*<" | tr -d "<>")
  144. if [ "$_domain_id" ]; then
  145. _sub_domain=$(printf "%s" "$domain" | cut -d . -f 1-$subdomain_part)
  146. _domain=$hostname
  147. return 0
  148. fi
  149. _err "Can't find domain with id: $hostname"
  150. return 1
  151. fi
  152. else
  153. _debug "Route 53 does not have a hosted zone for: $hostname."
  154. _debug "Moving on to next part of the hostname"
  155. fi
  156. else
  157. _err "Getting Route 53 hosted zones by name failed for: $domain"
  158. return 1
  159. fi
  160. subdomain_part=$field
  161. field=$(_math "$field" + 1)
  162. if [ -n "$AWS_DNS_SLOWRATE" ]; then
  163. _info "Slow rate activated: sleeping for $AWS_DNS_SLOWRATE seconds"
  164. _sleep "$AWS_DNS_SLOWRATE"
  165. else
  166. _sleep 1
  167. fi
  168. done
  169. _err "_get_root failed for domain: $domain"
  170. return 1
  171. }
  172. _use_container_role() {
  173. # automatically set if running inside ECS
  174. if [ -z "$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI" ]; then
  175. _debug "No ECS environment variable detected"
  176. return 1
  177. fi
  178. _use_metadata "169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"
  179. }
  180. _use_instance_role() {
  181. _url="http://169.254.169.254/latest/meta-data/iam/security-credentials/"
  182. _debug "_url" "$_url"
  183. if ! _get "$_url" true 1 | _head_n 1 | grep -Fq 200; then
  184. _debug "Unable to fetch IAM role from instance metadata"
  185. return 1
  186. fi
  187. _aws_role=$(_get "$_url" "" 1)
  188. _debug "_aws_role" "$_aws_role"
  189. _use_metadata "$_url$_aws_role"
  190. }
  191. _use_metadata() {
  192. _aws_creds="$(
  193. _get "$1" "" 1 |
  194. _normalizeJson |
  195. tr '{,}' '\n' |
  196. while read -r _line; do
  197. _key="$(echo "${_line%%:*}" | tr -d '"')"
  198. _value="${_line#*:}"
  199. _debug3 "_key" "$_key"
  200. _secure_debug3 "_value" "$_value"
  201. case "$_key" in
  202. AccessKeyId) echo "AWS_ACCESS_KEY_ID=$_value" ;;
  203. SecretAccessKey) echo "AWS_SECRET_ACCESS_KEY=$_value" ;;
  204. Token) echo "AWS_SESSION_TOKEN=$_value" ;;
  205. esac
  206. done |
  207. paste -sd' ' -
  208. )"
  209. _secure_debug "_aws_creds" "$_aws_creds"
  210. if [ -z "$_aws_creds" ]; then
  211. return 1
  212. fi
  213. eval "$_aws_creds"
  214. _using_role=true
  215. }
  216. #method uri qstr data
  217. aws_rest() {
  218. mtd="$1"
  219. ep="$2"
  220. qsr="$3"
  221. data="$4"
  222. _debug mtd "$mtd"
  223. _debug ep "$ep"
  224. _debug qsr "$qsr"
  225. _debug data "$data"
  226. CanonicalURI="/$ep"
  227. _debug2 CanonicalURI "$CanonicalURI"
  228. CanonicalQueryString="$qsr"
  229. _debug2 CanonicalQueryString "$CanonicalQueryString"
  230. RequestDate="$(date -u +"%Y%m%dT%H%M%SZ")"
  231. _debug2 RequestDate "$RequestDate"
  232. #RequestDate="20161120T141056Z" ##############
  233. export _H1="x-amz-date: $RequestDate"
  234. aws_host="$AWS_HOST"
  235. CanonicalHeaders="host:$aws_host\nx-amz-date:$RequestDate\n"
  236. SignedHeaders="host;x-amz-date"
  237. if [ -n "$AWS_SESSION_TOKEN" ]; then
  238. export _H3="x-amz-security-token: $AWS_SESSION_TOKEN"
  239. CanonicalHeaders="${CanonicalHeaders}x-amz-security-token:$AWS_SESSION_TOKEN\n"
  240. SignedHeaders="${SignedHeaders};x-amz-security-token"
  241. fi
  242. _debug2 CanonicalHeaders "$CanonicalHeaders"
  243. _debug2 SignedHeaders "$SignedHeaders"
  244. RequestPayload="$data"
  245. _debug2 RequestPayload "$RequestPayload"
  246. Hash="sha256"
  247. CanonicalRequest="$mtd\n$CanonicalURI\n$CanonicalQueryString\n$CanonicalHeaders\n$SignedHeaders\n$(printf "%s" "$RequestPayload" | _digest "$Hash" hex)"
  248. _debug2 CanonicalRequest "$CanonicalRequest"
  249. HashedCanonicalRequest="$(printf "$CanonicalRequest%s" | _digest "$Hash" hex)"
  250. _debug2 HashedCanonicalRequest "$HashedCanonicalRequest"
  251. Algorithm="AWS4-HMAC-SHA256"
  252. _debug2 Algorithm "$Algorithm"
  253. RequestDateOnly="$(echo "$RequestDate" | cut -c 1-8)"
  254. _debug2 RequestDateOnly "$RequestDateOnly"
  255. Region="us-east-1"
  256. Service="route53"
  257. CredentialScope="$RequestDateOnly/$Region/$Service/aws4_request"
  258. _debug2 CredentialScope "$CredentialScope"
  259. StringToSign="$Algorithm\n$RequestDate\n$CredentialScope\n$HashedCanonicalRequest"
  260. _debug2 StringToSign "$StringToSign"
  261. kSecret="AWS4$AWS_SECRET_ACCESS_KEY"
  262. #kSecret="wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY" ############################
  263. _secure_debug2 kSecret "$kSecret"
  264. kSecretH="$(printf "%s" "$kSecret" | _hex_dump | tr -d " ")"
  265. _secure_debug2 kSecretH "$kSecretH"
  266. kDateH="$(printf "$RequestDateOnly%s" | _hmac "$Hash" "$kSecretH" hex)"
  267. _debug2 kDateH "$kDateH"
  268. kRegionH="$(printf "$Region%s" | _hmac "$Hash" "$kDateH" hex)"
  269. _debug2 kRegionH "$kRegionH"
  270. kServiceH="$(printf "$Service%s" | _hmac "$Hash" "$kRegionH" hex)"
  271. _debug2 kServiceH "$kServiceH"
  272. kSigningH="$(printf "%s" "aws4_request" | _hmac "$Hash" "$kServiceH" hex)"
  273. _debug2 kSigningH "$kSigningH"
  274. signature="$(printf "$StringToSign%s" | _hmac "$Hash" "$kSigningH" hex)"
  275. _debug2 signature "$signature"
  276. Authorization="$Algorithm Credential=$AWS_ACCESS_KEY_ID/$CredentialScope, SignedHeaders=$SignedHeaders, Signature=$signature"
  277. _debug2 Authorization "$Authorization"
  278. _H2="Authorization: $Authorization"
  279. _debug _H2 "$_H2"
  280. url="$AWS_URL/$ep"
  281. if [ "$qsr" ]; then
  282. url="$AWS_URL/$ep?$qsr"
  283. fi
  284. if [ "$mtd" = "GET" ]; then
  285. response="$(_get "$url")"
  286. else
  287. response="$(_post "$data" "$url")"
  288. fi
  289. _ret="$?"
  290. _debug2 response "$response"
  291. if [ "$_ret" = "0" ]; then
  292. if _contains "$response" "<ErrorResponse"; then
  293. _err "Response error:$response"
  294. return 1
  295. fi
  296. fi
  297. return "$_ret"
  298. }