@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,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Password-Based Key-Derivation Function #2 implementation.
|
|
3
|
+
*
|
|
4
|
+
* See RFC 2898 for details.
|
|
5
|
+
*
|
|
6
|
+
* @author Dave Longley
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2010-2013 Digital Bazaar, Inc.
|
|
9
|
+
*/
|
|
10
|
+
var forge = require('./forge');
|
|
11
|
+
require('./hmac');
|
|
12
|
+
require('./md');
|
|
13
|
+
require('./util');
|
|
14
|
+
|
|
15
|
+
var pkcs5 = forge.pkcs5 = forge.pkcs5 || {};
|
|
16
|
+
|
|
17
|
+
var crypto;
|
|
18
|
+
if(forge.util.isNodejs && !forge.options.usePureJavaScript) {
|
|
19
|
+
crypto = require('crypto');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Derives a key from a password.
|
|
24
|
+
*
|
|
25
|
+
* @param p the password as a binary-encoded string of bytes.
|
|
26
|
+
* @param s the salt as a binary-encoded string of bytes.
|
|
27
|
+
* @param c the iteration count, a positive integer.
|
|
28
|
+
* @param dkLen the intended length, in bytes, of the derived key,
|
|
29
|
+
* (max: 2^32 - 1) * hash length of the PRF.
|
|
30
|
+
* @param [md] the message digest (or algorithm identifier as a string) to use
|
|
31
|
+
* in the PRF, defaults to SHA-1.
|
|
32
|
+
* @param [callback(err, key)] presence triggers asynchronous version, called
|
|
33
|
+
* once the operation completes.
|
|
34
|
+
*
|
|
35
|
+
* @return the derived key, as a binary-encoded string of bytes, for the
|
|
36
|
+
* synchronous version (if no callback is specified).
|
|
37
|
+
*/
|
|
38
|
+
module.exports = forge.pbkdf2 = pkcs5.pbkdf2 = function(
|
|
39
|
+
p, s, c, dkLen, md, callback) {
|
|
40
|
+
if(typeof md === 'function') {
|
|
41
|
+
callback = md;
|
|
42
|
+
md = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// use native implementation if possible and not disabled, note that
|
|
46
|
+
// some node versions only support SHA-1, others allow digest to be changed
|
|
47
|
+
if(forge.util.isNodejs && !forge.options.usePureJavaScript &&
|
|
48
|
+
crypto.pbkdf2 && (md === null || typeof md !== 'object') &&
|
|
49
|
+
(crypto.pbkdf2Sync.length > 4 || (!md || md === 'sha1'))) {
|
|
50
|
+
if(typeof md !== 'string') {
|
|
51
|
+
// default prf to SHA-1
|
|
52
|
+
md = 'sha1';
|
|
53
|
+
}
|
|
54
|
+
p = Buffer.from(p, 'binary');
|
|
55
|
+
s = Buffer.from(s, 'binary');
|
|
56
|
+
if(!callback) {
|
|
57
|
+
if(crypto.pbkdf2Sync.length === 4) {
|
|
58
|
+
return crypto.pbkdf2Sync(p, s, c, dkLen).toString('binary');
|
|
59
|
+
}
|
|
60
|
+
return crypto.pbkdf2Sync(p, s, c, dkLen, md).toString('binary');
|
|
61
|
+
}
|
|
62
|
+
if(crypto.pbkdf2Sync.length === 4) {
|
|
63
|
+
return crypto.pbkdf2(p, s, c, dkLen, function(err, key) {
|
|
64
|
+
if(err) {
|
|
65
|
+
return callback(err);
|
|
66
|
+
}
|
|
67
|
+
callback(null, key.toString('binary'));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return crypto.pbkdf2(p, s, c, dkLen, md, function(err, key) {
|
|
71
|
+
if(err) {
|
|
72
|
+
return callback(err);
|
|
73
|
+
}
|
|
74
|
+
callback(null, key.toString('binary'));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if(typeof md === 'undefined' || md === null) {
|
|
79
|
+
// default prf to SHA-1
|
|
80
|
+
md = 'sha1';
|
|
81
|
+
}
|
|
82
|
+
if(typeof md === 'string') {
|
|
83
|
+
if(!(md in forge.md.algorithms)) {
|
|
84
|
+
throw new Error('Unknown hash algorithm: ' + md);
|
|
85
|
+
}
|
|
86
|
+
md = forge.md[md].create();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var hLen = md.digestLength;
|
|
90
|
+
|
|
91
|
+
/* 1. If dkLen > (2^32 - 1) * hLen, output "derived key too long" and
|
|
92
|
+
stop. */
|
|
93
|
+
if(dkLen > (0xFFFFFFFF * hLen)) {
|
|
94
|
+
var err = new Error('Derived key is too long.');
|
|
95
|
+
if(callback) {
|
|
96
|
+
return callback(err);
|
|
97
|
+
}
|
|
98
|
+
throw err;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* 2. Let len be the number of hLen-octet blocks in the derived key,
|
|
102
|
+
rounding up, and let r be the number of octets in the last
|
|
103
|
+
block:
|
|
104
|
+
|
|
105
|
+
len = CEIL(dkLen / hLen),
|
|
106
|
+
r = dkLen - (len - 1) * hLen. */
|
|
107
|
+
var len = Math.ceil(dkLen / hLen);
|
|
108
|
+
var r = dkLen - (len - 1) * hLen;
|
|
109
|
+
|
|
110
|
+
/* 3. For each block of the derived key apply the function F defined
|
|
111
|
+
below to the password P, the salt S, the iteration count c, and
|
|
112
|
+
the block index to compute the block:
|
|
113
|
+
|
|
114
|
+
T_1 = F(P, S, c, 1),
|
|
115
|
+
T_2 = F(P, S, c, 2),
|
|
116
|
+
...
|
|
117
|
+
T_len = F(P, S, c, len),
|
|
118
|
+
|
|
119
|
+
where the function F is defined as the exclusive-or sum of the
|
|
120
|
+
first c iterates of the underlying pseudorandom function PRF
|
|
121
|
+
applied to the password P and the concatenation of the salt S
|
|
122
|
+
and the block index i:
|
|
123
|
+
|
|
124
|
+
F(P, S, c, i) = u_1 XOR u_2 XOR ... XOR u_c
|
|
125
|
+
|
|
126
|
+
where
|
|
127
|
+
|
|
128
|
+
u_1 = PRF(P, S || INT(i)),
|
|
129
|
+
u_2 = PRF(P, u_1),
|
|
130
|
+
...
|
|
131
|
+
u_c = PRF(P, u_{c-1}).
|
|
132
|
+
|
|
133
|
+
Here, INT(i) is a four-octet encoding of the integer i, most
|
|
134
|
+
significant octet first. */
|
|
135
|
+
var prf = forge.hmac.create();
|
|
136
|
+
prf.start(md, p);
|
|
137
|
+
var dk = '';
|
|
138
|
+
var xor, u_c, u_c1;
|
|
139
|
+
|
|
140
|
+
// sync version
|
|
141
|
+
if(!callback) {
|
|
142
|
+
for(var i = 1; i <= len; ++i) {
|
|
143
|
+
// PRF(P, S || INT(i)) (first iteration)
|
|
144
|
+
prf.start(null, null);
|
|
145
|
+
prf.update(s);
|
|
146
|
+
prf.update(forge.util.int32ToBytes(i));
|
|
147
|
+
xor = u_c1 = prf.digest().getBytes();
|
|
148
|
+
|
|
149
|
+
// PRF(P, u_{c-1}) (other iterations)
|
|
150
|
+
for(var j = 2; j <= c; ++j) {
|
|
151
|
+
prf.start(null, null);
|
|
152
|
+
prf.update(u_c1);
|
|
153
|
+
u_c = prf.digest().getBytes();
|
|
154
|
+
// F(p, s, c, i)
|
|
155
|
+
xor = forge.util.xorBytes(xor, u_c, hLen);
|
|
156
|
+
u_c1 = u_c;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/* 4. Concatenate the blocks and extract the first dkLen octets to
|
|
160
|
+
produce a derived key DK:
|
|
161
|
+
|
|
162
|
+
DK = T_1 || T_2 || ... || T_len<0..r-1> */
|
|
163
|
+
dk += (i < len) ? xor : xor.substr(0, r);
|
|
164
|
+
}
|
|
165
|
+
/* 5. Output the derived key DK. */
|
|
166
|
+
return dk;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// async version
|
|
170
|
+
var i = 1, j;
|
|
171
|
+
function outer() {
|
|
172
|
+
if(i > len) {
|
|
173
|
+
// done
|
|
174
|
+
return callback(null, dk);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// PRF(P, S || INT(i)) (first iteration)
|
|
178
|
+
prf.start(null, null);
|
|
179
|
+
prf.update(s);
|
|
180
|
+
prf.update(forge.util.int32ToBytes(i));
|
|
181
|
+
xor = u_c1 = prf.digest().getBytes();
|
|
182
|
+
|
|
183
|
+
// PRF(P, u_{c-1}) (other iterations)
|
|
184
|
+
j = 2;
|
|
185
|
+
inner();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function inner() {
|
|
189
|
+
if(j <= c) {
|
|
190
|
+
prf.start(null, null);
|
|
191
|
+
prf.update(u_c1);
|
|
192
|
+
u_c = prf.digest().getBytes();
|
|
193
|
+
// F(p, s, c, i)
|
|
194
|
+
xor = forge.util.xorBytes(xor, u_c, hLen);
|
|
195
|
+
u_c1 = u_c;
|
|
196
|
+
++j;
|
|
197
|
+
return forge.util.setImmediate(inner);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/* 4. Concatenate the blocks and extract the first dkLen octets to
|
|
201
|
+
produce a derived key DK:
|
|
202
|
+
|
|
203
|
+
DK = T_1 || T_2 || ... || T_len<0..r-1> */
|
|
204
|
+
dk += (i < len) ? xor : xor.substr(0, r);
|
|
205
|
+
|
|
206
|
+
++i;
|
|
207
|
+
outer();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
outer();
|
|
211
|
+
};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Javascript implementation of basic PEM (Privacy Enhanced Mail) algorithms.
|
|
3
|
+
*
|
|
4
|
+
* See: RFC 1421.
|
|
5
|
+
*
|
|
6
|
+
* @author Dave Longley
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2013-2014 Digital Bazaar, Inc.
|
|
9
|
+
*
|
|
10
|
+
* A Forge PEM object has the following fields:
|
|
11
|
+
*
|
|
12
|
+
* type: identifies the type of message (eg: "RSA PRIVATE KEY").
|
|
13
|
+
*
|
|
14
|
+
* procType: identifies the type of processing performed on the message,
|
|
15
|
+
* it has two subfields: version and type, eg: 4,ENCRYPTED.
|
|
16
|
+
*
|
|
17
|
+
* contentDomain: identifies the type of content in the message, typically
|
|
18
|
+
* only uses the value: "RFC822".
|
|
19
|
+
*
|
|
20
|
+
* dekInfo: identifies the message encryption algorithm and mode and includes
|
|
21
|
+
* any parameters for the algorithm, it has two subfields: algorithm and
|
|
22
|
+
* parameters, eg: DES-CBC,F8143EDE5960C597.
|
|
23
|
+
*
|
|
24
|
+
* headers: contains all other PEM encapsulated headers -- where order is
|
|
25
|
+
* significant (for pairing data like recipient ID + key info).
|
|
26
|
+
*
|
|
27
|
+
* body: the binary-encoded body.
|
|
28
|
+
*/
|
|
29
|
+
var forge = require('./forge');
|
|
30
|
+
require('./util');
|
|
31
|
+
|
|
32
|
+
// shortcut for pem API
|
|
33
|
+
var pem = module.exports = forge.pem = forge.pem || {};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Encodes (serializes) the given PEM object.
|
|
37
|
+
*
|
|
38
|
+
* @param msg the PEM message object to encode.
|
|
39
|
+
* @param options the options to use:
|
|
40
|
+
* maxline the maximum characters per line for the body, (default: 64).
|
|
41
|
+
*
|
|
42
|
+
* @return the PEM-formatted string.
|
|
43
|
+
*/
|
|
44
|
+
pem.encode = function(msg, options) {
|
|
45
|
+
options = options || {};
|
|
46
|
+
var rval = '-----BEGIN ' + msg.type + '-----\r\n';
|
|
47
|
+
|
|
48
|
+
// encode special headers
|
|
49
|
+
var header;
|
|
50
|
+
if(msg.procType) {
|
|
51
|
+
header = {
|
|
52
|
+
name: 'Proc-Type',
|
|
53
|
+
values: [String(msg.procType.version), msg.procType.type]
|
|
54
|
+
};
|
|
55
|
+
rval += foldHeader(header);
|
|
56
|
+
}
|
|
57
|
+
if(msg.contentDomain) {
|
|
58
|
+
header = {name: 'Content-Domain', values: [msg.contentDomain]};
|
|
59
|
+
rval += foldHeader(header);
|
|
60
|
+
}
|
|
61
|
+
if(msg.dekInfo) {
|
|
62
|
+
header = {name: 'DEK-Info', values: [msg.dekInfo.algorithm]};
|
|
63
|
+
if(msg.dekInfo.parameters) {
|
|
64
|
+
header.values.push(msg.dekInfo.parameters);
|
|
65
|
+
}
|
|
66
|
+
rval += foldHeader(header);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if(msg.headers) {
|
|
70
|
+
// encode all other headers
|
|
71
|
+
for(var i = 0; i < msg.headers.length; ++i) {
|
|
72
|
+
rval += foldHeader(msg.headers[i]);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// terminate header
|
|
77
|
+
if(msg.procType) {
|
|
78
|
+
rval += '\r\n';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// add body
|
|
82
|
+
rval += forge.util.encode64(msg.body, options.maxline || 64) + '\r\n';
|
|
83
|
+
|
|
84
|
+
rval += '-----END ' + msg.type + '-----\r\n';
|
|
85
|
+
return rval;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Decodes (deserializes) all PEM messages found in the given string.
|
|
90
|
+
*
|
|
91
|
+
* @param str the PEM-formatted string to decode.
|
|
92
|
+
*
|
|
93
|
+
* @return the PEM message objects in an array.
|
|
94
|
+
*/
|
|
95
|
+
pem.decode = function(str) {
|
|
96
|
+
var rval = [];
|
|
97
|
+
|
|
98
|
+
// split string into PEM messages (be lenient w/EOF on BEGIN line)
|
|
99
|
+
var rMessage = /\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g;
|
|
100
|
+
var rHeader = /([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/;
|
|
101
|
+
var rCRLF = /\r?\n/;
|
|
102
|
+
var match;
|
|
103
|
+
while(true) {
|
|
104
|
+
match = rMessage.exec(str);
|
|
105
|
+
if(!match) {
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// accept "NEW CERTIFICATE REQUEST" as "CERTIFICATE REQUEST"
|
|
110
|
+
// https://datatracker.ietf.org/doc/html/rfc7468#section-7
|
|
111
|
+
var type = match[1];
|
|
112
|
+
if(type === 'NEW CERTIFICATE REQUEST') {
|
|
113
|
+
type = 'CERTIFICATE REQUEST';
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
var msg = {
|
|
117
|
+
type: type,
|
|
118
|
+
procType: null,
|
|
119
|
+
contentDomain: null,
|
|
120
|
+
dekInfo: null,
|
|
121
|
+
headers: [],
|
|
122
|
+
body: forge.util.decode64(match[3])
|
|
123
|
+
};
|
|
124
|
+
rval.push(msg);
|
|
125
|
+
|
|
126
|
+
// no headers
|
|
127
|
+
if(!match[2]) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// parse headers
|
|
132
|
+
var lines = match[2].split(rCRLF);
|
|
133
|
+
var li = 0;
|
|
134
|
+
while(match && li < lines.length) {
|
|
135
|
+
// get line, trim any rhs whitespace
|
|
136
|
+
var line = lines[li].replace(/\s+$/, '');
|
|
137
|
+
|
|
138
|
+
// RFC2822 unfold any following folded lines
|
|
139
|
+
for(var nl = li + 1; nl < lines.length; ++nl) {
|
|
140
|
+
var next = lines[nl];
|
|
141
|
+
if(!/\s/.test(next[0])) {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
line += next;
|
|
145
|
+
li = nl;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// parse header
|
|
149
|
+
match = line.match(rHeader);
|
|
150
|
+
if(match) {
|
|
151
|
+
var header = {name: match[1], values: []};
|
|
152
|
+
var values = match[2].split(',');
|
|
153
|
+
for(var vi = 0; vi < values.length; ++vi) {
|
|
154
|
+
header.values.push(ltrim(values[vi]));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Proc-Type must be the first header
|
|
158
|
+
if(!msg.procType) {
|
|
159
|
+
if(header.name !== 'Proc-Type') {
|
|
160
|
+
throw new Error('Invalid PEM formatted message. The first ' +
|
|
161
|
+
'encapsulated header must be "Proc-Type".');
|
|
162
|
+
} else if(header.values.length !== 2) {
|
|
163
|
+
throw new Error('Invalid PEM formatted message. The "Proc-Type" ' +
|
|
164
|
+
'header must have two subfields.');
|
|
165
|
+
}
|
|
166
|
+
msg.procType = {version: values[0], type: values[1]};
|
|
167
|
+
} else if(!msg.contentDomain && header.name === 'Content-Domain') {
|
|
168
|
+
// special-case Content-Domain
|
|
169
|
+
msg.contentDomain = values[0] || '';
|
|
170
|
+
} else if(!msg.dekInfo && header.name === 'DEK-Info') {
|
|
171
|
+
// special-case DEK-Info
|
|
172
|
+
if(header.values.length === 0) {
|
|
173
|
+
throw new Error('Invalid PEM formatted message. The "DEK-Info" ' +
|
|
174
|
+
'header must have at least one subfield.');
|
|
175
|
+
}
|
|
176
|
+
msg.dekInfo = {algorithm: values[0], parameters: values[1] || null};
|
|
177
|
+
} else {
|
|
178
|
+
msg.headers.push(header);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
++li;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if(msg.procType === 'ENCRYPTED' && !msg.dekInfo) {
|
|
186
|
+
throw new Error('Invalid PEM formatted message. The "DEK-Info" ' +
|
|
187
|
+
'header must be present if "Proc-Type" is "ENCRYPTED".');
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if(rval.length === 0) {
|
|
192
|
+
throw new Error('Invalid PEM formatted message.');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return rval;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
function foldHeader(header) {
|
|
199
|
+
var rval = header.name + ': ';
|
|
200
|
+
|
|
201
|
+
// ensure values with CRLF are folded
|
|
202
|
+
var values = [];
|
|
203
|
+
var insertSpace = function(match, $1) {
|
|
204
|
+
return ' ' + $1;
|
|
205
|
+
};
|
|
206
|
+
for(var i = 0; i < header.values.length; ++i) {
|
|
207
|
+
values.push(header.values[i].replace(/^(\S+\r\n)/, insertSpace));
|
|
208
|
+
}
|
|
209
|
+
rval += values.join(',') + '\r\n';
|
|
210
|
+
|
|
211
|
+
// do folding
|
|
212
|
+
var length = 0;
|
|
213
|
+
var candidate = -1;
|
|
214
|
+
for(var i = 0; i < rval.length; ++i, ++length) {
|
|
215
|
+
if(length > 65 && candidate !== -1) {
|
|
216
|
+
var insert = rval[candidate];
|
|
217
|
+
if(insert === ',') {
|
|
218
|
+
++candidate;
|
|
219
|
+
rval = rval.substr(0, candidate) + '\r\n ' + rval.substr(candidate);
|
|
220
|
+
} else {
|
|
221
|
+
rval = rval.substr(0, candidate) +
|
|
222
|
+
'\r\n' + insert + rval.substr(candidate + 1);
|
|
223
|
+
}
|
|
224
|
+
length = (i - candidate - 1);
|
|
225
|
+
candidate = -1;
|
|
226
|
+
++i;
|
|
227
|
+
} else if(rval[i] === ' ' || rval[i] === '\t' || rval[i] === ',') {
|
|
228
|
+
candidate = i;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return rval;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function ltrim(str) {
|
|
236
|
+
return str.replace(/^\s+/, '');
|
|
237
|
+
}
|