@thangnm.nip/arouter 0.1.2 → 0.1.4
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/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/app-path-routes-manifest.json +5 -5
- package/.next/standalone/.next/build-manifest.json +2 -2
- package/.next/standalone/.next/prerender-manifest.json +3 -3
- package/.next/standalone/.next/server/app/(dashboard)/mitm/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +2 -2
- package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +3 -3
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/alias/route.js +2 -2
- package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/alias/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/console-logs/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/route.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/settings/route.js +2 -2
- package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/claude-settings/route.js +2 -2
- package/.next/standalone/.next/server/app/api/cli-tools/claude-settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/codex-settings/route.js +2 -2
- package/.next/standalone/.next/server/app/api/cli-tools/codex-settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/copilot-settings/route.js +2 -2
- package/.next/standalone/.next/server/app/api/cli-tools/copilot-settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/droid-settings/route.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/droid-settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/openclaw-settings/route.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/openclaw-settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/opencode-settings/route.js +1 -1
- package/.next/standalone/.next/server/app/api/cli-tools/opencode-settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/keys/[id]/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/keys/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/locale/route.js +2 -2
- package/.next/standalone/.next/server/app/api/locale/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/models/alias/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/models/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/providers/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/settings/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/api/version/route_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +4 -4
- package/.next/standalone/.next/server/app/index.segments/!KGRhc2hib2FyZCk/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/index.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
- package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/mitm.html +1 -1
- package/.next/standalone/.next/server/app/mitm.rsc +5 -5
- package/.next/standalone/.next/server/app/mitm.segments/!KGRhc2hib2FyZCk/mitm/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/mitm.segments/!KGRhc2hib2FyZCk/mitm.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/mitm.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/mitm.segments/_full.segment.rsc +5 -5
- package/.next/standalone/.next/server/app/mitm.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/mitm.segments/_index.segment.rsc +3 -3
- package/.next/standalone/.next/server/app/mitm.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app-paths-manifest.json +5 -5
- package/.next/standalone/.next/server/chunks/411.js +1 -1
- package/.next/standalone/.next/server/middleware.js +2 -2
- package/.next/standalone/.next/server/pages/404.html +1 -1
- package/.next/standalone/.next/server/pages/500.html +2 -2
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/static/chunks/{702-90a93bbee38dba8f.js → 702-0864796c00fc702e.js} +1 -1
- package/.next/standalone/node_modules/node-forge/LICENSE +331 -0
- package/.next/standalone/node_modules/node-forge/README.md +2071 -0
- package/.next/standalone/node_modules/node-forge/dist/forge.all.min.js +2 -0
- package/.next/standalone/node_modules/node-forge/dist/forge.all.min.js.map +1 -0
- package/.next/standalone/node_modules/node-forge/dist/forge.min.js +2 -0
- package/.next/standalone/node_modules/node-forge/dist/forge.min.js.map +1 -0
- package/.next/standalone/node_modules/node-forge/dist/prime.worker.min.js +2 -0
- package/.next/standalone/node_modules/node-forge/dist/prime.worker.min.js.map +1 -0
- package/.next/standalone/node_modules/node-forge/flash/swf/SocketPool.swf +0 -0
- package/.next/standalone/node_modules/node-forge/lib/aes.js +1091 -0
- package/.next/standalone/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
- package/.next/standalone/node_modules/node-forge/lib/asn1-validator.js +91 -0
- package/.next/standalone/node_modules/node-forge/lib/asn1.js +1503 -0
- package/.next/standalone/node_modules/node-forge/lib/baseN.js +186 -0
- package/.next/standalone/node_modules/node-forge/lib/cipher.js +230 -0
- package/.next/standalone/node_modules/node-forge/lib/cipherModes.js +999 -0
- package/.next/standalone/node_modules/node-forge/lib/des.js +496 -0
- package/.next/standalone/node_modules/node-forge/lib/ed25519.js +1072 -0
- package/.next/standalone/node_modules/node-forge/lib/forge.js +13 -0
- package/.next/standalone/node_modules/node-forge/lib/form.js +149 -0
- package/.next/standalone/node_modules/node-forge/lib/hmac.js +146 -0
- package/.next/standalone/node_modules/node-forge/lib/http.js +1346 -0
- package/.next/standalone/node_modules/node-forge/lib/index.all.js +16 -0
- package/.next/standalone/node_modules/node-forge/lib/index.js +33 -0
- package/.next/standalone/node_modules/node-forge/lib/jsbn.js +1264 -0
- package/.next/standalone/node_modules/node-forge/lib/kem.js +168 -0
- package/.next/standalone/node_modules/node-forge/lib/log.js +319 -0
- package/.next/standalone/node_modules/node-forge/lib/md.all.js +13 -0
- package/.next/standalone/node_modules/node-forge/lib/md.js +11 -0
- package/.next/standalone/node_modules/node-forge/lib/md5.js +289 -0
- package/.next/standalone/node_modules/node-forge/lib/mgf.js +12 -0
- package/.next/standalone/node_modules/node-forge/lib/mgf1.js +57 -0
- package/.next/standalone/node_modules/node-forge/lib/oids.js +179 -0
- package/.next/standalone/node_modules/node-forge/lib/pbe.js +1023 -0
- package/.next/standalone/node_modules/node-forge/lib/pbkdf2.js +211 -0
- package/.next/standalone/node_modules/node-forge/lib/pem.js +237 -0
- package/.next/standalone/node_modules/node-forge/lib/pkcs1.js +276 -0
- package/.next/standalone/node_modules/node-forge/lib/pkcs12.js +1078 -0
- package/.next/standalone/node_modules/node-forge/lib/pkcs7.js +1260 -0
- package/.next/standalone/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
- package/.next/standalone/node_modules/node-forge/lib/pki.js +102 -0
- package/.next/standalone/node_modules/node-forge/lib/prime.js +297 -0
- package/.next/standalone/node_modules/node-forge/lib/prime.worker.js +168 -0
- package/.next/standalone/node_modules/node-forge/lib/prng.js +419 -0
- package/.next/standalone/node_modules/node-forge/lib/pss.js +241 -0
- package/.next/standalone/node_modules/node-forge/lib/random.js +191 -0
- package/.next/standalone/node_modules/node-forge/lib/rc2.js +410 -0
- package/.next/standalone/node_modules/node-forge/lib/rsa.js +1949 -0
- package/.next/standalone/node_modules/node-forge/lib/sha1.js +319 -0
- package/.next/standalone/node_modules/node-forge/lib/sha256.js +327 -0
- package/.next/standalone/node_modules/node-forge/lib/sha512.js +561 -0
- package/.next/standalone/node_modules/node-forge/lib/socket.js +287 -0
- package/.next/standalone/node_modules/node-forge/lib/ssh.js +236 -0
- package/.next/standalone/node_modules/node-forge/lib/tls.js +4282 -0
- package/.next/standalone/node_modules/node-forge/lib/tlssocket.js +249 -0
- package/.next/standalone/node_modules/node-forge/lib/util.js +2652 -0
- package/.next/standalone/node_modules/node-forge/lib/x509.js +3242 -0
- package/.next/standalone/node_modules/node-forge/lib/xhr.js +738 -0
- package/.next/standalone/node_modules/node-forge/package.json +123 -0
- package/.next/standalone/node_modules/node-machine-id/.babelrc +26 -0
- package/.next/standalone/node_modules/node-machine-id/.eslintignore +2 -0
- package/.next/standalone/node_modules/node-machine-id/.eslintrc +140 -0
- package/.next/standalone/node_modules/node-machine-id/.flowconfig +9 -0
- package/.next/standalone/node_modules/node-machine-id/LICENSE +21 -0
- package/.next/standalone/node_modules/node-machine-id/README.md +84 -0
- package/.next/standalone/node_modules/node-machine-id/dist/index.js +1 -0
- package/.next/standalone/node_modules/node-machine-id/index.js +80 -0
- package/.next/standalone/node_modules/node-machine-id/package.json +74 -0
- package/.next/standalone/node_modules/node-machine-id/tests/index.js +45 -0
- package/.next/standalone/node_modules/node-machine-id/types/index.d.ts +17 -0
- package/.next/standalone/node_modules/node-machine-id/webpack.config.babel.js +59 -0
- package/.next/standalone/package.json +1 -1
- package/.next/standalone/src/mitm/cert/generate.js +32 -0
- package/.next/standalone/src/mitm/cert/install.js +176 -0
- package/.next/standalone/src/mitm/cert/rootCA.js +173 -0
- package/.next/standalone/src/mitm/dns/dnsConfig.js +216 -0
- package/.next/standalone/src/mitm/logger.js +8 -0
- package/.next/standalone/src/mitm/manager.js +603 -0
- package/.next/standalone/src/mitm/paths.js +16 -0
- package/package.json +1 -1
- /package/.next/standalone/.next/static/{Ws7kclTEFgfHRwd7pk9Ly → DkVxg6bby4SUixuq1vdO8}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{Ws7kclTEFgfHRwd7pk9Ly → DkVxg6bby4SUixuq1vdO8}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Socket implementation that uses flash SocketPool class as a backend.
|
|
3
|
+
*
|
|
4
|
+
* @author Dave Longley
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2010-2013 Digital Bazaar, Inc.
|
|
7
|
+
*/
|
|
8
|
+
var forge = require('./forge');
|
|
9
|
+
require('./util');
|
|
10
|
+
|
|
11
|
+
// define net namespace
|
|
12
|
+
var net = module.exports = forge.net = forge.net || {};
|
|
13
|
+
|
|
14
|
+
// map of flash ID to socket pool
|
|
15
|
+
net.socketPools = {};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates a flash socket pool.
|
|
19
|
+
*
|
|
20
|
+
* @param options:
|
|
21
|
+
* flashId: the dom ID for the flash object element.
|
|
22
|
+
* policyPort: the default policy port for sockets, 0 to use the
|
|
23
|
+
* flash default.
|
|
24
|
+
* policyUrl: the default policy file URL for sockets (if provided
|
|
25
|
+
* used instead of a policy port).
|
|
26
|
+
* msie: true if the browser is msie, false if not.
|
|
27
|
+
*
|
|
28
|
+
* @return the created socket pool.
|
|
29
|
+
*/
|
|
30
|
+
net.createSocketPool = function(options) {
|
|
31
|
+
// set default
|
|
32
|
+
options.msie = options.msie || false;
|
|
33
|
+
|
|
34
|
+
// initialize the flash interface
|
|
35
|
+
var spId = options.flashId;
|
|
36
|
+
var api = document.getElementById(spId);
|
|
37
|
+
api.init({marshallExceptions: !options.msie});
|
|
38
|
+
|
|
39
|
+
// create socket pool entry
|
|
40
|
+
var sp = {
|
|
41
|
+
// ID of the socket pool
|
|
42
|
+
id: spId,
|
|
43
|
+
// flash interface
|
|
44
|
+
flashApi: api,
|
|
45
|
+
// map of socket ID to sockets
|
|
46
|
+
sockets: {},
|
|
47
|
+
// default policy port
|
|
48
|
+
policyPort: options.policyPort || 0,
|
|
49
|
+
// default policy URL
|
|
50
|
+
policyUrl: options.policyUrl || null
|
|
51
|
+
};
|
|
52
|
+
net.socketPools[spId] = sp;
|
|
53
|
+
|
|
54
|
+
// create event handler, subscribe to flash events
|
|
55
|
+
if(options.msie === true) {
|
|
56
|
+
sp.handler = function(e) {
|
|
57
|
+
if(e.id in sp.sockets) {
|
|
58
|
+
// get handler function
|
|
59
|
+
var f;
|
|
60
|
+
switch(e.type) {
|
|
61
|
+
case 'connect':
|
|
62
|
+
f = 'connected';
|
|
63
|
+
break;
|
|
64
|
+
case 'close':
|
|
65
|
+
f = 'closed';
|
|
66
|
+
break;
|
|
67
|
+
case 'socketData':
|
|
68
|
+
f = 'data';
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
f = 'error';
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
/* IE calls javascript on the thread of the external object
|
|
75
|
+
that triggered the event (in this case flash) ... which will
|
|
76
|
+
either run concurrently with other javascript or pre-empt any
|
|
77
|
+
running javascript in the middle of its execution (BAD!) ...
|
|
78
|
+
calling setTimeout() will schedule the javascript to run on
|
|
79
|
+
the javascript thread and solve this EVIL problem. */
|
|
80
|
+
setTimeout(function() {sp.sockets[e.id][f](e);}, 0);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
} else {
|
|
84
|
+
sp.handler = function(e) {
|
|
85
|
+
if(e.id in sp.sockets) {
|
|
86
|
+
// get handler function
|
|
87
|
+
var f;
|
|
88
|
+
switch(e.type) {
|
|
89
|
+
case 'connect':
|
|
90
|
+
f = 'connected';
|
|
91
|
+
break;
|
|
92
|
+
case 'close':
|
|
93
|
+
f = 'closed';
|
|
94
|
+
break;
|
|
95
|
+
case 'socketData':
|
|
96
|
+
f = 'data';
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
f = 'error';
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
sp.sockets[e.id][f](e);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
var handler = 'forge.net.socketPools[\'' + spId + '\'].handler';
|
|
107
|
+
api.subscribe('connect', handler);
|
|
108
|
+
api.subscribe('close', handler);
|
|
109
|
+
api.subscribe('socketData', handler);
|
|
110
|
+
api.subscribe('ioError', handler);
|
|
111
|
+
api.subscribe('securityError', handler);
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Destroys a socket pool. The socket pool still needs to be cleaned
|
|
115
|
+
* up via net.cleanup().
|
|
116
|
+
*/
|
|
117
|
+
sp.destroy = function() {
|
|
118
|
+
delete net.socketPools[options.flashId];
|
|
119
|
+
for(var id in sp.sockets) {
|
|
120
|
+
sp.sockets[id].destroy();
|
|
121
|
+
}
|
|
122
|
+
sp.sockets = {};
|
|
123
|
+
api.cleanup();
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new socket.
|
|
128
|
+
*
|
|
129
|
+
* @param options:
|
|
130
|
+
* connected: function(event) called when the socket connects.
|
|
131
|
+
* closed: function(event) called when the socket closes.
|
|
132
|
+
* data: function(event) called when socket data has arrived,
|
|
133
|
+
* it can be read from the socket using receive().
|
|
134
|
+
* error: function(event) called when a socket error occurs.
|
|
135
|
+
*/
|
|
136
|
+
sp.createSocket = function(options) {
|
|
137
|
+
// default to empty options
|
|
138
|
+
options = options || {};
|
|
139
|
+
|
|
140
|
+
// create flash socket
|
|
141
|
+
var id = api.create();
|
|
142
|
+
|
|
143
|
+
// create javascript socket wrapper
|
|
144
|
+
var socket = {
|
|
145
|
+
id: id,
|
|
146
|
+
// set handlers
|
|
147
|
+
connected: options.connected || function(e) {},
|
|
148
|
+
closed: options.closed || function(e) {},
|
|
149
|
+
data: options.data || function(e) {},
|
|
150
|
+
error: options.error || function(e) {}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Destroys this socket.
|
|
155
|
+
*/
|
|
156
|
+
socket.destroy = function() {
|
|
157
|
+
api.destroy(id);
|
|
158
|
+
delete sp.sockets[id];
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Connects this socket.
|
|
163
|
+
*
|
|
164
|
+
* @param options:
|
|
165
|
+
* host: the host to connect to.
|
|
166
|
+
* port: the port to connect to.
|
|
167
|
+
* policyPort: the policy port to use (if non-default), 0 to
|
|
168
|
+
* use the flash default.
|
|
169
|
+
* policyUrl: the policy file URL to use (instead of port).
|
|
170
|
+
*/
|
|
171
|
+
socket.connect = function(options) {
|
|
172
|
+
// give precedence to policy URL over policy port
|
|
173
|
+
// if no policy URL and passed port isn't 0, use default port,
|
|
174
|
+
// otherwise use 0 for the port
|
|
175
|
+
var policyUrl = options.policyUrl || null;
|
|
176
|
+
var policyPort = 0;
|
|
177
|
+
if(policyUrl === null && options.policyPort !== 0) {
|
|
178
|
+
policyPort = options.policyPort || sp.policyPort;
|
|
179
|
+
}
|
|
180
|
+
api.connect(id, options.host, options.port, policyPort, policyUrl);
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Closes this socket.
|
|
185
|
+
*/
|
|
186
|
+
socket.close = function() {
|
|
187
|
+
api.close(id);
|
|
188
|
+
socket.closed({
|
|
189
|
+
id: socket.id,
|
|
190
|
+
type: 'close',
|
|
191
|
+
bytesAvailable: 0
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Determines if the socket is connected or not.
|
|
197
|
+
*
|
|
198
|
+
* @return true if connected, false if not.
|
|
199
|
+
*/
|
|
200
|
+
socket.isConnected = function() {
|
|
201
|
+
return api.isConnected(id);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Writes bytes to this socket.
|
|
206
|
+
*
|
|
207
|
+
* @param bytes the bytes (as a string) to write.
|
|
208
|
+
*
|
|
209
|
+
* @return true on success, false on failure.
|
|
210
|
+
*/
|
|
211
|
+
socket.send = function(bytes) {
|
|
212
|
+
return api.send(id, forge.util.encode64(bytes));
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Reads bytes from this socket (non-blocking). Fewer than the number
|
|
217
|
+
* of bytes requested may be read if enough bytes are not available.
|
|
218
|
+
*
|
|
219
|
+
* This method should be called from the data handler if there are
|
|
220
|
+
* enough bytes available. To see how many bytes are available, check
|
|
221
|
+
* the 'bytesAvailable' property on the event in the data handler or
|
|
222
|
+
* call the bytesAvailable() function on the socket. If the browser is
|
|
223
|
+
* msie, then the bytesAvailable() function should be used to avoid
|
|
224
|
+
* race conditions. Otherwise, using the property on the data handler's
|
|
225
|
+
* event may be quicker.
|
|
226
|
+
*
|
|
227
|
+
* @param count the maximum number of bytes to read.
|
|
228
|
+
*
|
|
229
|
+
* @return the bytes read (as a string) or null on error.
|
|
230
|
+
*/
|
|
231
|
+
socket.receive = function(count) {
|
|
232
|
+
var rval = api.receive(id, count).rval;
|
|
233
|
+
return (rval === null) ? null : forge.util.decode64(rval);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Gets the number of bytes available for receiving on the socket.
|
|
238
|
+
*
|
|
239
|
+
* @return the number of bytes available for receiving.
|
|
240
|
+
*/
|
|
241
|
+
socket.bytesAvailable = function() {
|
|
242
|
+
return api.getBytesAvailable(id);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
// store and return socket
|
|
246
|
+
sp.sockets[id] = socket;
|
|
247
|
+
return socket;
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return sp;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Destroys a flash socket pool.
|
|
255
|
+
*
|
|
256
|
+
* @param options:
|
|
257
|
+
* flashId: the dom ID for the flash object element.
|
|
258
|
+
*/
|
|
259
|
+
net.destroySocketPool = function(options) {
|
|
260
|
+
if(options.flashId in net.socketPools) {
|
|
261
|
+
var sp = net.socketPools[options.flashId];
|
|
262
|
+
sp.destroy();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Creates a new socket.
|
|
268
|
+
*
|
|
269
|
+
* @param options:
|
|
270
|
+
* flashId: the dom ID for the flash object element.
|
|
271
|
+
* connected: function(event) called when the socket connects.
|
|
272
|
+
* closed: function(event) called when the socket closes.
|
|
273
|
+
* data: function(event) called when socket data has arrived, it
|
|
274
|
+
* can be read from the socket using receive().
|
|
275
|
+
* error: function(event) called when a socket error occurs.
|
|
276
|
+
*
|
|
277
|
+
* @return the created socket.
|
|
278
|
+
*/
|
|
279
|
+
net.createSocket = function(options) {
|
|
280
|
+
var socket = null;
|
|
281
|
+
if(options.flashId in net.socketPools) {
|
|
282
|
+
// get related socket pool
|
|
283
|
+
var sp = net.socketPools[options.flashId];
|
|
284
|
+
socket = sp.createSocket(options);
|
|
285
|
+
}
|
|
286
|
+
return socket;
|
|
287
|
+
};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functions to output keys in SSH-friendly formats.
|
|
3
|
+
*
|
|
4
|
+
* This is part of the Forge project which may be used under the terms of
|
|
5
|
+
* either the BSD License or the GNU General Public License (GPL) Version 2.
|
|
6
|
+
*
|
|
7
|
+
* See: https://github.com/digitalbazaar/forge/blob/cbebca3780658703d925b61b2caffb1d263a6c1d/LICENSE
|
|
8
|
+
*
|
|
9
|
+
* @author https://github.com/shellac
|
|
10
|
+
*/
|
|
11
|
+
var forge = require('./forge');
|
|
12
|
+
require('./aes');
|
|
13
|
+
require('./hmac');
|
|
14
|
+
require('./md5');
|
|
15
|
+
require('./sha1');
|
|
16
|
+
require('./util');
|
|
17
|
+
|
|
18
|
+
var ssh = module.exports = forge.ssh = forge.ssh || {};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Encodes (and optionally encrypts) a private RSA key as a Putty PPK file.
|
|
22
|
+
*
|
|
23
|
+
* @param privateKey the key.
|
|
24
|
+
* @param passphrase a passphrase to protect the key (falsy for no encryption).
|
|
25
|
+
* @param comment a comment to include in the key file.
|
|
26
|
+
*
|
|
27
|
+
* @return the PPK file as a string.
|
|
28
|
+
*/
|
|
29
|
+
ssh.privateKeyToPutty = function(privateKey, passphrase, comment) {
|
|
30
|
+
comment = comment || '';
|
|
31
|
+
passphrase = passphrase || '';
|
|
32
|
+
var algorithm = 'ssh-rsa';
|
|
33
|
+
var encryptionAlgorithm = (passphrase === '') ? 'none' : 'aes256-cbc';
|
|
34
|
+
|
|
35
|
+
var ppk = 'PuTTY-User-Key-File-2: ' + algorithm + '\r\n';
|
|
36
|
+
ppk += 'Encryption: ' + encryptionAlgorithm + '\r\n';
|
|
37
|
+
ppk += 'Comment: ' + comment + '\r\n';
|
|
38
|
+
|
|
39
|
+
// public key into buffer for ppk
|
|
40
|
+
var pubbuffer = forge.util.createBuffer();
|
|
41
|
+
_addStringToBuffer(pubbuffer, algorithm);
|
|
42
|
+
_addBigIntegerToBuffer(pubbuffer, privateKey.e);
|
|
43
|
+
_addBigIntegerToBuffer(pubbuffer, privateKey.n);
|
|
44
|
+
|
|
45
|
+
// write public key
|
|
46
|
+
var pub = forge.util.encode64(pubbuffer.bytes(), 64);
|
|
47
|
+
var length = Math.floor(pub.length / 66) + 1; // 66 = 64 + \r\n
|
|
48
|
+
ppk += 'Public-Lines: ' + length + '\r\n';
|
|
49
|
+
ppk += pub;
|
|
50
|
+
|
|
51
|
+
// private key into a buffer
|
|
52
|
+
var privbuffer = forge.util.createBuffer();
|
|
53
|
+
_addBigIntegerToBuffer(privbuffer, privateKey.d);
|
|
54
|
+
_addBigIntegerToBuffer(privbuffer, privateKey.p);
|
|
55
|
+
_addBigIntegerToBuffer(privbuffer, privateKey.q);
|
|
56
|
+
_addBigIntegerToBuffer(privbuffer, privateKey.qInv);
|
|
57
|
+
|
|
58
|
+
// optionally encrypt the private key
|
|
59
|
+
var priv;
|
|
60
|
+
if(!passphrase) {
|
|
61
|
+
// use the unencrypted buffer
|
|
62
|
+
priv = forge.util.encode64(privbuffer.bytes(), 64);
|
|
63
|
+
} else {
|
|
64
|
+
// encrypt RSA key using passphrase
|
|
65
|
+
var encLen = privbuffer.length() + 16 - 1;
|
|
66
|
+
encLen -= encLen % 16;
|
|
67
|
+
|
|
68
|
+
// pad private key with sha1-d data -- needs to be a multiple of 16
|
|
69
|
+
var padding = _sha1(privbuffer.bytes());
|
|
70
|
+
|
|
71
|
+
padding.truncate(padding.length() - encLen + privbuffer.length());
|
|
72
|
+
privbuffer.putBuffer(padding);
|
|
73
|
+
|
|
74
|
+
var aeskey = forge.util.createBuffer();
|
|
75
|
+
aeskey.putBuffer(_sha1('\x00\x00\x00\x00', passphrase));
|
|
76
|
+
aeskey.putBuffer(_sha1('\x00\x00\x00\x01', passphrase));
|
|
77
|
+
|
|
78
|
+
// encrypt some bytes using CBC mode
|
|
79
|
+
// key is 40 bytes, so truncate *by* 8 bytes
|
|
80
|
+
var cipher = forge.aes.createEncryptionCipher(aeskey.truncate(8), 'CBC');
|
|
81
|
+
cipher.start(forge.util.createBuffer().fillWithByte(0, 16));
|
|
82
|
+
cipher.update(privbuffer.copy());
|
|
83
|
+
cipher.finish();
|
|
84
|
+
var encrypted = cipher.output;
|
|
85
|
+
|
|
86
|
+
// Note: this appears to differ from Putty -- is forge wrong, or putty?
|
|
87
|
+
// due to padding we finish as an exact multiple of 16
|
|
88
|
+
encrypted.truncate(16); // all padding
|
|
89
|
+
|
|
90
|
+
priv = forge.util.encode64(encrypted.bytes(), 64);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// output private key
|
|
94
|
+
length = Math.floor(priv.length / 66) + 1; // 64 + \r\n
|
|
95
|
+
ppk += '\r\nPrivate-Lines: ' + length + '\r\n';
|
|
96
|
+
ppk += priv;
|
|
97
|
+
|
|
98
|
+
// MAC
|
|
99
|
+
var mackey = _sha1('putty-private-key-file-mac-key', passphrase);
|
|
100
|
+
|
|
101
|
+
var macbuffer = forge.util.createBuffer();
|
|
102
|
+
_addStringToBuffer(macbuffer, algorithm);
|
|
103
|
+
_addStringToBuffer(macbuffer, encryptionAlgorithm);
|
|
104
|
+
_addStringToBuffer(macbuffer, comment);
|
|
105
|
+
macbuffer.putInt32(pubbuffer.length());
|
|
106
|
+
macbuffer.putBuffer(pubbuffer);
|
|
107
|
+
macbuffer.putInt32(privbuffer.length());
|
|
108
|
+
macbuffer.putBuffer(privbuffer);
|
|
109
|
+
|
|
110
|
+
var hmac = forge.hmac.create();
|
|
111
|
+
hmac.start('sha1', mackey);
|
|
112
|
+
hmac.update(macbuffer.bytes());
|
|
113
|
+
|
|
114
|
+
ppk += '\r\nPrivate-MAC: ' + hmac.digest().toHex() + '\r\n';
|
|
115
|
+
|
|
116
|
+
return ppk;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Encodes a public RSA key as an OpenSSH file.
|
|
121
|
+
*
|
|
122
|
+
* @param key the key.
|
|
123
|
+
* @param comment a comment.
|
|
124
|
+
*
|
|
125
|
+
* @return the public key in OpenSSH format.
|
|
126
|
+
*/
|
|
127
|
+
ssh.publicKeyToOpenSSH = function(key, comment) {
|
|
128
|
+
var type = 'ssh-rsa';
|
|
129
|
+
comment = comment || '';
|
|
130
|
+
|
|
131
|
+
var buffer = forge.util.createBuffer();
|
|
132
|
+
_addStringToBuffer(buffer, type);
|
|
133
|
+
_addBigIntegerToBuffer(buffer, key.e);
|
|
134
|
+
_addBigIntegerToBuffer(buffer, key.n);
|
|
135
|
+
|
|
136
|
+
return type + ' ' + forge.util.encode64(buffer.bytes()) + ' ' + comment;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Encodes a private RSA key as an OpenSSH file.
|
|
141
|
+
*
|
|
142
|
+
* @param key the key.
|
|
143
|
+
* @param passphrase a passphrase to protect the key (falsy for no encryption).
|
|
144
|
+
*
|
|
145
|
+
* @return the public key in OpenSSH format.
|
|
146
|
+
*/
|
|
147
|
+
ssh.privateKeyToOpenSSH = function(privateKey, passphrase) {
|
|
148
|
+
if(!passphrase) {
|
|
149
|
+
return forge.pki.privateKeyToPem(privateKey);
|
|
150
|
+
}
|
|
151
|
+
// OpenSSH private key is just a legacy format, it seems
|
|
152
|
+
return forge.pki.encryptRsaPrivateKey(privateKey, passphrase,
|
|
153
|
+
{legacy: true, algorithm: 'aes128'});
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Gets the SSH fingerprint for the given public key.
|
|
158
|
+
*
|
|
159
|
+
* @param options the options to use.
|
|
160
|
+
* [md] the message digest object to use (defaults to forge.md.md5).
|
|
161
|
+
* [encoding] an alternative output encoding, such as 'hex'
|
|
162
|
+
* (defaults to none, outputs a byte buffer).
|
|
163
|
+
* [delimiter] the delimiter to use between bytes for 'hex' encoded
|
|
164
|
+
* output, eg: ':' (defaults to none).
|
|
165
|
+
*
|
|
166
|
+
* @return the fingerprint as a byte buffer or other encoding based on options.
|
|
167
|
+
*/
|
|
168
|
+
ssh.getPublicKeyFingerprint = function(key, options) {
|
|
169
|
+
options = options || {};
|
|
170
|
+
var md = options.md || forge.md.md5.create();
|
|
171
|
+
|
|
172
|
+
var type = 'ssh-rsa';
|
|
173
|
+
var buffer = forge.util.createBuffer();
|
|
174
|
+
_addStringToBuffer(buffer, type);
|
|
175
|
+
_addBigIntegerToBuffer(buffer, key.e);
|
|
176
|
+
_addBigIntegerToBuffer(buffer, key.n);
|
|
177
|
+
|
|
178
|
+
// hash public key bytes
|
|
179
|
+
md.start();
|
|
180
|
+
md.update(buffer.getBytes());
|
|
181
|
+
var digest = md.digest();
|
|
182
|
+
if(options.encoding === 'hex') {
|
|
183
|
+
var hex = digest.toHex();
|
|
184
|
+
if(options.delimiter) {
|
|
185
|
+
return hex.match(/.{2}/g).join(options.delimiter);
|
|
186
|
+
}
|
|
187
|
+
return hex;
|
|
188
|
+
} else if(options.encoding === 'binary') {
|
|
189
|
+
return digest.getBytes();
|
|
190
|
+
} else if(options.encoding) {
|
|
191
|
+
throw new Error('Unknown encoding "' + options.encoding + '".');
|
|
192
|
+
}
|
|
193
|
+
return digest;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Adds len(val) then val to a buffer.
|
|
198
|
+
*
|
|
199
|
+
* @param buffer the buffer to add to.
|
|
200
|
+
* @param val a big integer.
|
|
201
|
+
*/
|
|
202
|
+
function _addBigIntegerToBuffer(buffer, val) {
|
|
203
|
+
var hexVal = val.toString(16);
|
|
204
|
+
// ensure 2s complement +ve
|
|
205
|
+
if(hexVal[0] >= '8') {
|
|
206
|
+
hexVal = '00' + hexVal;
|
|
207
|
+
}
|
|
208
|
+
var bytes = forge.util.hexToBytes(hexVal);
|
|
209
|
+
buffer.putInt32(bytes.length);
|
|
210
|
+
buffer.putBytes(bytes);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Adds len(val) then val to a buffer.
|
|
215
|
+
*
|
|
216
|
+
* @param buffer the buffer to add to.
|
|
217
|
+
* @param val a string.
|
|
218
|
+
*/
|
|
219
|
+
function _addStringToBuffer(buffer, val) {
|
|
220
|
+
buffer.putInt32(val.length);
|
|
221
|
+
buffer.putString(val);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Hashes the arguments into one value using SHA-1.
|
|
226
|
+
*
|
|
227
|
+
* @return the sha1 hash of the provided arguments.
|
|
228
|
+
*/
|
|
229
|
+
function _sha1() {
|
|
230
|
+
var sha = forge.md.sha1.create();
|
|
231
|
+
var num = arguments.length;
|
|
232
|
+
for (var i = 0; i < num; ++i) {
|
|
233
|
+
sha.update(arguments[i]);
|
|
234
|
+
}
|
|
235
|
+
return sha.digest();
|
|
236
|
+
}
|