setAuth($accessKey, $secretKey); } } /** * Set AWS access key and secret key * * @param string $accessKey Access key * @param string $secretKey Secret key * @return void */ public function setAuth($accessKey, $secretKey) { $this->__accessKey = $accessKey; $this->__secretKey = $secretKey; } /** * Return XML document for POST * * @param string $fqdn FQDN to set/update * @param string $ip IP to set for the FQDN * @param string $ttl TTL for the record * @return string XML document */ public function getRequestBody($fqdn, $ip, $ttl){ $xmlreq = ""; $xmlreq .= ""; $xmlreq .= ""; $xmlreq .= "UPSERT"; $xmlreq .= ""; $xmlreq .= sprintf("%s", $fqdn); $xmlreq .= "A"; $xmlreq .= sprintf("%d", $ttl); $xmlreq .= sprintf("%s", $ip); $xmlreq .= ""; $xmlreq .= ""; $xmlreq .= ""; return $xmlreq; } /** * Return API URL * * @param string $zoneid Amazon Zone ID * @return string URL */ public function getApiUrl($zoneid){ return sprintf("https://route53.amazonaws.com/2013-04-01/hostedzone/%s/rrset", $zoneid); } /** * Return HTTP post headers * * @param string zoneId Amazon Zone * @param string regionId Amazon Region Code (e.g. us-east-1) * @param string requestBodySHA256 SHA256 hash of the request body * @return Array headers */ public function getHttpPostHeaders($zoneId, $regionId, $requestBodySHA256){ $canonical_uri = sprintf("/2013-04-01/hostedzone/%s/rrset", $zoneId); $amz_date = sprintf("%sT%sZ", gmdate('Ymd'), gmdate('His')); $date_stamp = gmdate('Ymd'); $canonical_headers = sprintf("content-type:%s\nhost:%s\nx-amz-date:%s\n", "text/xml", "route53.amazonaws.com", $amz_date); $signed_headers = "content-type;host;x-amz-date"; $canonical_request = sprintf("%s\n%s\n\n%s\n%s\n%s", "POST", $canonical_uri, $canonical_headers, $signed_headers, $requestBodySHA256); $algorithm = "AWS4-HMAC-SHA256"; $credential_scope = sprintf("%s/%s/%s/%s", $date_stamp, $regionId, "route53", "aws4_request"); $string_to_sign = sprintf("%s\n%s\n%s\n%s", $algorithm, $amz_date, $credential_scope, hash("sha256", $canonical_request)); $kSecret = sprintf("AWS4%s", $this->__secretKey); $kDate = hash_hmac("sha256", $date_stamp, $kSecret, true); $kRegion = hash_hmac("sha256", $regionId, $kDate, true); $kService = hash_hmac("sha256", "route53", $kRegion, true); $signing_key = hash_hmac("sha256","aws4_request", $kService, true); $signature = bin2hex(hash_hmac("sha256", $string_to_sign, $signing_key, true)); $authorization_header = sprintf("%s Credential=%s/%s, SignedHeaders=%s, Signature=%s", $algorithm, $this->__accessKey, $credential_scope, $signed_headers, $signature); $httphead[] = "Content-Type: text/xml"; $httphead[] = sprintf("X-Amz-Date: %s", $amz_date); $httphead[] = sprintf("Authorization: %s", $authorization_header); return $httphead; } }