Skip to content

feat: publish imported key certificates in JWKS - #3257

Merged
tada5hi merged 2 commits into
masterfrom
feat/key-store-certificates
Jul 15, 2026
Merged

tada5hi merged 2 commits into
masterfrom
feat/key-store-certificates

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • accept an optional PEM certificate chain when importing signature key material and reject a leaf certificate whose public key does not match the imported key
  • publish leaf-first x5c and SHA-256 x5t#S256 metadata on global and realm JWKS collection/item endpoints, while keeping malformed stored certificate data from breaking JWKS reads
  • expose certificate import in the key form and update shared API/spec/i18n contracts
  • add stable certificate fixtures plus helper, service, and HTTP coverage

Testing

  • package builds: specs, core-kit, i18n, core-http-kit, client-web-kit
  • full apps/server-core build and type check
  • ESLint on all changed TypeScript/Vue sources
  • i18n suite: 77 passed
  • certificate helper suite: 5 passed
  • key service suite: 29 passed
  • key HTTP suite: 10 passed
  • full server-core run: 153 files passed; one unrelated shared-SQLite parallel failure in grant-refresh-token.spec.ts, whose isolated rerun passed 14/14

Notes

  • uses the existing nullable auth_keys.certificate column; no migration is required
  • RFC 8705 trust-anchor management remains a separate Stage C PR

Summary by CodeRabbit

  • New Features
    • Added optional certificate input for key create/import (with validation and localized UI label).
    • JWKS responses now include certificate-chain metadata (x5c) and SHA-256 thumbprint (x5t#S256) when certificates are provided and applicable.
  • Bug Fixes
    • Certificate material is now validated to match the related key; mismatches are rejected.
    • Malformed certificate data won’t prevent JWKS responses, and certificate fields are omitted when unavailable.
  • Documentation
    • Updated “Realm Key Store” documentation for plans 069/071 Stage B certificate attachment and publication behavior.
  • Tests
    • Added unit/integration coverage for certificate parsing, matching, and JWKS publishing/omission.

Copilot AI review requested due to automatic review settings July 14, 2026 19:49

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e44406d5-28c8-4d39-8797-d2ba8fb3cb46

📥 Commits

Reviewing files that changed from the base of the PR and between 115b2ef and 985b75e.

📒 Files selected for processing (3)
  • apps/server-core/src/core/key/certificate.ts
  • apps/server-core/test/unit/core/key/certificate.spec.ts
  • packages/client-web-kit/src/components/entities/key/AKeyForm.vue
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/server-core/test/unit/core/key/certificate.spec.ts
  • apps/server-core/src/core/key/certificate.ts
  • packages/client-web-kit/src/components/entities/key/AKeyForm.vue

📝 Walkthrough

Walkthrough

Adds certificate input and validation for imported signature keys, derives x5c and x5t#S256 metadata, publishes it through collection and single-key JWKS endpoints, and preserves JWKS publication when stored certificates are malformed.

Changes

Imported certificate support

Layer / File(s) Summary
Certificate input contract and form
packages/core-http-kit/..., packages/core-kit/..., packages/client-web-kit/..., packages/i18n/...
Key creation accepts an optional certificate, validates its length, exposes it in the key form, clears it for incompatible key types, and adds localized labels.
Certificate parsing and key validation
apps/server-core/src/core/key/..., apps/server-core/src/core/entities/key/service.ts, apps/server-core/test/unit/core/key/..., apps/server-core/test/unit/core/entities/key/..., .agents/architecture.md
PEM chains are parsed, leaf SPKI matching is enforced during creation, certificate encodings and thumbprints are derived, and certificate-specific behavior is tested and documented.
JWKS certificate metadata
packages/specs/..., apps/server-core/src/adapters/http/controllers/workflows/jwks/..., apps/server-core/test/unit/http/controllers/entities/key.spec.ts
JWKS collection and single-key responses optionally include x5c and x5t#S256; malformed stored certificates omit these fields without breaking usable JWK publication.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant KeyForm
  participant KeyService
  participant CertificateHelpers
  participant JWKSHandlers
  KeyForm->>KeyService: submit imported key and certificate
  KeyService->>CertificateHelpers: parse chain and match leaf SPKI
  CertificateHelpers-->>KeyService: validated certificate chain
  JWKSHandlers->>CertificateHelpers: derive x5c and x5t#S256
  CertificateHelpers-->>JWKSHandlers: optional certificate JWK fields
  JWKSHandlers-->>KeyForm: return JWKS with certificate metadata
Loading

Possibly related PRs

  • authup/authup#3255: Changes the overlapping JWKS controller path to filter keys by signing use and required fields.
  • authup/authup#3256: Changes the overlapping JWKS controller path to filter keys by status.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately captures the main change: publishing imported certificates in JWKS.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/key-store-certificates

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
apps/server-core/test/unit/core/entities/key/service.spec.ts (1)

9-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Certificate PEM fixture loading copy-pasted across two spec files. Both specs read the same certificate.pem/private-key.pem/public-key.pem files with identical readFileSync(new URL(...)) boilerplate.

  • apps/server-core/test/unit/core/entities/key/service.spec.ts#L9-L9,L29-L41: import CERTIFICATE/PRIVATE_KEY/PUBLIC_KEY from a shared test fixture helper instead of re-reading the files inline.
  • apps/server-core/test/unit/http/controllers/entities/key.spec.ts#L8-L9,L25-L37: same — import from the shared helper.
♻️ Proposed fix: shared test fixture module
+// apps/server-core/test/data/certificates/index.ts
+import { readFileSync } from 'node:fs';
+
+export const CERTIFICATE = readFileSync(
+    new URL('./certificate.pem', import.meta.url),
+    'utf8',
+);
+export const PRIVATE_KEY = readFileSync(
+    new URL('./private-key.pem', import.meta.url),
+    'utf8',
+);
+export const PUBLIC_KEY = readFileSync(
+    new URL('./public-key.pem', import.meta.url),
+    'utf8',
+);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/test/unit/core/entities/key/service.spec.ts` at line 9,
Replace the duplicated inline certificate fixture loading in
apps/server-core/test/unit/core/entities/key/service.spec.ts (lines 9 and 29-41)
and apps/server-core/test/unit/http/controllers/entities/key.spec.ts (lines 8-9
and 25-37) with imports of CERTIFICATE, PRIVATE_KEY, and PUBLIC_KEY from the
shared test fixture helper, removing the redundant fs imports and
readFileSync/new URL boilerplate in both specs.
apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts (1)

22-48: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Shared buildCertificateJwkFields copy-pasted between the two JWKS surfaces. Both files define byte-identical logic for deriving x5c/x5t#S256 and tolerating malformed certificates; the shared root cause is that this security-relevant derivation lives in two places that must be kept in sync by hand.

  • apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts#L22-L48: remove the local buildCertificateJwkFields and import a single shared implementation instead.
  • apps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.ts#L15-L35: remove the local buildCertificateJwkFields and import the same shared implementation.
♻️ Proposed fix: hoist the helper into `core/key/certificate.ts` (already home to `parseCertificateChain`/`buildX5c`/`buildX5tS256`)
+// apps/server-core/src/core/key/certificate.ts
+export function buildCertificateJwkFields(
+    certificate: string | null,
+): Partial<Pick<OAuth2JsonWebKey, 'x5c' | 'x5t#S256'>> {
+    if (!certificate) {
+        return {};
+    }
+
+    try {
+        const chain = parseCertificateChain(certificate);
+        return {
+            x5c: buildX5c(chain),
+            'x5t#S256': buildX5tS256(chain),
+        };
+    } catch {
+        return {};
+    }
+}
-import { buildX5c, buildX5tS256, parseCertificateChain } from '../../../../../core/index.ts';
+import { buildCertificateJwkFields } from '../../../../../core/index.ts';
-
-function buildCertificateJwkFields(
-    certificate: string | null,
-): Partial<Pick<OAuth2JsonWebKey, 'x5c' | 'x5t#S256'>> {
-    if (!certificate) {
-        return {};
-    }
-
-    try {
-        const chain = parseCertificateChain(certificate);
-        return {
-            x5c: buildX5c(chain),
-            'x5t#S256': buildX5tS256(chain),
-        };
-    } catch {
-        return {};
-    }
-}

(apply the same import swap in handlers/read.ts, adjusting the relative path depth.)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts`
around lines 22 - 48, Move the shared buildCertificateJwkFields implementation
into core/key/certificate.ts alongside parseCertificateChain, buildX5c, and
buildX5tS256, preserving its malformed-certificate fallback behavior. Remove the
local helper and import the shared implementation in
apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts lines
22-48 and
apps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.ts
lines 15-35, adjusting the relative import path in the latter.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/server-core/src/core/key/certificate.ts`:
- Line 8: Update the imported-key comparison flow in the certificate
key-matching logic around X509Certificate and createHash to parse spkiBase64
with Node’s createPublicKey, then export that parsed key as DER before comparing
it with the certificate’s exported public key. Keep the existing hash or byte
comparison behavior unchanged after both keys use the canonical serialization.

---

Nitpick comments:
In `@apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts`:
- Around line 22-48: Move the shared buildCertificateJwkFields implementation
into core/key/certificate.ts alongside parseCertificateChain, buildX5c, and
buildX5tS256, preserving its malformed-certificate fallback behavior. Remove the
local helper and import the shared implementation in
apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts lines
22-48 and
apps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.ts
lines 15-35, adjusting the relative import path in the latter.

In `@apps/server-core/test/unit/core/entities/key/service.spec.ts`:
- Line 9: Replace the duplicated inline certificate fixture loading in
apps/server-core/test/unit/core/entities/key/service.spec.ts (lines 9 and 29-41)
and apps/server-core/test/unit/http/controllers/entities/key.spec.ts (lines 8-9
and 25-37) with imports of CERTIFICATE, PRIVATE_KEY, and PUBLIC_KEY from the
shared test fixture helper, removing the redundant fs imports and
readFileSync/new URL boilerplate in both specs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e2710016-191a-41ed-8189-909bd9280e1b

📥 Commits

Reviewing files that changed from the base of the PR and between c69e9a2 and 115b2ef.

⛔ Files ignored due to path filters (4)
  • apps/server-core/test/data/certificates/certificate.pem is excluded by !**/*.pem
  • apps/server-core/test/data/certificates/private-key.pem is excluded by !**/*.pem
  • apps/server-core/test/data/certificates/public-key.pem is excluded by !**/*.pem
  • apps/server-core/test/data/certificates/secondary-certificate.pem is excluded by !**/*.pem
📒 Files selected for processing (18)
  • .agents/architecture.md
  • apps/server-core/src/adapters/http/controllers/workflows/jwks/handlers/read.ts
  • apps/server-core/src/adapters/http/controllers/workflows/jwks/module.ts
  • apps/server-core/src/core/entities/key/service.ts
  • apps/server-core/src/core/key/certificate.ts
  • apps/server-core/src/core/key/index.ts
  • apps/server-core/test/unit/core/entities/key/service.spec.ts
  • apps/server-core/test/unit/core/key/certificate.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/key.spec.ts
  • packages/client-web-kit/src/components/entities/key/AKeyForm.vue
  • packages/core-http-kit/src/domains/entities/key/types.ts
  • packages/core-kit/src/domains/key/validator.ts
  • packages/i18n/src/catalogs/de/field.ts
  • packages/i18n/src/catalogs/en/field.ts
  • packages/i18n/src/catalogs/es/field.ts
  • packages/i18n/src/catalogs/fr/field.ts
  • packages/i18n/src/constants.ts
  • packages/specs/src/oauth2/types.ts

@pkg-pr-new

pkg-pr-new Bot commented Jul 14, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3257

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3257

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3257

@authup/access

npm i https://pkg.pr.new/@authup/access@3257

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3257

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3257

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3257

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3257

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3257

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3257

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3257

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3257

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3257

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3257

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3257

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3257

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3257

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3257

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3257

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3257

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3257

commit: 985b75e

@tada5hi
tada5hi merged commit e59a075 into master Jul 15, 2026
12 checks passed
@tada5hi
tada5hi deleted the feat/key-store-certificates branch July 15, 2026 07:41
@github-actions github-actions Bot mentioned this pull request Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants