Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
# The gate in front of main. Everything it runs lives once in
# CtrlAltDevelop/ci-workflows, so a fix there fixes all of the packages at
# once — format, analyze --fatal-infos, test, the example, a CHANGELOG entry
# for the pubspec version, and the pub.dev score with no points lost.
# Runs the tests on a pull request into main — and on nothing else.
# The job lives once in CtrlAltDevelop/ci-workflows (dart-test.yml).

name: CI

on:
pull_request:
branches: [main]
push:
branches: [main]
workflow_dispatch:

concurrency:
group: ci-${{ github.ref }}
Expand All @@ -19,9 +14,9 @@ concurrency:
permissions: {}

jobs:
package:
name: Package
uses: CtrlAltDevelop/ci-workflows/.github/workflows/dart-package.yml@v1.1.0
test:
name: Test
uses: CtrlAltDevelop/ci-workflows/.github/workflows/dart-test.yml@v1.2.0
permissions:
contents: read
with:
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Publishes the demo in example/web to
# https://ctrlaltdevelop.github.io/dpop_client/ when a pull request is merged
# into main. Repo Settings → Pages → Source must be "GitHub Actions".
#
# The job is not shared from CtrlAltDevelop/ci-workflows the way the Flutter
# one is: this is a pure Dart package, so the demo is `dart compile js` rather
# than `flutter build web`, and it is three lines. Move it there if a second
# package needs the same.

name: Pages

on:
push:
branches: [main]

concurrency:
group: pages
cancel-in-progress: true

permissions: {}

jobs:
build:
name: Compile the demo
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7

- uses: dart-lang/setup-dart@v1

- name: Install dependencies
run: dart pub get

- name: Compile
# Paths in index.html are relative, so the site needs no base href.
run: >-
dart compile js -O2
-o example/web/main.dart.js
example/web/main.dart

- uses: actions/upload-pages-artifact@v3
with:
path: example/web

deploy:
name: Deploy to GitHub Pages
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
69 changes: 7 additions & 62 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
# Publishes the package to pub.dev when a version tag is pushed.
#
# Push a tag from main — `v2.2.0` publishes version 2.2.0. Nothing is published
# unless the tag is on main, matches the version in pubspec.yaml and has its
# CHANGELOG entry.
#
# One-off setup on pub.dev (package Admin tab > Automated publishing):
# - enable publishing from GitHub Actions for CtrlAltDevelop/dpop_client
# - tag pattern: v{{version}}
# - require the GitHub Actions environment: pub.dev
# and create an environment named `pub.dev` in the repository settings, with
# a required reviewer if every publish should be approved by hand.
# `v<version>` publishes that version. The checks (tag on main, matches the
# pubspec, has a CHANGELOG entry) and the one-off pub.dev setup live in
# CtrlAltDevelop/ci-workflows (dart-publish.yml).

name: Publish

Expand All @@ -20,59 +13,11 @@ on:
permissions: {}

jobs:
verify:
name: Verify the release
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0

- name: The tag is on main
run: |
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
echo "::error::$GITHUB_REF_NAME is not on main; release from main."
exit 1
fi

- name: The tag matches the pubspec version
run: |
version=$(sed -n 's/^version: *//p' pubspec.yaml | tr -d '\r')
if [ "v$version" != "$GITHUB_REF_NAME" ]; then
echo "::error::Tag $GITHUB_REF_NAME does not match pubspec version $version."
exit 1
fi

- name: The CHANGELOG has an entry for it
run: |
version="${GITHUB_REF_NAME#v}"
if ! grep -q "^## $version\b" CHANGELOG.md; then
echo "::error::CHANGELOG.md has no '## $version' entry."
exit 1
fi

publish:
name: Publish to pub.dev
needs: verify
runs-on: ubuntu-latest
environment: pub.dev
name: Publish
uses: CtrlAltDevelop/ci-workflows/.github/workflows/dart-publish.yml@v1.2.0
permissions:
contents: read
# Lets pub.dev trust this run without a stored secret.
id-token: write
steps:
- uses: actions/checkout@v7

# Pure Dart package: no Flutter SDK needed. This also sets up the
# credentials pub.dev issues to this run.
- uses: dart-lang/setup-dart@v1

- run: dart pub get

- name: Dry run
run: dart pub publish --dry-run

- name: Publish
run: dart pub publish --force
with:
sdk: dart
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ example/pubspec.lock
.flutter-plugins-dependencies
/build/
/coverage/

# The demo compiled for GitHub Pages; built in CI, never committed.
example/web/main.dart.js*
75 changes: 75 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
## 2.4.0

### Added

- **`DPoPNonceStore`** remembers the most recent `DPoP-Nonce` each server
issued, keyed by origin, and `DPoPClient(keyPair, nonces: store)` — or
`DPoPSignerClient(signer, nonces: store)` — puts it in every proof without
the call site passing it. `store.update(url, response.headers)` reads the
header off any response, case-insensitively, and returns `true` only when
the nonce is one this store had not already tried, which is exactly the
condition for retrying a `use_dpop_nonce` rejection and the guard against
retrying forever. An explicit `nonce:` still wins. `forget(url)` drops one
origin, `clear()` the lot.
- **`DPoPKeyPair.fromPrivateJwk` and `privateJwk`** store and restore a key as
a JWK (RFC 7518 §6.2.2) rather than a PEM — the shape
`crypto.subtle.exportKey('jwk', …)` gives, a JOSE library in another
language hands you, and storage that holds JSON wants. `privateJwk` is the
public `jwk` plus `d`, so the two forms are the same key; `fromPrivateJwk`
reads only `kty`, `crv`, `d`, `x` and `y`, so a WebCrypto export can be
passed through with its `ext` and `key_ops` still on it.

`x` and `y` are optional, since the public half is derived from `d`, and
**checked** when present: a JWK whose coordinates do not belong to its `d`
is refused rather than used to publish a key that cannot verify its own
signatures. A JWK that is not a readable P-256 private key — no `d`,
another curve, a scalar out of range — throws a `FormatException`, as the
PEM constructors do.
- **A live demo**, built from the package with `dart compile js` and published
to [ctrlaltdevelop.github.io/dpop_client](https://ctrlaltdevelop.github.io/dpop_client/):
generate a key — or paste your own, as a PEM or a JWK — sign a proof for a
request you describe, and read the claims a server would check. The source
is in `example/web`, and no key or token leaves the browser.

### Changed

- **Proofs are signed about eleven times faster: ~0.23 ms on the Dart VM,
down from ~2.8 ms.** Two changes, neither of which alters a signature:

`pointycastle` holds curve points in affine coordinates, so every addition
and doubling divides — one modular inverse each, the most expensive
operation in the field, some 340 of them for a single `k * G`. The
generator now multiplies in Jacobian coordinates, deferring the division to
a single inverse at the end. And because the generator never changes, its
multiples are precomputed into a Lim–Lee comb of eight blocks, so `k * G`
costs 32 doublings and 32 additions rather than 256 of one and 64 of the
other. `DPoPKeyPair.generate` and `fromPrivateKeyPem` multiply too, and got
the same.

The 255-entry table is built on the first signature — about 15 ms, once,
and roughly 35 KB held for the life of the process, so a process that signs
a single proof and exits is slower than it was. The entries are converted
to affine form a layer at a time with Montgomery's trick, nine modular
inverses rather than 255, which is what keeps that build from costing more
than the first forty signatures.

`ECDSASigner` still derives `k` (RFC 6979) and computes `r` and `s`: the
only borrowed work is the multiplication, and the tests check it against
pointycastle's own result for 250 random scalars, for every single-bit
scalar in all 256 positions, at the comb's row boundaries and on the curve
equation itself. Signatures are byte-for-byte what they were.
- The P-256 domain parameters are built once per process instead of per call.
`ECCurve_prime256v1()` decompresses the generator each time it is
constructed, which `isP256` alone was paying for twice per key.

### Notes

- Nothing in this release changes a proof's bytes, and nothing is removed.
`DPoPClient(keyPair)` with no store behaves exactly as before.
- A scalar wider than 256 bits is reduced modulo the group order rather than
refused. `G` has order `n`, so it is the same point pointycastle returns.
- Like `pointycastle` — and like Dart's `BigInt` underneath it — the faster
multiplication is not constant-time. That is the exposure the package
already had, and it is why a key that must resist a local side-channel
attacker belongs in a keystore behind a `DPoPSigner`.

## 2.3.0

### Added
Expand Down
Loading