@omindu/yaksha 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.
@@ -0,0 +1,316 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Yaksha Security Levels Manager
5
+ * Centralized configuration for different security levels
6
+ */
7
+
8
+ const SECURITY_LEVELS = {
9
+ LOW: 'low',
10
+ MEDIUM: 'medium',
11
+ HIGH: 'high',
12
+ CUSTOM: 'custom'
13
+ };
14
+
15
+ // Security level configurations
16
+ const LEVEL_CONFIGS = {
17
+ low: {
18
+ encryption: 'chacha20-poly1305',
19
+ keyExchange: 'psk',
20
+ keySize: 256,
21
+ auth: 'password',
22
+ sniSpoofing: 'static', bugHost: null, obfuscation: 'xor',
23
+ multiPath: 2,
24
+ dnsMode: 'override',
25
+ tlsCamouflage: 'basic',
26
+ keyRotation: false,
27
+ antiReplay: false,
28
+ certificateValidation: false,
29
+ perfectForwardSecrecy: false,
30
+ performance: 'maximum',
31
+ throughput: '~2000 MB/s'
32
+ },
33
+
34
+ medium: {
35
+ encryption: 'aes-256-gcm',
36
+ keyExchange: 'ecdh',
37
+ keySize: 256,
38
+ auth: 'token',
39
+ sniSpoofing: 'random',
40
+ obfuscation: 'chacha20',
41
+ multiPath: 4,
42
+ dnsMode: 'doh',
43
+ tlsCamouflage: 'full',
44
+ keyRotation: false,
45
+ antiReplay: true,
46
+ certificateValidation: false,
47
+ perfectForwardSecrecy: true,
48
+ performance: 'balanced',
49
+ throughput: '~1000 MB/s'
50
+ },
51
+
52
+ high: {
53
+ encryption: 'double',
54
+ keyExchange: 'x25519-rotate',
55
+ keySize: 256,
56
+ auth: 'certificate',
57
+ sniSpoofing: 'context-aware',
58
+ bugHost: null,
59
+ obfuscation: 'aes-256-gcm',
60
+ multiPath: 5,
61
+ dnsMode: 'dot-dnssec',
62
+ tlsCamouflage: 'nested',
63
+ keyRotation: true,
64
+ keyRotationInterval: 1000,
65
+ antiReplay: true,
66
+ replayWindow: 5000,
67
+ certificateValidation: true,
68
+ twoFactorAuth: true,
69
+ perfectForwardSecrecy: true,
70
+ performance: 'security',
71
+ throughput: '~500 MB/s'
72
+ },
73
+
74
+ custom: {
75
+ // Custom configuration - can be overridden by user
76
+ // Defaults to medium level settings
77
+ encryption: 'aes-256-gcm',
78
+ keyExchange: 'ecdh',
79
+ keySize: 256,
80
+ auth: 'token',
81
+ sniSpoofing: 'random',
82
+ bugHost: null,
83
+ obfuscation: 'chacha20',
84
+ multiPath: 4,
85
+ dnsMode: 'doh',
86
+ tlsCamouflage: 'full',
87
+ keyRotation: false,
88
+ antiReplay: true,
89
+ certificateValidation: false,
90
+ perfectForwardSecrecy: true,
91
+ performance: 'custom',
92
+ throughput: 'varies',
93
+ // Flag to indicate this is customizable
94
+ customizable: true
95
+ }
96
+ };
97
+
98
+ class SecurityLevels {
99
+ /**
100
+ * Get configuration for a security level
101
+ */
102
+ static getConfig(level, customConfig = null) {
103
+ level = level.toLowerCase();
104
+
105
+ if (!LEVEL_CONFIGS[level]) {
106
+ throw new Error(`Invalid security level: ${level}. Must be: low, medium, high, or custom`);
107
+ }
108
+
109
+ const config = { ...LEVEL_CONFIGS[level] };
110
+
111
+ // If custom level and custom config provided, merge them
112
+ if (level === 'custom' && customConfig) {
113
+ return { ...config, ...customConfig };
114
+ }
115
+
116
+ return config;
117
+ }
118
+
119
+ /**
120
+ * Create custom security configuration
121
+ * @param {Object} customConfig - Custom configuration options
122
+ * @param {string} baseLevel - Base level to start from (low, medium, or high)
123
+ * @returns {Object} Custom security configuration
124
+ */
125
+ static createCustomConfig(customConfig = {}, baseLevel = 'medium') {
126
+ if (!['low', 'medium', 'high'].includes(baseLevel)) {
127
+ throw new Error('Base level must be: low, medium, or high');
128
+ }
129
+
130
+ // Start with base level configuration
131
+ const baseConfig = { ...LEVEL_CONFIGS[baseLevel] };
132
+
133
+ // Merge with custom settings
134
+ return {
135
+ ...baseConfig,
136
+ ...customConfig,
137
+ customizable: true,
138
+ baseLevel
139
+ };
140
+ }
141
+
142
+ /**
143
+ * Validate security level
144
+ */
145
+ static isValid(level) {
146
+ return Object.values(SECURITY_LEVELS).includes(level.toLowerCase());
147
+ }
148
+
149
+ /**
150
+ * Get all available security levels
151
+ */
152
+ static getAvailableLevels() {
153
+ return Object.keys(LEVEL_CONFIGS);
154
+ }
155
+
156
+ /**
157
+ * Check if level is custom
158
+ */
159
+ static isCustom(level) {
160
+ return level.toLowerCase() === 'custom';
161
+ }
162
+
163
+ /**
164
+ * Compare security levels
165
+ * Returns: -1 if level1 < level2, 0 if equal, 1 if level1 > level2
166
+ * Note: Custom level cannot be compared
167
+ */
168
+ static compare(level1, level2) {
169
+ const order = { low: 0, medium: 1, high: 2, custom: -1 };
170
+ const l1 = order[level1.toLowerCase()];
171
+ const l2 = order[level2.toLowerCase()];
172
+
173
+ if (l1 === undefined || l2 === undefined) {
174
+ throw new Error('Invalid security level for comparison');
175
+ }
176
+
177
+ // Custom level cannot be compared
178
+ if (l1 === -1 || l2 === -1) {
179
+ throw new Error('Cannot compare custom security level');
180
+ }
181
+
182
+ return l1 < l2 ? -1 : (l1 > l2 ? 1 : 0);
183
+ }
184
+
185
+ /**
186
+ * Get recommended settings based on use case
187
+ */
188
+ static getRecommended(useCase) {
189
+ const recommendations = {
190
+ 'streaming': 'low', // Maximum speed for video/audio
191
+ 'browsing': 'medium', // Balanced for general use
192
+ 'banking': 'high', // Maximum security for sensitive data
193
+ 'gaming': 'low', // Low latency priority
194
+ 'corporate': 'high', // Enterprise security
195
+ 'public-wifi': 'high', // Protection on untrusted networks
196
+ 'default': 'medium'
197
+ };
198
+
199
+ return recommendations[useCase.toLowerCase()] || recommendations.default;
200
+ }
201
+
202
+ /**
203
+ * Get feature requirements for a level
204
+ */
205
+ static getFeatureRequirements(level) {
206
+ const config = this.getConfig(level);
207
+
208
+ return {
209
+ requiresKeyExchange: config.keyExchange !== 'psk',
210
+ requiresCertificates: config.auth === 'certificate',
211
+ requires2FA: config.twoFactorAuth === true,
212
+ requiresDNSSEC: config.dnsMode === 'dot-dnssec',
213
+ requiresMultiPath: config.multiPath > 2,
214
+ requiresObfuscation: config.obfuscation !== 'none'
215
+ };
216
+ }
217
+
218
+ /**
219
+ * Get performance characteristics
220
+ */
221
+ static getPerformanceProfile(level) {
222
+ const config = this.getConfig(level);
223
+
224
+ const profiles = {
225
+ low: {
226
+ latencyOverhead: '<2ms',
227
+ cpuUsage: 'low',
228
+ memoryPerConnection: '~30KB',
229
+ throughput: config.throughput,
230
+ connections: '10000+'
231
+ },
232
+ medium: {
233
+ latencyOverhead: '<5ms',
234
+ cpuUsage: 'medium',
235
+ memoryPerConnection: '~40KB',
236
+ throughput: config.throughput,
237
+ connections: '8000+'
238
+ },
239
+ high: {
240
+ latencyOverhead: '<10ms',
241
+ cpuUsage: 'high',
242
+ memoryPerConnection: '~60KB',
243
+ throughput: config.throughput,
244
+ connections: '5000+'
245
+ },
246
+ custom: {
247
+ latencyOverhead: 'varies',
248
+ cpuUsage: 'varies',
249
+ memoryPerConnection: 'varies',
250
+ throughput: config.throughput,
251
+ connections: 'varies',
252
+ note: 'Performance depends on custom configuration'
253
+ }
254
+ };
255
+
256
+ return profiles[level.toLowerCase()];
257
+ }
258
+
259
+ /**
260
+ * Get security guarantees
261
+ */
262
+ static getSecurityGuarantees(level) {
263
+ const config = this.getConfig(level);
264
+
265
+ return {
266
+ encryption: config.encryption,
267
+ keySize: config.keySize,
268
+ perfectForwardSecrecy: config.perfectForwardSecrecy,
269
+ antiReplay: config.antiReplay,
270
+ authenticated: true,
271
+ dpiResistance: level !== 'low',
272
+ certificatePinning: config.certificateValidation,
273
+ quantumResistant: false // Future enhancement
274
+ };
275
+ }
276
+
277
+ /**
278
+ * Upgrade security level
279
+ */
280
+ static upgrade(currentLevel) {
281
+ const order = ['low', 'medium', 'high'];
282
+ const index = order.indexOf(currentLevel.toLowerCase());
283
+
284
+ if (index === -1) {
285
+ throw new Error('Invalid current level');
286
+ }
287
+
288
+ if (index === order.length - 1) {
289
+ return currentLevel; // Already at highest
290
+ }
291
+
292
+ return order[index + 1];
293
+ }
294
+
295
+ /**
296
+ * Downgrade security level
297
+ */
298
+ static downgrade(currentLevel) {
299
+ const order = ['low', 'medium', 'high'];
300
+ const index = order.indexOf(currentLevel.toLowerCase());
301
+
302
+ if (index === -1) {
303
+ throw new Error('Invalid current level');
304
+ }
305
+
306
+ if (index === 0) {
307
+ return currentLevel; // Already at lowest
308
+ }
309
+
310
+ return order[index - 1];
311
+ }
312
+ }
313
+
314
+ module.exports = SecurityLevels;
315
+ module.exports.SECURITY_LEVELS = SECURITY_LEVELS;
316
+ module.exports.LEVEL_CONFIGS = LEVEL_CONFIGS;