@first-ch/tools-mcp 0.4.0 → 0.24.0
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/README.md +132 -30
- package/aspect-ratio.mjs +706 -0
- package/base64.mjs +356 -0
- package/color.mjs +629 -0
- package/cron.mjs +633 -0
- package/diff.mjs +322 -0
- package/hash.mjs +234 -0
- package/html-escape.mjs +308 -0
- package/json-yaml.mjs +1693 -0
- package/jwt.mjs +639 -0
- package/lib.mjs +103 -0
- package/markdown-table.mjs +641 -0
- package/marp-theme.css +51 -0
- package/marp.mjs +219 -0
- package/package.json +132 -6
- package/px-rem.mjs +488 -0
- package/qr.mjs +744 -0
- package/server.mjs +942 -2
- package/sql-format.mjs +694 -0
- package/testdata.mjs +608 -0
- package/unixtime.mjs +505 -0
- package/url.mjs +415 -0
- package/user-agent.mjs +633 -0
- package/uuid.mjs +238 -0
- package/vendor/jsquash-webp/CHECKSUMS.sha256 +10 -0
package/jwt.mjs
ADDED
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
// JWT(JSON Web Token)のデコード・有効期限チェック・署名の検証
|
|
2
|
+
// (tools.first-ch.com/jwt/ と同一の仕様)
|
|
3
|
+
//
|
|
4
|
+
// 2箇所ルール: デコードのコア(normalizeInput / decodeSegment / decodeJwt / analyzeTiming /
|
|
5
|
+
// collectWarnings / verifySignature)は site/jwt/app.js と対になっている。
|
|
6
|
+
// 片方を直したらもう片方も同じ内容で直す(site側が正本)。
|
|
7
|
+
// 署名の検証は site 側がブラウザの Web Crypto、こちらは node:crypto の webcrypto を使う。
|
|
8
|
+
// importKey / verify の呼び出し方は同じで、対応アルゴリズムも揃えてある。
|
|
9
|
+
// トークンも鍵もこのプロセスの中だけで扱い、ネットワークへは一切出さない。
|
|
10
|
+
import { webcrypto } from 'node:crypto';
|
|
11
|
+
|
|
12
|
+
export class JwtError extends Error {}
|
|
13
|
+
|
|
14
|
+
const subtle = webcrypto.subtle;
|
|
15
|
+
|
|
16
|
+
/** 署名アルゴリズムの一覧。JWS(RFC 7518)で定義されているもの+EdDSA(RFC 8037) */
|
|
17
|
+
export const ALGS = {
|
|
18
|
+
HS256: { kind: 'hmac', hash: 'SHA-256' },
|
|
19
|
+
HS384: { kind: 'hmac', hash: 'SHA-384' },
|
|
20
|
+
HS512: { kind: 'hmac', hash: 'SHA-512' },
|
|
21
|
+
RS256: { kind: 'rsa', hash: 'SHA-256' },
|
|
22
|
+
RS384: { kind: 'rsa', hash: 'SHA-384' },
|
|
23
|
+
RS512: { kind: 'rsa', hash: 'SHA-512' },
|
|
24
|
+
PS256: { kind: 'rsapss', hash: 'SHA-256', saltLength: 32 },
|
|
25
|
+
PS384: { kind: 'rsapss', hash: 'SHA-384', saltLength: 48 },
|
|
26
|
+
PS512: { kind: 'rsapss', hash: 'SHA-512', saltLength: 64 },
|
|
27
|
+
ES256: { kind: 'ec', hash: 'SHA-256', curve: 'P-256' },
|
|
28
|
+
ES384: { kind: 'ec', hash: 'SHA-384', curve: 'P-384' },
|
|
29
|
+
ES512: { kind: 'ec', hash: 'SHA-512', curve: 'P-521' },
|
|
30
|
+
EdDSA: { kind: 'eddsa' },
|
|
31
|
+
none: { kind: 'none' },
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** base64url(標準Base64・パディング付きも許す)を Buffer にする */
|
|
35
|
+
export function b64uToBytes(seg) {
|
|
36
|
+
let s = String(seg).replace(/\s+/g, '').replace(/-/g, '+').replace(/_/g, '/');
|
|
37
|
+
const rest = s.length % 4;
|
|
38
|
+
// 4で割った余りが1になる長さのBase64は存在しない
|
|
39
|
+
if (rest === 1) throw new JwtError('base64');
|
|
40
|
+
if (rest) s += '='.repeat(4 - rest);
|
|
41
|
+
if (!/^[A-Za-z0-9+/]*={0,2}$/.test(s)) throw new JwtError('base64');
|
|
42
|
+
return Buffer.from(s, 'base64');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const UTF8 = new TextDecoder('utf-8', { fatal: true });
|
|
46
|
+
|
|
47
|
+
/** 1セグメントをデコードして {text, json, error} を返す */
|
|
48
|
+
function decodeSegment(seg) {
|
|
49
|
+
let bytes;
|
|
50
|
+
try {
|
|
51
|
+
bytes = b64uToBytes(seg);
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return { text: '', json: null, error: 'base64' };
|
|
54
|
+
}
|
|
55
|
+
let text;
|
|
56
|
+
try {
|
|
57
|
+
text = UTF8.decode(bytes);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
return { text: '', json: null, error: 'utf8' };
|
|
60
|
+
}
|
|
61
|
+
try {
|
|
62
|
+
return { text, json: JSON.parse(text), error: '' };
|
|
63
|
+
} catch (e) {
|
|
64
|
+
return { text, json: null, error: 'json' };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 貼り付けられた文字列からトークン本体を取り出す。
|
|
70
|
+
* `Authorization: Bearer <token>` の行・引用符・途中の改行や空白をそのまま渡せる。
|
|
71
|
+
*/
|
|
72
|
+
export function normalizeInput(raw) {
|
|
73
|
+
const cleanups = [];
|
|
74
|
+
const mark = (c) => { if (cleanups.indexOf(c) === -1) cleanups.push(c); };
|
|
75
|
+
let s = String(raw == null ? '' : raw).trim();
|
|
76
|
+
if (!s) return { token: '', cleanups };
|
|
77
|
+
// `"Bearer …",` のように包みが重なっていることがあるので、変化しなくなるまで繰り返す
|
|
78
|
+
for (let i = 0; i < 4; i += 1) {
|
|
79
|
+
const before = s;
|
|
80
|
+
const header = s.match(/^authorization\s*:\s*(.*)$/is);
|
|
81
|
+
if (header) {
|
|
82
|
+
s = header[1].trim();
|
|
83
|
+
mark('header');
|
|
84
|
+
}
|
|
85
|
+
const bearer = s.match(/^bearer\s+(.*)$/is);
|
|
86
|
+
if (bearer) {
|
|
87
|
+
s = bearer[1].trim();
|
|
88
|
+
mark('bearer');
|
|
89
|
+
}
|
|
90
|
+
// 末尾のカンマ・セミコロンはコードからコピーしたときに付いてくる
|
|
91
|
+
const tail = s.replace(/[,;]+$/, '');
|
|
92
|
+
if (tail !== s) {
|
|
93
|
+
s = tail.trim();
|
|
94
|
+
mark('punct');
|
|
95
|
+
}
|
|
96
|
+
if (s.length > 1 && /^["'`]/.test(s) && s[0] === s[s.length - 1]) {
|
|
97
|
+
s = s.slice(1, -1).trim();
|
|
98
|
+
mark('quoted');
|
|
99
|
+
}
|
|
100
|
+
if (s === before) break;
|
|
101
|
+
}
|
|
102
|
+
if (/\s/.test(s)) {
|
|
103
|
+
s = s.replace(/\s+/g, '');
|
|
104
|
+
cleanups.push('whitespace');
|
|
105
|
+
}
|
|
106
|
+
return { token: s, cleanups };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** JWT(JWS compact serialization)をデコードする。署名の検証は行わない */
|
|
110
|
+
export function decodeJwt(raw) {
|
|
111
|
+
const { token, cleanups } = normalizeInput(raw);
|
|
112
|
+
const out = {
|
|
113
|
+
ok: false,
|
|
114
|
+
token,
|
|
115
|
+
cleanups,
|
|
116
|
+
type: '',
|
|
117
|
+
parts: token ? token.split('.') : [],
|
|
118
|
+
header: null,
|
|
119
|
+
payload: null,
|
|
120
|
+
headerText: '',
|
|
121
|
+
payloadText: '',
|
|
122
|
+
signature: '',
|
|
123
|
+
signingInput: '',
|
|
124
|
+
errors: [],
|
|
125
|
+
};
|
|
126
|
+
if (!token) {
|
|
127
|
+
out.errors.push('empty');
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
const parts = out.parts;
|
|
131
|
+
if (parts.length === 5) {
|
|
132
|
+
// JWE(暗号化トークン)はヘッダーしか読めない
|
|
133
|
+
out.type = 'jwe';
|
|
134
|
+
const h = decodeSegment(parts[0]);
|
|
135
|
+
out.header = h.json;
|
|
136
|
+
out.headerText = h.json ? JSON.stringify(h.json, null, 2) : h.text;
|
|
137
|
+
if (h.error) out.errors.push('header_' + h.error);
|
|
138
|
+
out.errors.push('jwe');
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
if (parts.length < 2 || parts.length > 3) {
|
|
142
|
+
out.errors.push('not_jwt');
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
out.type = 'jws';
|
|
146
|
+
if (parts.length === 2) out.errors.push('two_parts');
|
|
147
|
+
|
|
148
|
+
const h = decodeSegment(parts[0]);
|
|
149
|
+
if (h.error) {
|
|
150
|
+
out.errors.push('header_' + h.error);
|
|
151
|
+
out.headerText = h.text;
|
|
152
|
+
} else {
|
|
153
|
+
out.header = h.json;
|
|
154
|
+
out.headerText = JSON.stringify(h.json, null, 2);
|
|
155
|
+
if (h.json === null || typeof h.json !== 'object' || Array.isArray(h.json)) {
|
|
156
|
+
out.errors.push('header_not_object');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const p = decodeSegment(parts[1]);
|
|
161
|
+
if (p.error) {
|
|
162
|
+
out.errors.push('payload_' + p.error);
|
|
163
|
+
out.payloadText = p.text;
|
|
164
|
+
} else {
|
|
165
|
+
out.payload = p.json;
|
|
166
|
+
out.payloadText = JSON.stringify(p.json, null, 2);
|
|
167
|
+
if (p.json === null || typeof p.json !== 'object' || Array.isArray(p.json)) {
|
|
168
|
+
out.errors.push('payload_not_object');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
out.signature = parts[2] || '';
|
|
173
|
+
out.signingInput = parts[0] + '.' + parts[1];
|
|
174
|
+
// ヘッダーとペイロードが読めていれば「デコードできた」とみなす(署名の有無は別)
|
|
175
|
+
out.ok = !h.error && !p.error;
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** 数値のクレームを読む。文字列の数値・ミリ秒での指定も拾う */
|
|
180
|
+
export function readTimeClaim(payload, key) {
|
|
181
|
+
if (!payload || typeof payload !== 'object') return null;
|
|
182
|
+
const v = payload[key];
|
|
183
|
+
let num = null;
|
|
184
|
+
let coerced = false;
|
|
185
|
+
if (typeof v === 'number' && isFinite(v)) {
|
|
186
|
+
num = v;
|
|
187
|
+
} else if (typeof v === 'string' && /^-?\d+(?:\.\d+)?$/.test(v.trim())) {
|
|
188
|
+
num = Number(v);
|
|
189
|
+
coerced = true;
|
|
190
|
+
} else {
|
|
191
|
+
return v === undefined ? null : { raw: v, seconds: null, ms: false, coerced: false, invalid: true };
|
|
192
|
+
}
|
|
193
|
+
// 1e11 秒は西暦5138年。この桁はまずミリ秒の入れ間違い(Date.now() をそのまま入れた)
|
|
194
|
+
const ms = Math.abs(num) >= 1e11;
|
|
195
|
+
return { raw: v, seconds: ms ? Math.floor(num / 1000) : Math.floor(num), ms, coerced, invalid: false };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** exp / nbf / iat から有効期限の状態を出す */
|
|
199
|
+
export function analyzeTiming(payload, nowSec, tolerance) {
|
|
200
|
+
const tol = tolerance || 0;
|
|
201
|
+
const exp = readTimeClaim(payload, 'exp');
|
|
202
|
+
const nbf = readTimeClaim(payload, 'nbf');
|
|
203
|
+
const iat = readTimeClaim(payload, 'iat');
|
|
204
|
+
const t = {
|
|
205
|
+
now: nowSec,
|
|
206
|
+
exp: exp && !exp.invalid ? exp.seconds : null,
|
|
207
|
+
nbf: nbf && !nbf.invalid ? nbf.seconds : null,
|
|
208
|
+
iat: iat && !iat.invalid ? iat.seconds : null,
|
|
209
|
+
expMs: Boolean(exp && exp.ms),
|
|
210
|
+
nbfMs: Boolean(nbf && nbf.ms),
|
|
211
|
+
iatMs: Boolean(iat && iat.ms),
|
|
212
|
+
invalid: [exp, nbf, iat].some((c) => c && c.invalid),
|
|
213
|
+
status: 'no_exp',
|
|
214
|
+
remaining: null,
|
|
215
|
+
age: null,
|
|
216
|
+
lifetime: null,
|
|
217
|
+
progress: null,
|
|
218
|
+
start: null,
|
|
219
|
+
};
|
|
220
|
+
if (t.exp !== null) {
|
|
221
|
+
t.remaining = t.exp - nowSec;
|
|
222
|
+
t.status = nowSec - tol >= t.exp ? 'expired' : 'valid';
|
|
223
|
+
}
|
|
224
|
+
if (t.nbf !== null && nowSec + tol < t.nbf && t.status !== 'expired') t.status = 'not_yet';
|
|
225
|
+
if (t.iat !== null) t.age = nowSec - t.iat;
|
|
226
|
+
// 経過の割合を出す基準。iat が無ければ nbf を使う
|
|
227
|
+
const start = t.iat !== null ? t.iat : t.nbf;
|
|
228
|
+
if (start !== null && t.exp !== null && t.exp > start) {
|
|
229
|
+
t.start = start;
|
|
230
|
+
t.lifetime = t.exp - start;
|
|
231
|
+
t.progress = Math.min(1, Math.max(0, (nowSec - start) / t.lifetime));
|
|
232
|
+
}
|
|
233
|
+
return t;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** ペイロードに入っていたら注意したいキー */
|
|
237
|
+
const SECRET_KEYS = /^(password|passwd|pwd|secret|client_secret|api_?key|access_?key|private_?key|credit_?card|card_?number|cvv|cvc|ssn|my_?number|pin)$/i;
|
|
238
|
+
const PII_KEYS = /^(email|mail|e_?mail|phone|tel|telephone|mobile|address|birthdate|birth_?day|name|given_?name|family_?name|preferred_username)$/i;
|
|
239
|
+
|
|
240
|
+
/** デコード結果から指摘事項のコード一覧を作る(文言は下の WARN が持つ) */
|
|
241
|
+
export function collectWarnings(decoded, timing) {
|
|
242
|
+
const w = [];
|
|
243
|
+
const header = decoded.header || {};
|
|
244
|
+
const payload = decoded.payload && typeof decoded.payload === 'object' ? decoded.payload : {};
|
|
245
|
+
const alg = typeof header.alg === 'string' ? header.alg : '';
|
|
246
|
+
|
|
247
|
+
for (const c of decoded.cleanups) w.push({ code: 'clean_' + c, level: 'info' });
|
|
248
|
+
|
|
249
|
+
if (decoded.errors.indexOf('jwe') !== -1) w.push({ code: 'jwe', level: 'warn' });
|
|
250
|
+
if (decoded.errors.indexOf('not_jwt') !== -1) w.push({ code: 'not_jwt', level: 'warn' });
|
|
251
|
+
if (decoded.errors.indexOf('two_parts') !== -1) w.push({ code: 'two_parts', level: 'warn' });
|
|
252
|
+
for (const seg of ['header', 'payload']) {
|
|
253
|
+
if (decoded.errors.indexOf(seg + '_base64') !== -1) w.push({ code: seg + '_base64', level: 'warn' });
|
|
254
|
+
if (decoded.errors.indexOf(seg + '_utf8') !== -1) w.push({ code: seg + '_utf8', level: 'warn' });
|
|
255
|
+
if (decoded.errors.indexOf(seg + '_json') !== -1) w.push({ code: seg + '_json', level: 'warn' });
|
|
256
|
+
}
|
|
257
|
+
if (!decoded.ok) return w;
|
|
258
|
+
|
|
259
|
+
if (!alg) {
|
|
260
|
+
w.push({ code: 'no_alg', level: 'warn' });
|
|
261
|
+
} else if (alg.toLowerCase() === 'none') {
|
|
262
|
+
w.push({ code: 'alg_none', level: 'warn' });
|
|
263
|
+
} else if (!ALGS[alg]) {
|
|
264
|
+
w.push({ code: 'unknown_alg', level: 'warn', arg: alg });
|
|
265
|
+
}
|
|
266
|
+
if (alg && alg.toLowerCase() !== 'none' && !decoded.signature) w.push({ code: 'no_signature', level: 'warn' });
|
|
267
|
+
if (header.typ !== undefined && String(header.typ).toUpperCase() !== 'JWT' && String(header.typ).toLowerCase() !== 'at+jwt') {
|
|
268
|
+
w.push({ code: 'typ_other', level: 'info', arg: String(header.typ) });
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (timing.invalid) w.push({ code: 'time_invalid', level: 'warn' });
|
|
272
|
+
if (timing.expMs || timing.iatMs || timing.nbfMs) w.push({ code: 'time_ms', level: 'warn' });
|
|
273
|
+
if (timing.status === 'expired') w.push({ code: 'expired', level: 'warn', arg: -timing.remaining });
|
|
274
|
+
if (timing.status === 'not_yet') w.push({ code: 'not_yet', level: 'warn', arg: timing.nbf - timing.now });
|
|
275
|
+
if (timing.exp === null) w.push({ code: 'no_exp', level: 'warn' });
|
|
276
|
+
if (timing.lifetime !== null && timing.lifetime > 86400 * 30) {
|
|
277
|
+
w.push({ code: 'lifetime_long', level: 'warn', arg: timing.lifetime });
|
|
278
|
+
} else if (timing.lifetime !== null && timing.lifetime > 86400) {
|
|
279
|
+
w.push({ code: 'lifetime_day', level: 'info', arg: timing.lifetime });
|
|
280
|
+
}
|
|
281
|
+
if (timing.iat !== null && timing.iat - timing.now > 60) w.push({ code: 'iat_future', level: 'warn' });
|
|
282
|
+
|
|
283
|
+
const keys = Object.keys(payload);
|
|
284
|
+
const secret = keys.filter((k) => SECRET_KEYS.test(k));
|
|
285
|
+
if (secret.length) w.push({ code: 'secret_claim', level: 'warn', arg: secret.join(', ') });
|
|
286
|
+
const pii = keys.filter((k) => PII_KEYS.test(k));
|
|
287
|
+
if (pii.length) w.push({ code: 'pii_claim', level: 'info', arg: pii.join(', ') });
|
|
288
|
+
if (payload.aud === undefined) w.push({ code: 'no_aud', level: 'info' });
|
|
289
|
+
if (payload.jti === undefined && timing.exp !== null) w.push({ code: 'no_jti', level: 'info' });
|
|
290
|
+
|
|
291
|
+
w.push({ code: 'not_verified', level: 'info' });
|
|
292
|
+
return w;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/* ==================== 署名の検証(site/jwt/app.js と同じ呼び出し方) ==================== */
|
|
296
|
+
|
|
297
|
+
const ENC = new TextEncoder();
|
|
298
|
+
|
|
299
|
+
function pemToBytes(text) {
|
|
300
|
+
const body = text.replace(/-----(BEGIN|END)[^-]+-----/g, '').replace(/\s+/g, '');
|
|
301
|
+
return b64uToBytes(body);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** JWK から Web Crypto へ渡す最小限の members だけを取り出す(alg / use の不一致で弾かれないため) */
|
|
305
|
+
function cleanJwk(jwk) {
|
|
306
|
+
const out = { kty: jwk.kty, ext: true };
|
|
307
|
+
for (const k of ['n', 'e', 'crv', 'x', 'y']) if (jwk[k] !== undefined) out[k] = jwk[k];
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function jwkParams(alg, spec) {
|
|
312
|
+
if (spec.kind === 'rsa') return { name: 'RSASSA-PKCS1-v1_5', hash: spec.hash };
|
|
313
|
+
if (spec.kind === 'rsapss') return { name: 'RSA-PSS', hash: spec.hash };
|
|
314
|
+
if (spec.kind === 'ec') return { name: 'ECDSA', namedCurve: spec.curve };
|
|
315
|
+
return { name: 'Ed25519' };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function verifyParams(spec) {
|
|
319
|
+
if (spec.kind === 'hmac') return { name: 'HMAC' };
|
|
320
|
+
if (spec.kind === 'rsa') return { name: 'RSASSA-PKCS1-v1_5' };
|
|
321
|
+
if (spec.kind === 'rsapss') return { name: 'RSA-PSS', saltLength: spec.saltLength };
|
|
322
|
+
if (spec.kind === 'ec') return { name: 'ECDSA', hash: spec.hash };
|
|
323
|
+
return { name: 'Ed25519' };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** HMAC の鍵素材を作る。encoding は utf8 / base64url / base64 / hex */
|
|
327
|
+
export function secretToBytes(secret, encoding) {
|
|
328
|
+
if (encoding === 'hex') {
|
|
329
|
+
const s = secret.replace(/[\s:-]/g, '');
|
|
330
|
+
if (!/^[0-9a-fA-F]*$/.test(s) || s.length % 2) throw new JwtError('key_format:hex');
|
|
331
|
+
return Buffer.from(s, 'hex');
|
|
332
|
+
}
|
|
333
|
+
if (encoding === 'base64' || encoding === 'base64url') {
|
|
334
|
+
try {
|
|
335
|
+
return b64uToBytes(secret);
|
|
336
|
+
} catch (e) {
|
|
337
|
+
throw new JwtError('key_format:base64');
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return Buffer.from(secret, 'utf8');
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 署名を検証する。鍵はこのプロセスから出ない。
|
|
345
|
+
* @returns {Promise<{status: string, code: string, arg?: string}>}
|
|
346
|
+
* status: verified | failed | error | skipped
|
|
347
|
+
*/
|
|
348
|
+
export async function verifySignature(decoded, key, encoding) {
|
|
349
|
+
if (!decoded.ok || decoded.type !== 'jws') return { status: 'skipped', code: 'no_token' };
|
|
350
|
+
const alg = decoded.header && typeof decoded.header.alg === 'string' ? decoded.header.alg : '';
|
|
351
|
+
const spec = ALGS[alg];
|
|
352
|
+
if (!alg) return { status: 'error', code: 'no_alg' };
|
|
353
|
+
if (alg.toLowerCase() === 'none') return { status: 'error', code: 'alg_none' };
|
|
354
|
+
if (!spec) return { status: 'error', code: 'unknown_alg', arg: alg };
|
|
355
|
+
if (!decoded.signature) return { status: 'error', code: 'no_signature' };
|
|
356
|
+
if (!String(key == null ? '' : key).trim()) return { status: 'skipped', code: 'no_key' };
|
|
357
|
+
|
|
358
|
+
let sig;
|
|
359
|
+
try {
|
|
360
|
+
sig = b64uToBytes(decoded.signature);
|
|
361
|
+
} catch (e) {
|
|
362
|
+
return { status: 'error', code: 'bad_signature' };
|
|
363
|
+
}
|
|
364
|
+
// ECDSA の署名は R‖S の生バイト(DER ではない)。長さで取り違えを検出できる
|
|
365
|
+
if (spec.kind === 'ec') {
|
|
366
|
+
const need = { 'P-256': 64, 'P-384': 96, 'P-521': 132 }[spec.curve];
|
|
367
|
+
if (sig.length !== need) return { status: 'error', code: 'ec_sig_length', arg: sig.length + ' / ' + need };
|
|
368
|
+
}
|
|
369
|
+
const data = ENC.encode(decoded.signingInput);
|
|
370
|
+
const text = String(key).trim();
|
|
371
|
+
|
|
372
|
+
let cryptoKey;
|
|
373
|
+
try {
|
|
374
|
+
if (spec.kind === 'hmac') {
|
|
375
|
+
let raw;
|
|
376
|
+
if (text[0] === '{') {
|
|
377
|
+
const jwk = JSON.parse(text);
|
|
378
|
+
const k = jwk.keys ? (jwk.keys.find((x) => x.kid === (decoded.header || {}).kid) || jwk.keys[0]) : jwk;
|
|
379
|
+
if (!k || k.kty !== 'oct' || !k.k) return { status: 'error', code: 'jwk_not_oct' };
|
|
380
|
+
raw = b64uToBytes(k.k);
|
|
381
|
+
} else {
|
|
382
|
+
raw = secretToBytes(text, encoding);
|
|
383
|
+
}
|
|
384
|
+
if (!raw.length) return { status: 'error', code: 'empty_key' };
|
|
385
|
+
cryptoKey = await subtle.importKey('raw', raw, { name: 'HMAC', hash: spec.hash }, false, ['verify']);
|
|
386
|
+
} else if (text[0] === '{') {
|
|
387
|
+
const parsed = JSON.parse(text);
|
|
388
|
+
const jwk = parsed.keys
|
|
389
|
+
? (parsed.keys.find((x) => x.kid === (decoded.header || {}).kid) || parsed.keys[0])
|
|
390
|
+
: parsed;
|
|
391
|
+
if (!jwk || !jwk.kty) return { status: 'error', code: 'jwk_invalid' };
|
|
392
|
+
if (jwk.d) return { status: 'error', code: 'private_key' };
|
|
393
|
+
cryptoKey = await subtle.importKey('jwk', cleanJwk(jwk), jwkParams(alg, spec), false, ['verify']);
|
|
394
|
+
} else {
|
|
395
|
+
if (/BEGIN [A-Z ]*PRIVATE KEY/.test(text)) return { status: 'error', code: 'private_key' };
|
|
396
|
+
if (/BEGIN CERTIFICATE/.test(text)) return { status: 'error', code: 'certificate' };
|
|
397
|
+
if (/BEGIN RSA PUBLIC KEY/.test(text)) return { status: 'error', code: 'pkcs1' };
|
|
398
|
+
cryptoKey = await subtle.importKey('spki', pemToBytes(text), jwkParams(alg, spec), false, ['verify']);
|
|
399
|
+
}
|
|
400
|
+
} catch (e) {
|
|
401
|
+
if (String(e && e.message).indexOf('key_format:') === 0) {
|
|
402
|
+
return { status: 'error', code: 'key_format', arg: String(e.message).split(':')[1] };
|
|
403
|
+
}
|
|
404
|
+
if (e instanceof SyntaxError) return { status: 'error', code: 'jwk_invalid' };
|
|
405
|
+
return { status: 'error', code: 'key_import', arg: String((e && e.message) || e) };
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
let ok;
|
|
409
|
+
try {
|
|
410
|
+
ok = await subtle.verify(verifyParams(spec), cryptoKey, sig, data);
|
|
411
|
+
} catch (e) {
|
|
412
|
+
return { status: 'error', code: 'verify_failed', arg: String((e && e.message) || e) };
|
|
413
|
+
}
|
|
414
|
+
return ok ? { status: 'verified', code: 'verified' } : { status: 'failed', code: 'mismatch' };
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/* ==================== 文言(site 側の T.W / T.V と同じ内容) ==================== */
|
|
418
|
+
|
|
419
|
+
const WARN = {
|
|
420
|
+
clean_header: () => '先頭の `Authorization:` を取り除いてからデコードしました。',
|
|
421
|
+
clean_bearer: () => '先頭の `Bearer ` を取り除いてからデコードしました。',
|
|
422
|
+
clean_quoted: () => '前後の引用符を取り除いてからデコードしました。',
|
|
423
|
+
clean_punct: () => '末尾のカンマ・セミコロンを取り除いてからデコードしました。',
|
|
424
|
+
clean_whitespace: () => 'トークンの途中にあった改行・空白を詰めてデコードしました。JWTは切れ目のない1本の文字列です。',
|
|
425
|
+
empty: () => 'トークンが空です。',
|
|
426
|
+
not_jwt: () => 'JWTとして読めません。JWTは `ヘッダー.ペイロード.署名` の3つをドットでつないだ形です。',
|
|
427
|
+
two_parts: () => 'セグメントが2つしかありません。署名なし(alg: none)のトークンでも末尾のドットは必要です。',
|
|
428
|
+
jwe: () => 'セグメントが5つあります。これは JWE(暗号化されたトークン)で、読めるのはヘッダーだけです。復号には受信者の秘密鍵が要ります。',
|
|
429
|
+
header_base64: () => 'ヘッダー部が base64url として壊れています。',
|
|
430
|
+
payload_base64: () => 'ペイロード部が base64url として壊れています。',
|
|
431
|
+
header_utf8: () => 'ヘッダー部が UTF-8 として読めません。',
|
|
432
|
+
payload_utf8: () => 'ペイロード部が UTF-8 として読めません。',
|
|
433
|
+
header_json: () => 'ヘッダー部はデコードできましたが、JSONとして読めません。',
|
|
434
|
+
payload_json: () => 'ペイロード部はデコードできましたが、JSONとして読めません(入れ子のJWTなど、JWSでは正しい場合もあります)。',
|
|
435
|
+
header_not_object: () => 'ヘッダーがJSONのオブジェクトではありません。',
|
|
436
|
+
payload_not_object: () => 'ペイロードがJSONのオブジェクトではないため、読み取れるクレームがありません。',
|
|
437
|
+
no_alg: () => 'ヘッダーに `alg` がありません。JWSのヘッダーには必ず必要です。',
|
|
438
|
+
alg_none: () => '`alg: none` — 署名がないトークンです。誰でもペイロードを書き換えられるので、意図して許可している場合を除き、受け取る側は拒否しなければいけません。',
|
|
439
|
+
unknown_alg: (a) => `未知のアルゴリズム \`${a}\` です。署名を検証できません。`,
|
|
440
|
+
no_signature: () => 'アルゴリズムが指定されているのに署名部が空です。このトークンは検証できません。',
|
|
441
|
+
typ_other: (t) => `\`typ\` が \`JWT\` ではなく \`${t}\` です(OAuthのアクセストークンの \`at+jwt\` など、規格上は正しい形です)。`,
|
|
442
|
+
time_invalid: () => '`exp` / `nbf` / `iat` は数値(1970年からの秒数)である必要があります。数値でない値が入っています。',
|
|
443
|
+
time_ms: () => '時刻のクレームがミリ秒(`Date.now()` の値)に見えます。JWTの時刻は秒です。1000で割り忘れていると、事実上いつまでも期限切れになりません。',
|
|
444
|
+
expired: (d) => `このトークンは ${d} 前に期限切れです。正しく実装されたサーバーは受け付けません。`,
|
|
445
|
+
not_yet: (d) => `まだ有効ではありません(\`nbf\` が ${d} 先)。発行側と受信側の時計のズレが原因のことが多いです。`,
|
|
446
|
+
no_exp: () => '`exp` が無いため、このトークンは自然には失効しません。漏れた場合、鍵を替えるかサーバー側で失効させるまで使われ続けます。',
|
|
447
|
+
lifetime_long: (d) => `有効期間が ${d} あります。アクセストークンとしては長すぎます(短命のアクセストークン+リフレッシュトークンが一般的)。`,
|
|
448
|
+
lifetime_day: (d) => `有効期間は ${d} です。`,
|
|
449
|
+
iat_future: () => '`iat` が未来の時刻です。発行側の時計が進んでいる可能性があります。',
|
|
450
|
+
secret_claim: (k) => `ペイロードに \`${k}\` が入っています。JWTのペイロードは base64url で符号化されているだけで暗号化ではありません。秘密情報を入れてはいけません。`,
|
|
451
|
+
pii_claim: (k) => `ペイロードに個人情報(\`${k}\`)が入っています。トークンを持つ人は誰でも読めることを前提にしてください。`,
|
|
452
|
+
no_aud: () => '`aud`(想定する受け手)がありません。同じ鍵を信頼している別のサービスへ使い回されるおそれがあります。',
|
|
453
|
+
no_jti: () => '`jti`(トークンID)がありません。個別のトークンの失効や二重使用の検出に使えます。',
|
|
454
|
+
not_verified: () => 'デコードは署名の検証ではありません。改ざんの有無を確かめるには key を渡して署名を検証してください。',
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
const VERDICT = {
|
|
458
|
+
no_token: () => 'デコードできるトークンがありません。',
|
|
459
|
+
no_key: () => 'key を渡すと署名を検証します。',
|
|
460
|
+
no_alg: () => 'ヘッダーに `alg` が無いため検証できません。',
|
|
461
|
+
alg_none: () => '`alg: none` のため検証する署名がありません。意図して許可していない限り、このトークンは拒否してください。',
|
|
462
|
+
unknown_alg: (a) => `\`${a}\` は検証に対応していません。`,
|
|
463
|
+
no_signature: () => '署名部が空です。',
|
|
464
|
+
bad_signature: () => '署名部が base64url として壊れています。',
|
|
465
|
+
ec_sig_length: (a) => `署名の長さが曲線と合いません(${a} バイト)。JWSのECDSA署名は DER ではなく R‖S の生の形です。`,
|
|
466
|
+
jwk_not_oct: () => 'HS* の検証に使うJWKは共有鍵(`"kty":"oct"` と `k`)である必要があります。',
|
|
467
|
+
jwk_invalid: () => '鍵をJSON(JWK / JWKS)として読み取れませんでした。',
|
|
468
|
+
private_key: () => '秘密鍵が渡されています。検証に使うのは公開鍵(SPKI形式のPEM)または公開鍵のJWKです。',
|
|
469
|
+
certificate: () => 'X.509証明書が渡されています。`openssl x509 -pubkey -noout -in cert.pem` で公開鍵を取り出してください。',
|
|
470
|
+
pkcs1: () => 'PKCS#1形式(`BEGIN RSA PUBLIC KEY`)です。`openssl rsa -RSAPublicKey_in -in key.pem -pubout` でSPKI形式へ変換してください。',
|
|
471
|
+
key_format: (f) => `鍵を ${f} として読み取れませんでした。keyEncoding を確認してください。`,
|
|
472
|
+
empty_key: () => '鍵が空です。',
|
|
473
|
+
key_import: (m) => `鍵を読み込めませんでした: ${m}`,
|
|
474
|
+
verify_failed: (m) => `検証を実行できませんでした: ${m}`,
|
|
475
|
+
verified: () => '署名は正しく、ヘッダーとペイロードは署名された時点から書き換えられていません。',
|
|
476
|
+
mismatch: () => '署名が一致しません。鍵が違うか、署名後にトークンが書き換えられています。',
|
|
477
|
+
short_secret: () => '共有鍵がハッシュ長より短いです。RFC 7518 はHMACの鍵にハッシュと同じ長さ(HS256なら32バイト)以上を求めています。',
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/** クレームの説明(site 側 CLAIMS の日本語と同じ) */
|
|
481
|
+
export const CLAIM_DOCS = {
|
|
482
|
+
iss: 'Issuer — このトークンを発行したサーバー。受け取る側は想定した発行者かを必ず確認する。',
|
|
483
|
+
sub: 'Subject — トークンが誰(何)についてのものか。多くはユーザーID。',
|
|
484
|
+
aud: 'Audience — このトークンを受け取ってよいサービス。自分宛でなければ拒否する。',
|
|
485
|
+
exp: 'Expiration Time — この時刻を過ぎたトークンは受け付けてはいけない。',
|
|
486
|
+
nbf: 'Not Before — この時刻より前は受け付けてはいけない。',
|
|
487
|
+
iat: 'Issued At — トークンが作られた時刻。',
|
|
488
|
+
jti: 'JWT ID — トークン1件ごとの識別子。失効管理や二重使用の検出に使う。',
|
|
489
|
+
azp: 'Authorized Party — このトークンの発行を受けたクライアント(OIDC)。',
|
|
490
|
+
nonce: 'Nonce — 認可リクエストで送った値。リプレイ攻撃の検出に使う(OIDC)。',
|
|
491
|
+
auth_time: 'Authentication Time — 利用者が実際に認証を行った時刻(OIDC)。',
|
|
492
|
+
acr: 'Auth Context Class — 満たされた認証の強度(OIDC)。',
|
|
493
|
+
amr: 'Auth Methods — 実際に使われた認証手段(OIDC)。',
|
|
494
|
+
scope: 'Scope — このトークンで許可されている操作の範囲(空白区切り)。',
|
|
495
|
+
scp: 'Scope — スコープの別表記(Azure AD など)。',
|
|
496
|
+
client_id: 'Client ID — トークンの発行を受けたアプリケーション。',
|
|
497
|
+
sid: 'Session ID — シングルログアウトで使うセッションの識別子(OIDC)。',
|
|
498
|
+
email: 'Email — 利用者のメールアドレス。誰でも読めることに注意。',
|
|
499
|
+
email_verified: 'Email Verified — メールアドレスが確認済みかどうか。',
|
|
500
|
+
name: 'Name — 利用者の表示名。',
|
|
501
|
+
given_name: 'Given Name — 利用者の名。',
|
|
502
|
+
family_name: 'Family Name — 利用者の姓。',
|
|
503
|
+
preferred_username: 'Preferred Username — 利用者が名乗っている名前。一意とは限らない。',
|
|
504
|
+
picture: 'Picture — プロフィール画像のURL。',
|
|
505
|
+
locale: 'Locale — 利用者の言語・地域設定。',
|
|
506
|
+
updated_at: 'Updated At — プロフィールが最後に更新された時刻。',
|
|
507
|
+
roles: 'Roles — アプリケーション側の権限(独自クレーム)。',
|
|
508
|
+
permissions: 'Permissions — 個別に許可された操作(独自クレーム)。',
|
|
509
|
+
groups: 'Groups — 所属グループ(独自クレーム)。',
|
|
510
|
+
token_use: 'Token Use — access か id か(Amazon Cognito)。',
|
|
511
|
+
alg: 'Algorithm — 署名に使われたアルゴリズム。',
|
|
512
|
+
typ: 'Type — トークンの型。通常は JWT。',
|
|
513
|
+
cty: 'Content Type — 入れ子のJWTなど、ペイロードの型。',
|
|
514
|
+
kid: 'Key ID — 検証に使う公開鍵を JWKS から選ぶための識別子。',
|
|
515
|
+
jku: 'JWK Set URL — 公開鍵の一覧(JWKS)の場所。信頼できるURLか必ず確認する。',
|
|
516
|
+
x5t: 'X.509 Thumbprint — 検証に使う証明書のSHA-1指紋。',
|
|
517
|
+
x5c: 'X.509 Chain — 検証に使う証明書そのもの。',
|
|
518
|
+
crit: 'Critical — 受け取る側が必ず解釈しなければならない拡張ヘッダーの一覧。',
|
|
519
|
+
enc: 'Encryption — JWEで本文の暗号化に使うアルゴリズム。',
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
const TIME_CLAIMS = ['exp', 'nbf', 'iat', 'auth_time', 'updated_at'];
|
|
523
|
+
|
|
524
|
+
/** 秒数を「2日3時間」のような文字列にする(site 側 fmtDuration と同じ規則) */
|
|
525
|
+
export function formatDuration(sec) {
|
|
526
|
+
const s = Math.max(0, Math.floor(Math.abs(sec)));
|
|
527
|
+
const d = Math.floor(s / 86400);
|
|
528
|
+
const h = Math.floor((s % 86400) / 3600);
|
|
529
|
+
const m = Math.floor((s % 3600) / 60);
|
|
530
|
+
const ss = s % 60;
|
|
531
|
+
const parts = [];
|
|
532
|
+
if (d) parts.push(d + '日');
|
|
533
|
+
if (h) parts.push(h + '時間');
|
|
534
|
+
if (m && d === 0) parts.push(m + '分');
|
|
535
|
+
if (!d && !h && (ss || !m)) parts.push(ss + '秒');
|
|
536
|
+
return parts.join('');
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function warnText(w) {
|
|
540
|
+
const f = WARN[w.code];
|
|
541
|
+
if (!f) return w.code;
|
|
542
|
+
if (['expired', 'not_yet', 'lifetime_long', 'lifetime_day'].indexOf(w.code) !== -1) return f(formatDuration(w.arg));
|
|
543
|
+
return f(w.arg);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const iso = (sec) => {
|
|
547
|
+
const d = new Date(sec * 1000);
|
|
548
|
+
return isNaN(d.getTime()) ? null : d.toISOString();
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* JWTをデコードし、有効期限を判定して(鍵があれば)署名を検証する。
|
|
553
|
+
*
|
|
554
|
+
* @param {object} opts
|
|
555
|
+
* @param {string} opts.token デコードするJWT(`Authorization: Bearer …` のままでも可)
|
|
556
|
+
* @param {string} [opts.key] 署名の検証に使う共有鍵(HS*)または公開鍵(PEM / JWK / JWKS)
|
|
557
|
+
* @param {'utf8'|'base64url'|'base64'|'hex'} [opts.keyEncoding='utf8'] 共有鍵の読み方
|
|
558
|
+
* @param {number} [opts.clockTolerance=0] 許容する時計のズレ(秒)
|
|
559
|
+
* @param {number} [opts.now] 判定に使う現在時刻(UNIX秒。既定は実時刻)
|
|
560
|
+
*/
|
|
561
|
+
export async function jwtDecode(opts = {}) {
|
|
562
|
+
if (typeof opts.token !== 'string' || !opts.token.trim()) throw new JwtError('token を渡してください');
|
|
563
|
+
const keyEncoding = opts.keyEncoding || 'utf8';
|
|
564
|
+
if (['utf8', 'base64url', 'base64', 'hex'].indexOf(keyEncoding) === -1) {
|
|
565
|
+
throw new JwtError(`keyEncoding は utf8 / base64url / base64 / hex: ${opts.keyEncoding}`);
|
|
566
|
+
}
|
|
567
|
+
const tolerance = opts.clockTolerance === undefined ? 0 : Number(opts.clockTolerance);
|
|
568
|
+
if (!isFinite(tolerance) || tolerance < 0) throw new JwtError('clockTolerance は0以上の秒数で渡してください');
|
|
569
|
+
const now = opts.now === undefined ? Math.floor(Date.now() / 1000) : Math.floor(Number(opts.now));
|
|
570
|
+
if (!isFinite(now)) throw new JwtError('now はUNIX秒で渡してください');
|
|
571
|
+
|
|
572
|
+
const decoded = decodeJwt(opts.token);
|
|
573
|
+
const timing = analyzeTiming(decoded.payload, now, tolerance);
|
|
574
|
+
const warnings = collectWarnings(decoded, timing);
|
|
575
|
+
|
|
576
|
+
const result = {
|
|
577
|
+
format: decoded.type || 'unknown',
|
|
578
|
+
decoded: decoded.ok,
|
|
579
|
+
header: decoded.header,
|
|
580
|
+
payload: decoded.payload,
|
|
581
|
+
signature: decoded.signature || null,
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
if (decoded.type === 'jws') {
|
|
585
|
+
result.expiry = {
|
|
586
|
+
status: timing.status, // valid / expired / not_yet / no_exp
|
|
587
|
+
checked_at: iso(now),
|
|
588
|
+
clock_tolerance_seconds: tolerance,
|
|
589
|
+
expires_at: timing.exp === null ? null : iso(timing.exp),
|
|
590
|
+
not_before: timing.nbf === null ? null : iso(timing.nbf),
|
|
591
|
+
issued_at: timing.iat === null ? null : iso(timing.iat),
|
|
592
|
+
remaining_seconds: timing.remaining,
|
|
593
|
+
remaining: timing.remaining === null ? null
|
|
594
|
+
: (timing.remaining >= 0 ? `残り${formatDuration(timing.remaining)}` : `${formatDuration(timing.remaining)}前に期限切れ`),
|
|
595
|
+
lifetime_seconds: timing.lifetime,
|
|
596
|
+
elapsed_ratio: timing.progress === null ? null : Math.round(timing.progress * 1000) / 1000,
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
// 説明を付けられるクレームだけを一覧にする(独自クレームは payload をそのまま見る)
|
|
600
|
+
const claims = [];
|
|
601
|
+
for (const [where, obj] of [['header', decoded.header], ['payload', decoded.payload]]) {
|
|
602
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) continue;
|
|
603
|
+
for (const k of Object.keys(obj)) {
|
|
604
|
+
const entry = { name: k, in: where, value: obj[k] };
|
|
605
|
+
if (CLAIM_DOCS[k]) entry.meaning = CLAIM_DOCS[k];
|
|
606
|
+
if (where === 'payload' && TIME_CLAIMS.indexOf(k) !== -1) {
|
|
607
|
+
const t = readTimeClaim(obj, k);
|
|
608
|
+
if (t && !t.invalid) entry.datetime = iso(t.seconds);
|
|
609
|
+
}
|
|
610
|
+
claims.push(entry);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
result.claims = claims;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
const verification = await verifySignature(decoded, opts.key, keyEncoding);
|
|
617
|
+
const vf = VERDICT[verification.code];
|
|
618
|
+
result.verification = {
|
|
619
|
+
status: verification.status, // verified / failed / error / skipped
|
|
620
|
+
message: typeof vf === 'function' ? vf(verification.arg) : verification.code,
|
|
621
|
+
};
|
|
622
|
+
if (verification.status === 'verified' && decoded.header && /^HS(256|384|512)$/.test(String(decoded.header.alg))) {
|
|
623
|
+
const need = { HS256: 32, HS384: 48, HS512: 64 }[decoded.header.alg];
|
|
624
|
+
let len = need;
|
|
625
|
+
try {
|
|
626
|
+
len = secretToBytes(String(opts.key).trim(), keyEncoding).length;
|
|
627
|
+
} catch (e) {
|
|
628
|
+
len = need;
|
|
629
|
+
}
|
|
630
|
+
if (len < need) result.verification.warning = VERDICT.short_secret();
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// 署名を検証できたあとに「検証していません」と出し続けない(site 側 renderNotes と同じ)
|
|
634
|
+
const shown = verification.status === 'verified'
|
|
635
|
+
? warnings.filter((w) => w.code !== 'not_verified')
|
|
636
|
+
: warnings;
|
|
637
|
+
result.warnings = shown.map((w) => warnText(w));
|
|
638
|
+
return result;
|
|
639
|
+
}
|