Skip to content

[dummy_ci 2/7] Add Ed25519PublicJwk model and SPKI PEM/JWK parser - #5230

Open
ievdokdm wants to merge 2 commits into
197798-1-dummy-ci-scaffoldfrom
197798-2-dummy-ci-ed25519-jwk
Open

ievdokdm wants to merge 2 commits into
197798-1-dummy-ci-scaffoldfrom
197798-2-dummy-ci-ed25519-jwk

Conversation

@ievdokdm

@ievdokdm ievdokdm commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Adds the self-contained Ed25519PublicJwk model and SPKI PEM/JWK parser to dummy_ci, mirroring Cocoon PR #5196.

Summary

  • Adds collection, crypto, jose_plus, and pem dependencies to dummy_ci/pubspec.yaml and updates dummy_ci/pubspec.lock.
  • Implements dummy_ci/lib/src/model/ed25519_jwk.dart with strict 44-byte RFC 8410 Ed25519 SPKI DER validation, RFC 7638 SHA-256 thumbprint kid, RFC 8037 JWK serialization, toJoseKey(), toPublicKeyPem(), and isValidJwksKeyId().
  • Exports ed25519_jwk.dart from dummy_ci/lib/dummy_ci.dart.
  • Adds unit tests in dummy_ci/test/model/ed25519_jwk_test.dart covering RFC 8037 Appendix A.1/A.3/A.4 and RFC 8410 test vectors, jose_plus EdDSA verification, and malformed SPKI/PEM/kid rejection.

Stack

Testing

  • dart pub get, dart format --set-exit-if-changed ., dart analyze --fatal-infos, dart test --test-randomize-ordering-seed=random --reporter expanded
  • dart --enable-asserts analyze.dart and dart run dev/cocoon_code_health/bin/check.dart

Towards flutter/flutter#197798

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Dec 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the Ed25519PublicJwk class to represent Ed25519 public keys as RFC 8037 Octet Key Pair (OKP) JSON Web Keys, along with corresponding tests and dependency updates. The review feedback focuses on performance optimizations and code simplification within the new model. Key recommendations include avoiding unnecessary memory allocations by utilizing Uint8List.sublistView, UnmodifiableUint8ListView, and setRange instead of list copying and spread operators, as well as simplifying the == operator and hashCode implementation to compare only the unique x coordinate.

Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved

@jtmcdole jtmcdole left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're going to have a bad time with ci.yaml checks. this is why I started a thread to talk about removing it from cocoon as a required passing test.

Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I personally do not like barrel imports.

@jtmcdole jtmcdole left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds Ed25519PublicJwk and isValidJwksKeyId to dummy_ci as layer 2 of 7 (#5229 to #5235), mirroring app_dart/lib/src/model/jwks/ed25519_jwk.dart. Static checks, formatting, dart compile exe, and all 10 unit tests pass locally (54/54 lines covered, max cognitive complexity 6). The main items to address are boundary validation gaps (computeThumbprintForX, isValidJwksKeyId, fromPublicKeyBytes, mixed PEM blocks), missing negative test assertions, day-0 drift against app_dart, and one open barrel-export nit.

against HEAD and local scratch runs (Executed / Read). Active flags: codefu-review three-lens pass (Simplicity/Scope, Resilience/Security, Modern Dart/Tests) with local throwaway verification (SAFE_FOR_LOCAL_EXECUTION, author_association: MEMBER).

🤖 Agent-generated

Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
final fromBytes = Ed25519PublicJwk.fromPublicKeyBytes(
decodeBase64UrlUnpadded(rfcExpectedX),
);
expect(fromBytes, parsed);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing verifies that two distinct keys compare unequal, that mutating the input list after fromPublicKeyBytes leaves the JWK intact, or that toJoseKey() rejects a JWS signed by a different key. A broken operator == (I removed && other.x == x locally and all 6 tests passed) or a missing defensive copy goes undetected.

Assert expect(parsed, isNot(rfc8410Parsed)), mutate the byte list passed to fromPublicKeyBytes and confirm fromBytes.publicKeyBytes is unchanged, and verify rfc8037SignedJws fails with JoseException against rfc8410Parsed.toJoseKey().

Details

Impact: A broken operator == (I removed && other.x == x locally and all 6 tests passed) or a missing defensive copy goes undetected.

Evidence (Executed): Mutated ed25519_jwk.dart:173 to drop && other.x == x and ran dart test test/model/ed25519_jwk_test.dart; all 6 tests still passed.

rfc8410Parsed is already constructed three lines below at line 69, so both the negative equality check and the wrong-key JWS rejection test need only a few lines.

🤖 Agent-generated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

throwsFormatException,
);
expect(
() => Ed25519PublicJwk.fromPublicKeyPem(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every negative test uses bare throwsFormatException, even though fromPublicKeyPem has four distinct FormatException branches. Because package:pem silently skips invalid base64, a broken fixture hits blocks.isEmpty and still passes. Bare throwsFormatException cannot distinguish a regression in SPKI validation or multi-block detection from an unrelated PEM parse failure.

Match the failure reason on each case with throwsA(isA<FormatException>().having((e) => e.message, 'message', contains(...))) (such as 'BEGIN PUBLIC KEY', 'single PEM block', 'Invalid SPKI DER', and 'thumbprint').

Details

Impact: Bare throwsFormatException cannot distinguish a regression in SPKI validation or multi-block detection from an unrelated PEM parse failure.

Evidence (Executed): Ed25519PublicJwk.fromPublicKeyPem('-----BEGIN PUBLIC KEY-----\n-----END PUBLIC KEY-----') threw Invalid SPKI DER structure for Ed25519 public key. rather than Expected PEM block.

Line 112 ('-----BEGIN PUBLIC KEY-----\n-----END PUBLIC KEY-----') currently decodes as an empty byte list under package:pem lax mode and throws Invalid SPKI DER structure for Ed25519 public key.. Matching message substrings pins each branch directly.

🤖 Agent-generated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -0,0 +1,180 @@
// Copyright 2026 The Flutter Authors. All rights reserved.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates app_dart/lib/src/model/jwks/ed25519_jwk.dart and has already drifted on day 0 (asUnmodifiableView() and simplified ==/hashCode are only here). Keeping dummy_ci/ self-contained for Cloud Run explains the copy, so add a short header comment naming the mirror. Future security or parser fixes to one copy will be missed in the other without an explicit sync note or shared package.

Add a brief file comment noting this mirrors app_dart/lib/src/model/jwks/ed25519_jwk.dart, and backport any fixes from this review (asUnmodifiableView(), ==/hashCode, and boundary checks) to app_dart.

Details

Impact: Future security or parser fixes to one copy will be missed in the other without an explicit sync note or shared package.

Evidence (Read): diff -u app_dart/lib/src/model/jwks/ed25519_jwk.dart dummy_ci/lib/src/model/ed25519_jwk.dart shows identical 180-line files except asUnmodifiableView() (line 116) and simplified ==/hashCode (lines 172-176) exist only in dummy_ci.

Option C: if we do not need single-directory gcloud run deploy --source dummy_ci builds, extract a tiny pure-Dart package (depending only on crypto, meta, and pem) shared by both app_dart and dummy_ci. Otherwise, keep the standalone copy and keep the two files aligned.

🤖 Agent-generated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move it to common place once all stacked PR's for jwks and dummy_ci landed

Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
Comment thread dummy_ci/lib/src/model/ed25519_jwk.dart Resolved
@ievdokdm
ievdokdm force-pushed the 197798-1-dummy-ci-scaffold branch from 1fa4682 to 36bdcd3 Compare December 4, 2026 22:04
@ievdokdm
ievdokdm force-pushed the 197798-2-dummy-ci-ed25519-jwk branch from 2011823 to 1139f52 Compare December 5, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants