@tamga-network/onboard 0.0.0-stage → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +190 -0
- package/README.md +160 -2
- package/lib/application.d.ts +116 -0
- package/lib/application.d.ts.map +1 -0
- package/lib/application.js +262 -0
- package/lib/application.js.map +1 -0
- package/lib/checks.d.ts +124 -0
- package/lib/checks.d.ts.map +1 -0
- package/lib/checks.js +1028 -0
- package/lib/checks.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.d.ts.map +1 -0
- package/lib/cli.js +515 -0
- package/lib/cli.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -0
- package/lib/index.js.map +1 -0
- package/lib/keys.d.ts +116 -0
- package/lib/keys.d.ts.map +1 -0
- package/lib/keys.js +274 -0
- package/lib/keys.js.map +1 -0
- package/lib/mcp.d.ts +240 -0
- package/lib/mcp.d.ts.map +1 -0
- package/lib/mcp.js +459 -0
- package/lib/mcp.js.map +1 -0
- package/lib/network.d.ts +22 -0
- package/lib/network.d.ts.map +1 -0
- package/lib/network.js +37 -0
- package/lib/network.js.map +1 -0
- package/lib/node.d.ts +200 -0
- package/lib/node.d.ts.map +1 -0
- package/lib/node.js +931 -0
- package/lib/node.js.map +1 -0
- package/lib/paths.d.ts +12 -0
- package/lib/paths.d.ts.map +1 -0
- package/lib/paths.js +60 -0
- package/lib/paths.js.map +1 -0
- package/lib/rules.d.ts +65 -0
- package/lib/rules.d.ts.map +1 -0
- package/lib/rules.js +357 -0
- package/lib/rules.js.map +1 -0
- package/package.json +47 -4
package/lib/checks.js
ADDED
|
@@ -0,0 +1,1028 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `tamga-onboard check` — kurumun kendi kurulumunu ve (katıldıktan sonra) imzalı güven listesindeki görünümünü YALNIZ OKUYARAK
|
|
3
|
+
* denetler. Hiçbir şey yazmaz, ağa sunum göndermez, kişisel veri kullanmaz (sorgu ucu yalnız geçersiz isteklerle yoklanır).
|
|
4
|
+
*
|
|
5
|
+
* İki aşama:
|
|
6
|
+
* kurulum başvuru dosyaları, anahtar ve CSR'lar (dosya izni, anahtar ↔ CSR ↔ sertifika), alan adı (DNS, TXT teyidi), https
|
|
7
|
+
* adresleri, kendi servisi olan kurumda `.well-known` meta verisi, sorgu ucu erişimi, doğrulayıcının alan adı
|
|
8
|
+
* liste imzalı liste (pakete gömülü kök pinleriyle, BT4: `@tamga-network/trust` yükleyicisi), kurumun durumu, kayıt verisi,
|
|
9
|
+
* belge türü yetkileri, üst makam, iptal listesi çapası, kayıt sertifikaları, doğrulayıcı kaydı, kapı grupları; servis
|
|
10
|
+
* meta verisi ve imzalı meta verinin sertifika zinciri → listedeki kök; yerel sertifikanın listedeki köke zinciri
|
|
11
|
+
* Liste aşaması operatörün iç denetim aracındaki salt-okur denetimlerin kamuya açık olanlarıdır (iç servis sağlığı ve operatör
|
|
12
|
+
* komutları yok; düzeltme önerileri kurumun yapacaklarıdır).
|
|
13
|
+
*/
|
|
14
|
+
import { X509Certificate, createHash, verify as nodeVerify } from "node:crypto";
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { request as httpRequest } from "node:http";
|
|
17
|
+
import { request as httpsRequest } from "node:https";
|
|
18
|
+
import { BlockList, isIP } from "node:net";
|
|
19
|
+
import { loadTrustSet } from "@tamga-network/trust";
|
|
20
|
+
import { validateProfile } from "./application.js";
|
|
21
|
+
import { csrExpectations, inspectCsr, privateKeyPermissionOk, privateKeySpkiSha256, csrSpkiSha256 } from "./keys.js";
|
|
22
|
+
import { APPLICATION_FILE_RE, within } from "./paths.js";
|
|
23
|
+
import { CERT_NAME_RE, validateIssuerApplication, validateRpApplication } from "./rules.js";
|
|
24
|
+
import { NETWORKS } from "./network.js";
|
|
25
|
+
/**
|
|
26
|
+
* Adres yerel ağa mı işaret ediyor (SSRF; 2026-11-04 güvenlik turu O4): loopback, özel (RFC 1918), bağlantı-yerel, CGNAT
|
|
27
|
+
* (100.64/10), "bu ağ" (0/8), çok noktaya yayın, ayrılmış, IPv6 ULA (fc00::/7), bağlantı-yerel (fe80::/10), IPv4 eşlemeli IPv6.
|
|
28
|
+
*/
|
|
29
|
+
const PRIVATE = (() => {
|
|
30
|
+
const b = new BlockList();
|
|
31
|
+
for (const [net, bits] of [
|
|
32
|
+
["0.0.0.0", 8],
|
|
33
|
+
["10.0.0.0", 8],
|
|
34
|
+
["100.64.0.0", 10],
|
|
35
|
+
["127.0.0.0", 8],
|
|
36
|
+
["169.254.0.0", 16],
|
|
37
|
+
["172.16.0.0", 12],
|
|
38
|
+
["192.0.0.0", 24],
|
|
39
|
+
["192.0.2.0", 24],
|
|
40
|
+
["192.168.0.0", 16],
|
|
41
|
+
["198.18.0.0", 15],
|
|
42
|
+
["198.51.100.0", 24],
|
|
43
|
+
["203.0.113.0", 24],
|
|
44
|
+
["224.0.0.0", 4],
|
|
45
|
+
["240.0.0.0", 4],
|
|
46
|
+
])
|
|
47
|
+
b.addSubnet(net, bits, "ipv4");
|
|
48
|
+
for (const [net, bits] of [
|
|
49
|
+
["::", 128],
|
|
50
|
+
["::1", 128],
|
|
51
|
+
["fc00::", 7],
|
|
52
|
+
["fe80::", 10],
|
|
53
|
+
["fec0::", 10],
|
|
54
|
+
["ff00::", 8],
|
|
55
|
+
["2001:db8::", 32],
|
|
56
|
+
])
|
|
57
|
+
b.addSubnet(net, bits, "ipv6");
|
|
58
|
+
return b;
|
|
59
|
+
})();
|
|
60
|
+
export function isPrivateAddress(ip) {
|
|
61
|
+
const v = isIP(ip);
|
|
62
|
+
if (v === 4)
|
|
63
|
+
return PRIVATE.check(ip, "ipv4");
|
|
64
|
+
if (v !== 6)
|
|
65
|
+
return true; // tanınmayan biçim: güvenli taraf
|
|
66
|
+
const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(ip)?.[1];
|
|
67
|
+
if (mapped)
|
|
68
|
+
return PRIVATE.check(mapped, "ipv4");
|
|
69
|
+
if (/^::ffff:/i.test(ip))
|
|
70
|
+
return true; // onaltılı yazılmış eşlemeli adres
|
|
71
|
+
return PRIVATE.check(ip, "ipv6");
|
|
72
|
+
}
|
|
73
|
+
/** Bağlantı anındaki çözüm denetlenir (DNS yeniden bağlama da yakalanır): bir adres bile yerel ağdaysa bağlantı kurulmaz. */
|
|
74
|
+
const guardedLookup = (resolveAll) => (host, opts, cb) => {
|
|
75
|
+
resolveAll(host).then((addrs) => {
|
|
76
|
+
const bad = addrs.find((a) => isPrivateAddress(a.address));
|
|
77
|
+
if (!addrs.length)
|
|
78
|
+
return cb(Object.assign(new Error(`çözülemedi: ${host}`), { code: "ENOTFOUND" }), "");
|
|
79
|
+
if (bad)
|
|
80
|
+
return cb(Object.assign(new Error(`yerel / özel ağ adresi okunmaz: ${host} → ${bad.address} (--allow-private)`), {
|
|
81
|
+
code: "EPRIVATE",
|
|
82
|
+
}), "");
|
|
83
|
+
if (opts?.all)
|
|
84
|
+
return cb(null, addrs);
|
|
85
|
+
cb(null, addrs[0].address, addrs[0].family);
|
|
86
|
+
}, (e) => cb(e, ""));
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Varsayılan HTTP (O4): zaman aşımı, en çok 2 MB gövde; https dışı adres yalnız `allowHttp` ile; yönlendirmeler elle izlenir
|
|
90
|
+
* (her adımda şema ve adres denetimi); alan adı çözümünden sonra yerel / özel ağ adresi reddedilir (`allowPrivate` hariç).
|
|
91
|
+
*/
|
|
92
|
+
export function defaultHttp(o = {}) {
|
|
93
|
+
const resolveAll = o.resolveAll ?? (async (h) => (await import("node:dns/promises")).lookup(h, { all: true, verbatim: true }));
|
|
94
|
+
const lookup = o.allowPrivate ? undefined : guardedLookup(resolveAll);
|
|
95
|
+
const once = (u, init) => new Promise((ok, fail) => {
|
|
96
|
+
const req = (u.protocol === "https:" ? httpsRequest : httpRequest)(u, {
|
|
97
|
+
method: init?.method ?? "GET",
|
|
98
|
+
headers: init?.headers,
|
|
99
|
+
timeout: o.timeoutMs ?? 15000,
|
|
100
|
+
...(lookup ? { lookup: lookup } : {}),
|
|
101
|
+
}, (res) => {
|
|
102
|
+
const chunks = [];
|
|
103
|
+
let size = 0;
|
|
104
|
+
res.on("data", (c) => {
|
|
105
|
+
size += c.length;
|
|
106
|
+
if (size > 2 * 1024 * 1024) {
|
|
107
|
+
req.destroy(new Error("yanıt çok büyük (2 MB üstü)"));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
chunks.push(c);
|
|
111
|
+
});
|
|
112
|
+
res.on("end", () => ok({
|
|
113
|
+
status: res.statusCode ?? 0,
|
|
114
|
+
text: Buffer.concat(chunks).toString("utf8"),
|
|
115
|
+
contentType: String(res.headers["content-type"] ?? ""),
|
|
116
|
+
location: typeof res.headers.location === "string" ? res.headers.location : undefined,
|
|
117
|
+
}));
|
|
118
|
+
res.on("error", fail);
|
|
119
|
+
});
|
|
120
|
+
req.on("timeout", () => req.destroy(new Error("zaman aşımı")));
|
|
121
|
+
req.on("error", fail);
|
|
122
|
+
if (init?.body !== undefined)
|
|
123
|
+
req.write(init.body);
|
|
124
|
+
req.end();
|
|
125
|
+
});
|
|
126
|
+
const allowed = (u) => {
|
|
127
|
+
if (u.protocol !== "https:" && !(o.allowHttp && u.protocol === "http:"))
|
|
128
|
+
throw new Error(`yalnız https adresleri okunur: ${u.protocol}//${u.host}`);
|
|
129
|
+
if (u.username || u.password)
|
|
130
|
+
throw new Error("adreste kullanıcı bilgisi kabul edilmez");
|
|
131
|
+
const host = u.hostname.replace(/^\[|\]$/g, "");
|
|
132
|
+
if (!o.allowPrivate && isIP(host) && isPrivateAddress(host))
|
|
133
|
+
throw new Error(`yerel / özel ağ adresi okunmaz: ${host} (--allow-private)`);
|
|
134
|
+
};
|
|
135
|
+
return async (url, init) => {
|
|
136
|
+
let u = new URL(url);
|
|
137
|
+
let req = init;
|
|
138
|
+
for (let hop = 0;; hop++) {
|
|
139
|
+
allowed(u);
|
|
140
|
+
const r = await once(u, req);
|
|
141
|
+
if (![301, 302, 303, 307, 308].includes(r.status) || !r.location) {
|
|
142
|
+
const { location: _l, ...rest } = r;
|
|
143
|
+
return rest;
|
|
144
|
+
}
|
|
145
|
+
if (hop >= (o.maxRedirects ?? 5))
|
|
146
|
+
throw new Error("çok fazla yönlendirme");
|
|
147
|
+
u = new URL(r.location, u);
|
|
148
|
+
// 303 (ve POST'ta 301/302): gövdesiz GET — fetch ile aynı
|
|
149
|
+
if (r.status === 303 || ((r.status === 301 || r.status === 302) && req?.method === "POST"))
|
|
150
|
+
req = { headers: req?.headers };
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
export async function defaultDns() {
|
|
155
|
+
const d = await import("node:dns/promises");
|
|
156
|
+
return {
|
|
157
|
+
lookup: async (h) => (await d.lookup(h, { all: true })).map((a) => a.address),
|
|
158
|
+
resolveTxt: (h) => d.resolveTxt(h),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/** Dış kaynaktan gelen metni rapora güvenli koy: denetim karakterleri yok, en çok 300 karakter. */
|
|
162
|
+
export const clean = (s) => String(s ?? "")
|
|
163
|
+
// eslint-disable-next-line no-control-regex
|
|
164
|
+
.replace(/[\u0000-\u001f\u007f-\u009f--]/g, " ")
|
|
165
|
+
.slice(0, 300);
|
|
166
|
+
const sha256Hex = (b) => createHash("sha256").update(b).digest("hex");
|
|
167
|
+
const der = (b64) => Buffer.from(b64, "base64");
|
|
168
|
+
const activeAt = (from, until, now) => Date.parse(from) <= now.getTime() && (!until || now.getTime() < Date.parse(until));
|
|
169
|
+
const missing = (rec, fields) => fields.filter((f) => rec[f] === undefined || rec[f] === null || (Array.isArray(rec[f]) && !rec[f].length));
|
|
170
|
+
const REG_FIELDS_ISSUER = ["trade_name", "identifiers", "postal_address", "contact", "supervisory_authority"];
|
|
171
|
+
const REG_FIELDS_RP = [...REG_FIELDS_ISSUER, "service_description", "is_public_sector_body", "entitlements"];
|
|
172
|
+
const safe = async (http, url, init) => {
|
|
173
|
+
try {
|
|
174
|
+
return await http(url, init);
|
|
175
|
+
}
|
|
176
|
+
catch (e) {
|
|
177
|
+
return { status: 0, text: e.message, contentType: "" };
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
/** RFC 8414 / OpenID4VCI §12.2.2: `.well-known/<tür>` alan adıyla yolun arasına girer. */
|
|
181
|
+
export const wellKnown = (issuerUrl, kind) => {
|
|
182
|
+
const u = new URL(issuerUrl);
|
|
183
|
+
return `${u.origin}/.well-known/${kind}${u.pathname.replace(/\/$/, "")}`;
|
|
184
|
+
};
|
|
185
|
+
export async function listingChecks(http, o) {
|
|
186
|
+
const rows = [];
|
|
187
|
+
const now = o.now ?? new Date();
|
|
188
|
+
const net = NETWORKS[o.environment];
|
|
189
|
+
const base = (o.trustBase ?? net.trust).replace(/\/$/, "");
|
|
190
|
+
const pins = (o.pins?.length ? o.pins : net.pins).map((p) => p.toLowerCase());
|
|
191
|
+
const strict = o.environment === "production";
|
|
192
|
+
// D4: pakete gömülü pin yerine elle verilen değer — yalnız bant dışı doğrulanmış değerle; raporda görünür
|
|
193
|
+
if (o.pins?.length)
|
|
194
|
+
rows.push({
|
|
195
|
+
id: "L0",
|
|
196
|
+
check: "Kök pinleri",
|
|
197
|
+
result: "warn",
|
|
198
|
+
detail: "pin elle verildi (pakete gömülü değer yerine)",
|
|
199
|
+
fix: "değeri tamga.network/trust-anchor'daki değerle bant dışında karşılaştırdığınızdan emin olun",
|
|
200
|
+
});
|
|
201
|
+
const read = async (rel) => {
|
|
202
|
+
const r = await safe(http, `${base}/${rel}`);
|
|
203
|
+
return r.status === 200 ? r.text.trim() : null;
|
|
204
|
+
};
|
|
205
|
+
const lotlJws = await read("lotl.jws");
|
|
206
|
+
if (!lotlJws) {
|
|
207
|
+
rows.push({
|
|
208
|
+
id: "L1",
|
|
209
|
+
check: "İmzalı liste okundu",
|
|
210
|
+
result: "fail",
|
|
211
|
+
detail: `${base}/lotl.jws okunamadı`,
|
|
212
|
+
fix: "ağ bağlantısı / vekil sunucu; adres doğru mu (--trust)",
|
|
213
|
+
});
|
|
214
|
+
return rows;
|
|
215
|
+
}
|
|
216
|
+
const national = {};
|
|
217
|
+
try {
|
|
218
|
+
const payload = JSON.parse(Buffer.from(lotlJws.split(".")[1] ?? "", "base64url").toString("utf8"));
|
|
219
|
+
for (const n of payload.national_lists ?? [])
|
|
220
|
+
if (n.status === "ACTIVE") {
|
|
221
|
+
const t = await read(`tl-${n.state_code.toLowerCase()}.jws`);
|
|
222
|
+
if (t)
|
|
223
|
+
national[n.state_code.toUpperCase()] = t;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
/* yükleyici imzayı ve biçimi aşağıda reddeder */
|
|
228
|
+
}
|
|
229
|
+
const wrprcText = await read("wrprc/index.json");
|
|
230
|
+
let wrprcIndex = null;
|
|
231
|
+
try {
|
|
232
|
+
wrprcIndex = wrprcText ? JSON.parse(wrprcText) : null;
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
wrprcIndex = null;
|
|
236
|
+
}
|
|
237
|
+
let store;
|
|
238
|
+
try {
|
|
239
|
+
({ store } = await loadTrustSet({
|
|
240
|
+
lotlJws,
|
|
241
|
+
nationalListJws: national,
|
|
242
|
+
anchorsJsonl: (await read("anchors.jsonl")) ?? "",
|
|
243
|
+
rootFingerprints: pins,
|
|
244
|
+
environment: o.environment,
|
|
245
|
+
anchorMaxAgeMs: (o.anchorMaxAgeHours ?? 2) * 3600_000,
|
|
246
|
+
versionMemory: "none",
|
|
247
|
+
now,
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
rows.push({
|
|
252
|
+
id: "L1",
|
|
253
|
+
check: "İmzalı liste doğrulandı (kök pini, imza, ortam)",
|
|
254
|
+
result: "fail",
|
|
255
|
+
detail: clean(e.message),
|
|
256
|
+
fix: "ortam (--env) doğru mu; pin değiştiyse tamga.network/trust-anchor'daki değerle karşılaştırın (--pin) ya da aracı güncelleyin",
|
|
257
|
+
});
|
|
258
|
+
return rows;
|
|
259
|
+
}
|
|
260
|
+
const f = store.getFreshness();
|
|
261
|
+
rows.push({
|
|
262
|
+
id: "L1",
|
|
263
|
+
check: "İmzalı liste doğrulandı (kök pini, imza, ortam)",
|
|
264
|
+
result: f?.healthy ? "pass" : strict ? "fail" : "warn",
|
|
265
|
+
detail: `${base} · lotl v${f?.lotlVersion} · ulusal listeler ${[...store.national.keys()].join(",")} · taze ${f?.healthy ? "evet" : "HAYIR"}`,
|
|
266
|
+
fix: f?.healthy
|
|
267
|
+
? undefined
|
|
268
|
+
: "liste bayat görünüyor — birkaç dakika sonra tekrar deneyin; sürerse operatöre bildirin",
|
|
269
|
+
});
|
|
270
|
+
let issuer;
|
|
271
|
+
let statusListUris = [];
|
|
272
|
+
const wrprcPaths = [];
|
|
273
|
+
let vcts = [];
|
|
274
|
+
const idx = wrprcIndex?.items ?? [];
|
|
275
|
+
if (o.slug) {
|
|
276
|
+
issuer = [...store.issuers.values()].find((i) => i.slug === o.slug);
|
|
277
|
+
if (!issuer) {
|
|
278
|
+
rows.push({
|
|
279
|
+
id: "L2",
|
|
280
|
+
check: `Kurum listede (${o.slug})`,
|
|
281
|
+
result: "fail",
|
|
282
|
+
detail: "imzalı listede bu kısa ad yok",
|
|
283
|
+
fix: "kayıt operatörde yapılır: başvuru + CSR'ları gönderin; kayıttan ve yayından sonra (en geç 24 saat) tekrar deneyin. Sandbox test kurumunun kısa adı t-… biçimindedir",
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
const active = issuer.status === "ACTIVE" && activeAt(issuer.valid_from, issuer.valid_until, now);
|
|
288
|
+
rows.push({
|
|
289
|
+
id: "L2",
|
|
290
|
+
check: `Kurum listede ve ACTIVE (${o.slug})`,
|
|
291
|
+
result: active ? "pass" : "fail",
|
|
292
|
+
detail: clean(`${issuer.legal_name} · ${issuer.category}/${issuer.class}/${issuer.assurance} · ${issuer.status} · ${issuer.valid_from.slice(0, 10)} → ${issuer.valid_until.slice(0, 10)}${issuer.test_institution ? " · test kurumu" : ""}`),
|
|
293
|
+
fix: active ? undefined : "kurum askıda, geri çekilmiş ya da geçerlilik dışında — operatörle görüşün",
|
|
294
|
+
});
|
|
295
|
+
const miss = missing(issuer, REG_FIELDS_ISSUER);
|
|
296
|
+
rows.push({
|
|
297
|
+
id: "L3",
|
|
298
|
+
check: "Kayıt verisi eksiksiz (ADR-0024)",
|
|
299
|
+
result: miss.length ? (strict ? "fail" : "warn") : "pass",
|
|
300
|
+
detail: miss.length ? `eksik: ${miss.join(", ")}` : "ticari ad, kimlik no, adres, iletişim, denetim makamı var",
|
|
301
|
+
fix: miss.length ? "eksik alanları operatöre gönderin (kayıt verisi güncellemesi)" : undefined,
|
|
302
|
+
});
|
|
303
|
+
vcts = issuer.schema_authorizations
|
|
304
|
+
.filter((a) => a.allowed && activeAt(a.valid_from, a.valid_until, now))
|
|
305
|
+
.map((a) => store.schemas.get(a.schema_id)?.vct)
|
|
306
|
+
.filter((v) => typeof v === "string");
|
|
307
|
+
const lacking = (o.expectVcts ?? []).filter((v) => !vcts.includes(v));
|
|
308
|
+
rows.push({
|
|
309
|
+
id: "L4",
|
|
310
|
+
check: "Belge türü yetkileri",
|
|
311
|
+
result: !vcts.length || lacking.length ? "fail" : "pass",
|
|
312
|
+
detail: `yetkili: ${vcts.join(", ") || "yok"}${lacking.length ? ` · beklenen ama yok: ${lacking.join(", ")}` : ""}`,
|
|
313
|
+
fix: !vcts.length || lacking.length ? "eksik belge türü için operatöre yetki isteği" : undefined,
|
|
314
|
+
});
|
|
315
|
+
const root = store.root_cas.get(issuer.parent_ca_id);
|
|
316
|
+
const rootOk = !!root && root.status === "ACTIVE";
|
|
317
|
+
rows.push({
|
|
318
|
+
id: "L5",
|
|
319
|
+
check: "Üst sertifika makamı listede ve ACTIVE",
|
|
320
|
+
result: rootOk ? "pass" : "fail",
|
|
321
|
+
detail: root ? clean(`${root.legal_name} · ${root.status}`) : "üst makam listede yok",
|
|
322
|
+
fix: rootOk ? undefined : "sertifikanın ağın kökünce verilmesi gerekir — operatöre bildirin",
|
|
323
|
+
});
|
|
324
|
+
const anchors = [...store.status_anchors.values()].filter((a) => a.issuer_id === issuer.issuer_id);
|
|
325
|
+
statusListUris = anchors.map((a) => a.list_uri);
|
|
326
|
+
rows.push({
|
|
327
|
+
id: "L6",
|
|
328
|
+
check: "İptal listesi yayınlandı ve çapalandı",
|
|
329
|
+
result: anchors.length ? "pass" : "warn",
|
|
330
|
+
detail: anchors.length
|
|
331
|
+
? `${anchors.length} liste · son yayın ${anchors
|
|
332
|
+
.map((a) => a.published_at)
|
|
333
|
+
.sort()
|
|
334
|
+
.pop()}`
|
|
335
|
+
: "çapa yok — yeni kurumda ilk yayından önce beklenir (doğrulamada geçici 'şu an doğrulanamadı')",
|
|
336
|
+
fix: anchors.length ? undefined : "servis açık mı; bir yayın aralığı bekleyip tekrar deneyin",
|
|
337
|
+
});
|
|
338
|
+
const issuerWrprc = idx.filter((x) => x.kind === "issuer" && x.slug === o.slug);
|
|
339
|
+
rows.push({
|
|
340
|
+
id: "L7",
|
|
341
|
+
check: "Kurumun kayıt sertifikası (ADR-0026)",
|
|
342
|
+
result: wrprcIndex ? (issuerWrprc.length ? "pass" : "fail") : "skip",
|
|
343
|
+
detail: !wrprcIndex
|
|
344
|
+
? "wrprc/index.json okunamadı"
|
|
345
|
+
: issuerWrprc.length
|
|
346
|
+
? `${issuerWrprc.length} sertifika (dizin imzasız — sertifikaların imzası H5'te doğrulanır)`
|
|
347
|
+
: "kurum için kayıt sertifikası yok (dizin imzasız)",
|
|
348
|
+
fix: wrprcIndex && !issuerWrprc.length
|
|
349
|
+
? "kurum sertifikasında organizationIdentifier olmalı (tamga-onboard keys bunu CSR'a yazar) — operatöre bildirin"
|
|
350
|
+
: undefined,
|
|
351
|
+
});
|
|
352
|
+
wrprcPaths.push(...issuerWrprc.map((x) => String(x.path)));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
if (o.rp) {
|
|
356
|
+
const rp = store.relying_parties_by_dns.get(o.rp);
|
|
357
|
+
// ADR-0075: ad birden çok ülke listesinde ve makinece okunur devir yoksa doğrulayıcı kaynağı kaydı tanımaz (kapalı güvenli)
|
|
358
|
+
const ambiguous = !!rp && store.relyingPartyAmbiguous(o.rp);
|
|
359
|
+
const rpActive = !!rp && !ambiguous && rp.status === "ACTIVE";
|
|
360
|
+
const scopes = (rp?.scopes ?? []).filter((s) => activeAt(s.valid_from, s.valid_until, now));
|
|
361
|
+
const states = [...(store.relying_party_states.get(o.rp) ?? [])].sort().join(", ");
|
|
362
|
+
rows.push({
|
|
363
|
+
id: "R1",
|
|
364
|
+
check: `Doğrulayıcı / kimlik eşleştirme kaydı (${o.rp})`,
|
|
365
|
+
result: rpActive && scopes.length ? "pass" : "fail",
|
|
366
|
+
detail: !rp
|
|
367
|
+
? "listede yok"
|
|
368
|
+
: ambiguous
|
|
369
|
+
? `ad belirsiz: birden çok ülke listesinde (${states}) ve devir kaydı (reassigned_to) yok — doğrulayıcılar kaydı tanımaz`
|
|
370
|
+
: clean(`${rp.status} · etkin kullanım: ${scopes.map((s) => `${s.scope_id} (${s.vct}: ${s.claims.join("+")})`).join("; ") || "yok"}`),
|
|
371
|
+
fix: ambiguous
|
|
372
|
+
? "eski ülke listesindeki kayıt devirle kapatılmalı (rp-status <dns_name> REVOKED --reassigned-to <CC> --approval <onay>) — operatöre bildirin"
|
|
373
|
+
: rpActive && scopes.length
|
|
374
|
+
? undefined
|
|
375
|
+
: "kayıt operatörde yapılır; kayıttan ve yayından sonra tekrar deneyin",
|
|
376
|
+
});
|
|
377
|
+
if (rp) {
|
|
378
|
+
const rmiss = missing(rp, REG_FIELDS_RP);
|
|
379
|
+
const noPrivacy = scopes
|
|
380
|
+
.filter((s) => !s.privacy_policy_uri)
|
|
381
|
+
.map((s) => `scopes[${s.scope_id}].privacy_policy_uri`);
|
|
382
|
+
const all = [...rmiss, ...noPrivacy];
|
|
383
|
+
rows.push({
|
|
384
|
+
id: "R2",
|
|
385
|
+
check: "Doğrulayıcı kayıt verisi eksiksiz (ADR-0024)",
|
|
386
|
+
result: all.length ? (strict ? "fail" : "warn") : "pass",
|
|
387
|
+
detail: all.length ? `eksik: ${all.join(", ")}` : "tam",
|
|
388
|
+
fix: all.length
|
|
389
|
+
? "eksik alanları operatöre gönderin (her kullanım için gizlilik politikası adresi)"
|
|
390
|
+
: undefined,
|
|
391
|
+
});
|
|
392
|
+
const rpItems = idx.filter((x) => x.kind === "rp" && scopes.some((s) => s.scope_id === x.scope_id));
|
|
393
|
+
const noCert = scopes.filter((s) => !rpItems.some((x) => x.scope_id === s.scope_id)).map((s) => s.scope_id);
|
|
394
|
+
rows.push({
|
|
395
|
+
id: "R3",
|
|
396
|
+
check: "Her kullanım için kayıt sertifikası (isteğe eklenir)",
|
|
397
|
+
result: !wrprcIndex ? "skip" : noCert.length ? "fail" : "pass",
|
|
398
|
+
detail: !wrprcIndex
|
|
399
|
+
? "wrprc/index.json okunamadı"
|
|
400
|
+
: noCert.length
|
|
401
|
+
? `sertifikasız kullanım: ${noCert.join(", ")}`
|
|
402
|
+
: `${rpItems.length} sertifika (dizin imzasız — imzalar H5'te) — her isteğe kullanımın kayıt sertifikasını ekleyin (yoksa cüzdan reddeder)`,
|
|
403
|
+
fix: noCert.length ? "erişim sertifikasında organizationIdentifier olmalı — operatöre bildirin" : undefined,
|
|
404
|
+
});
|
|
405
|
+
wrprcPaths.push(...rpItems.map((x) => String(x.path)));
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
if (o.slug || o.rp) {
|
|
409
|
+
const groups = [...store.relying_parties.values()].flatMap((r) => (r.terminal_groups ?? [])
|
|
410
|
+
.filter((g) => (o.slug && g.institution_id === o.slug) || (o.rp && g.institution_id === o.rp))
|
|
411
|
+
.filter((g) => activeAt(g.valid_from, g.valid_until, now))
|
|
412
|
+
.map((g) => `${g.group_id} @${r.dns_name}`));
|
|
413
|
+
rows.push({
|
|
414
|
+
id: "L8",
|
|
415
|
+
check: "Kapı grupları (ADR-0069)",
|
|
416
|
+
result: groups.length ? "pass" : "skip",
|
|
417
|
+
detail: groups.length
|
|
418
|
+
? clean(groups.join("; "))
|
|
419
|
+
: "kuruma ait kapı grubu yok (kapı/turnike kullanılmıyorsa gerekmez)",
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
// yerel sertifikalar → listedeki kök (operatör sertifikayı verdikten sonra)
|
|
423
|
+
for (const c of o.localCerts ?? []) {
|
|
424
|
+
let x;
|
|
425
|
+
try {
|
|
426
|
+
x = new X509Certificate(c.pem);
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
rows.push({ id: "C2", check: `${c.name}: sertifika okunamadı`, result: "fail", detail: "PEM X.509 bekleniyor" });
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
const root = [...store.root_cas.values()].find((r) => {
|
|
433
|
+
try {
|
|
434
|
+
return !!r.cert_pem && x.verify(new X509Certificate(r.cert_pem).publicKey);
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
const fp = sha256Hex(x.raw);
|
|
441
|
+
const listed = c.name.startsWith("issuer-") && issuer && !c.name.endsWith("-status")
|
|
442
|
+
? issuer.cert_fingerprint_sha256 === fp
|
|
443
|
+
? " · listedeki kurum sertifikasıyla aynı"
|
|
444
|
+
: " · DİKKAT: listedeki kurum sertifikasından farklı"
|
|
445
|
+
: "";
|
|
446
|
+
rows.push({
|
|
447
|
+
id: "C2",
|
|
448
|
+
check: `${c.name}: sertifika listedeki köke bağlı`,
|
|
449
|
+
result: root && root.status === "ACTIVE" && !listed.includes("DİKKAT") ? "pass" : "fail",
|
|
450
|
+
detail: root ? clean(`${root.legal_name} (${root.status})${listed}`) : "listedeki hiçbir kökçe imzalı değil",
|
|
451
|
+
fix: root
|
|
452
|
+
? undefined
|
|
453
|
+
: "sertifika başka ortamın (sandbox / gerçek ağ) kökünden olabilir — --env ve dosyayı kontrol edin",
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
// D5: wrprc/index.json imzasızdır — her kayıt sertifikası indirilir ve imzası listedeki kayıt kurumu anahtarıyla doğrulanır
|
|
457
|
+
if (wrprcPaths.length) {
|
|
458
|
+
const fps = registrarFingerprints(store);
|
|
459
|
+
const bad = [];
|
|
460
|
+
for (const p of wrprcPaths) {
|
|
461
|
+
if (!/^wrprc\/[A-Za-z0-9._/-]+\.jwt$/.test(p) || p.includes("..")) {
|
|
462
|
+
bad.push(`${p} (geçersiz yol)`);
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
const r = await safe(http, `${base}/${p}`);
|
|
466
|
+
if (r.status !== 200) {
|
|
467
|
+
bad.push(`${p} (HTTP ${r.status || "erişilemedi"})`);
|
|
468
|
+
continue;
|
|
469
|
+
}
|
|
470
|
+
const v = verifyRegistrationCert(r.text.trim(), fps, now);
|
|
471
|
+
if (v)
|
|
472
|
+
bad.push(`${p} (${v})`);
|
|
473
|
+
}
|
|
474
|
+
rows.push({
|
|
475
|
+
id: "H5",
|
|
476
|
+
check: "Kayıt sertifikaları yayında ve kayıt kurumunca imzalı",
|
|
477
|
+
result: bad.length ? "fail" : "pass",
|
|
478
|
+
detail: bad.length ? clean(`sorunlu: ${bad.join(", ")}`) : `${wrprcPaths.length} sertifika — imza geçerli`,
|
|
479
|
+
fix: bad.length ? "yayın birkaç dakika gecikebilir; sürerse operatöre bildirin" : undefined,
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
if (o.services === false || !issuer)
|
|
483
|
+
return rows;
|
|
484
|
+
// servis meta verisi (listedeki issuer_url; kurumun kendi servisi de) — RFC 8414 adres kuralı
|
|
485
|
+
const md = await safe(http, wellKnown(issuer.issuer_url, "openid-credential-issuer"));
|
|
486
|
+
let configs = [];
|
|
487
|
+
let mdIssuer = "";
|
|
488
|
+
try {
|
|
489
|
+
const j = JSON.parse(md.text);
|
|
490
|
+
configs = Object.keys(j.credential_configurations_supported ?? {});
|
|
491
|
+
mdIssuer = String(j.credential_issuer ?? "");
|
|
492
|
+
}
|
|
493
|
+
catch {
|
|
494
|
+
/* aşağıda */
|
|
495
|
+
}
|
|
496
|
+
const lacking = vcts.filter((v) => !configs.includes(v));
|
|
497
|
+
rows.push({
|
|
498
|
+
id: "H1",
|
|
499
|
+
check: "Belge veren meta verisi (OpenID4VCI)",
|
|
500
|
+
result: md.status !== 200 ? "fail" : lacking.length || mdIssuer !== issuer.issuer_url ? "warn" : "pass",
|
|
501
|
+
detail: md.status === 200
|
|
502
|
+
? clean(`HTTP 200 · ${configs.length} belge türü${lacking.length ? ` · listede yetkili ama meta veride yok: ${lacking.join(", ")}` : ""}${mdIssuer !== issuer.issuer_url ? ` · credential_issuer listedekinden farklı (${mdIssuer})` : ""}`)
|
|
503
|
+
: `HTTP ${md.status} — ${clean(wellKnown(issuer.issuer_url, "openid-credential-issuer"))}`,
|
|
504
|
+
fix: md.status !== 200
|
|
505
|
+
? "kendi servisinizde meta veri adresi; barındırılan serviste operatöre bildirin"
|
|
506
|
+
: lacking.length
|
|
507
|
+
? "bu türleri verecekseniz servis yapılandırmasına ekleyin; vermeyecekseniz yetkinin kapatılmasını isteyin"
|
|
508
|
+
: undefined,
|
|
509
|
+
});
|
|
510
|
+
const signed = await safe(http, wellKnown(issuer.issuer_url, "openid-credential-issuer"), {
|
|
511
|
+
headers: { accept: "application/jwt" },
|
|
512
|
+
});
|
|
513
|
+
const root = store.root_cas.get(issuer.parent_ca_id);
|
|
514
|
+
const chain = signed.status === 200
|
|
515
|
+
? checkMetadataChain(signed.text.trim(), issuer.cert_fingerprint_sha256, root?.cert_pem)
|
|
516
|
+
: { ok: false, detail: `HTTP ${signed.status}` };
|
|
517
|
+
rows.push({
|
|
518
|
+
id: "H2",
|
|
519
|
+
check: "Sertifika zinciri (imzalı meta veri x5c → listedeki kök)",
|
|
520
|
+
result: chain.ok ? "pass" : "fail",
|
|
521
|
+
detail: clean(chain.detail),
|
|
522
|
+
fix: chain.ok
|
|
523
|
+
? undefined
|
|
524
|
+
: "servisin imza anahtarı kayıttaki sertifikayla aynı mı; sertifika yenilendiyse liste güncellendi mi",
|
|
525
|
+
});
|
|
526
|
+
const as = await safe(http, wellKnown(issuer.issuer_url, "oauth-authorization-server"));
|
|
527
|
+
rows.push({
|
|
528
|
+
id: "H3",
|
|
529
|
+
check: "Yetkilendirme sunucusu meta verisi",
|
|
530
|
+
result: as.status === 200 ? "pass" : "fail",
|
|
531
|
+
detail: `HTTP ${as.status}`,
|
|
532
|
+
fix: as.status === 200 ? undefined : "servis meta veri adresi (RFC 8414)",
|
|
533
|
+
});
|
|
534
|
+
if (statusListUris.length) {
|
|
535
|
+
const sl = await safe(http, statusListUris[statusListUris.length - 1]);
|
|
536
|
+
rows.push({
|
|
537
|
+
id: "H4",
|
|
538
|
+
check: "İptal listesi erişilebilir",
|
|
539
|
+
result: sl.status === 200 && /statuslist\+(jwt|cwt)/.test(sl.contentType) ? "pass" : "fail",
|
|
540
|
+
detail: clean(`HTTP ${sl.status} · ${sl.contentType || "içerik türü yok"}`),
|
|
541
|
+
fix: sl.status === 200 ? undefined : "iptal listesi adresi (status_list_base) yayında mı",
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
return rows;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* İmzalı meta veri JWT'sinin x5c zinciri: yaprak listedeki parmak iziyle aynı, her halka bir üsttekince imzalı, son halka listedeki
|
|
548
|
+
* kökçe imzalı ve JWT imzası yaprağın anahtarıyla geçerli.
|
|
549
|
+
*/
|
|
550
|
+
export function checkMetadataChain(jwt, listFingerprint, rootPem) {
|
|
551
|
+
const [h, p, s] = jwt.split(".");
|
|
552
|
+
if (!h || !p || !s)
|
|
553
|
+
return { ok: false, detail: "imzalı meta veri JWT değil" };
|
|
554
|
+
let header;
|
|
555
|
+
try {
|
|
556
|
+
header = JSON.parse(Buffer.from(h, "base64url").toString("utf8"));
|
|
557
|
+
}
|
|
558
|
+
catch {
|
|
559
|
+
return { ok: false, detail: "JWT başlığı okunamadı" };
|
|
560
|
+
}
|
|
561
|
+
if (!header.x5c?.length)
|
|
562
|
+
return { ok: false, detail: "x5c yok" };
|
|
563
|
+
let chain;
|
|
564
|
+
try {
|
|
565
|
+
chain = header.x5c.map((c) => new X509Certificate(der(c)));
|
|
566
|
+
}
|
|
567
|
+
catch {
|
|
568
|
+
return { ok: false, detail: "x5c sertifikaları okunamadı" };
|
|
569
|
+
}
|
|
570
|
+
const leafFp = sha256Hex(der(header.x5c[0]));
|
|
571
|
+
if (leafFp !== listFingerprint)
|
|
572
|
+
return {
|
|
573
|
+
ok: false,
|
|
574
|
+
detail: `yaprak parmak izi listedekiyle aynı değil (${leafFp.slice(0, 12)}… ≠ ${listFingerprint.slice(0, 12)}…)`,
|
|
575
|
+
};
|
|
576
|
+
for (let i = 0; i + 1 < chain.length; i++)
|
|
577
|
+
if (!chain[i].verify(chain[i + 1].publicKey))
|
|
578
|
+
return { ok: false, detail: `x5c[${i}] x5c[${i + 1}]'ce imzalı değil` };
|
|
579
|
+
if (!rootPem)
|
|
580
|
+
return { ok: false, detail: "listede kök sertifikası yok — zincir sona kadar denetlenemedi" };
|
|
581
|
+
const root = new X509Certificate(rootPem);
|
|
582
|
+
if (!chain[chain.length - 1].verify(root.publicKey))
|
|
583
|
+
return { ok: false, detail: "zincirin son halkası listedeki kökçe imzalı değil" };
|
|
584
|
+
const sigOk = nodeVerify("sha256", Buffer.from(`${h}.${p}`), { key: chain[0].publicKey, dsaEncoding: "ieee-p1363" }, Buffer.from(s, "base64url"));
|
|
585
|
+
if (!sigOk)
|
|
586
|
+
return { ok: false, detail: "meta veri imzası yaprak anahtarıyla doğrulanmadı" };
|
|
587
|
+
return { ok: true, detail: `${chain.length} halka → ${root.subject.split("\n").find((l) => l.startsWith("CN="))}` };
|
|
588
|
+
}
|
|
589
|
+
/** LOTL'deki (imzası doğrulanmış) ulusal listelerin kayıt kurumu imza anahtarları (etkin; SHA-256 parmak izi). */
|
|
590
|
+
function registrarFingerprints(store) {
|
|
591
|
+
const out = new Set();
|
|
592
|
+
for (const n of (store.lotl?.national_lists ?? []))
|
|
593
|
+
for (const k of (n.roles?.registrar?.signing_keys ?? []))
|
|
594
|
+
if (!k.status || k.status === "ACTIVE")
|
|
595
|
+
out.add(String(k.fingerprint_sha256).toLowerCase());
|
|
596
|
+
return out;
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Kayıt sertifikası (WRPRC, `rc-wrp+jwt`, ADR-0026): imzacı (x5c[0]) listedeki bir kayıt kurumu anahtarı, ES256 imzası geçerli,
|
|
600
|
+
* süresi dolmamış. Sorun yoksa null, varsa kısa neden.
|
|
601
|
+
*/
|
|
602
|
+
export function verifyRegistrationCert(jwt, registrarFps, now = new Date()) {
|
|
603
|
+
const parts = jwt.split(".");
|
|
604
|
+
if (parts.length !== 3)
|
|
605
|
+
return "JWT değil";
|
|
606
|
+
const [h, p, s] = parts;
|
|
607
|
+
let header;
|
|
608
|
+
let payload;
|
|
609
|
+
try {
|
|
610
|
+
header = JSON.parse(Buffer.from(h, "base64url").toString("utf8"));
|
|
611
|
+
payload = JSON.parse(Buffer.from(p, "base64url").toString("utf8"));
|
|
612
|
+
}
|
|
613
|
+
catch {
|
|
614
|
+
return "okunamadı";
|
|
615
|
+
}
|
|
616
|
+
if (String(header.typ ?? "").toLowerCase() !== "rc-wrp+jwt")
|
|
617
|
+
return "typ rc-wrp+jwt değil";
|
|
618
|
+
if (header.alg !== "ES256")
|
|
619
|
+
return "alg ES256 değil";
|
|
620
|
+
const x5c = header.x5c;
|
|
621
|
+
if (!Array.isArray(x5c) || typeof x5c[0] !== "string")
|
|
622
|
+
return "x5c yok";
|
|
623
|
+
let leaf;
|
|
624
|
+
try {
|
|
625
|
+
leaf = new X509Certificate(der(x5c[0]));
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
return "x5c okunamadı";
|
|
629
|
+
}
|
|
630
|
+
if (!registrarFps.has(sha256Hex(leaf.raw)))
|
|
631
|
+
return "imzacı listedeki kayıt kurumu değil";
|
|
632
|
+
const ok = nodeVerify("sha256", Buffer.from(`${h}.${p}`), { key: leaf.publicKey, dsaEncoding: "ieee-p1363" }, Buffer.from(s, "base64url"));
|
|
633
|
+
if (!ok)
|
|
634
|
+
return "imza geçersiz";
|
|
635
|
+
if (typeof payload.exp === "number" && payload.exp * 1000 <= now.getTime())
|
|
636
|
+
return "süresi dolmuş";
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Katılım klasörünü okur (onboarding.json + başvurular). O3: profil `validateProfile` ile denetlenir (bozuksa durur); başvuru
|
|
641
|
+
* dosyası adları `<kısa ad>.issuer|rp.json`, her yol (bağlar çözülünce) klasörün içinde.
|
|
642
|
+
*/
|
|
643
|
+
export function readOnboardingDir(dir) {
|
|
644
|
+
const pf = within(dir, "onboarding.json");
|
|
645
|
+
if (!existsSync(pf))
|
|
646
|
+
throw new Error(`${pf} yok — önce: tamga-onboard init`);
|
|
647
|
+
let raw;
|
|
648
|
+
try {
|
|
649
|
+
raw = JSON.parse(readFileSync(pf, "utf8"));
|
|
650
|
+
}
|
|
651
|
+
catch {
|
|
652
|
+
throw new Error("onboarding.json okunamadı (JSON değil)");
|
|
653
|
+
}
|
|
654
|
+
const problems = validateProfile(raw);
|
|
655
|
+
if (problems.length)
|
|
656
|
+
throw new Error(`onboarding.json geçersiz: ${problems.join("; ")}`);
|
|
657
|
+
const profile = raw;
|
|
658
|
+
const rd = (f) => {
|
|
659
|
+
if (!f)
|
|
660
|
+
return undefined;
|
|
661
|
+
if (!APPLICATION_FILE_RE.test(f))
|
|
662
|
+
throw new Error(`başvuru dosyası adı geçersiz: ${clean(f)}`);
|
|
663
|
+
const p = within(dir, f);
|
|
664
|
+
if (!existsSync(p))
|
|
665
|
+
return undefined;
|
|
666
|
+
try {
|
|
667
|
+
return JSON.parse(readFileSync(p, "utf8"));
|
|
668
|
+
}
|
|
669
|
+
catch {
|
|
670
|
+
throw new Error(`${f} okunamadı (JSON değil)`);
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
return { profile, issuer: rd(profile.applications?.issuer), rp: rd(profile.applications?.rp) };
|
|
674
|
+
}
|
|
675
|
+
export async function installationChecks(input, deps) {
|
|
676
|
+
const rows = [];
|
|
677
|
+
let { profile, issuer, rp } = input;
|
|
678
|
+
if (input.dir) {
|
|
679
|
+
try {
|
|
680
|
+
({ profile, issuer, rp } = readOnboardingDir(input.dir));
|
|
681
|
+
}
|
|
682
|
+
catch (e) {
|
|
683
|
+
rows.push({ id: "A0", check: "Katılım klasörü", result: "fail", detail: e.message });
|
|
684
|
+
return rows;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
// A — başvuru dosyaları
|
|
688
|
+
for (const [id, label, app, fn] of [
|
|
689
|
+
["A1", "Belge veren başvurusu", issuer, validateIssuerApplication],
|
|
690
|
+
["A2", "Doğrulayıcı / kimlik eşleştirme başvurusu", rp, validateRpApplication],
|
|
691
|
+
]) {
|
|
692
|
+
if (!app)
|
|
693
|
+
continue;
|
|
694
|
+
const f = fn(app);
|
|
695
|
+
rows.push({
|
|
696
|
+
id,
|
|
697
|
+
check: `${label} (kayıt kuralları)`,
|
|
698
|
+
result: f.problems.length ? "fail" : f.warnings.length ? "warn" : "pass",
|
|
699
|
+
detail: f.problems.length
|
|
700
|
+
? f.problems.join("; ")
|
|
701
|
+
: f.warnings.length
|
|
702
|
+
? f.warnings.join("; ")
|
|
703
|
+
: "kayıt aracının kurallarına uyuyor",
|
|
704
|
+
fix: f.problems.length ? "başvuruyu düzeltin (tamga-onboard validate)" : undefined,
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
if (!issuer && !rp)
|
|
708
|
+
rows.push({ id: "A1", check: "Başvuru dosyası", result: "fail", detail: "başvuru yok", fix: "tamga-onboard init" });
|
|
709
|
+
// K — anahtarlar, CSR'lar, operatörün verdiği sertifikalar
|
|
710
|
+
if (profile && input.dir) {
|
|
711
|
+
const kdir = within(input.dir, "keys");
|
|
712
|
+
let exps = [];
|
|
713
|
+
try {
|
|
714
|
+
exps = csrExpectations(profile.keys ?? [], { issuer, rp });
|
|
715
|
+
}
|
|
716
|
+
catch (e) {
|
|
717
|
+
rows.push({ id: "K0", check: "Anahtar beklentileri", result: "fail", detail: e.message });
|
|
718
|
+
}
|
|
719
|
+
for (const e of exps) {
|
|
720
|
+
if (!CERT_NAME_RE.test(e.name))
|
|
721
|
+
throw new Error(`anahtar adı geçersiz: ${clean(e.name)}`);
|
|
722
|
+
const keyPath = within(input.dir, "keys", `${e.name}.key.pem`);
|
|
723
|
+
const csrPath = within(input.dir, "keys", `${e.name}.csr.pem`);
|
|
724
|
+
const certPath = within(input.dir, "keys", `${e.name}.cert.pem`);
|
|
725
|
+
const problems = [];
|
|
726
|
+
const notes = [];
|
|
727
|
+
let keySpki;
|
|
728
|
+
if (!existsSync(keyPath))
|
|
729
|
+
notes.push("özel anahtar bu klasörde yok (HSM / uzaktan imza hizmetinde olabilir)");
|
|
730
|
+
else {
|
|
731
|
+
const perm = privateKeyPermissionOk(keyPath);
|
|
732
|
+
if (perm === false)
|
|
733
|
+
problems.push("özel anahtar dosyası başkalarınca okunabilir (chmod 600)");
|
|
734
|
+
if (perm === null)
|
|
735
|
+
notes.push("Windows: dosya iznini denetleyin (yalnız siz)");
|
|
736
|
+
try {
|
|
737
|
+
keySpki = privateKeySpkiSha256(readFileSync(keyPath, "utf8"), input.passphrase);
|
|
738
|
+
}
|
|
739
|
+
catch {
|
|
740
|
+
notes.push("özel anahtar açılamadı (şifreliyse --passphrase-env)");
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
if (!existsSync(csrPath))
|
|
744
|
+
problems.push("CSR yok (tamga-onboard keys)");
|
|
745
|
+
else {
|
|
746
|
+
const csrPem = readFileSync(csrPath, "utf8");
|
|
747
|
+
const r = await inspectCsr(csrPem, e);
|
|
748
|
+
problems.push(...r.problems.filter((x) => !x.includes("uyarı")));
|
|
749
|
+
notes.push(...r.problems.filter((x) => x.includes("uyarı")));
|
|
750
|
+
if (keySpki && keySpki !== (await csrSpkiSha256(csrPem).catch(() => "")))
|
|
751
|
+
problems.push("CSR bu özel anahtarın değil");
|
|
752
|
+
}
|
|
753
|
+
rows.push({
|
|
754
|
+
id: "K1",
|
|
755
|
+
check: `${e.name}: anahtar ve CSR`,
|
|
756
|
+
result: problems.length ? "fail" : notes.length ? "warn" : "pass",
|
|
757
|
+
detail: [...problems, ...notes].join("; ") || `P-256 · ${e.orgId}${e.dns ? ` · SAN ${e.dns}` : ""}`,
|
|
758
|
+
fix: problems.length
|
|
759
|
+
? "tamga-onboard keys (eski dosyaları taşıyıp yeniden) ya da keys --inspect ile dış CSR"
|
|
760
|
+
: undefined,
|
|
761
|
+
});
|
|
762
|
+
if (existsSync(certPath))
|
|
763
|
+
rows.push(certRow(e, readFileSync(certPath, "utf8"), keySpki));
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
// O4 (MCP): denetim, dosyalardaki adreslere istek gönderir — kurumun alan adı dışındaki adresler ayrıca gösterilir (yapay zekâ
|
|
767
|
+
// aracına verilmiş bir dosya isteği başka bir yere yönlendirmesin; kullanıcı görsün)
|
|
768
|
+
if (input.warnOffDomain && profile?.domain) {
|
|
769
|
+
const d = profile.domain.toLowerCase();
|
|
770
|
+
const hosts = new Set();
|
|
771
|
+
const add = (u) => {
|
|
772
|
+
try {
|
|
773
|
+
if (typeof u === "string" && u)
|
|
774
|
+
hosts.add(new URL(u).hostname.toLowerCase());
|
|
775
|
+
}
|
|
776
|
+
catch {
|
|
777
|
+
hosts.add(clean(u));
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
for (const app of [issuer, rp]) {
|
|
781
|
+
if (!app)
|
|
782
|
+
continue;
|
|
783
|
+
for (const u of [app.contact?.support_uri, app.info_uri, app.revocation_policy_uri, app.issuer_url])
|
|
784
|
+
add(u);
|
|
785
|
+
for (const s of (app.scopes ?? []))
|
|
786
|
+
add(s.privacy_policy_uri);
|
|
787
|
+
}
|
|
788
|
+
add(profile.lookup_url);
|
|
789
|
+
if (rp?.dns_name)
|
|
790
|
+
hosts.add(String(rp.dns_name).toLowerCase());
|
|
791
|
+
const off = [...hosts].filter((h) => h !== d && !h.endsWith(`.${d}`));
|
|
792
|
+
if (off.length)
|
|
793
|
+
rows.push({
|
|
794
|
+
id: "S1",
|
|
795
|
+
check: `İstek gönderilecek adresler kurumun alan adında (${d})`,
|
|
796
|
+
result: "warn",
|
|
797
|
+
detail: clean(`alan adı dışında: ${off.join(", ")}`),
|
|
798
|
+
fix: "bu adreslerin kurumunuza ait olduğunu doğrulayın; değilse başvuru dosyasını düzeltin",
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
if (input.offline)
|
|
802
|
+
return rows;
|
|
803
|
+
const dns = deps.dns ?? (await defaultDns());
|
|
804
|
+
// N — alan adı
|
|
805
|
+
const domain = profile?.domain;
|
|
806
|
+
if (domain) {
|
|
807
|
+
const addrs = await dns.lookup(domain).catch(() => []);
|
|
808
|
+
rows.push({
|
|
809
|
+
id: "N1",
|
|
810
|
+
check: `Alan adı çözülüyor (${domain})`,
|
|
811
|
+
result: addrs.length ? "pass" : "fail",
|
|
812
|
+
detail: addrs.length ? `${addrs.length} adres` : "çözülemedi",
|
|
813
|
+
fix: addrs.length ? undefined : "DNS kaydı",
|
|
814
|
+
});
|
|
815
|
+
const want = input.dnsTxt ?? profile?.dns_txt;
|
|
816
|
+
if (want) {
|
|
817
|
+
const txt = (await dns.resolveTxt(domain).catch(() => [])).map((r) => r.join(""));
|
|
818
|
+
rows.push({
|
|
819
|
+
id: "N2",
|
|
820
|
+
check: "Alan adı teyidi (DNS TXT)",
|
|
821
|
+
result: txt.includes(want) ? "pass" : "fail",
|
|
822
|
+
detail: txt.includes(want)
|
|
823
|
+
? "operatörün verdiği değer yayında"
|
|
824
|
+
: `değer bulunamadı (${txt.length} TXT kaydı var)`,
|
|
825
|
+
fix: txt.includes(want)
|
|
826
|
+
? undefined
|
|
827
|
+
: `${domain} için TXT kaydı olarak operatörün verdiği değeri ekleyin; yayılması saatler sürebilir`,
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
else
|
|
831
|
+
rows.push({
|
|
832
|
+
id: "N2",
|
|
833
|
+
check: "Alan adı teyidi (DNS TXT)",
|
|
834
|
+
result: "skip",
|
|
835
|
+
detail: "operatörün tek kullanımlık değeri henüz yok (--dns-txt <değer> ya da onboarding.json dns_txt)",
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
// U — kayıttaki https adresleri
|
|
839
|
+
const urls = new Set();
|
|
840
|
+
for (const app of [issuer, rp]) {
|
|
841
|
+
if (!app)
|
|
842
|
+
continue;
|
|
843
|
+
for (const u of [app.contact?.support_uri, app.info_uri, app.revocation_policy_uri])
|
|
844
|
+
if (u)
|
|
845
|
+
urls.add(u);
|
|
846
|
+
for (const s of (app.scopes ?? []))
|
|
847
|
+
if (s.privacy_policy_uri)
|
|
848
|
+
urls.add(s.privacy_policy_uri);
|
|
849
|
+
}
|
|
850
|
+
if (urls.size) {
|
|
851
|
+
const bad = [];
|
|
852
|
+
for (const u of urls) {
|
|
853
|
+
const r = await safe(deps.http, u);
|
|
854
|
+
if (!(r.status >= 200 && r.status < 400))
|
|
855
|
+
bad.push(`${u} (${r.status || "erişilemedi"})`);
|
|
856
|
+
}
|
|
857
|
+
rows.push({
|
|
858
|
+
id: "U1",
|
|
859
|
+
check: "Kayıttaki adresler açılıyor (destek, bilgi, gizlilik politikası)",
|
|
860
|
+
result: bad.length ? "fail" : "pass",
|
|
861
|
+
detail: bad.length ? clean(bad.join("; ")) : `${urls.size} adres`,
|
|
862
|
+
fix: bad.length ? "cüzdan bu adresleri kişiye gösterir — yayında olmalı" : undefined,
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
// M — kendi servisi olan kurum: meta veri
|
|
866
|
+
if (issuer?.issuer_url) {
|
|
867
|
+
const md = await safe(deps.http, wellKnown(issuer.issuer_url, "openid-credential-issuer"));
|
|
868
|
+
let j = {};
|
|
869
|
+
try {
|
|
870
|
+
j = JSON.parse(md.text);
|
|
871
|
+
}
|
|
872
|
+
catch {
|
|
873
|
+
/* aşağıda */
|
|
874
|
+
}
|
|
875
|
+
const configs = Object.keys(j.credential_configurations_supported ?? {});
|
|
876
|
+
const lacking = (issuer.vcts ?? []).filter((v) => !configs.includes(v));
|
|
877
|
+
rows.push({
|
|
878
|
+
id: "M1",
|
|
879
|
+
check: "Belge veren meta verisi (.well-known/openid-credential-issuer)",
|
|
880
|
+
result: md.status !== 200 ? "fail" : j.credential_issuer !== issuer.issuer_url || lacking.length ? "fail" : "pass",
|
|
881
|
+
detail: md.status !== 200
|
|
882
|
+
? `HTTP ${md.status}`
|
|
883
|
+
: clean(`credential_issuer ${j.credential_issuer === issuer.issuer_url ? "doğru" : `farklı (${j.credential_issuer})`} · ${configs.length} belge türü${lacking.length ? ` · eksik: ${lacking.join(", ")}` : ""}`),
|
|
884
|
+
fix: md.status !== 200 ? "RFC 8414 adres kuralı: /.well-known/openid-credential-issuer/<yol>" : undefined,
|
|
885
|
+
});
|
|
886
|
+
const as = await safe(deps.http, wellKnown(issuer.issuer_url, "oauth-authorization-server"));
|
|
887
|
+
rows.push({
|
|
888
|
+
id: "M2",
|
|
889
|
+
check: "Yetkilendirme sunucusu meta verisi",
|
|
890
|
+
result: as.status === 200 ? "pass" : "fail",
|
|
891
|
+
detail: `HTTP ${as.status}`,
|
|
892
|
+
});
|
|
893
|
+
const signed = await safe(deps.http, wellKnown(issuer.issuer_url, "openid-credential-issuer"), {
|
|
894
|
+
headers: { accept: "application/jwt" },
|
|
895
|
+
});
|
|
896
|
+
const certPath = input.dir && CERT_NAME_RE.test(String(issuer.cert ?? ""))
|
|
897
|
+
? within(input.dir, "keys", `${issuer.cert}.cert.pem`)
|
|
898
|
+
: "";
|
|
899
|
+
let leafOk = null;
|
|
900
|
+
try {
|
|
901
|
+
const x5c = JSON.parse(Buffer.from(signed.text.split(".")[0], "base64url").toString("utf8")).x5c;
|
|
902
|
+
if (certPath && existsSync(certPath))
|
|
903
|
+
leafOk = sha256Hex(der(x5c[0])) === sha256Hex(new X509Certificate(readFileSync(certPath)).raw);
|
|
904
|
+
else
|
|
905
|
+
leafOk = x5c?.length > 0 ? null : false;
|
|
906
|
+
}
|
|
907
|
+
catch {
|
|
908
|
+
leafOk = false;
|
|
909
|
+
}
|
|
910
|
+
rows.push({
|
|
911
|
+
id: "M3",
|
|
912
|
+
check: "İmzalı meta veri (x5c)",
|
|
913
|
+
result: signed.status !== 200 || leafOk === false ? "fail" : leafOk ? "pass" : "warn",
|
|
914
|
+
detail: signed.status !== 200
|
|
915
|
+
? `HTTP ${signed.status} (Accept: application/jwt)`
|
|
916
|
+
: leafOk
|
|
917
|
+
? "yaprak operatörün verdiği sertifikayla aynı"
|
|
918
|
+
: leafOk === null
|
|
919
|
+
? "x5c var; sertifika dosyası klasörde yok — katıldıktan sonra --listing zinciri listedeki köke denetler"
|
|
920
|
+
: "x5c yok ya da yaprak sertifikanızdan farklı",
|
|
921
|
+
fix: signed.status !== 200 || leafOk === false
|
|
922
|
+
? "imzalı meta veri kurum anahtarıyla, x5c'de operatörün verdiği sertifika"
|
|
923
|
+
: undefined,
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
// Q — sorgu ucu (kişisel veri yok: yalnız geçersiz isteklerle yoklanır)
|
|
927
|
+
if (profile?.lookup_url) {
|
|
928
|
+
const u = profile.lookup_url;
|
|
929
|
+
const get = await safe(deps.http, u);
|
|
930
|
+
const empty = await safe(deps.http, u, {
|
|
931
|
+
method: "POST",
|
|
932
|
+
headers: { "content-type": "application/json" },
|
|
933
|
+
body: "{}",
|
|
934
|
+
});
|
|
935
|
+
const forged = await safe(deps.http, u, {
|
|
936
|
+
method: "POST",
|
|
937
|
+
headers: { "content-type": "application/json" },
|
|
938
|
+
body: JSON.stringify({ request: "e30.e30.AA" }),
|
|
939
|
+
});
|
|
940
|
+
const all = [get, empty, forged];
|
|
941
|
+
const reachable = all.every((r) => r.status > 0);
|
|
942
|
+
const leaks = all.some((r) => r.status >= 200 && r.status < 300);
|
|
943
|
+
const errors = all.some((r) => r.status >= 500);
|
|
944
|
+
// örnek 05: boş gövde 400, imzasız istek 400/401 — 404/405 ise bu adreste uç yok gibi
|
|
945
|
+
const rejects = [empty, forged].every((r) => [400, 401, 403, 415, 422].includes(r.status));
|
|
946
|
+
rows.push({
|
|
947
|
+
id: "Q1",
|
|
948
|
+
check: "Sorgu ucu erişilebilir ve imzasız isteği reddediyor",
|
|
949
|
+
result: !reachable || leaks ? "fail" : errors || !rejects ? "warn" : "pass",
|
|
950
|
+
detail: `GET ${get.status || "erişilemedi"} · boş POST ${empty.status || "-"} · imzasız POST ${forged.status || "-"} (beklenen: 405 · 400 · 401)`,
|
|
951
|
+
fix: leaks
|
|
952
|
+
? "imzasız isteğe 2xx dönülmemeli — örnek 05'teki denetimler (imza, çağıran, aud, süre, jti)"
|
|
953
|
+
: !reachable
|
|
954
|
+
? "adres dışarıdan https ile açık mı (Tamga'nın barındırılan servisi bu adrese bağlanır)"
|
|
955
|
+
: errors
|
|
956
|
+
? "5xx yanıtı: geçersiz istek 400/401 ile reddedilmeli"
|
|
957
|
+
: !rejects
|
|
958
|
+
? "POST isteği 400/401 ile reddedilmedi — adres sorgu ucunun kendisi mi (examples/05-institution-source)"
|
|
959
|
+
: undefined,
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
// V — doğrulayıcının alan adı
|
|
963
|
+
if (profile?.role === "verifier" && rp?.dns_name) {
|
|
964
|
+
const r = await safe(deps.http, `https://${rp.dns_name}/`);
|
|
965
|
+
rows.push({
|
|
966
|
+
id: "V1",
|
|
967
|
+
check: `Doğrulayıcı alan adı https ile açık (${rp.dns_name})`,
|
|
968
|
+
result: r.status > 0 && r.status < 500 ? "pass" : "fail",
|
|
969
|
+
detail: r.status ? `HTTP ${r.status}` : clean(r.text),
|
|
970
|
+
fix: r.status > 0 && r.status < 500
|
|
971
|
+
? undefined
|
|
972
|
+
: "erişim sertifikasındaki alan adı istek gönderen sitenin alan adıdır",
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
return rows;
|
|
976
|
+
}
|
|
977
|
+
/** Operatörün verdiği sertifika: aynı anahtar, kurum kimlik no, geçerlilik, erişim sertifikasında SAN. */
|
|
978
|
+
function certRow(e, pem, keySpki) {
|
|
979
|
+
const p = [];
|
|
980
|
+
let x;
|
|
981
|
+
try {
|
|
982
|
+
x = new X509Certificate(pem);
|
|
983
|
+
}
|
|
984
|
+
catch {
|
|
985
|
+
return { id: "K2", check: `${e.name}: sertifika`, result: "fail", detail: "okunamadı (PEM X.509 bekleniyor)" };
|
|
986
|
+
}
|
|
987
|
+
const spki = sha256Hex(x.publicKey.export({ type: "spki", format: "der" }));
|
|
988
|
+
if (keySpki && spki !== keySpki)
|
|
989
|
+
p.push("sertifika bu özel anahtarın değil");
|
|
990
|
+
if (!x.subject.includes(e.orgId))
|
|
991
|
+
p.push(`organizationIdentifier ${e.orgId} yok`);
|
|
992
|
+
const now = Date.now();
|
|
993
|
+
if (Date.parse(x.validFrom) > now || Date.parse(x.validTo) < now)
|
|
994
|
+
p.push(`geçerlilik dışında (${x.validFrom} → ${x.validTo})`);
|
|
995
|
+
if (e.dns && !(x.subjectAltName ?? "").includes(`DNS:${e.dns}`))
|
|
996
|
+
p.push(`SAN'da ${e.dns} yok`);
|
|
997
|
+
return {
|
|
998
|
+
id: "K2",
|
|
999
|
+
check: `${e.name}: operatörün verdiği sertifika`,
|
|
1000
|
+
result: p.length ? "fail" : "pass",
|
|
1001
|
+
detail: p.length
|
|
1002
|
+
? p.join("; ")
|
|
1003
|
+
: `bitiş ${new Date(x.validTo).toISOString().slice(0, 10)} · sha256 ${sha256Hex(x.raw).slice(0, 16)}…`,
|
|
1004
|
+
fix: p.length ? "operatörle görüşün (yanlış CSR'dan verilmiş olabilir)" : undefined,
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
/** Katılım klasöründeki sertifikalar (liste aşamasında köke zincir denetimi için). */
|
|
1008
|
+
export function localCertificates(dir, profile) {
|
|
1009
|
+
return (profile.keys ?? [])
|
|
1010
|
+
.filter((k) => CERT_NAME_RE.test(k.name))
|
|
1011
|
+
.map((k) => ({ name: k.name, path: within(dir, "keys", `${k.name}.cert.pem`) }))
|
|
1012
|
+
.filter((k) => existsSync(k.path))
|
|
1013
|
+
.map((k) => ({ name: k.name, pem: readFileSync(k.path, "utf8") }));
|
|
1014
|
+
}
|
|
1015
|
+
/** Kişiye gösterim: Markdown tablo + özet (kişisel veri yok). */
|
|
1016
|
+
export function formatRows(rows) {
|
|
1017
|
+
const L = { pass: "GEÇTİ", fail: "KALDI", warn: "UYARI", skip: "ATLANDI" };
|
|
1018
|
+
const esc = (s) => s.replace(/\|/g, "\\|");
|
|
1019
|
+
const n = (r) => rows.filter((x) => x.result === r).length;
|
|
1020
|
+
return [
|
|
1021
|
+
"| # | Denetim | Sonuç | Ayrıntı | Düzeltme |",
|
|
1022
|
+
"|---|---|---|---|---|",
|
|
1023
|
+
...rows.map((r) => `| ${r.id} | ${esc(r.check)} | ${L[r.result]} | ${esc(r.detail)} | ${esc(r.fix ?? "")} |`),
|
|
1024
|
+
"",
|
|
1025
|
+
`özet: ${n("pass")} geçti · ${n("fail")} kaldı · ${n("warn")} uyarı · ${n("skip")} atlandı`,
|
|
1026
|
+
].join("\n");
|
|
1027
|
+
}
|
|
1028
|
+
//# sourceMappingURL=checks.js.map
|