Alternera.Plugins.Sqs.SigV4 (alternera_plugin_sqs v0.9.0)

Copy Markdown View Source

AWS Signature Version 4 for one request, signed in the Authorization header (AWS4-HMAC-SHA256), for Alternera.Plugins.Sqs.

It is generic over the method, path, query, headers, body, region and service: it signs exactly the headers it is given (each name lowercased, each value trimmed, inner runs of spaces folded to one), which must include host and x-amz-date. The path is signed as given, already URI-encoded once, as every service but S3 expects; the query is sorted by name and then value and each part encoded as RFC 3986 unreserved.

The tests check it against the AWS SigV4 test suite's get-vanilla, post-vanilla and get-vanilla-query signatures, and against a request signed by an independent implementation.

Summary

Types

A request to sign: path encoded, query a list of {name, value}.

Who signs and for what: the key pair, the region and service, and the time.

Functions

The time as SigV4 writes it, YYYYMMDDTHHMMSSZ, in UTC.

The Authorization header's value for request, signed by signer. request's headers must hold the x-amz-date that signer.amz_date names.

The canonical request, as {signed_headers, text}: the method, path, canonical query, the headers as name:value lines, the signed header names joined by ;, and the hex SHA-256 of the body.

The credential scope: <date>/<region>/<service>/aws4_request.

The string to sign for a canonical request.

Types

request()

@type request() :: %{
  method: String.t(),
  path: String.t(),
  query: [{String.t(), String.t()}],
  headers: [{String.t(), String.t()}],
  body: iodata()
}

A request to sign: path encoded, query a list of {name, value}.

signer()

@type signer() :: %{
  access_key_id: String.t(),
  secret_access_key: String.t(),
  region: String.t(),
  service: String.t(),
  amz_date: String.t()
}

Who signs and for what: the key pair, the region and service, and the time.

Functions

amz_date(time)

@spec amz_date(DateTime.t()) :: String.t()

The time as SigV4 writes it, YYYYMMDDTHHMMSSZ, in UTC.

authorization(request, signer)

@spec authorization(request(), signer()) :: String.t()

The Authorization header's value for request, signed by signer. request's headers must hold the x-amz-date that signer.amz_date names.

canonical_request(request)

@spec canonical_request(request()) :: {String.t(), String.t()}

The canonical request, as {signed_headers, text}: the method, path, canonical query, the headers as name:value lines, the signed header names joined by ;, and the hex SHA-256 of the body.

scope(signer)

@spec scope(signer()) :: String.t()

The credential scope: <date>/<region>/<service>/aws4_request.

string_to_sign(canonical, signer)

@spec string_to_sign(String.t(), signer()) :: String.t()

The string to sign for a canonical request.