@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,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base-N/Base-X encoding/decoding functions.
|
|
3
|
+
*
|
|
4
|
+
* Original implementation from base-x:
|
|
5
|
+
* https://github.com/cryptocoinjs/base-x
|
|
6
|
+
*
|
|
7
|
+
* Which is MIT licensed:
|
|
8
|
+
*
|
|
9
|
+
* The MIT License (MIT)
|
|
10
|
+
*
|
|
11
|
+
* Copyright base-x contributors (c) 2016
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
+
* in the Software without restriction, including without limitation the rights
|
|
16
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
+
* furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included in
|
|
21
|
+
* all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
28
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
29
|
+
* DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
var api = {};
|
|
32
|
+
module.exports = api;
|
|
33
|
+
|
|
34
|
+
// baseN alphabet indexes
|
|
35
|
+
var _reverseAlphabets = {};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* BaseN-encodes a Uint8Array using the given alphabet.
|
|
39
|
+
*
|
|
40
|
+
* @param input the Uint8Array to encode.
|
|
41
|
+
* @param maxline the maximum number of encoded characters per line to use,
|
|
42
|
+
* defaults to none.
|
|
43
|
+
*
|
|
44
|
+
* @return the baseN-encoded output string.
|
|
45
|
+
*/
|
|
46
|
+
api.encode = function(input, alphabet, maxline) {
|
|
47
|
+
if(typeof alphabet !== 'string') {
|
|
48
|
+
throw new TypeError('"alphabet" must be a string.');
|
|
49
|
+
}
|
|
50
|
+
if(maxline !== undefined && typeof maxline !== 'number') {
|
|
51
|
+
throw new TypeError('"maxline" must be a number.');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var output = '';
|
|
55
|
+
|
|
56
|
+
if(!(input instanceof Uint8Array)) {
|
|
57
|
+
// assume forge byte buffer
|
|
58
|
+
output = _encodeWithByteBuffer(input, alphabet);
|
|
59
|
+
} else {
|
|
60
|
+
var i = 0;
|
|
61
|
+
var base = alphabet.length;
|
|
62
|
+
var first = alphabet.charAt(0);
|
|
63
|
+
var digits = [0];
|
|
64
|
+
for(i = 0; i < input.length; ++i) {
|
|
65
|
+
for(var j = 0, carry = input[i]; j < digits.length; ++j) {
|
|
66
|
+
carry += digits[j] << 8;
|
|
67
|
+
digits[j] = carry % base;
|
|
68
|
+
carry = (carry / base) | 0;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
while(carry > 0) {
|
|
72
|
+
digits.push(carry % base);
|
|
73
|
+
carry = (carry / base) | 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// deal with leading zeros
|
|
78
|
+
for(i = 0; input[i] === 0 && i < input.length - 1; ++i) {
|
|
79
|
+
output += first;
|
|
80
|
+
}
|
|
81
|
+
// convert digits to a string
|
|
82
|
+
for(i = digits.length - 1; i >= 0; --i) {
|
|
83
|
+
output += alphabet[digits[i]];
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if(maxline) {
|
|
88
|
+
var regex = new RegExp('.{1,' + maxline + '}', 'g');
|
|
89
|
+
output = output.match(regex).join('\r\n');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return output;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Decodes a baseN-encoded (using the given alphabet) string to a
|
|
97
|
+
* Uint8Array.
|
|
98
|
+
*
|
|
99
|
+
* @param input the baseN-encoded input string.
|
|
100
|
+
*
|
|
101
|
+
* @return the Uint8Array.
|
|
102
|
+
*/
|
|
103
|
+
api.decode = function(input, alphabet) {
|
|
104
|
+
if(typeof input !== 'string') {
|
|
105
|
+
throw new TypeError('"input" must be a string.');
|
|
106
|
+
}
|
|
107
|
+
if(typeof alphabet !== 'string') {
|
|
108
|
+
throw new TypeError('"alphabet" must be a string.');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
var table = _reverseAlphabets[alphabet];
|
|
112
|
+
if(!table) {
|
|
113
|
+
// compute reverse alphabet
|
|
114
|
+
table = _reverseAlphabets[alphabet] = [];
|
|
115
|
+
for(var i = 0; i < alphabet.length; ++i) {
|
|
116
|
+
table[alphabet.charCodeAt(i)] = i;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// remove whitespace characters
|
|
121
|
+
input = input.replace(/\s/g, '');
|
|
122
|
+
|
|
123
|
+
var base = alphabet.length;
|
|
124
|
+
var first = alphabet.charAt(0);
|
|
125
|
+
var bytes = [0];
|
|
126
|
+
for(var i = 0; i < input.length; i++) {
|
|
127
|
+
var value = table[input.charCodeAt(i)];
|
|
128
|
+
if(value === undefined) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
for(var j = 0, carry = value; j < bytes.length; ++j) {
|
|
133
|
+
carry += bytes[j] * base;
|
|
134
|
+
bytes[j] = carry & 0xff;
|
|
135
|
+
carry >>= 8;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
while(carry > 0) {
|
|
139
|
+
bytes.push(carry & 0xff);
|
|
140
|
+
carry >>= 8;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// deal with leading zeros
|
|
145
|
+
for(var k = 0; input[k] === first && k < input.length - 1; ++k) {
|
|
146
|
+
bytes.push(0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if(typeof Buffer !== 'undefined') {
|
|
150
|
+
return Buffer.from(bytes.reverse());
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return new Uint8Array(bytes.reverse());
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
function _encodeWithByteBuffer(input, alphabet) {
|
|
157
|
+
var i = 0;
|
|
158
|
+
var base = alphabet.length;
|
|
159
|
+
var first = alphabet.charAt(0);
|
|
160
|
+
var digits = [0];
|
|
161
|
+
for(i = 0; i < input.length(); ++i) {
|
|
162
|
+
for(var j = 0, carry = input.at(i); j < digits.length; ++j) {
|
|
163
|
+
carry += digits[j] << 8;
|
|
164
|
+
digits[j] = carry % base;
|
|
165
|
+
carry = (carry / base) | 0;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
while(carry > 0) {
|
|
169
|
+
digits.push(carry % base);
|
|
170
|
+
carry = (carry / base) | 0;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var output = '';
|
|
175
|
+
|
|
176
|
+
// deal with leading zeros
|
|
177
|
+
for(i = 0; input.at(i) === 0 && i < input.length() - 1; ++i) {
|
|
178
|
+
output += first;
|
|
179
|
+
}
|
|
180
|
+
// convert digits to a string
|
|
181
|
+
for(i = digits.length - 1; i >= 0; --i) {
|
|
182
|
+
output += alphabet[digits[i]];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return output;
|
|
186
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cipher base API.
|
|
3
|
+
*
|
|
4
|
+
* @author Dave Longley
|
|
5
|
+
*
|
|
6
|
+
* Copyright (c) 2010-2014 Digital Bazaar, Inc.
|
|
7
|
+
*/
|
|
8
|
+
var forge = require('./forge');
|
|
9
|
+
require('./util');
|
|
10
|
+
|
|
11
|
+
module.exports = forge.cipher = forge.cipher || {};
|
|
12
|
+
|
|
13
|
+
// registered algorithms
|
|
14
|
+
forge.cipher.algorithms = forge.cipher.algorithms || {};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Creates a cipher object that can be used to encrypt data using the given
|
|
18
|
+
* algorithm and key. The algorithm may be provided as a string value for a
|
|
19
|
+
* previously registered algorithm or it may be given as a cipher algorithm
|
|
20
|
+
* API object.
|
|
21
|
+
*
|
|
22
|
+
* @param algorithm the algorithm to use, either a string or an algorithm API
|
|
23
|
+
* object.
|
|
24
|
+
* @param key the key to use, as a binary-encoded string of bytes or a
|
|
25
|
+
* byte buffer.
|
|
26
|
+
*
|
|
27
|
+
* @return the cipher.
|
|
28
|
+
*/
|
|
29
|
+
forge.cipher.createCipher = function(algorithm, key) {
|
|
30
|
+
var api = algorithm;
|
|
31
|
+
if(typeof api === 'string') {
|
|
32
|
+
api = forge.cipher.getAlgorithm(api);
|
|
33
|
+
if(api) {
|
|
34
|
+
api = api();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if(!api) {
|
|
38
|
+
throw new Error('Unsupported algorithm: ' + algorithm);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// assume block cipher
|
|
42
|
+
return new forge.cipher.BlockCipher({
|
|
43
|
+
algorithm: api,
|
|
44
|
+
key: key,
|
|
45
|
+
decrypt: false
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Creates a decipher object that can be used to decrypt data using the given
|
|
51
|
+
* algorithm and key. The algorithm may be provided as a string value for a
|
|
52
|
+
* previously registered algorithm or it may be given as a cipher algorithm
|
|
53
|
+
* API object.
|
|
54
|
+
*
|
|
55
|
+
* @param algorithm the algorithm to use, either a string or an algorithm API
|
|
56
|
+
* object.
|
|
57
|
+
* @param key the key to use, as a binary-encoded string of bytes or a
|
|
58
|
+
* byte buffer.
|
|
59
|
+
*
|
|
60
|
+
* @return the cipher.
|
|
61
|
+
*/
|
|
62
|
+
forge.cipher.createDecipher = function(algorithm, key) {
|
|
63
|
+
var api = algorithm;
|
|
64
|
+
if(typeof api === 'string') {
|
|
65
|
+
api = forge.cipher.getAlgorithm(api);
|
|
66
|
+
if(api) {
|
|
67
|
+
api = api();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if(!api) {
|
|
71
|
+
throw new Error('Unsupported algorithm: ' + algorithm);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// assume block cipher
|
|
75
|
+
return new forge.cipher.BlockCipher({
|
|
76
|
+
algorithm: api,
|
|
77
|
+
key: key,
|
|
78
|
+
decrypt: true
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Registers an algorithm by name. If the name was already registered, the
|
|
84
|
+
* algorithm API object will be overwritten.
|
|
85
|
+
*
|
|
86
|
+
* @param name the name of the algorithm.
|
|
87
|
+
* @param algorithm the algorithm API object.
|
|
88
|
+
*/
|
|
89
|
+
forge.cipher.registerAlgorithm = function(name, algorithm) {
|
|
90
|
+
name = name.toUpperCase();
|
|
91
|
+
forge.cipher.algorithms[name] = algorithm;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets a registered algorithm by name.
|
|
96
|
+
*
|
|
97
|
+
* @param name the name of the algorithm.
|
|
98
|
+
*
|
|
99
|
+
* @return the algorithm, if found, null if not.
|
|
100
|
+
*/
|
|
101
|
+
forge.cipher.getAlgorithm = function(name) {
|
|
102
|
+
name = name.toUpperCase();
|
|
103
|
+
if(name in forge.cipher.algorithms) {
|
|
104
|
+
return forge.cipher.algorithms[name];
|
|
105
|
+
}
|
|
106
|
+
return null;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
var BlockCipher = forge.cipher.BlockCipher = function(options) {
|
|
110
|
+
this.algorithm = options.algorithm;
|
|
111
|
+
this.mode = this.algorithm.mode;
|
|
112
|
+
this.blockSize = this.mode.blockSize;
|
|
113
|
+
this._finish = false;
|
|
114
|
+
this._input = null;
|
|
115
|
+
this.output = null;
|
|
116
|
+
this._op = options.decrypt ? this.mode.decrypt : this.mode.encrypt;
|
|
117
|
+
this._decrypt = options.decrypt;
|
|
118
|
+
this.algorithm.initialize(options);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Starts or restarts the encryption or decryption process, whichever
|
|
123
|
+
* was previously configured.
|
|
124
|
+
*
|
|
125
|
+
* For non-GCM mode, the IV may be a binary-encoded string of bytes, an array
|
|
126
|
+
* of bytes, a byte buffer, or an array of 32-bit integers. If the IV is in
|
|
127
|
+
* bytes, then it must be Nb (16) bytes in length. If the IV is given in as
|
|
128
|
+
* 32-bit integers, then it must be 4 integers long.
|
|
129
|
+
*
|
|
130
|
+
* Note: an IV is not required or used in ECB mode.
|
|
131
|
+
*
|
|
132
|
+
* For GCM-mode, the IV must be given as a binary-encoded string of bytes or
|
|
133
|
+
* a byte buffer. The number of bytes should be 12 (96 bits) as recommended
|
|
134
|
+
* by NIST SP-800-38D but another length may be given.
|
|
135
|
+
*
|
|
136
|
+
* @param options the options to use:
|
|
137
|
+
* iv the initialization vector to use as a binary-encoded string of
|
|
138
|
+
* bytes, null to reuse the last ciphered block from a previous
|
|
139
|
+
* update() (this "residue" method is for legacy support only).
|
|
140
|
+
* additionalData additional authentication data as a binary-encoded
|
|
141
|
+
* string of bytes, for 'GCM' mode, (default: none).
|
|
142
|
+
* tagLength desired length of authentication tag, in bits, for
|
|
143
|
+
* 'GCM' mode (0-128, default: 128).
|
|
144
|
+
* tag the authentication tag to check if decrypting, as a
|
|
145
|
+
* binary-encoded string of bytes.
|
|
146
|
+
* output the output the buffer to write to, null to create one.
|
|
147
|
+
*/
|
|
148
|
+
BlockCipher.prototype.start = function(options) {
|
|
149
|
+
options = options || {};
|
|
150
|
+
var opts = {};
|
|
151
|
+
for(var key in options) {
|
|
152
|
+
opts[key] = options[key];
|
|
153
|
+
}
|
|
154
|
+
opts.decrypt = this._decrypt;
|
|
155
|
+
this._finish = false;
|
|
156
|
+
this._input = forge.util.createBuffer();
|
|
157
|
+
this.output = options.output || forge.util.createBuffer();
|
|
158
|
+
this.mode.start(opts);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Updates the next block according to the cipher mode.
|
|
163
|
+
*
|
|
164
|
+
* @param input the buffer to read from.
|
|
165
|
+
*/
|
|
166
|
+
BlockCipher.prototype.update = function(input) {
|
|
167
|
+
if(input) {
|
|
168
|
+
// input given, so empty it into the input buffer
|
|
169
|
+
this._input.putBuffer(input);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// do cipher operation until it needs more input and not finished
|
|
173
|
+
while(!this._op.call(this.mode, this._input, this.output, this._finish) &&
|
|
174
|
+
!this._finish) {}
|
|
175
|
+
|
|
176
|
+
// free consumed memory from input buffer
|
|
177
|
+
this._input.compact();
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Finishes encrypting or decrypting.
|
|
182
|
+
*
|
|
183
|
+
* @param pad a padding function to use in CBC mode, null for default,
|
|
184
|
+
* signature(blockSize, buffer, decrypt).
|
|
185
|
+
*
|
|
186
|
+
* @return true if successful, false on error.
|
|
187
|
+
*/
|
|
188
|
+
BlockCipher.prototype.finish = function(pad) {
|
|
189
|
+
// backwards-compatibility w/deprecated padding API
|
|
190
|
+
// Note: will overwrite padding functions even after another start() call
|
|
191
|
+
if(pad && (this.mode.name === 'ECB' || this.mode.name === 'CBC')) {
|
|
192
|
+
this.mode.pad = function(input) {
|
|
193
|
+
return pad(this.blockSize, input, false);
|
|
194
|
+
};
|
|
195
|
+
this.mode.unpad = function(output) {
|
|
196
|
+
return pad(this.blockSize, output, true);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// build options for padding and afterFinish functions
|
|
201
|
+
var options = {};
|
|
202
|
+
options.decrypt = this._decrypt;
|
|
203
|
+
|
|
204
|
+
// get # of bytes that won't fill a block
|
|
205
|
+
options.overflow = this._input.length() % this.blockSize;
|
|
206
|
+
|
|
207
|
+
if(!this._decrypt && this.mode.pad) {
|
|
208
|
+
if(!this.mode.pad(this._input, options)) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// do final update
|
|
214
|
+
this._finish = true;
|
|
215
|
+
this.update();
|
|
216
|
+
|
|
217
|
+
if(this._decrypt && this.mode.unpad) {
|
|
218
|
+
if(!this.mode.unpad(this.output, options)) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if(this.mode.afterFinish) {
|
|
224
|
+
if(!this.mode.afterFinish(this.output, options)) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return true;
|
|
230
|
+
};
|