Login page and Settings → eGov: relay session with a server-side challenge/nonce, QR + eGov Mobile deep link, polling, one-shot completion; IIN from the signer's certificate (own DER reader), users.egov_iin. The relay is trusted (PM decision): no own XMLDSig check. CLI peppa user egov, mock-kazeds-relay, tests. Dev mode: /_next/static is no-store (Cloudflare cached stale chunks). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.9 KiB
JavaScript
40 lines
1.9 KiB
JavaScript
// LOCAL UI TEST ONLY. This returns fabricated XML and MUST NOT be used to
|
|
// authenticate users or be exposed publicly.
|
|
const express = require('express');
|
|
const crypto = require('node:crypto');
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
const sessions = new Map();
|
|
|
|
app.post('/v1/egov/sessions', (req, res) => {
|
|
const id = crypto.randomUUID();
|
|
const source = req.body?.documentsToSign?.[0]?.documentXml || '';
|
|
const challenge = source.match(/<challenge>([^<]+)<\/challenge>/)?.[1] || 'MISSING_CHALLENGE';
|
|
const nonce = source.match(/<nonce>([^<]+)<\/nonce>/)?.[1] || 'MISSING_NONCE';
|
|
sessions.set(id, { createdAt: Date.now(), polls: 0, challenge, nonce });
|
|
res.status(201).json({
|
|
session_id: id,
|
|
qr_content: `mobileSign:https://example.invalid/mgovSign/${id}`,
|
|
deeplink: `https://m.egov.kz/mobileSign?link=https%3A%2F%2Fexample.invalid%2FmgovSign%2F${id}`,
|
|
expires_at: new Date(Date.now() + 5 * 60_000).toISOString(),
|
|
});
|
|
});
|
|
|
|
app.get('/v1/egov/:id/status', (req, res) => {
|
|
const session = sessions.get(req.params.id);
|
|
if (!session) return res.status(404).json({ error: 'Mock session not found' });
|
|
session.polls += 1;
|
|
if (session.polls < 3) return res.json({ status: session.polls === 1 ? 'scanned' : 'pending', expires_in: 290 });
|
|
sessions.delete(req.params.id);
|
|
const signed = `<auth><challenge>${session.challenge}</challenge><nonce>${session.nonce}</nonce><SignatureValue>NOT_A_SIGNATURE</SignatureValue><X509Certificate>NOT_A_CERTIFICATE</X509Certificate></auth>`;
|
|
return res.json({
|
|
status: 'completed',
|
|
// Deliberately fabricated: only exercises UI plumbing; not a valid signature.
|
|
signedDocuments: [{ id: 1, nameRu: 'Mock response (not signed)', documentXml: signed }],
|
|
});
|
|
});
|
|
|
|
const port = Number(process.env.MOCK_PORT || 3103);
|
|
app.listen(port, '127.0.0.1', () => console.log(`TEST MOCK ONLY at http://127.0.0.1:${port}/v1`));
|