imzo-agnost 1.0.0 → 1.2.1
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 +15 -15
- package/README.md +27 -6
- package/dist/index.cjs +614 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +163 -15
- package/dist/index.d.ts +163 -15
- package/dist/index.js +614 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +613 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -30,6 +30,18 @@ var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
|
30
30
|
return __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
// polyfills/process-polyfill.js
|
|
34
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.process === "undefined") {
|
|
35
|
+
globalThis.process = {
|
|
36
|
+
env: {
|
|
37
|
+
NODE_ENV: "production"
|
|
38
|
+
},
|
|
39
|
+
versions: {
|
|
40
|
+
node: null
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
// src/e-imzo/capiws.ts
|
|
34
46
|
var CAPIWS = typeof EIMZOEXT !== "undefined" ? EIMZOEXT : {
|
|
35
47
|
URL: (window.location.protocol.toLowerCase() === "https:" ? "wss://127.0.0.1:64443" : "ws://127.0.0.1:64646") + "/service/cryptapi",
|
|
@@ -1094,12 +1106,383 @@ _init7 = __decoratorStart(_a7);
|
|
|
1094
1106
|
IDCardPlugin = __decorateElement(_init7, 0, "IDCardPlugin", _IDCardPlugin_decorators, IDCardPlugin);
|
|
1095
1107
|
__runInitializers(_init7, 1, IDCardPlugin);
|
|
1096
1108
|
|
|
1109
|
+
// src/core/session-manager.ts
|
|
1110
|
+
var EIMZOSessionManager = class {
|
|
1111
|
+
config;
|
|
1112
|
+
sessions = /* @__PURE__ */ new Map();
|
|
1113
|
+
cleanupInterval = null;
|
|
1114
|
+
constructor(config = {}) {
|
|
1115
|
+
this.config = {
|
|
1116
|
+
storageType: "sessionStorage",
|
|
1117
|
+
autoUnloadAfter: 6 * 60 * 60 * 1e3,
|
|
1118
|
+
// 6 hours default
|
|
1119
|
+
keyPrefix: "eimzo_key_",
|
|
1120
|
+
...config
|
|
1121
|
+
};
|
|
1122
|
+
this.initializeFromStorage();
|
|
1123
|
+
this.startCleanupTimer();
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* KeyId ni session storage ga saqlash
|
|
1127
|
+
*/
|
|
1128
|
+
saveKeySession(keyId, certificateId, certificate, autoUnload = true) {
|
|
1129
|
+
const now = Date.now();
|
|
1130
|
+
const session = {
|
|
1131
|
+
keyId,
|
|
1132
|
+
certificateId,
|
|
1133
|
+
loadedAt: now,
|
|
1134
|
+
expiresAt: now + this.config.autoUnloadAfter,
|
|
1135
|
+
certificate,
|
|
1136
|
+
autoUnload
|
|
1137
|
+
};
|
|
1138
|
+
this.sessions.set(certificateId, session);
|
|
1139
|
+
this.saveToStorage(certificateId, session);
|
|
1140
|
+
console.log(
|
|
1141
|
+
`\u{1F511} Key session saved: ${certificateId} (expires in ${this.config.autoUnloadAfter / 1e3 / 60} minutes)`
|
|
1142
|
+
);
|
|
1143
|
+
}
|
|
1144
|
+
/**
|
|
1145
|
+
* Certificate ID bo'yicha keyId ni olish
|
|
1146
|
+
*/
|
|
1147
|
+
getKeyId(certificateId) {
|
|
1148
|
+
const session = this.sessions.get(certificateId);
|
|
1149
|
+
if (!session) {
|
|
1150
|
+
this.loadFromStorage(certificateId);
|
|
1151
|
+
return this.sessions.get(certificateId)?.keyId ?? null;
|
|
1152
|
+
}
|
|
1153
|
+
if (Date.now() > session.expiresAt) {
|
|
1154
|
+
void this.removeKeySession(certificateId);
|
|
1155
|
+
return null;
|
|
1156
|
+
}
|
|
1157
|
+
return session.keyId;
|
|
1158
|
+
}
|
|
1159
|
+
/**
|
|
1160
|
+
* Barcha active key sessions ni olish
|
|
1161
|
+
*/
|
|
1162
|
+
getActiveSessions() {
|
|
1163
|
+
const now = Date.now();
|
|
1164
|
+
const activeSessions = [];
|
|
1165
|
+
for (const [certId, session] of this.sessions.entries()) {
|
|
1166
|
+
if (now <= session.expiresAt) {
|
|
1167
|
+
activeSessions.push(session);
|
|
1168
|
+
} else {
|
|
1169
|
+
void this.removeKeySession(certId);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return activeSessions;
|
|
1173
|
+
}
|
|
1174
|
+
/**
|
|
1175
|
+
* Session ni kengaytirish (6 soat yana qo'shish)
|
|
1176
|
+
*/
|
|
1177
|
+
extendSession(certificateId) {
|
|
1178
|
+
const session = this.sessions.get(certificateId);
|
|
1179
|
+
if (!session) return false;
|
|
1180
|
+
const now = Date.now();
|
|
1181
|
+
session.expiresAt = now + this.config.autoUnloadAfter;
|
|
1182
|
+
void this.saveToStorage(certificateId, session);
|
|
1183
|
+
console.log(`\u23F0 Session extended for ${certificateId}`);
|
|
1184
|
+
return true;
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Key session ni o'chirish
|
|
1188
|
+
*/
|
|
1189
|
+
async removeKeySession(certificateId) {
|
|
1190
|
+
const session = this.sessions.get(certificateId);
|
|
1191
|
+
if (session) {
|
|
1192
|
+
if (session.autoUnload) {
|
|
1193
|
+
await this.unloadKeyFromEIMZO(session.keyId);
|
|
1194
|
+
}
|
|
1195
|
+
this.sessions.delete(certificateId);
|
|
1196
|
+
this.removeFromStorage(certificateId);
|
|
1197
|
+
console.log(`\u{1F5D1}\uFE0F Key session removed: ${certificateId}`);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Barcha sessionlarni tozalash
|
|
1202
|
+
*/
|
|
1203
|
+
async clearAllSessions() {
|
|
1204
|
+
const sessions = Array.from(this.sessions.keys());
|
|
1205
|
+
for (const certId of sessions) {
|
|
1206
|
+
await this.removeKeySession(certId);
|
|
1207
|
+
}
|
|
1208
|
+
console.log("\u{1F9F9} All key sessions cleared");
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Storage configuration ni o'zgartirish
|
|
1212
|
+
*/
|
|
1213
|
+
updateConfig(newConfig) {
|
|
1214
|
+
this.config = { ...this.config, ...newConfig };
|
|
1215
|
+
if (this.cleanupInterval) {
|
|
1216
|
+
clearInterval(this.cleanupInterval);
|
|
1217
|
+
}
|
|
1218
|
+
this.startCleanupTimer();
|
|
1219
|
+
}
|
|
1220
|
+
// Private methods
|
|
1221
|
+
saveToStorage(certificateId, session) {
|
|
1222
|
+
const key = this.config.keyPrefix + certificateId;
|
|
1223
|
+
const data = JSON.stringify(session);
|
|
1224
|
+
try {
|
|
1225
|
+
switch (this.config.storageType) {
|
|
1226
|
+
case "sessionStorage":
|
|
1227
|
+
if (typeof sessionStorage !== "undefined") {
|
|
1228
|
+
sessionStorage.setItem(key, data);
|
|
1229
|
+
}
|
|
1230
|
+
break;
|
|
1231
|
+
case "localStorage":
|
|
1232
|
+
if (typeof localStorage !== "undefined") {
|
|
1233
|
+
localStorage.setItem(key, data);
|
|
1234
|
+
}
|
|
1235
|
+
break;
|
|
1236
|
+
case "cookie":
|
|
1237
|
+
this.setCookie(key, data, session.expiresAt);
|
|
1238
|
+
break;
|
|
1239
|
+
case "memory":
|
|
1240
|
+
break;
|
|
1241
|
+
}
|
|
1242
|
+
} catch (error) {
|
|
1243
|
+
console.warn("Failed to save to storage:", error);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
loadFromStorage(certificateId) {
|
|
1247
|
+
const key = this.config.keyPrefix + certificateId;
|
|
1248
|
+
try {
|
|
1249
|
+
let data = null;
|
|
1250
|
+
switch (this.config.storageType) {
|
|
1251
|
+
case "sessionStorage":
|
|
1252
|
+
if (typeof sessionStorage !== "undefined") {
|
|
1253
|
+
data = sessionStorage.getItem(key);
|
|
1254
|
+
}
|
|
1255
|
+
break;
|
|
1256
|
+
case "localStorage":
|
|
1257
|
+
if (typeof localStorage !== "undefined") {
|
|
1258
|
+
data = localStorage.getItem(key);
|
|
1259
|
+
}
|
|
1260
|
+
break;
|
|
1261
|
+
case "cookie":
|
|
1262
|
+
data = this.getCookie(key);
|
|
1263
|
+
break;
|
|
1264
|
+
case "memory":
|
|
1265
|
+
return null;
|
|
1266
|
+
}
|
|
1267
|
+
if (data) {
|
|
1268
|
+
const session = JSON.parse(data);
|
|
1269
|
+
if (Date.now() > session.expiresAt) {
|
|
1270
|
+
this.removeFromStorage(certificateId);
|
|
1271
|
+
return null;
|
|
1272
|
+
}
|
|
1273
|
+
this.sessions.set(certificateId, session);
|
|
1274
|
+
return session;
|
|
1275
|
+
}
|
|
1276
|
+
} catch (error) {
|
|
1277
|
+
console.warn("Failed to load from storage:", error);
|
|
1278
|
+
}
|
|
1279
|
+
return null;
|
|
1280
|
+
}
|
|
1281
|
+
removeFromStorage(certificateId) {
|
|
1282
|
+
const key = this.config.keyPrefix + certificateId;
|
|
1283
|
+
try {
|
|
1284
|
+
switch (this.config.storageType) {
|
|
1285
|
+
case "sessionStorage":
|
|
1286
|
+
if (typeof sessionStorage !== "undefined") {
|
|
1287
|
+
sessionStorage.removeItem(key);
|
|
1288
|
+
}
|
|
1289
|
+
break;
|
|
1290
|
+
case "localStorage":
|
|
1291
|
+
if (typeof localStorage !== "undefined") {
|
|
1292
|
+
localStorage.removeItem(key);
|
|
1293
|
+
}
|
|
1294
|
+
break;
|
|
1295
|
+
case "cookie":
|
|
1296
|
+
this.deleteCookie(key);
|
|
1297
|
+
break;
|
|
1298
|
+
case "memory":
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
} catch (error) {
|
|
1302
|
+
console.warn("Failed to remove from storage:", error);
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
initializeFromStorage() {
|
|
1306
|
+
if (typeof window === "undefined") return;
|
|
1307
|
+
try {
|
|
1308
|
+
const keys = [];
|
|
1309
|
+
switch (this.config.storageType) {
|
|
1310
|
+
case "sessionStorage":
|
|
1311
|
+
if (typeof sessionStorage !== "undefined") {
|
|
1312
|
+
for (let i = 0; i < sessionStorage.length; i++) {
|
|
1313
|
+
const key = sessionStorage.key(i);
|
|
1314
|
+
if (key?.startsWith(this.config.keyPrefix)) {
|
|
1315
|
+
keys.push(key);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
break;
|
|
1320
|
+
case "localStorage":
|
|
1321
|
+
if (typeof localStorage !== "undefined") {
|
|
1322
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
1323
|
+
const key = localStorage.key(i);
|
|
1324
|
+
if (key?.startsWith(this.config.keyPrefix)) {
|
|
1325
|
+
keys.push(key);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
break;
|
|
1330
|
+
case "cookie":
|
|
1331
|
+
break;
|
|
1332
|
+
}
|
|
1333
|
+
keys.forEach((key) => {
|
|
1334
|
+
const certificateId = key.replace(this.config.keyPrefix, "");
|
|
1335
|
+
this.loadFromStorage(certificateId);
|
|
1336
|
+
});
|
|
1337
|
+
} catch (error) {
|
|
1338
|
+
console.warn("Failed to initialize from storage:", error);
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
startCleanupTimer() {
|
|
1342
|
+
this.cleanupInterval = setInterval(
|
|
1343
|
+
() => {
|
|
1344
|
+
void this.cleanupExpiredSessions();
|
|
1345
|
+
},
|
|
1346
|
+
10 * 60 * 1e3
|
|
1347
|
+
);
|
|
1348
|
+
}
|
|
1349
|
+
async cleanupExpiredSessions() {
|
|
1350
|
+
const now = Date.now();
|
|
1351
|
+
const expiredSessions = [];
|
|
1352
|
+
for (const [certId, session] of this.sessions.entries()) {
|
|
1353
|
+
if (now > session.expiresAt) {
|
|
1354
|
+
expiredSessions.push(certId);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
for (const certId of expiredSessions) {
|
|
1358
|
+
await this.removeKeySession(certId);
|
|
1359
|
+
}
|
|
1360
|
+
if (expiredSessions.length > 0) {
|
|
1361
|
+
console.log(`\u{1F552} Cleaned up ${expiredSessions.length} expired sessions`);
|
|
1362
|
+
}
|
|
1363
|
+
}
|
|
1364
|
+
async unloadKeyFromEIMZO(keyId) {
|
|
1365
|
+
try {
|
|
1366
|
+
if (typeof window !== "undefined") {
|
|
1367
|
+
const windowWithCAPiWS = window;
|
|
1368
|
+
if (windowWithCAPiWS.CAPIWS) {
|
|
1369
|
+
const CAPIWS2 = windowWithCAPiWS.CAPIWS;
|
|
1370
|
+
return new Promise((resolve) => {
|
|
1371
|
+
CAPIWS2.callFunction({
|
|
1372
|
+
plugin: "pfx",
|
|
1373
|
+
name: "unloadKey",
|
|
1374
|
+
arguments: [keyId],
|
|
1375
|
+
onSuccess: () => {
|
|
1376
|
+
console.log(`\u{1F513} Key unloaded from E-IMZO: ${keyId}`);
|
|
1377
|
+
resolve();
|
|
1378
|
+
},
|
|
1379
|
+
onError: (error, reason) => {
|
|
1380
|
+
console.warn(`Failed to unload key ${keyId}:`, reason);
|
|
1381
|
+
resolve();
|
|
1382
|
+
}
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
} catch (error) {
|
|
1388
|
+
console.warn("Failed to unload key from E-IMZO:", error);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
// Cookie utility methods
|
|
1392
|
+
setCookie(name, value, expiresAt) {
|
|
1393
|
+
if (typeof document === "undefined") return;
|
|
1394
|
+
const expires = new Date(expiresAt).toUTCString();
|
|
1395
|
+
const options = this.config.cookieOptions ?? {};
|
|
1396
|
+
let cookieString = `${name}=${encodeURIComponent(value)}; expires=${expires}`;
|
|
1397
|
+
if (options.domain) cookieString += `; domain=${options.domain}`;
|
|
1398
|
+
if (options.path) cookieString += `; path=${options.path}`;
|
|
1399
|
+
if (options.secure) cookieString += "; secure";
|
|
1400
|
+
if (options.sameSite) cookieString += `; samesite=${options.sameSite}`;
|
|
1401
|
+
document.cookie = cookieString;
|
|
1402
|
+
}
|
|
1403
|
+
getCookie(name) {
|
|
1404
|
+
if (typeof document === "undefined") return null;
|
|
1405
|
+
const nameEQ = name + "=";
|
|
1406
|
+
const cookies = document.cookie.split(";");
|
|
1407
|
+
for (let cookie of cookies) {
|
|
1408
|
+
cookie = cookie.trim();
|
|
1409
|
+
if (cookie.startsWith(nameEQ)) {
|
|
1410
|
+
return decodeURIComponent(cookie.substring(nameEQ.length));
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
return null;
|
|
1414
|
+
}
|
|
1415
|
+
deleteCookie(name) {
|
|
1416
|
+
if (typeof document === "undefined") return;
|
|
1417
|
+
const options = this.config.cookieOptions ?? {};
|
|
1418
|
+
let cookieString = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC`;
|
|
1419
|
+
if (options.domain) cookieString += `; domain=${options.domain}`;
|
|
1420
|
+
if (options.path) cookieString += `; path=${options.path}`;
|
|
1421
|
+
document.cookie = cookieString;
|
|
1422
|
+
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Cleanup when instance is destroyed
|
|
1425
|
+
*/
|
|
1426
|
+
destroy() {
|
|
1427
|
+
if (this.cleanupInterval) {
|
|
1428
|
+
clearInterval(this.cleanupInterval);
|
|
1429
|
+
this.cleanupInterval = null;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
};
|
|
1433
|
+
var sessionManager = new EIMZOSessionManager();
|
|
1434
|
+
|
|
1097
1435
|
// src/plugins/pfx.ts
|
|
1098
1436
|
var _PfxPlugin_decorators, _init8, _a8;
|
|
1099
1437
|
_PfxPlugin_decorators = [RegisterPlugin];
|
|
1100
1438
|
var PfxPlugin = class extends (_a8 = EIMZOPlugin) {
|
|
1101
1439
|
name = "pfx";
|
|
1102
|
-
description = "Plugin for working with PFX key storage files";
|
|
1440
|
+
description = "Plugin for working with PFX key storage files with session management";
|
|
1441
|
+
// Session management configuration
|
|
1442
|
+
updateSessionConfig(config) {
|
|
1443
|
+
sessionManager.updateConfig(config);
|
|
1444
|
+
}
|
|
1445
|
+
// Certificate cache for keyId lookup
|
|
1446
|
+
certificateCache = /* @__PURE__ */ new Map();
|
|
1447
|
+
/**
|
|
1448
|
+
* Get keyId from certificate identifier
|
|
1449
|
+
* Used for: await pfxPlugin.verifyPasswordAsync(keyId);
|
|
1450
|
+
* @param certificateId - Format: "disk:path:name:alias" or just "alias"
|
|
1451
|
+
* @returns keyId or null if not found
|
|
1452
|
+
*/
|
|
1453
|
+
getKeyId(certificateId) {
|
|
1454
|
+
return sessionManager.getKeyId(certificateId);
|
|
1455
|
+
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Get all active key sessions
|
|
1458
|
+
*/
|
|
1459
|
+
getActiveSessions() {
|
|
1460
|
+
return sessionManager.getActiveSessions();
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Find certificate ID by partial match (alias, name, etc.)
|
|
1464
|
+
*/
|
|
1465
|
+
findCertificateId(searchTerm) {
|
|
1466
|
+
for (const [certId, cert] of this.certificateCache.entries()) {
|
|
1467
|
+
if (cert.alias === searchTerm || cert.name === searchTerm || certId.includes(searchTerm)) {
|
|
1468
|
+
return certId;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
const sessions = sessionManager.getActiveSessions();
|
|
1472
|
+
for (const session of sessions) {
|
|
1473
|
+
if (session.certificateId.includes(searchTerm)) {
|
|
1474
|
+
return session.certificateId;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
return null;
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Clear all sessions
|
|
1481
|
+
*/
|
|
1482
|
+
async clearAllSessions() {
|
|
1483
|
+
await sessionManager.clearAllSessions();
|
|
1484
|
+
this.certificateCache.clear();
|
|
1485
|
+
}
|
|
1103
1486
|
// Callback-based methods
|
|
1104
1487
|
/**
|
|
1105
1488
|
* Get list of available disks
|
|
@@ -1120,10 +1503,60 @@ var PfxPlugin = class extends (_a8 = EIMZOPlugin) {
|
|
|
1120
1503
|
this.callMethod("list_all_certificates", [], onSuccess, onError);
|
|
1121
1504
|
};
|
|
1122
1505
|
/**
|
|
1123
|
-
* Load key and get key identifier
|
|
1506
|
+
* Load key and get key identifier with session management
|
|
1507
|
+
* @param disk - Storage disk name
|
|
1508
|
+
* @param path - Path to PFX file
|
|
1509
|
+
* @param name - File name
|
|
1510
|
+
* @param alias - Certificate alias
|
|
1511
|
+
* @param saveForHours - Save in session for automatic management (6 hours default)
|
|
1124
1512
|
*/
|
|
1125
|
-
loadKey = (disk, path, name, alias, onSuccess, onError) => {
|
|
1126
|
-
|
|
1513
|
+
loadKey = (disk, path, name, alias, onSuccess, onError, saveForHours) => {
|
|
1514
|
+
const originalOnSuccess = (event, response) => {
|
|
1515
|
+
if (!response.data) return;
|
|
1516
|
+
const keyResponse = response.data;
|
|
1517
|
+
const certificateId = `${disk}:${path}:${name}:${alias}`;
|
|
1518
|
+
const certificate = {
|
|
1519
|
+
disk,
|
|
1520
|
+
path,
|
|
1521
|
+
name,
|
|
1522
|
+
alias,
|
|
1523
|
+
serialNumber: "",
|
|
1524
|
+
subjectName: "",
|
|
1525
|
+
validFromDate: "",
|
|
1526
|
+
validToDate: "",
|
|
1527
|
+
issuerName: "",
|
|
1528
|
+
subjectId: "",
|
|
1529
|
+
publicKeyAlgorithm: "",
|
|
1530
|
+
signAlgorithm: "",
|
|
1531
|
+
keyUsage: "",
|
|
1532
|
+
extendedKeyUsage: "",
|
|
1533
|
+
crlDistributionPoints: "",
|
|
1534
|
+
authorityInfoAccess: "",
|
|
1535
|
+
subjectAltName: "",
|
|
1536
|
+
issuerAltName: "",
|
|
1537
|
+
subjectKeyIdentifier: "",
|
|
1538
|
+
authorityKeyIdentifier: "",
|
|
1539
|
+
basicConstraints: "",
|
|
1540
|
+
certificatePolicies: "",
|
|
1541
|
+
keyUsageNonRepudiation: false,
|
|
1542
|
+
keyUsageDigitalSignature: false,
|
|
1543
|
+
keyUsageContentCommitment: false,
|
|
1544
|
+
extendedKeyUsageTimeStamping: false
|
|
1545
|
+
};
|
|
1546
|
+
this.certificateCache.set(certificateId, certificate);
|
|
1547
|
+
if (saveForHours && saveForHours > 0 && keyResponse.keyId) {
|
|
1548
|
+
sessionManager.saveKeySession(
|
|
1549
|
+
keyResponse.keyId,
|
|
1550
|
+
certificateId,
|
|
1551
|
+
certificate,
|
|
1552
|
+
true
|
|
1553
|
+
// Auto unload enabled
|
|
1554
|
+
);
|
|
1555
|
+
console.log(`\u{1F4BE} Key session saved for ${saveForHours} hours: ${certificateId}`);
|
|
1556
|
+
}
|
|
1557
|
+
onSuccess(event, response);
|
|
1558
|
+
};
|
|
1559
|
+
this.callMethod("load_key", [disk, path, name, alias], originalOnSuccess, onError);
|
|
1127
1560
|
};
|
|
1128
1561
|
/**
|
|
1129
1562
|
* Unload key by identifier
|
|
@@ -1189,11 +1622,32 @@ var PfxPlugin = class extends (_a8 = EIMZOPlugin) {
|
|
|
1189
1622
|
*/
|
|
1190
1623
|
listAllCertificatesAsync = this.createPromiseMethod("list_all_certificates");
|
|
1191
1624
|
/**
|
|
1192
|
-
* Load key (Promise version)
|
|
1625
|
+
* Load key (Promise version) with session management
|
|
1626
|
+
* @param disk Storage disk name
|
|
1627
|
+
* @param path Path to PFX file
|
|
1628
|
+
* @param name File name
|
|
1629
|
+
* @param alias Certificate alias
|
|
1630
|
+
* @param saveForHours Save in session for automatic management
|
|
1193
1631
|
*/
|
|
1194
|
-
loadKeyAsync =
|
|
1195
|
-
|
|
1196
|
-
|
|
1632
|
+
loadKeyAsync = async (disk, path, name, alias, saveForHours) => {
|
|
1633
|
+
return new Promise((resolve, reject) => {
|
|
1634
|
+
this.loadKey(
|
|
1635
|
+
disk,
|
|
1636
|
+
path,
|
|
1637
|
+
name,
|
|
1638
|
+
alias,
|
|
1639
|
+
(event, response) => {
|
|
1640
|
+
if (response.success && response.data) {
|
|
1641
|
+
resolve(response.data);
|
|
1642
|
+
} else {
|
|
1643
|
+
reject(new Error(response.reason ?? "Unknown error"));
|
|
1644
|
+
}
|
|
1645
|
+
},
|
|
1646
|
+
reject,
|
|
1647
|
+
saveForHours
|
|
1648
|
+
);
|
|
1649
|
+
});
|
|
1650
|
+
};
|
|
1197
1651
|
/**
|
|
1198
1652
|
* Unload key (Promise version)
|
|
1199
1653
|
*/
|
|
@@ -1261,11 +1715,52 @@ _Pkcs7Plugin_decorators = [RegisterPlugin];
|
|
|
1261
1715
|
var Pkcs7Plugin = class extends (_a10 = EIMZOPlugin) {
|
|
1262
1716
|
name = "pkcs7";
|
|
1263
1717
|
description = "Plugin for working with PKCS#7/CMS format";
|
|
1718
|
+
// Utility method to check if string is base64
|
|
1719
|
+
isBase64(str) {
|
|
1720
|
+
try {
|
|
1721
|
+
const base64Pattern = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
1722
|
+
if (!base64Pattern.test(str)) return false;
|
|
1723
|
+
const decoded = atob(str);
|
|
1724
|
+
const encoded = btoa(decoded);
|
|
1725
|
+
return encoded === str;
|
|
1726
|
+
} catch {
|
|
1727
|
+
return false;
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1264
1730
|
// Callback-based methods
|
|
1265
1731
|
/**
|
|
1266
|
-
* Create PKCS#7/CMS document by signing with key
|
|
1732
|
+
* Create PKCS#7/CMS document by signing with key (enhanced version)
|
|
1733
|
+
* @param data - String data or already base64 encoded data
|
|
1734
|
+
* @param keyId - Key identifier
|
|
1735
|
+
* @param options - Creation options with smart defaults
|
|
1736
|
+
*/
|
|
1737
|
+
createPkcs7Enhanced = (data, keyId, options = {}, onSuccess, onError) => {
|
|
1738
|
+
const {
|
|
1739
|
+
detached = false,
|
|
1740
|
+
// Default to attached (no)
|
|
1741
|
+
autoBase64 = true
|
|
1742
|
+
// Default to auto base64 encoding
|
|
1743
|
+
} = options;
|
|
1744
|
+
let data64 = data;
|
|
1745
|
+
if (autoBase64 && !this.isBase64(data)) {
|
|
1746
|
+
try {
|
|
1747
|
+
data64 = btoa(data);
|
|
1748
|
+
} catch (_error) {
|
|
1749
|
+
data64 = btoa(unescape(encodeURIComponent(data)));
|
|
1750
|
+
}
|
|
1751
|
+
}
|
|
1752
|
+
let detachedParam = "";
|
|
1753
|
+
if (typeof detached === "boolean") {
|
|
1754
|
+
detachedParam = detached ? "yes" : "no";
|
|
1755
|
+
} else {
|
|
1756
|
+
detachedParam = detached;
|
|
1757
|
+
}
|
|
1758
|
+
this.callMethod("create_pkcs7", [data64, keyId, detachedParam], onSuccess, onError);
|
|
1759
|
+
};
|
|
1760
|
+
/**
|
|
1761
|
+
* Create PKCS#7/CMS document by signing with key (original method)
|
|
1267
1762
|
*/
|
|
1268
|
-
createPkcs7 = (data64, keyId, detached = "", onSuccess, onError) => {
|
|
1763
|
+
createPkcs7 = (data64, keyId, detached = "no", onSuccess, onError) => {
|
|
1269
1764
|
this.callMethod("create_pkcs7", [data64, keyId, detached], onSuccess, onError);
|
|
1270
1765
|
};
|
|
1271
1766
|
/**
|
|
@@ -1275,7 +1770,21 @@ var Pkcs7Plugin = class extends (_a10 = EIMZOPlugin) {
|
|
|
1275
1770
|
this.callMethod("get_pkcs7_attached_info", [pkcs764, trustStoreId], onSuccess, onError);
|
|
1276
1771
|
};
|
|
1277
1772
|
/**
|
|
1278
|
-
* Get full information about PKCS#7/CMS document (detached)
|
|
1773
|
+
* Get full information about PKCS#7/CMS document (detached) with auto base64
|
|
1774
|
+
*/
|
|
1775
|
+
getPkcs7DetachedInfoEnhanced = (data, pkcs764, trustStoreId = "", autoBase64 = true, onSuccess, onError) => {
|
|
1776
|
+
let data64 = data;
|
|
1777
|
+
if (autoBase64 && !this.isBase64(data)) {
|
|
1778
|
+
try {
|
|
1779
|
+
data64 = btoa(data);
|
|
1780
|
+
} catch (_error) {
|
|
1781
|
+
data64 = btoa(unescape(encodeURIComponent(data)));
|
|
1782
|
+
}
|
|
1783
|
+
}
|
|
1784
|
+
this.callMethod("get_pkcs7_detached_info", [data64, pkcs764, trustStoreId], onSuccess, onError);
|
|
1785
|
+
};
|
|
1786
|
+
/**
|
|
1787
|
+
* Get full information about PKCS#7/CMS document (detached) - original
|
|
1279
1788
|
*/
|
|
1280
1789
|
getPkcs7DetachedInfo = (data64, pkcs764, trustStoreId = "", onSuccess, onError) => {
|
|
1281
1790
|
this.callMethod("get_pkcs7_detached_info", [data64, pkcs764, trustStoreId], onSuccess, onError);
|
|
@@ -1291,6 +1800,25 @@ var Pkcs7Plugin = class extends (_a10 = EIMZOPlugin) {
|
|
|
1291
1800
|
onError
|
|
1292
1801
|
);
|
|
1293
1802
|
};
|
|
1803
|
+
/**
|
|
1804
|
+
* Verify PKCS#7/CMS document (detached) with auto base64
|
|
1805
|
+
*/
|
|
1806
|
+
verifyPkcs7DetachedEnhanced = (data, pkcs764, trustStoreId, requesterId = "", autoBase64 = true, onSuccess, onError) => {
|
|
1807
|
+
let data64 = data;
|
|
1808
|
+
if (autoBase64 && !this.isBase64(data)) {
|
|
1809
|
+
try {
|
|
1810
|
+
data64 = btoa(data);
|
|
1811
|
+
} catch (_error) {
|
|
1812
|
+
data64 = btoa(unescape(encodeURIComponent(data)));
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
this.callMethod(
|
|
1816
|
+
"verify_pkcs7_detached",
|
|
1817
|
+
[data64, pkcs764, trustStoreId, requesterId],
|
|
1818
|
+
onSuccess,
|
|
1819
|
+
onError
|
|
1820
|
+
);
|
|
1821
|
+
};
|
|
1294
1822
|
/**
|
|
1295
1823
|
* Verify PKCS#7/CMS document (detached) - STUB
|
|
1296
1824
|
*/
|
|
@@ -1349,9 +1877,32 @@ var Pkcs7Plugin = class extends (_a10 = EIMZOPlugin) {
|
|
|
1349
1877
|
};
|
|
1350
1878
|
// Promise-based methods
|
|
1351
1879
|
/**
|
|
1352
|
-
* Create PKCS#7/CMS document (Promise version)
|
|
1880
|
+
* Create PKCS#7/CMS document (Enhanced Promise version)
|
|
1881
|
+
* @param data String data (auto base64 encoded) or base64 data
|
|
1882
|
+
* @param keyId Key identifier
|
|
1883
|
+
* @param options Creation options with smart defaults
|
|
1884
|
+
*/
|
|
1885
|
+
createPkcs7Async = async (data, keyId, options = {}) => {
|
|
1886
|
+
return new Promise((resolve, reject) => {
|
|
1887
|
+
this.createPkcs7Enhanced(
|
|
1888
|
+
data,
|
|
1889
|
+
keyId,
|
|
1890
|
+
options,
|
|
1891
|
+
(_event, response) => {
|
|
1892
|
+
if (response.success && response.data) {
|
|
1893
|
+
resolve(response.data);
|
|
1894
|
+
} else {
|
|
1895
|
+
reject(new Error(response.reason ?? "Unknown error"));
|
|
1896
|
+
}
|
|
1897
|
+
},
|
|
1898
|
+
reject
|
|
1899
|
+
);
|
|
1900
|
+
});
|
|
1901
|
+
};
|
|
1902
|
+
/**
|
|
1903
|
+
* Create PKCS#7/CMS document (Original Promise version for backward compatibility)
|
|
1353
1904
|
*/
|
|
1354
|
-
|
|
1905
|
+
createPkcs7LegacyAsync = this.createPromiseMethod("create_pkcs7");
|
|
1355
1906
|
/**
|
|
1356
1907
|
* Get PKCS#7 attached info (Promise version)
|
|
1357
1908
|
*/
|
|
@@ -1359,17 +1910,60 @@ var Pkcs7Plugin = class extends (_a10 = EIMZOPlugin) {
|
|
|
1359
1910
|
"get_pkcs7_attached_info"
|
|
1360
1911
|
);
|
|
1361
1912
|
/**
|
|
1362
|
-
* Get PKCS#7 detached info (Promise version)
|
|
1913
|
+
* Get PKCS#7 detached info (Enhanced Promise version)
|
|
1914
|
+
*/
|
|
1915
|
+
getPkcs7DetachedInfoAsync = async (data, pkcs764, trustStoreId = "", autoBase64 = true) => {
|
|
1916
|
+
return new Promise((resolve, reject) => {
|
|
1917
|
+
this.getPkcs7DetachedInfoEnhanced(
|
|
1918
|
+
data,
|
|
1919
|
+
pkcs764,
|
|
1920
|
+
trustStoreId,
|
|
1921
|
+
autoBase64,
|
|
1922
|
+
(_event, response) => {
|
|
1923
|
+
if (response.success && response.data) {
|
|
1924
|
+
resolve(response.data);
|
|
1925
|
+
} else {
|
|
1926
|
+
reject(new Error(response.reason ?? "Unknown error"));
|
|
1927
|
+
}
|
|
1928
|
+
},
|
|
1929
|
+
reject
|
|
1930
|
+
);
|
|
1931
|
+
});
|
|
1932
|
+
};
|
|
1933
|
+
/**
|
|
1934
|
+
* Get PKCS#7 detached info (Original Promise version)
|
|
1363
1935
|
*/
|
|
1364
|
-
|
|
1936
|
+
getPkcs7DetachedInfoLegacyAsync = this.createPromiseMethod("get_pkcs7_detached_info");
|
|
1365
1937
|
/**
|
|
1366
1938
|
* Verify PKCS#7 attached (Promise version)
|
|
1367
1939
|
*/
|
|
1368
1940
|
verifyPkcs7AttachedAsync = this.createPromiseMethod("verify_pkcs7_attached");
|
|
1369
1941
|
/**
|
|
1370
|
-
* Verify PKCS#7 detached (Promise version)
|
|
1942
|
+
* Verify PKCS#7 detached (Enhanced Promise version)
|
|
1943
|
+
*/
|
|
1944
|
+
verifyPkcs7DetachedAsync = async (data, pkcs764, trustStoreId, requesterId = "", autoBase64 = true) => {
|
|
1945
|
+
return new Promise((resolve, reject) => {
|
|
1946
|
+
this.verifyPkcs7DetachedEnhanced(
|
|
1947
|
+
data,
|
|
1948
|
+
pkcs764,
|
|
1949
|
+
trustStoreId,
|
|
1950
|
+
requesterId,
|
|
1951
|
+
autoBase64,
|
|
1952
|
+
(_event, response) => {
|
|
1953
|
+
if (response.success && response.data) {
|
|
1954
|
+
resolve(response.data);
|
|
1955
|
+
} else {
|
|
1956
|
+
reject(new Error(response.reason ?? "Unknown error"));
|
|
1957
|
+
}
|
|
1958
|
+
},
|
|
1959
|
+
reject
|
|
1960
|
+
);
|
|
1961
|
+
});
|
|
1962
|
+
};
|
|
1963
|
+
/**
|
|
1964
|
+
* Verify PKCS#7 detached (Original Promise version)
|
|
1371
1965
|
*/
|
|
1372
|
-
|
|
1966
|
+
verifyPkcs7DetachedLegacyAsync = this.createPromiseMethod("verify_pkcs7_detached");
|
|
1373
1967
|
/**
|
|
1374
1968
|
* Attach timestamp token (Promise version)
|
|
1375
1969
|
*/
|
|
@@ -1770,38 +2364,11 @@ function setupGlobalObjects() {
|
|
|
1770
2364
|
win.EIMZOClient = e_imzo_client_default;
|
|
1771
2365
|
win.capiws = capiws_default;
|
|
1772
2366
|
win.eimzoApi = eimzoApi;
|
|
1773
|
-
|
|
1774
|
-
const isDev = typeof process !== "undefined" && processEnv.NODE_ENV === "development";
|
|
1775
|
-
if (isDev) {
|
|
1776
|
-
win.imzoPlugins = {
|
|
1777
|
-
version: "1.0.0",
|
|
1778
|
-
loaded: true,
|
|
1779
|
-
plugins: [],
|
|
1780
|
-
debug: true
|
|
1781
|
-
};
|
|
1782
|
-
console.info("\u{1F527} E-IMZO Agnostic Library - Development Mode");
|
|
1783
|
-
console.info("Available APIs:", {
|
|
1784
|
-
CAPIWS: "Main CAPIWS client for E-IMZO communication",
|
|
1785
|
-
EIMZOClient: "Legacy E-IMZO client wrapper",
|
|
1786
|
-
capiws: "Legacy alias for CAPIWS",
|
|
1787
|
-
eimzoApi: "Modern plugin-based E-IMZO API",
|
|
1788
|
-
imzoPlugins: "Plugin system information"
|
|
1789
|
-
});
|
|
1790
|
-
}
|
|
1791
|
-
if (isDev) {
|
|
1792
|
-
console.info("\u2705 E-IMZO Global Setup - Success");
|
|
1793
|
-
console.info("Global status:", {
|
|
1794
|
-
CAPIWS: Boolean(win.CAPIWS),
|
|
1795
|
-
EIMZOClient: Boolean(win.EIMZOClient),
|
|
1796
|
-
capiws: Boolean(win.capiws),
|
|
1797
|
-
eimzoApi: Boolean(win.eimzoApi),
|
|
1798
|
-
imzoPlugins: Boolean(win.imzoPlugins)
|
|
1799
|
-
});
|
|
1800
|
-
}
|
|
2367
|
+
typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions.node);
|
|
1801
2368
|
}
|
|
1802
2369
|
}
|
|
1803
2370
|
setupGlobalObjects();
|
|
1804
2371
|
|
|
1805
|
-
export { capiws_default as CAPIWS, EIMZOApi, e_imzo_client_default as EIMZOClient, EIMZOPlugin, PluginManager, dates, eimzo_api_default as eimzoApi, ftjcPlugin, pfxPlugin, pkcs7Plugin };
|
|
2372
|
+
export { capiws_default as CAPIWS, EIMZOApi, e_imzo_client_default as EIMZOClient, EIMZOPlugin, EIMZOSessionManager, PluginManager, dates, eimzo_api_default as eimzoApi, ftjcPlugin, pfxPlugin, pkcs7Plugin, sessionManager };
|
|
1806
2373
|
//# sourceMappingURL=index.mjs.map
|
|
1807
2374
|
//# sourceMappingURL=index.mjs.map
|