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