feat(smime): client-side certificate enrolment — web S/MIME now fully functional
New enroll.js: generates an RSA-2048 keypair with WebCrypto (extractable only long enough to export to PKCS#8), builds and signs a real CSR with pkijs (same per-call-engine convention as smime-sign.js/smime-verify.js — nativeEngine() passed explicitly, no global pkijs.setEngine call), POSTs it to the already-existing /api/smime/enroll (same-origin fetch — the plugin's privileged tier gets allow-same-origin, cookies included by default), and packages the result into a key record using the EXACT same encrypted-at-rest convention as a PKCS#12 import (AES-GCM/PBKDF2 600k, exported from pkcs12.js) so every downstream sign/encrypt/decrypt/verify path is identical regardless of how the key arrived. New "Get a certificate" button in the settings-section UI, next to "Import key" — prompts for a storage passphrase, calls enroll(), saves the key record, and refreshes the list. No changes needed to the CA route or the CA provider — both were already real and already tested. Live end-to-end verified (not just unit-level): logged in via the real dev-mode session flow, clicked through the actual plugin UI, got back a real certificate (RSA-2048, correct validity window, real fingerprint) for dev@localhost, then unlocked it with the same passphrase — the encrypted private key round-trips correctly through the identical code path a PKCS#12 import would use. Also fixes a real bug hit during that verification: SESSION_SECRET must be >= 32 chars (lib/auth/crypto.ts), but .env.dev.example's own documented placeholder was 29 - failing "Failed to store Stalwart auth context" on every feature needing the real session-cookie flow (this enrolment route, offline sync, AI server class). Anyone following the setup doc verbatim would have hit this. Padded the placeholder to 37 chars.
This commit is contained in:
@@ -12,7 +12,7 @@ import { generateUUID } from './util.js';
|
||||
import { extractCertificateInfo, classifyCapabilities } from './certificate-utils.js';
|
||||
import { withLinerEngine, getLinerCrypto } from './crypto-engine.js';
|
||||
|
||||
const KDF_ITERATIONS = 600_000;
|
||||
export const KDF_ITERATIONS = 600_000;
|
||||
const AES_KEY_LENGTH = 256;
|
||||
|
||||
function stringToAB(str) {
|
||||
@@ -149,7 +149,7 @@ async function deriveWrappingKey(passphrase, salt, iterations) {
|
||||
);
|
||||
}
|
||||
|
||||
async function encryptPrivateKey(pkcs8Bytes, passphrase) {
|
||||
export async function encryptPrivateKey(pkcs8Bytes, passphrase) {
|
||||
const salt = crypto.getRandomValues(new Uint8Array(32)).buffer;
|
||||
const iv = crypto.getRandomValues(new Uint8Array(12)).buffer;
|
||||
const wrappingKey = await deriveWrappingKey(passphrase, salt, KDF_ITERATIONS);
|
||||
|
||||
Reference in New Issue
Block a user