@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.
- package/LICENSE +21 -0
- package/bin/yaksha.js +329 -0
- package/package.json +28 -0
- package/src/bypass/firewall-evasion.js +354 -0
- package/src/client/index.js +544 -0
- package/src/core/connection.js +393 -0
- package/src/core/encryption.js +299 -0
- package/src/core/protocol.js +268 -0
- package/src/features/dns-override.js +403 -0
- package/src/features/multi-path.js +394 -0
- package/src/features/sni-spoof.js +355 -0
- package/src/features/tls-camouflage.js +369 -0
- package/src/features/traffic-obfuscation.js +338 -0
- package/src/index.js +106 -0
- package/src/security/auth.js +441 -0
- package/src/security/levels.js +316 -0
- package/src/server/index.js +551 -0
- package/src/utils/buffer-pool.js +150 -0
- package/src/utils/config.js +205 -0
- package/src/utils/logger.js +105 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Yaksha Configuration Manager
|
|
5
|
+
* Handles configuration with validation and environment variable support
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
// Default configuration
|
|
12
|
+
const DEFAULT_CONFIG = {
|
|
13
|
+
// Server settings
|
|
14
|
+
server: {
|
|
15
|
+
host: '0.0.0.0',
|
|
16
|
+
port: 8443,
|
|
17
|
+
maxConnections: 10000,
|
|
18
|
+
keepaliveInterval: 30000,
|
|
19
|
+
timeout: 60000
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
// Client settings
|
|
23
|
+
client: {
|
|
24
|
+
autoReconnect: true,
|
|
25
|
+
reconnectDelay: 1000,
|
|
26
|
+
maxReconnectDelay: 30000,
|
|
27
|
+
reconnectBackoff: 2.0,
|
|
28
|
+
keepaliveInterval: 30000
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
// Security settings
|
|
32
|
+
security: {
|
|
33
|
+
level: 'medium', // low, medium, high
|
|
34
|
+
authMethod: 'token', // password, token, certificate
|
|
35
|
+
rateLimit: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
maxAttempts: 5,
|
|
38
|
+
windowMs: 60000
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
// Features
|
|
43
|
+
features: {
|
|
44
|
+
sniSpoofing: true,
|
|
45
|
+
trafficObfuscation: true,
|
|
46
|
+
multiPath: true,
|
|
47
|
+
dnsOverride: true,
|
|
48
|
+
tlsCamouflage: true,
|
|
49
|
+
firewallEvasion: true
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
// Performance
|
|
53
|
+
performance: {
|
|
54
|
+
bufferPooling: true,
|
|
55
|
+
zeroCopy: true,
|
|
56
|
+
compression: false
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
// Logging
|
|
60
|
+
logging: {
|
|
61
|
+
level: 'info', // debug, info, warn, error, none
|
|
62
|
+
timestamps: true,
|
|
63
|
+
colors: true
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
class Config {
|
|
68
|
+
constructor(customConfig = {}) {
|
|
69
|
+
this.config = this._merge(DEFAULT_CONFIG, customConfig);
|
|
70
|
+
this._loadFromEnv();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Deep merge two objects
|
|
75
|
+
*/
|
|
76
|
+
_merge(target, source) {
|
|
77
|
+
const result = { ...target };
|
|
78
|
+
for (const key in source) {
|
|
79
|
+
if (source[key] && typeof source[key] === 'object' && !Array.isArray(source[key])) {
|
|
80
|
+
result[key] = this._merge(target[key] || {}, source[key]);
|
|
81
|
+
} else {
|
|
82
|
+
result[key] = source[key];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Load configuration from environment variables
|
|
90
|
+
*/
|
|
91
|
+
_loadFromEnv() {
|
|
92
|
+
// Server
|
|
93
|
+
if (process.env.YAKSHA_HOST) {
|
|
94
|
+
this.config.server.host = process.env.YAKSHA_HOST;
|
|
95
|
+
}
|
|
96
|
+
if (process.env.YAKSHA_PORT) {
|
|
97
|
+
this.config.server.port = parseInt(process.env.YAKSHA_PORT, 10);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Security
|
|
101
|
+
if (process.env.YAKSHA_SECURITY_LEVEL) {
|
|
102
|
+
this.config.security.level = process.env.YAKSHA_SECURITY_LEVEL.toLowerCase();
|
|
103
|
+
}
|
|
104
|
+
if (process.env.YAKSHA_AUTH_METHOD) {
|
|
105
|
+
this.config.security.authMethod = process.env.YAKSHA_AUTH_METHOD.toLowerCase();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Logging
|
|
109
|
+
if (process.env.YAKSHA_LOG_LEVEL) {
|
|
110
|
+
this.config.logging.level = process.env.YAKSHA_LOG_LEVEL.toLowerCase();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Load configuration from file
|
|
116
|
+
*/
|
|
117
|
+
loadFromFile(filePath) {
|
|
118
|
+
try {
|
|
119
|
+
const absolutePath = path.resolve(filePath);
|
|
120
|
+
const fileContent = fs.readFileSync(absolutePath, 'utf8');
|
|
121
|
+
const fileConfig = JSON.parse(fileContent);
|
|
122
|
+
this.config = this._merge(this.config, fileConfig);
|
|
123
|
+
return true;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
throw new Error(`Failed to load config from ${filePath}: ${error.message}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Get configuration value by path (e.g., 'server.port')
|
|
131
|
+
*/
|
|
132
|
+
get(path) {
|
|
133
|
+
const keys = path.split('.');
|
|
134
|
+
let value = this.config;
|
|
135
|
+
for (const key of keys) {
|
|
136
|
+
if (value && typeof value === 'object' && key in value) {
|
|
137
|
+
value = value[key];
|
|
138
|
+
} else {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return value;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Set configuration value by path
|
|
147
|
+
*/
|
|
148
|
+
set(path, value) {
|
|
149
|
+
const keys = path.split('.');
|
|
150
|
+
const lastKey = keys.pop();
|
|
151
|
+
let obj = this.config;
|
|
152
|
+
|
|
153
|
+
for (const key of keys) {
|
|
154
|
+
if (!(key in obj)) {
|
|
155
|
+
obj[key] = {};
|
|
156
|
+
}
|
|
157
|
+
obj = obj[key];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
obj[lastKey] = value;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Get all configuration
|
|
165
|
+
*/
|
|
166
|
+
getAll() {
|
|
167
|
+
return { ...this.config };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Validate configuration
|
|
172
|
+
*/
|
|
173
|
+
validate() {
|
|
174
|
+
const errors = [];
|
|
175
|
+
|
|
176
|
+
// Validate security level
|
|
177
|
+
if (!['low', 'medium', 'high'].includes(this.config.security.level)) {
|
|
178
|
+
errors.push('Invalid security level. Must be: low, medium, or high');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Validate auth method
|
|
182
|
+
if (!['password', 'token', 'certificate'].includes(this.config.security.authMethod)) {
|
|
183
|
+
errors.push('Invalid auth method. Must be: password, token, or certificate');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Validate port
|
|
187
|
+
if (this.config.server.port < 1 || this.config.server.port > 65535) {
|
|
188
|
+
errors.push('Invalid port number. Must be between 1 and 65535');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Validate log level
|
|
192
|
+
if (!['debug', 'info', 'warn', 'error', 'none'].includes(this.config.logging.level)) {
|
|
193
|
+
errors.push('Invalid log level. Must be: debug, info, warn, error, or none');
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if (errors.length > 0) {
|
|
197
|
+
throw new Error(`Configuration validation failed:\n${errors.join('\n')}`);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
module.exports = Config;
|
|
205
|
+
module.exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Yaksha Logger - Performance-optimized logging utility
|
|
5
|
+
* Supports multiple log levels and async operation
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const LOG_LEVELS = {
|
|
9
|
+
DEBUG: 0,
|
|
10
|
+
INFO: 1,
|
|
11
|
+
WARN: 2,
|
|
12
|
+
ERROR: 3,
|
|
13
|
+
NONE: 4
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
class Logger {
|
|
17
|
+
constructor(options = {}) {
|
|
18
|
+
this.level = LOG_LEVELS[options.level] || LOG_LEVELS.INFO;
|
|
19
|
+
this.prefix = options.prefix || 'Yaksha';
|
|
20
|
+
this.timestamps = options.timestamps !== false;
|
|
21
|
+
this.colors = options.colors !== false && process.stdout.isTTY;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Format timestamp
|
|
26
|
+
*/
|
|
27
|
+
_getTimestamp() {
|
|
28
|
+
if (!this.timestamps) return '';
|
|
29
|
+
const now = new Date();
|
|
30
|
+
return `[${now.toISOString()}] `;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Colorize output for terminal
|
|
35
|
+
*/
|
|
36
|
+
_colorize(text, color) {
|
|
37
|
+
if (!this.colors) return text;
|
|
38
|
+
const colors = {
|
|
39
|
+
reset: '\x1b[0m',
|
|
40
|
+
red: '\x1b[31m',
|
|
41
|
+
yellow: '\x1b[33m',
|
|
42
|
+
blue: '\x1b[34m',
|
|
43
|
+
gray: '\x1b[90m'
|
|
44
|
+
};
|
|
45
|
+
return `${colors[color]}${text}${colors.reset}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Log debug message
|
|
50
|
+
*/
|
|
51
|
+
debug(message, ...args) {
|
|
52
|
+
if (this.level <= LOG_LEVELS.DEBUG) {
|
|
53
|
+
const msg = `${this._getTimestamp()}${this._colorize('[DEBUG]', 'gray')} ${this.prefix}: ${message}`;
|
|
54
|
+
console.log(msg, ...args);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Log info message
|
|
60
|
+
*/
|
|
61
|
+
info(message, ...args) {
|
|
62
|
+
if (this.level <= LOG_LEVELS.INFO) {
|
|
63
|
+
const msg = `${this._getTimestamp()}${this._colorize('[INFO]', 'blue')} ${this.prefix}: ${message}`;
|
|
64
|
+
console.log(msg, ...args);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Log warning message
|
|
70
|
+
*/
|
|
71
|
+
warn(message, ...args) {
|
|
72
|
+
if (this.level <= LOG_LEVELS.WARN) {
|
|
73
|
+
const msg = `${this._getTimestamp()}${this._colorize('[WARN]', 'yellow')} ${this.prefix}: ${message}`;
|
|
74
|
+
console.warn(msg, ...args);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Log error message
|
|
80
|
+
*/
|
|
81
|
+
error(message, ...args) {
|
|
82
|
+
if (this.level <= LOG_LEVELS.ERROR) {
|
|
83
|
+
const msg = `${this._getTimestamp()}${this._colorize('[ERROR]', 'red')} ${this.prefix}: ${message}`;
|
|
84
|
+
console.error(msg, ...args);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Set log level
|
|
90
|
+
*/
|
|
91
|
+
setLevel(level) {
|
|
92
|
+
if (typeof level === 'string') {
|
|
93
|
+
this.level = LOG_LEVELS[level.toUpperCase()] || LOG_LEVELS.INFO;
|
|
94
|
+
} else {
|
|
95
|
+
this.level = level;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Default logger instance
|
|
101
|
+
const defaultLogger = new Logger();
|
|
102
|
+
|
|
103
|
+
module.exports = Logger;
|
|
104
|
+
module.exports.LOG_LEVELS = LOG_LEVELS;
|
|
105
|
+
module.exports.default = defaultLogger;
|