dpop_client 2.3.0
dpop_client: ^2.3.0 copied to clipboard
DPoP proof JWTs for Dart (RFC 9449) — ES256 key handling, PEM storage, JWK thumbprints, access-token binding and server-supplied nonces.
2.3.0 #
Added #
DPoPSignerandDPoPSignerClientsign proofs with a key the app cannot read: a WebCryptoCryptoKey(extractable: false) or a platform keystore. ImplementDPoPSigner(publicJwk, and an asyncsignreturning the raw 64 byter || s) and pass it toDPoPSignerClient, whosecreateProofisFuture-returning but otherwise identical toDPoPClient.createProof. Both clients build claims with the same code. A signature of the wrong length, such as a DER one, throws aStateErrorinstead of yielding a proof no server can verify, and a JWK carrying the private memberdis refused before anything is signed.DPoPKeyPairimplementsDPoPSigner, soDPoPSignerClient(keyPair)works and one code path can serve both kinds of key.dpopThumbprint(publicJwk)returns the RFC 7638jktof a bare public JWK, for a key with noDPoPKeyPair— before any proof exists, at sign-in, say.DPoPKeyPair.thumbprintnow uses it.
Fixed #
createProofdrops the default port ofwsandwssURLs.wss://host:443/wsis nowhtu: wss://host/ws, andws://host:80/loses its port, ashttpandhttpsalready did. Dart'sUrionly normalises the latter two, so a WebSocket handshake proof with an explicit default port would not have matched the server's copy of the URI.
Notes #
- Any absolute URL with a host is accepted,
wsandwssincluded. - An empty
nonceis treated as no nonce, likenull: the claim is omitted. - Proofs are now assembled by this package instead of
dart_jsonwebtoken, which still produces the ES256 signature. Output is unchanged.
2.2.0 #
Added #
DPoPKeyPair.isBoundTo(accessToken)compares a JWT access token'scnf.jktclaim with the key's thumbprint:truefor a match,falsefor a different key — the usual sign of a key regenerated while an old token was kept — andnullwhen the token carries no readablecnf.jkt, as an opaque token does. The token is not verified; this is a local staleness check.
Fixed #
fromPrivateKeyPemreads the output ofopenssl ecparam -genkey. That command writes anEC PARAMETERSblock ahead of theEC PRIVATE KEY, and the two bodies were joined and rejected as invalid base64. The key block is now picked out of a bundle, so the file works as it is.
Changed #
- Publishing to pub.dev is automated: pushing a
v<version>tag onmainverifies the tag againstpubspec.yamlandCHANGELOG.md, then publishes through GitHub Actions OIDC, with no stored secret.
2.1.0 #
Fixed #
createProofrejects a URL that is not absolute.Uri.parse('/orders')or a URL missing its scheme, such asapi.example.com/orders, used to be signed with anhtuof///orders— a claim no server can match, reported only as a flatinvalid_dpop_proof. It now throws anArgumentErrorthat names the argument and shows the expected shape.- The
DPoPKeyPairconstructor rejects a key on any curve but P-256. It documented the requirement without checking it, so a P-384 pair was published undercrv: P-256and failed at the server as a bad signature. The named constructors already refused other curves; this closes the same gap for keys passed in directly. - The library-level example called
proof.headersas a getter; it is a method, so the snippet on the package page did not do what it appeared to.
Changed #
- CI moved to the shared reusable workflow in CtrlAltDevelop/ci-workflows:
formatting,
analyze --fatal-infos, the tests, the example, a changelog entry per version, and a pana score with no points lost — the same gate across every package here. - The SDK floor moves to Dart 3.12.0, from Dart 3.11.0. This is the floor every package here is gated on rather than something the code needs.
- Dependency bounds are explicit ranges rather than carets — a floor that resolves on the supported SDK, the next major as the ceiling — so a consumer already on an older version in the same major is not forced to move.
- The README carries the pub, pub points, CI and licence badges the other packages here carry.
2.0.0 #
Bug fixes to htu, a much cheaper signing path, and a dependency tree cut down
to what a proof signer actually needs.
Fixed #
htuno longer carries the userinfo component. A target URI (RFC 9110 §7.1) has none, so a URL of the formhttps://user:pass@host/pathproduced a claim the server could never match — and wrote the password into a JWT payload the server is free to log.htunormalises an empty path to/. RFC 9110 §7.1 has the client send/when the path is empty, so a proof forhttps://api.example.comwas compared against the server'shttps://api.example.com/and rejected.- The SEC 1 private key PEM pads the scalar to the full 32 octets. RFC 5915
§3 fixes the
privateKeyOCTET STRING at the curve's octet length; the previous encoder emitted a minimal-length field, so roughly one generated key in 256 was written to storage in a form strict parsers reject. Existing PEMs still read back correctly.
Added #
DPoPProof.headers()returns theAuthorizationheader too, under theDPoPscheme rather thanBearer, as RFC 9449 §7.1 requires for a bound token. The token is taken from the proof itself, so the header cannot disagree with theathclaim.DPoPProof.isTokenBoundreports whether a proof carries one.DPoPKeyPair.fromPrivateKeyPemaccepts PKCS#8PRIVATE KEYPEMs alongside the SEC 1EC PRIVATE KEYform, which is what most non-Dart tooling emits.- A key on any curve but P-256 is now refused with a clear message instead of being reinterpreted against P-256's parameters and failing later as an unexplained bad signature.
DPoPKeyPair.fromPemrejects a private and public half that do not belong together, rather than producing proofs whose embedded JWK cannot verify them.DPoPProofimplements==andhashCodeover its token.- A GitHub Actions workflow covering the SDK floor and
stable, a run against the oldest permitted dependency versions, and a publish dry run.
Changed #
- Signing a proof is roughly twice as fast. The private key was re-encoded to PEM and re-parsed on every single request, which cost more than the ECDSA signature itself; the signer now takes the parsed key directly, and the PEMs, the JWK and the thumbprint are each computed once per key pair.
basic_utilsis no longer a dependency, replaced bypointycastleandasn1libdirectly. This dropsarchive,ffi,http,http_parser,json_annotation,loggingandposixfrom the tree — a proof signer has no use for an HTTP client or an archive reader.privateKeyandpublicKeyremain the samepointycastletypes.keyPair.jwkis unmodifiable, now that one map is shared by every proof.- Unreadable key material throws
FormatExceptionconsistently. - Dependency lower bounds are widened to the oldest versions the package is tested against, so it resolves alongside more of the ecosystem. The SDK floor stays at 3.13.0.
1.0.0 #
Initial release, extracted from an internal application module and corrected against RFC 9449 on the way out.
DPoPKeyPair— ES256 (P-256) key handling:generate, PEM round-tripping viaprivateKeyPem, andfromPrivateKeyPem, which derives the public half from the private scalar so only one PEM has to be stored.DPoPKeyPair.jwk/jwkJson— the public key as a JWK, the form that travels in a proof's JWT header.DPoPKeyPair.thumbprint— the RFC 7638 SHA-256 JWK thumbprint, for checking an access token'scnf.jktagainst the key actually held.DPoPClient.createProof— a signeddpop+jwtper request, carryinghtm,htu,iatandjti, plusathwhen an access token is supplied andnoncewhen a server has demanded one.DPoPProof— the token with itsheaders()map, defaulting to the standardDPoPheader name and accepting a gateway-specific one.htunow excludes the query string and fragment, as RFC 9449 §4.2 requires. The internal original signed the full request URI, which a strict server rejects — and did so invisibly, since the offending query parameter was usually added by an interceptor after the call site.iatis truncated to whole seconds rather than rounded, so it cannot land up to half a second in the future and be refused by a server with no clock-skew allowance. This requirednoIssueAt: trueon the underlying signer, which otherwise overwritesiatwith its own clock — meaning the original's computed value never reached the token at all.- Dartdoc across the public API, a runnable
example/, and 36 tests covering the claim set, the header, signature verification,htunormalisation andathhashing.