@dimzxzzx07/file-watcher 1.0.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.
Files changed (100) hide show
  1. package/.env +13 -0
  2. package/.eslintrc.json +128 -0
  3. package/.prettierrc +18 -0
  4. package/Dimzxzzx07.png +0 -0
  5. package/README.md +1024 -0
  6. package/dist/core/BackupManager.d.ts +25 -0
  7. package/dist/core/BackupManager.d.ts.map +1 -0
  8. package/dist/core/BackupManager.js +290 -0
  9. package/dist/core/BackupManager.js.map +1 -0
  10. package/dist/core/IntegrityValidator.d.ts +18 -0
  11. package/dist/core/IntegrityValidator.d.ts.map +1 -0
  12. package/dist/core/IntegrityValidator.js +212 -0
  13. package/dist/core/IntegrityValidator.js.map +1 -0
  14. package/dist/core/SecurityManager.d.ts +40 -0
  15. package/dist/core/SecurityManager.d.ts.map +1 -0
  16. package/dist/core/SecurityManager.js +320 -0
  17. package/dist/core/SecurityManager.js.map +1 -0
  18. package/dist/core/WatcherEngine.d.ts +44 -0
  19. package/dist/core/WatcherEngine.d.ts.map +1 -0
  20. package/dist/core/WatcherEngine.js +470 -0
  21. package/dist/core/WatcherEngine.js.map +1 -0
  22. package/dist/crypto/HashGenerator.d.ts +26 -0
  23. package/dist/crypto/HashGenerator.d.ts.map +1 -0
  24. package/dist/crypto/HashGenerator.js +220 -0
  25. package/dist/crypto/HashGenerator.js.map +1 -0
  26. package/dist/crypto/KeyManager.d.ts +30 -0
  27. package/dist/crypto/KeyManager.d.ts.map +1 -0
  28. package/dist/crypto/KeyManager.js +235 -0
  29. package/dist/crypto/KeyManager.js.map +1 -0
  30. package/dist/crypto/SignatureValidator.d.ts +11 -0
  31. package/dist/crypto/SignatureValidator.d.ts.map +1 -0
  32. package/dist/crypto/SignatureValidator.js +102 -0
  33. package/dist/crypto/SignatureValidator.js.map +1 -0
  34. package/dist/detectors/AnomalyDetector.d.ts +24 -0
  35. package/dist/detectors/AnomalyDetector.d.ts.map +1 -0
  36. package/dist/detectors/AnomalyDetector.js +209 -0
  37. package/dist/detectors/AnomalyDetector.js.map +1 -0
  38. package/dist/detectors/InjectionDetector.d.ts +14 -0
  39. package/dist/detectors/InjectionDetector.d.ts.map +1 -0
  40. package/dist/detectors/InjectionDetector.js +204 -0
  41. package/dist/detectors/InjectionDetector.js.map +1 -0
  42. package/dist/detectors/PatternMatcher.d.ts +28 -0
  43. package/dist/detectors/PatternMatcher.d.ts.map +1 -0
  44. package/dist/detectors/PatternMatcher.js +283 -0
  45. package/dist/detectors/PatternMatcher.js.map +1 -0
  46. package/dist/guards/FileGuard.d.ts +35 -0
  47. package/dist/guards/FileGuard.d.ts.map +1 -0
  48. package/dist/guards/FileGuard.js +357 -0
  49. package/dist/guards/FileGuard.js.map +1 -0
  50. package/dist/guards/MemoryGuard.d.ts +28 -0
  51. package/dist/guards/MemoryGuard.d.ts.map +1 -0
  52. package/dist/guards/MemoryGuard.js +256 -0
  53. package/dist/guards/MemoryGuard.js.map +1 -0
  54. package/dist/guards/ProcessGuard.d.ts +25 -0
  55. package/dist/guards/ProcessGuard.d.ts.map +1 -0
  56. package/dist/guards/ProcessGuard.js +221 -0
  57. package/dist/guards/ProcessGuard.js.map +1 -0
  58. package/dist/index.d.ts +19 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +186 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/types/index.d.ts +69 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +3 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/dist/utils/Constants.d.ts +407 -0
  67. package/dist/utils/Constants.d.ts.map +1 -0
  68. package/dist/utils/Constants.js +505 -0
  69. package/dist/utils/Constants.js.map +1 -0
  70. package/dist/utils/Logger.d.ts +45 -0
  71. package/dist/utils/Logger.d.ts.map +1 -0
  72. package/dist/utils/Logger.js +285 -0
  73. package/dist/utils/Logger.js.map +1 -0
  74. package/dist/utils/Validator.d.ts +27 -0
  75. package/dist/utils/Validator.d.ts.map +1 -0
  76. package/dist/utils/Validator.js +245 -0
  77. package/dist/utils/Validator.js.map +1 -0
  78. package/favicon.png +0 -0
  79. package/jest.config.js +69 -0
  80. package/package.json +69 -0
  81. package/src/core/BackupManager.ts +305 -0
  82. package/src/core/IntegrityValidator.ts +200 -0
  83. package/src/core/SecurityManager.ts +348 -0
  84. package/src/core/WatcherEngine.ts +537 -0
  85. package/src/crypto/HashGenerator.ts +234 -0
  86. package/src/crypto/KeyManager.ts +249 -0
  87. package/src/crypto/SignatureValidator.ts +76 -0
  88. package/src/detectors/AnomalyDetector.ts +247 -0
  89. package/src/detectors/InjectionDetector.ts +233 -0
  90. package/src/detectors/PatternMatcher.ts +319 -0
  91. package/src/guards/FileGuard.ts +385 -0
  92. package/src/guards/MemoryGuard.ts +263 -0
  93. package/src/guards/ProcessGuard.ts +219 -0
  94. package/src/index.ts +189 -0
  95. package/src/types/index.ts +72 -0
  96. package/src/utils/Constants.ts +532 -0
  97. package/src/utils/Logger.ts +279 -0
  98. package/src/utils/Validator.ts +248 -0
  99. package/tests/setup.ts +80 -0
  100. package/tsconfig.json +42 -0
@@ -0,0 +1,470 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.WatcherEngine = void 0;
37
+ const chokidar = __importStar(require("chokidar"));
38
+ const fs = __importStar(require("fs/promises"));
39
+ const path = __importStar(require("path"));
40
+ const events_1 = require("events");
41
+ const IntegrityValidator_1 = require("./IntegrityValidator");
42
+ const SecurityManager_1 = require("./SecurityManager");
43
+ const BackupManager_1 = require("./BackupManager");
44
+ const Logger_1 = require("../utils/Logger");
45
+ const ProcessGuard_1 = require("../guards/ProcessGuard");
46
+ class WatcherEngine extends events_1.EventEmitter {
47
+ watcher = null;
48
+ config;
49
+ validator;
50
+ securityManager;
51
+ backupManager;
52
+ logger;
53
+ processGuard;
54
+ fileCache;
55
+ watchState;
56
+ isShuttingDown = false;
57
+ scanInterval = null;
58
+ constructor(config) {
59
+ super();
60
+ this.config = config;
61
+ this.fileCache = new Map();
62
+ this.watchState = new Map();
63
+ this.logger = Logger_1.Logger.getInstance();
64
+ this.validator = new IntegrityValidator_1.IntegrityValidator(config);
65
+ this.securityManager = SecurityManager_1.SecurityManager.getInstance(config);
66
+ this.backupManager = new BackupManager_1.BackupManager(config);
67
+ this.processGuard = ProcessGuard_1.ProcessGuard.getInstance();
68
+ this.initialize();
69
+ }
70
+ async initialize() {
71
+ try {
72
+ await this.verifyEnvironment();
73
+ await this.initializeDirectories();
74
+ await this.loadExistingFiles();
75
+ await this.establishSecureConnection();
76
+ this.startSelfProtection();
77
+ this.logger.info('WatcherEngine initialized successfully', {
78
+ watchDir: this.config.watchDir,
79
+ integrityLevel: this.config.integrityLevel
80
+ });
81
+ }
82
+ catch (error) {
83
+ this.logger.error('Failed to initialize WatcherEngine', { error });
84
+ throw error;
85
+ }
86
+ }
87
+ async verifyEnvironment() {
88
+ if (process.version < 'v18.0.0') {
89
+ throw new Error('Node.js version 18+ required');
90
+ }
91
+ if (process.execArgv.some(arg => arg.includes('--inspect'))) {
92
+ this.logger.warning('Debugger detected - running in secure mode');
93
+ this.securityManager.setDebugMode(true);
94
+ }
95
+ try {
96
+ await fs.access(this.config.watchDir, fs.constants.R_OK | fs.constants.W_OK);
97
+ }
98
+ catch {
99
+ throw new Error(`Insufficient permissions for ${this.config.watchDir}`);
100
+ }
101
+ }
102
+ async initializeDirectories() {
103
+ const dirs = [
104
+ this.config.backupDir,
105
+ this.config.quarantineDir,
106
+ path.join(this.config.watchDir, '.secure')
107
+ ];
108
+ for (const dir of dirs) {
109
+ try {
110
+ await fs.mkdir(dir, { recursive: true, mode: 0o700 });
111
+ }
112
+ catch (error) {
113
+ this.logger.error(`Failed to create directory: ${dir}`, { error });
114
+ }
115
+ }
116
+ }
117
+ async loadExistingFiles() {
118
+ const files = await this.scanDirectory(this.config.watchDir);
119
+ for (const file of files) {
120
+ try {
121
+ const metadata = await this.validator.generateFileMetadata(file);
122
+ this.fileCache.set(file, metadata);
123
+ await this.backupManager.createBackup(file, metadata);
124
+ const isValid = await this.validator.validateFile(file, metadata);
125
+ if (!isValid) {
126
+ this.handleIntegrityViolation({
127
+ id: crypto.randomUUID(),
128
+ timestamp: new Date(),
129
+ filePath: file,
130
+ violationType: 'hash_mismatch',
131
+ severity: 'high',
132
+ details: { initialValidation: false },
133
+ actionTaken: 'alert'
134
+ });
135
+ }
136
+ }
137
+ catch (error) {
138
+ this.logger.error(`Failed to load file: ${file}`, { error });
139
+ }
140
+ }
141
+ this.logger.info(`Loaded ${this.fileCache.size} files into cache`);
142
+ }
143
+ async scanDirectory(dir) {
144
+ const files = [];
145
+ try {
146
+ const entries = await fs.readdir(dir, { withFileTypes: true });
147
+ for (const entry of entries) {
148
+ const fullPath = path.join(dir, entry.name);
149
+ if (this.shouldIgnore(fullPath)) {
150
+ continue;
151
+ }
152
+ if (entry.isDirectory()) {
153
+ files.push(...await this.scanDirectory(fullPath));
154
+ }
155
+ else if (entry.isFile()) {
156
+ files.push(fullPath);
157
+ }
158
+ }
159
+ }
160
+ catch (error) {
161
+ this.logger.error(`Error scanning directory: ${dir}`, { error });
162
+ }
163
+ return files;
164
+ }
165
+ shouldIgnore(filePath) {
166
+ const ignorePatterns = [
167
+ /node_modules/,
168
+ /\.git/,
169
+ /\.secure/,
170
+ /\.backup/,
171
+ /\.quarantine/,
172
+ /\.DS_Store/,
173
+ /Thumbs\.db/,
174
+ /\.tmp$/,
175
+ /\.temp$/,
176
+ /\.log$/
177
+ ];
178
+ return ignorePatterns.some(pattern => pattern.test(filePath));
179
+ }
180
+ async establishSecureConnection() {
181
+ const secureChannel = await this.securityManager.createSecureChannel();
182
+ this.emit('secure:connected', secureChannel);
183
+ }
184
+ startSelfProtection() {
185
+ this.processGuard.protectProcess();
186
+ setInterval(() => {
187
+ this.securityManager.validateMemoryIntegrity();
188
+ }, 5000);
189
+ setInterval(() => {
190
+ if (this.processGuard.detectDebugger()) {
191
+ this.emit('security:debugger-detected');
192
+ }
193
+ }, 1000);
194
+ }
195
+ startWatching() {
196
+ if (this.watcher) {
197
+ return;
198
+ }
199
+ const watchOptions = {
200
+ ignored: (file) => this.shouldIgnore(file),
201
+ persistent: true,
202
+ ignoreInitial: true,
203
+ followSymlinks: false,
204
+ usePolling: true,
205
+ interval: 100,
206
+ binaryInterval: 300,
207
+ awaitWriteFinish: {
208
+ stabilityThreshold: 200,
209
+ pollInterval: 50
210
+ }
211
+ };
212
+ this.watcher = chokidar.watch(this.config.watchDir, watchOptions);
213
+ this.watcher
214
+ .on('add', (filePath) => this.handleFileAdd(filePath))
215
+ .on('change', (filePath) => this.handleFileChange(filePath))
216
+ .on('unlink', (filePath) => this.handleFileDelete(filePath))
217
+ .on('error', (error) => this.handleWatcherError(error));
218
+ if (this.config.scanInterval > 0) {
219
+ this.scanInterval = setInterval(() => this.performSecurityScan(), this.config.scanInterval * 1000);
220
+ }
221
+ this.logger.info('File watcher started successfully');
222
+ }
223
+ async handleFileAdd(filePath) {
224
+ this.logger.info(`New file detected: ${filePath}`);
225
+ try {
226
+ if (!this.isAllowedFileType(filePath)) {
227
+ await this.handleDisallowedFile(filePath);
228
+ return;
229
+ }
230
+ const metadata = await this.validator.generateFileMetadata(filePath);
231
+ const isClean = await this.securityManager.scanFile(filePath);
232
+ if (!isClean) {
233
+ await this.handleInfectedFile(filePath);
234
+ return;
235
+ }
236
+ await this.backupManager.createBackup(filePath, metadata);
237
+ this.fileCache.set(filePath, metadata);
238
+ if (this.config.signatureVerification) {
239
+ const isValid = await this.validator.verifySignature(filePath, metadata);
240
+ if (!isValid) {
241
+ throw new Error('Invalid file signature');
242
+ }
243
+ }
244
+ this.emit('file:added', { filePath, metadata });
245
+ }
246
+ catch (error) {
247
+ this.logger.error(`Error handling new file: ${filePath}`, { error });
248
+ await this.handleSuspiciousFile(filePath, error);
249
+ }
250
+ }
251
+ async handleFileChange(filePath) {
252
+ this.logger.info(`File modified: ${filePath}`);
253
+ try {
254
+ const oldMetadata = this.fileCache.get(filePath);
255
+ if (!oldMetadata) {
256
+ await this.handleFileAdd(filePath);
257
+ return;
258
+ }
259
+ const newMetadata = await this.validator.generateFileMetadata(filePath);
260
+ const isAuthorized = await this.securityManager.isAuthorizedChange(filePath, oldMetadata, newMetadata);
261
+ if (!isAuthorized) {
262
+ throw new Error('Unauthorized file modification');
263
+ }
264
+ const isValid = await this.validator.validateFile(filePath, newMetadata);
265
+ if (!isValid) {
266
+ if (this.config.autoRollback) {
267
+ await this.backupManager.rollbackFile(filePath);
268
+ this.logger.info(`File rolled back: ${filePath}`);
269
+ }
270
+ else {
271
+ throw new Error('Integrity check failed');
272
+ }
273
+ }
274
+ else {
275
+ this.fileCache.set(filePath, newMetadata);
276
+ await this.backupManager.updateBackup(filePath, newMetadata);
277
+ this.emit('file:changed', { filePath, oldMetadata, newMetadata });
278
+ }
279
+ }
280
+ catch (error) {
281
+ this.logger.error(`Error handling file change: ${filePath}`, { error });
282
+ await this.handleIntegrityViolation({
283
+ id: crypto.randomUUID(),
284
+ timestamp: new Date(),
285
+ filePath,
286
+ violationType: 'hash_mismatch',
287
+ severity: 'high',
288
+ details: { error },
289
+ actionTaken: this.config.autoRollback ? 'rollback' : 'alert'
290
+ });
291
+ }
292
+ }
293
+ async handleFileDelete(filePath) {
294
+ this.logger.warning(`File deleted: ${filePath}`);
295
+ try {
296
+ const metadata = this.fileCache.get(filePath);
297
+ if (metadata) {
298
+ const restored = await this.backupManager.restoreFile(filePath);
299
+ if (restored) {
300
+ this.logger.info(`File restored from backup: ${filePath}`);
301
+ const restoredMetadata = await this.validator.generateFileMetadata(filePath);
302
+ this.fileCache.set(filePath, restoredMetadata);
303
+ this.emit('file:restored', { filePath, metadata: restoredMetadata });
304
+ }
305
+ else {
306
+ this.fileCache.delete(filePath);
307
+ this.emit('file:deleted', { filePath, metadata });
308
+ }
309
+ }
310
+ }
311
+ catch (error) {
312
+ this.logger.error(`Error handling file deletion: ${filePath}`, { error });
313
+ }
314
+ }
315
+ async handleIntegrityViolation(violation) {
316
+ this.logger.critical('Integrity violation detected', violation);
317
+ if (violation.severity === 'critical' || violation.severity === 'high') {
318
+ await this.quarantineFile(violation.filePath);
319
+ }
320
+ this.emit('integrity:violation', violation);
321
+ switch (violation.severity) {
322
+ case 'critical':
323
+ await this.handleCriticalViolation(violation);
324
+ break;
325
+ case 'high':
326
+ await this.handleHighSeverityViolation(violation);
327
+ break;
328
+ default:
329
+ await this.handleLowSeverityViolation(violation);
330
+ }
331
+ }
332
+ async quarantineFile(filePath) {
333
+ try {
334
+ const quarantinePath = path.join(this.config.quarantineDir, path.basename(filePath) + '.quarantined');
335
+ await fs.copyFile(filePath, quarantinePath);
336
+ await this.securityManager.encryptFile(quarantinePath);
337
+ this.logger.info(`File quarantined: ${filePath} -> ${quarantinePath}`);
338
+ if (this.config.integrityLevel === 'paranoid') {
339
+ await fs.unlink(filePath);
340
+ }
341
+ }
342
+ catch (error) {
343
+ this.logger.error(`Failed to quarantine file: ${filePath}`, { error });
344
+ }
345
+ }
346
+ async handleCriticalViolation(violation) {
347
+ this.logger.emergency('Critical security violation - initiating shutdown');
348
+ this.stopWatching();
349
+ this.emit('security:critical', violation);
350
+ await this.performSecureShutdown();
351
+ process.exit(1);
352
+ }
353
+ async handleHighSeverityViolation(violation) {
354
+ this.watchState.set(violation.filePath, false);
355
+ if (this.config.autoRollback) {
356
+ const restored = await this.backupManager.rollbackFile(violation.filePath);
357
+ if (restored) {
358
+ this.logger.info(`File rolled back successfully: ${violation.filePath}`);
359
+ this.watchState.delete(violation.filePath);
360
+ }
361
+ }
362
+ this.emit('security:alert', violation);
363
+ }
364
+ async handleLowSeverityViolation(violation) {
365
+ this.logger.warning('Low severity violation', violation);
366
+ this.emit('security:warning', violation);
367
+ }
368
+ async handleSuspiciousFile(filePath, error) {
369
+ this.logger.warning(`Suspicious file detected: ${filePath}`, { error });
370
+ await this.quarantineFile(filePath);
371
+ this.emit('file:suspicious', { filePath, error });
372
+ }
373
+ async handleInfectedFile(filePath) {
374
+ this.logger.critical(`Infected file detected: ${filePath}`);
375
+ await this.quarantineFile(filePath);
376
+ this.emit('security:infected', { filePath });
377
+ }
378
+ async handleDisallowedFile(filePath) {
379
+ this.logger.warning(`Disallowed file type: ${filePath}`);
380
+ if (this.config.integrityLevel === 'paranoid') {
381
+ await fs.unlink(filePath);
382
+ this.logger.info(`Disallowed file deleted: ${filePath}`);
383
+ }
384
+ this.emit('file:disallowed', { filePath });
385
+ }
386
+ isAllowedFileType(filePath) {
387
+ const ext = path.extname(filePath).toLowerCase();
388
+ return this.config.allowedExtensions.includes(ext);
389
+ }
390
+ handleWatcherError(error) {
391
+ this.logger.error('Watcher error', { error });
392
+ this.emit('watcher:error', error);
393
+ }
394
+ async performSecurityScan() {
395
+ this.logger.debug('Performing security scan...');
396
+ for (const [filePath, metadata] of this.fileCache.entries()) {
397
+ try {
398
+ const isValid = await this.validator.validateFile(filePath, metadata);
399
+ if (!isValid) {
400
+ await this.handleIntegrityViolation({
401
+ id: crypto.randomUUID(),
402
+ timestamp: new Date(),
403
+ filePath,
404
+ violationType: 'hash_mismatch',
405
+ severity: 'high',
406
+ details: { scan: 'periodic' },
407
+ actionTaken: 'alert'
408
+ });
409
+ }
410
+ if (!await this.fileExists(filePath)) {
411
+ await this.handleFileDelete(filePath);
412
+ }
413
+ }
414
+ catch (error) {
415
+ this.logger.error(`Scan error for ${filePath}`, { error });
416
+ }
417
+ }
418
+ const allFiles = await this.scanDirectory(this.config.watchDir);
419
+ for (const file of allFiles) {
420
+ if (!this.fileCache.has(file)) {
421
+ await this.handleFileAdd(file);
422
+ }
423
+ }
424
+ this.logger.debug('Security scan completed');
425
+ }
426
+ async fileExists(filePath) {
427
+ try {
428
+ await fs.access(filePath);
429
+ return true;
430
+ }
431
+ catch {
432
+ return false;
433
+ }
434
+ }
435
+ async performSecureShutdown() {
436
+ this.isShuttingDown = true;
437
+ this.logger.info('Performing secure shutdown...');
438
+ this.stopWatching();
439
+ await this.securityManager.encryptSensitiveData();
440
+ this.fileCache.clear();
441
+ this.watchState.clear();
442
+ await this.backupManager.performFinalBackup();
443
+ this.logger.info('Secure shutdown completed');
444
+ }
445
+ stopWatching() {
446
+ if (this.scanInterval) {
447
+ clearInterval(this.scanInterval);
448
+ this.scanInterval = null;
449
+ }
450
+ if (this.watcher) {
451
+ this.watcher.close();
452
+ this.watcher = null;
453
+ }
454
+ this.logger.info('File watcher stopped');
455
+ }
456
+ getStatus() {
457
+ return {
458
+ watching: this.watcher !== null,
459
+ filesWatched: this.fileCache.size,
460
+ cacheSize: this.fileCache.size,
461
+ scanInterval: this.config.scanInterval,
462
+ integrityLevel: this.config.integrityLevel,
463
+ uptime: process.uptime(),
464
+ memoryUsage: process.memoryUsage(),
465
+ isShuttingDown: this.isShuttingDown
466
+ };
467
+ }
468
+ }
469
+ exports.WatcherEngine = WatcherEngine;
470
+ //# sourceMappingURL=WatcherEngine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WatcherEngine.js","sourceRoot":"","sources":["../../src/core/WatcherEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAAqC;AACrC,gDAAkC;AAClC,2CAA6B;AAC7B,mCAAsC;AAEtC,6DAA0D;AAC1D,uDAAoD;AACpD,mDAAgD;AAChD,4CAAyC;AACzC,yDAAsD;AAEtD,MAAa,aAAc,SAAQ,qBAAY;IACnC,OAAO,GAA8B,IAAI,CAAC;IACjC,MAAM,CAAiB;IACvB,SAAS,CAAqB;IAC9B,eAAe,CAAkB;IACjC,aAAa,CAAgB;IAC7B,MAAM,CAAS;IACf,YAAY,CAAe;IAC3B,SAAS,CAA4B;IACrC,UAAU,CAAuB;IAC1C,cAAc,GAAY,KAAK,CAAC;IAChC,YAAY,GAA0B,IAAI,CAAC;IAEnD,YAAY,MAAsB;QAC9B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,eAAM,CAAC,WAAW,EAAE,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,IAAI,uCAAkB,CAAC,MAAM,CAAC,CAAC;QAChD,IAAI,CAAC,eAAe,GAAG,iCAAe,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC3D,IAAI,CAAC,aAAa,GAAG,IAAI,6BAAa,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,2BAAY,CAAC,WA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CAAC;QAElD,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QAExB,MAAM,IAAI,CAAC,aAAa,CAAC,kBAAkB,EAAE,CAAC;QAE9C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;IAClD,CAAC;IAEM,YAAY;QACf,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YACjC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC7B,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACrB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACxB,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAC7C,CAAC;IAEM,SAAS;QACZ,OAAO;YACH,QAAQ,EAAE,IAAI,CAAC,OAAO,KAAK,IAAI;YAC/B,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI;YACjC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI;YAC9B,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;YACtC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;YAC1C,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE;YACxB,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE;YAClC,cAAc,EAAE,IAAI,CAAC,cAAc;SACtC,CAAC;IACN,CAAC;CACJ;AA7gBD,sCA6gBC","sourcesContent":["import * as chokidar from 'chokidar';\nimport * as fs from 'fs/promises';\nimport * as path from 'path';\nimport { EventEmitter } from 'events';\nimport { SecurityConfig, FileMetadata, IntegrityViolation } from '../types';\nimport { IntegrityValidator } from './IntegrityValidator';\nimport { SecurityManager } from './SecurityManager';\nimport { BackupManager } from './BackupManager';\nimport { Logger } from '../utils/Logger';\nimport { ProcessGuard } from '../guards/ProcessGuard';\n\nexport class WatcherEngine extends EventEmitter {\n private watcher: chokidar.FSWatcher | null = null;\n private readonly config: SecurityConfig;\n private readonly validator: IntegrityValidator;\n private readonly securityManager: SecurityManager;\n private readonly backupManager: BackupManager;\n private readonly logger: Logger;\n private readonly processGuard: ProcessGuard;\n private readonly fileCache: Map<string, FileMetadata>;\n private readonly watchState: Map<string, boolean>;\n private isShuttingDown: boolean = false;\n private scanInterval: NodeJS.Timeout | null = null;\n\n constructor(config: SecurityConfig) {\n super();\n this.config = config;\n this.fileCache = new Map();\n this.watchState = new Map();\n this.logger = Logger.getInstance();\n this.validator = new IntegrityValidator(config);\n this.securityManager = SecurityManager.getInstance(config);\n this.backupManager = new BackupManager(config);\n this.processGuard = ProcessGuard.getInstance();\n \n this.initialize();\n }\n\n private async initialize(): Promise<void> {\n try {\n await this.verifyEnvironment();\n await this.initializeDirectories();\n await this.loadExistingFiles();\n await this.establishSecureConnection();\n this.startSelfProtection();\n \n this.logger.info('WatcherEngine initialized successfully', {\n watchDir: this.config.watchDir,\n integrityLevel: this.config.integrityLevel\n });\n } catch (error) {\n this.logger.error('Failed to initialize WatcherEngine', { error });\n throw error;\n }\n }\n\n private async verifyEnvironment(): Promise<void> {\n if (process.version < 'v18.0.0') {\n throw new Error('Node.js version 18+ required');\n }\n\n if (process.execArgv.some(arg => arg.includes('--inspect'))) {\n this.logger.warning('Debugger detected - running in secure mode');\n this.securityManager.setDebugMode(true);\n }\n\n try {\n await fs.access(this.config.watchDir, fs.constants.R_OK | fs.constants.W_OK);\n } catch {\n throw new Error(`Insufficient permissions for ${this.config.watchDir}`);\n }\n }\n\n private async initializeDirectories(): Promise<void> {\n const dirs = [\n this.config.backupDir,\n this.config.quarantineDir,\n path.join(this.config.watchDir, '.secure')\n ];\n\n for (const dir of dirs) {\n try {\n await fs.mkdir(dir, { recursive: true, mode: 0o700 });\n } catch (error) {\n this.logger.error(`Failed to create directory: ${dir}`, { error });\n }\n }\n }\n\n private async loadExistingFiles(): Promise<void> {\n const files = await this.scanDirectory(this.config.watchDir);\n \n for (const file of files) {\n try {\n const metadata = await this.validator.generateFileMetadata(file);\n this.fileCache.set(file, metadata);\n \n await this.backupManager.createBackup(file, metadata);\n \n const isValid = await this.validator.validateFile(file, metadata);\n if (!isValid) {\n this.handleIntegrityViolation({\n id: crypto.randomUUID(),\n timestamp: new Date(),\n filePath: file,\n violationType: 'hash_mismatch',\n severity: 'high',\n details: { initialValidation: false },\n actionTaken: 'alert'\n });\n }\n } catch (error) {\n this.logger.error(`Failed to load file: ${file}`, { error });\n }\n }\n \n this.logger.info(`Loaded ${this.fileCache.size} files into cache`);\n }\n\n private async scanDirectory(dir: string): Promise<string[]> {\n const files: string[] = [];\n \n try {\n const entries = await fs.readdir(dir, { withFileTypes: true });\n \n for (const entry of entries) {\n const fullPath = path.join(dir, entry.name);\n \n if (this.shouldIgnore(fullPath)) {\n continue;\n }\n \n if (entry.isDirectory()) {\n files.push(...await this.scanDirectory(fullPath));\n } else if (entry.isFile()) {\n files.push(fullPath);\n }\n }\n } catch (error) {\n this.logger.error(`Error scanning directory: ${dir}`, { error });\n }\n \n return files;\n }\n\n private shouldIgnore(filePath: string): boolean {\n const ignorePatterns = [\n /node_modules/,\n /\\.git/,\n /\\.secure/,\n /\\.backup/,\n /\\.quarantine/,\n /\\.DS_Store/,\n /Thumbs\\.db/,\n /\\.tmp$/,\n /\\.temp$/,\n /\\.log$/\n ];\n \n return ignorePatterns.some(pattern => pattern.test(filePath));\n }\n\n private async establishSecureConnection(): Promise<void> {\n const secureChannel = await this.securityManager.createSecureChannel();\n this.emit('secure:connected', secureChannel);\n }\n\n private startSelfProtection(): void {\n this.processGuard.protectProcess();\n \n setInterval(() => {\n this.securityManager.validateMemoryIntegrity();\n }, 5000);\n \n setInterval(() => {\n if (this.processGuard.detectDebugger()) {\n this.emit('security:debugger-detected');\n }\n }, 1000);\n }\n\n public startWatching(): void {\n if (this.watcher) {\n return;\n }\n\n const watchOptions: chokidar.WatchOptions = {\n ignored: (file: string) => this.shouldIgnore(file),\n persistent: true,\n ignoreInitial: true,\n followSymlinks: false,\n usePolling: true,\n interval: 100,\n binaryInterval: 300,\n awaitWriteFinish: {\n stabilityThreshold: 200,\n pollInterval: 50\n }\n };\n\n this.watcher = chokidar.watch(this.config.watchDir, watchOptions);\n\n this.watcher\n .on('add', (filePath: string) => this.handleFileAdd(filePath))\n .on('change', (filePath: string) => this.handleFileChange(filePath))\n .on('unlink', (filePath: string) => this.handleFileDelete(filePath))\n .on('error', (error: Error) => this.handleWatcherError(error));\n\n if (this.config.scanInterval > 0) {\n this.scanInterval = setInterval(\n () => this.performSecurityScan(),\n this.config.scanInterval * 1000\n );\n }\n\n this.logger.info('File watcher started successfully');\n }\n\n private async handleFileAdd(filePath: string): Promise<void> {\n this.logger.info(`New file detected: ${filePath}`);\n \n try {\n if (!this.isAllowedFileType(filePath)) {\n await this.handleDisallowedFile(filePath);\n return;\n }\n\n const metadata = await this.validator.generateFileMetadata(filePath);\n \n const isClean = await this.securityManager.scanFile(filePath);\n if (!isClean) {\n await this.handleInfectedFile(filePath);\n return;\n }\n\n await this.backupManager.createBackup(filePath, metadata);\n \n this.fileCache.set(filePath, metadata);\n \n if (this.config.signatureVerification) {\n const isValid = await this.validator.verifySignature(filePath, metadata);\n if (!isValid) {\n throw new Error('Invalid file signature');\n }\n }\n\n this.emit('file:added', { filePath, metadata });\n \n } catch (error) {\n this.logger.error(`Error handling new file: ${filePath}`, { error });\n await this.handleSuspiciousFile(filePath, error);\n }\n }\n\n private async handleFileChange(filePath: string): Promise<void> {\n this.logger.info(`File modified: ${filePath}`);\n \n try {\n const oldMetadata = this.fileCache.get(filePath);\n \n if (!oldMetadata) {\n await this.handleFileAdd(filePath);\n return;\n }\n\n const newMetadata = await this.validator.generateFileMetadata(filePath);\n \n const isAuthorized = await this.securityManager.isAuthorizedChange(\n filePath,\n oldMetadata,\n newMetadata\n );\n\n if (!isAuthorized) {\n throw new Error('Unauthorized file modification');\n }\n\n const isValid = await this.validator.validateFile(filePath, newMetadata);\n \n if (!isValid) {\n if (this.config.autoRollback) {\n await this.backupManager.rollbackFile(filePath);\n this.logger.info(`File rolled back: ${filePath}`);\n } else {\n throw new Error('Integrity check failed');\n }\n } else {\n this.fileCache.set(filePath, newMetadata);\n \n await this.backupManager.updateBackup(filePath, newMetadata);\n \n this.emit('file:changed', { filePath, oldMetadata, newMetadata });\n }\n \n } catch (error) {\n this.logger.error(`Error handling file change: ${filePath}`, { error });\n await this.handleIntegrityViolation({\n id: crypto.randomUUID(),\n timestamp: new Date(),\n filePath,\n violationType: 'hash_mismatch',\n severity: 'high',\n details: { error },\n actionTaken: this.config.autoRollback ? 'rollback' : 'alert'\n });\n }\n }\n\n private async handleFileDelete(filePath: string): Promise<void> {\n this.logger.warning(`File deleted: ${filePath}`);\n \n try {\n const metadata = this.fileCache.get(filePath);\n \n if (metadata) {\n const restored = await this.backupManager.restoreFile(filePath);\n \n if (restored) {\n this.logger.info(`File restored from backup: ${filePath}`);\n \n const restoredMetadata = await this.validator.generateFileMetadata(filePath);\n this.fileCache.set(filePath, restoredMetadata);\n \n this.emit('file:restored', { filePath, metadata: restoredMetadata });\n } else {\n this.fileCache.delete(filePath);\n this.emit('file:deleted', { filePath, metadata });\n }\n }\n \n } catch (error) {\n this.logger.error(`Error handling file deletion: ${filePath}`, { error });\n }\n }\n\n private async handleIntegrityViolation(violation: IntegrityViolation): Promise<void> {\n this.logger.critical('Integrity violation detected', violation);\n \n if (violation.severity === 'critical' || violation.severity === 'high') {\n await this.quarantineFile(violation.filePath);\n }\n \n this.emit('integrity:violation', violation);\n \n switch (violation.severity) {\n case 'critical':\n await this.handleCriticalViolation(violation);\n break;\n case 'high':\n await this.handleHighSeverityViolation(violation);\n break;\n default:\n await this.handleLowSeverityViolation(violation);\n }\n }\n\n private async quarantineFile(filePath: string): Promise<void> {\n try {\n const quarantinePath = path.join(\n this.config.quarantineDir,\n path.basename(filePath) + '.quarantined'\n );\n \n await fs.copyFile(filePath, quarantinePath);\n \n await this.securityManager.encryptFile(quarantinePath);\n \n this.logger.info(`File quarantined: ${filePath} -> ${quarantinePath}`);\n \n if (this.config.integrityLevel === 'paranoid') {\n await fs.unlink(filePath);\n }\n \n } catch (error) {\n this.logger.error(`Failed to quarantine file: ${filePath}`, { error });\n }\n }\n\n private async handleCriticalViolation(violation: IntegrityViolation): Promise<void> {\n this.logger.emergency('Critical security violation - initiating shutdown');\n \n this.stopWatching();\n \n this.emit('security:critical', violation);\n \n await this.performSecureShutdown();\n \n process.exit(1);\n }\n\n private async handleHighSeverityViolation(violation: IntegrityViolation): Promise<void> {\n this.watchState.set(violation.filePath, false);\n \n if (this.config.autoRollback) {\n const restored = await this.backupManager.rollbackFile(violation.filePath);\n if (restored) {\n this.logger.info(`File rolled back successfully: ${violation.filePath}`);\n this.watchState.delete(violation.filePath);\n }\n }\n \n this.emit('security:alert', violation);\n }\n\n private async handleLowSeverityViolation(violation: IntegrityViolation): Promise<void> {\n this.logger.warning('Low severity violation', violation);\n this.emit('security:warning', violation);\n }\n\n private async handleSuspiciousFile(filePath: string, error: any): Promise<void> {\n this.logger.warning(`Suspicious file detected: ${filePath}`, { error });\n \n await this.quarantineFile(filePath);\n \n this.emit('file:suspicious', { filePath, error });\n }\n\n private async handleInfectedFile(filePath: string): Promise<void> {\n this.logger.critical(`Infected file detected: ${filePath}`);\n \n await this.quarantineFile(filePath);\n \n this.emit('security:infected', { filePath });\n }\n\n private async handleDisallowedFile(filePath: string): Promise<void> {\n this.logger.warning(`Disallowed file type: ${filePath}`);\n \n if (this.config.integrityLevel === 'paranoid') {\n await fs.unlink(filePath);\n this.logger.info(`Disallowed file deleted: ${filePath}`);\n }\n \n this.emit('file:disallowed', { filePath });\n }\n\n private isAllowedFileType(filePath: string): boolean {\n const ext = path.extname(filePath).toLowerCase();\n return this.config.allowedExtensions.includes(ext);\n }\n\n private handleWatcherError(error: Error): void {\n this.logger.error('Watcher error', { error });\n this.emit('watcher:error', error);\n }\n\n private async performSecurityScan(): Promise<void> {\n this.logger.debug('Performing security scan...');\n \n for (const [filePath, metadata] of this.fileCache.entries()) {\n try {\n const isValid = await this.validator.validateFile(filePath, metadata);\n \n if (!isValid) {\n await this.handleIntegrityViolation({\n id: crypto.randomUUID(),\n timestamp: new Date(),\n filePath,\n violationType: 'hash_mismatch',\n severity: 'high',\n details: { scan: 'periodic' },\n actionTaken: 'alert'\n });\n }\n \n if (!await this.fileExists(filePath)) {\n await this.handleFileDelete(filePath);\n }\n \n } catch (error) {\n this.logger.error(`Scan error for ${filePath}`, { error });\n }\n }\n \n const allFiles = await this.scanDirectory(this.config.watchDir);\n for (const file of allFiles) {\n if (!this.fileCache.has(file)) {\n await this.handleFileAdd(file);\n }\n }\n \n this.logger.debug('Security scan completed');\n }\n\n private async fileExists(filePath: string): Promise<boolean> {\n try {\n await fs.access(filePath);\n return true;\n } catch {\n return false;\n }\n }\n\n private async performSecureShutdown(): Promise<void> {\n this.isShuttingDown = true;\n \n this.logger.info('Performing secure shutdown...');\n \n this.stopWatching();\n \n await this.securityManager.encryptSensitiveData();\n \n this.fileCache.clear();\n this.watchState.clear();\n \n await this.backupManager.performFinalBackup();\n \n this.logger.info('Secure shutdown completed');\n }\n\n public stopWatching(): void {\n if (this.scanInterval) {\n clearInterval(this.scanInterval);\n this.scanInterval = null;\n }\n \n if (this.watcher) {\n this.watcher.close();\n this.watcher = null;\n }\n \n this.logger.info('File watcher stopped');\n }\n\n public getStatus(): any {\n return {\n watching: this.watcher !== null,\n filesWatched: this.fileCache.size,\n cacheSize: this.fileCache.size,\n scanInterval: this.config.scanInterval,\n integrityLevel: this.config.integrityLevel,\n uptime: process.uptime(),\n memoryUsage: process.memoryUsage(),\n isShuttingDown: this.isShuttingDown\n };\n }\n}"]}
@@ -0,0 +1,26 @@
1
+ import { SecurityConfig } from '../types';
2
+ export declare class HashGenerator {
3
+ private readonly config;
4
+ private readonly algorithms;
5
+ private readonly salt;
6
+ constructor(config: SecurityConfig);
7
+ generateHash(data: Buffer | string): string;
8
+ generateEncryptedHash(data: Buffer | string): string;
9
+ generateMultiHash(data: Buffer): string[];
10
+ generateRollingHash(data: Buffer, chunkSize?: number): string[];
11
+ generateMerkleRoot(data: Buffer): string;
12
+ private buildMerkleTree;
13
+ generateHMAC(data: Buffer | string, key?: Buffer): string;
14
+ generateKeyedHash(data: Buffer, key: Buffer): string;
15
+ generateTimeBasedHash(data: Buffer, timestamp?: number): string;
16
+ generateHashChain(data: Buffer, chainLength?: number): string[];
17
+ verifyHashChain(chain: string[]): boolean;
18
+ generateFingerprint(data: Buffer): string;
19
+ private calculateEntropy;
20
+ private getFirstBytes;
21
+ private getLastBytes;
22
+ private combineHashes;
23
+ getSalt(): Buffer;
24
+ getAlgorithms(): string[];
25
+ }
26
+ //# sourceMappingURL=HashGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HashGenerator.d.ts","sourceRoot":"","sources":["../../src/crypto/HashGenerator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;gBAElB,MAAM,EAAE,cAAc;IAM3B,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAgB3C,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAmBpD,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAczC,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAa,GAAG,MAAM,EAAE;IAcrE,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAe/C,OAAO,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