Skip to content

Publish the /dims5/ signing algorithm as a library, with Go and Java clients #124

Description

@beetlebugorg

What

/dims5/ requires an HMAC-SHA256 signature over the commands, the image URL, and the canonical query. A caller in any language has to reproduce that message byte for byte, and today nothing in this repository lets one do so without reading C.

Three pieces:

  1. A C library that exposes the signing rules, so a caller links it rather than reimplementing it.
  2. A Go client.
  3. A Java client.

Why

src/signature.c holds the rules and src/signature.h declares them, but every function takes an apr_pool_t and the header includes mod_dims.h, which pulls in httpd. A caller outside the module cannot use it.

test/endurance/sign.c reimplements the same rules against OpenSSL for the soak client. Its header says so: "Every function here reproduces what the module checks. A change to the module's rules that this file does not follow appears in a run as a signed request the service refuses." That is a second copy, and a third copy exists in go-dims.

The message format is easy to get wrong. dims_signed_query orders the parameters by name, percent encodes each one with uppercase hex, writes a space as a plus, and leaves out sig, url, eurl, _keys, and download. A client that sorts differently or escapes a tilde produces a signature the module refuses, and the failure says only "Key mismatch".

Scope

The C library. Split the pool and httpd types out of signature.h so the rules take plain C strings and a caller-supplied buffer. The module keeps its pool-based wrapper. Ship a header and a static library, and a dims-sign command that signs a URL from the shell.

Go. A package with one exported function that takes the key, the base URL, the commands, the image URL, and the query, and returns the signed URL. go-dims already has an implementation to compare against.

Java. The same shape, using javax.crypto.Mac with HmacSHA256.

Verify

The signature is portable between mod_dims and go-dims, and a test asserts it. Extend that: one fixture file of message and signature pairs, read by the C, Go, and Java test suites. A client that disagrees fails its own suite rather than a soak run.

Cover the cases that differ between naive implementations:

  • a query parameter with several values
  • a parameter name that sorts after another only when compared byte by byte
  • a space, a plus, and a tilde in a value
  • a value holding a percent sign
  • _keys naming a parameter that is absent

Notes

docs/docs/endpoints/dims5.md documents the URL shape. The signing rules belong beside it once a caller can follow them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions