@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,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Partial implementation of PKCS#1 v2.2: RSA-OEAP
|
|
3
|
+
*
|
|
4
|
+
* Modified but based on the following MIT and BSD licensed code:
|
|
5
|
+
*
|
|
6
|
+
* https://github.com/kjur/jsjws/blob/master/rsa.js:
|
|
7
|
+
*
|
|
8
|
+
* The 'jsjws'(JSON Web Signature JavaScript Library) License
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2012 Kenji Urushima
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in
|
|
20
|
+
* all copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
28
|
+
* THE SOFTWARE.
|
|
29
|
+
*
|
|
30
|
+
* http://webrsa.cvs.sourceforge.net/viewvc/webrsa/Client/RSAES-OAEP.js?content-type=text%2Fplain:
|
|
31
|
+
*
|
|
32
|
+
* RSAES-OAEP.js
|
|
33
|
+
* $Id: RSAES-OAEP.js,v 1.1.1.1 2003/03/19 15:37:20 ellispritchard Exp $
|
|
34
|
+
* JavaScript Implementation of PKCS #1 v2.1 RSA CRYPTOGRAPHY STANDARD (RSA Laboratories, June 14, 2002)
|
|
35
|
+
* Copyright (C) Ellis Pritchard, Guardian Unlimited 2003.
|
|
36
|
+
* Contact: ellis@nukinetics.com
|
|
37
|
+
* Distributed under the BSD License.
|
|
38
|
+
*
|
|
39
|
+
* Official documentation: http://www.rsa.com/rsalabs/node.asp?id=2125
|
|
40
|
+
*
|
|
41
|
+
* @author Evan Jones (http://evanjones.ca/)
|
|
42
|
+
* @author Dave Longley
|
|
43
|
+
*
|
|
44
|
+
* Copyright (c) 2013-2014 Digital Bazaar, Inc.
|
|
45
|
+
*/
|
|
46
|
+
var forge = require('./forge');
|
|
47
|
+
require('./util');
|
|
48
|
+
require('./random');
|
|
49
|
+
require('./sha1');
|
|
50
|
+
|
|
51
|
+
// shortcut for PKCS#1 API
|
|
52
|
+
var pkcs1 = module.exports = forge.pkcs1 = forge.pkcs1 || {};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Encode the given RSAES-OAEP message (M) using key, with optional label (L)
|
|
56
|
+
* and seed.
|
|
57
|
+
*
|
|
58
|
+
* This method does not perform RSA encryption, it only encodes the message
|
|
59
|
+
* using RSAES-OAEP.
|
|
60
|
+
*
|
|
61
|
+
* @param key the RSA key to use.
|
|
62
|
+
* @param message the message to encode.
|
|
63
|
+
* @param options the options to use:
|
|
64
|
+
* label an optional label to use.
|
|
65
|
+
* seed the seed to use.
|
|
66
|
+
* md the message digest object to use, undefined for SHA-1.
|
|
67
|
+
* mgf1 optional mgf1 parameters:
|
|
68
|
+
* md the message digest object to use for MGF1.
|
|
69
|
+
*
|
|
70
|
+
* @return the encoded message bytes.
|
|
71
|
+
*/
|
|
72
|
+
pkcs1.encode_rsa_oaep = function(key, message, options) {
|
|
73
|
+
// parse arguments
|
|
74
|
+
var label;
|
|
75
|
+
var seed;
|
|
76
|
+
var md;
|
|
77
|
+
var mgf1Md;
|
|
78
|
+
// legacy args (label, seed, md)
|
|
79
|
+
if(typeof options === 'string') {
|
|
80
|
+
label = options;
|
|
81
|
+
seed = arguments[3] || undefined;
|
|
82
|
+
md = arguments[4] || undefined;
|
|
83
|
+
} else if(options) {
|
|
84
|
+
label = options.label || undefined;
|
|
85
|
+
seed = options.seed || undefined;
|
|
86
|
+
md = options.md || undefined;
|
|
87
|
+
if(options.mgf1 && options.mgf1.md) {
|
|
88
|
+
mgf1Md = options.mgf1.md;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// default OAEP to SHA-1 message digest
|
|
93
|
+
if(!md) {
|
|
94
|
+
md = forge.md.sha1.create();
|
|
95
|
+
} else {
|
|
96
|
+
md.start();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// default MGF-1 to same as OAEP
|
|
100
|
+
if(!mgf1Md) {
|
|
101
|
+
mgf1Md = md;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// compute length in bytes and check output
|
|
105
|
+
var keyLength = Math.ceil(key.n.bitLength() / 8);
|
|
106
|
+
var maxLength = keyLength - 2 * md.digestLength - 2;
|
|
107
|
+
if(message.length > maxLength) {
|
|
108
|
+
var error = new Error('RSAES-OAEP input message length is too long.');
|
|
109
|
+
error.length = message.length;
|
|
110
|
+
error.maxLength = maxLength;
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if(!label) {
|
|
115
|
+
label = '';
|
|
116
|
+
}
|
|
117
|
+
md.update(label, 'raw');
|
|
118
|
+
var lHash = md.digest();
|
|
119
|
+
|
|
120
|
+
var PS = '';
|
|
121
|
+
var PS_length = maxLength - message.length;
|
|
122
|
+
for(var i = 0; i < PS_length; i++) {
|
|
123
|
+
PS += '\x00';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
var DB = lHash.getBytes() + PS + '\x01' + message;
|
|
127
|
+
|
|
128
|
+
if(!seed) {
|
|
129
|
+
seed = forge.random.getBytes(md.digestLength);
|
|
130
|
+
} else if(seed.length !== md.digestLength) {
|
|
131
|
+
var error = new Error('Invalid RSAES-OAEP seed. The seed length must ' +
|
|
132
|
+
'match the digest length.');
|
|
133
|
+
error.seedLength = seed.length;
|
|
134
|
+
error.digestLength = md.digestLength;
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
var dbMask = rsa_mgf1(seed, keyLength - md.digestLength - 1, mgf1Md);
|
|
139
|
+
var maskedDB = forge.util.xorBytes(DB, dbMask, DB.length);
|
|
140
|
+
|
|
141
|
+
var seedMask = rsa_mgf1(maskedDB, md.digestLength, mgf1Md);
|
|
142
|
+
var maskedSeed = forge.util.xorBytes(seed, seedMask, seed.length);
|
|
143
|
+
|
|
144
|
+
// return encoded message
|
|
145
|
+
return '\x00' + maskedSeed + maskedDB;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Decode the given RSAES-OAEP encoded message (EM) using key, with optional
|
|
150
|
+
* label (L).
|
|
151
|
+
*
|
|
152
|
+
* This method does not perform RSA decryption, it only decodes the message
|
|
153
|
+
* using RSAES-OAEP.
|
|
154
|
+
*
|
|
155
|
+
* @param key the RSA key to use.
|
|
156
|
+
* @param em the encoded message to decode.
|
|
157
|
+
* @param options the options to use:
|
|
158
|
+
* label an optional label to use.
|
|
159
|
+
* md the message digest object to use for OAEP, undefined for SHA-1.
|
|
160
|
+
* mgf1 optional mgf1 parameters:
|
|
161
|
+
* md the message digest object to use for MGF1.
|
|
162
|
+
*
|
|
163
|
+
* @return the decoded message bytes.
|
|
164
|
+
*/
|
|
165
|
+
pkcs1.decode_rsa_oaep = function(key, em, options) {
|
|
166
|
+
// parse args
|
|
167
|
+
var label;
|
|
168
|
+
var md;
|
|
169
|
+
var mgf1Md;
|
|
170
|
+
// legacy args
|
|
171
|
+
if(typeof options === 'string') {
|
|
172
|
+
label = options;
|
|
173
|
+
md = arguments[3] || undefined;
|
|
174
|
+
} else if(options) {
|
|
175
|
+
label = options.label || undefined;
|
|
176
|
+
md = options.md || undefined;
|
|
177
|
+
if(options.mgf1 && options.mgf1.md) {
|
|
178
|
+
mgf1Md = options.mgf1.md;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// compute length in bytes
|
|
183
|
+
var keyLength = Math.ceil(key.n.bitLength() / 8);
|
|
184
|
+
|
|
185
|
+
if(em.length !== keyLength) {
|
|
186
|
+
var error = new Error('RSAES-OAEP encoded message length is invalid.');
|
|
187
|
+
error.length = em.length;
|
|
188
|
+
error.expectedLength = keyLength;
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// default OAEP to SHA-1 message digest
|
|
193
|
+
if(md === undefined) {
|
|
194
|
+
md = forge.md.sha1.create();
|
|
195
|
+
} else {
|
|
196
|
+
md.start();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// default MGF-1 to same as OAEP
|
|
200
|
+
if(!mgf1Md) {
|
|
201
|
+
mgf1Md = md;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if(keyLength < 2 * md.digestLength + 2) {
|
|
205
|
+
throw new Error('RSAES-OAEP key is too short for the hash function.');
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if(!label) {
|
|
209
|
+
label = '';
|
|
210
|
+
}
|
|
211
|
+
md.update(label, 'raw');
|
|
212
|
+
var lHash = md.digest().getBytes();
|
|
213
|
+
|
|
214
|
+
// split the message into its parts
|
|
215
|
+
var y = em.charAt(0);
|
|
216
|
+
var maskedSeed = em.substring(1, md.digestLength + 1);
|
|
217
|
+
var maskedDB = em.substring(1 + md.digestLength);
|
|
218
|
+
|
|
219
|
+
var seedMask = rsa_mgf1(maskedDB, md.digestLength, mgf1Md);
|
|
220
|
+
var seed = forge.util.xorBytes(maskedSeed, seedMask, maskedSeed.length);
|
|
221
|
+
|
|
222
|
+
var dbMask = rsa_mgf1(seed, keyLength - md.digestLength - 1, mgf1Md);
|
|
223
|
+
var db = forge.util.xorBytes(maskedDB, dbMask, maskedDB.length);
|
|
224
|
+
|
|
225
|
+
var lHashPrime = db.substring(0, md.digestLength);
|
|
226
|
+
|
|
227
|
+
// constant time check that all values match what is expected
|
|
228
|
+
var error = (y !== '\x00');
|
|
229
|
+
|
|
230
|
+
// constant time check lHash vs lHashPrime
|
|
231
|
+
for(var i = 0; i < md.digestLength; ++i) {
|
|
232
|
+
error |= (lHash.charAt(i) !== lHashPrime.charAt(i));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// "constant time" find the 0x1 byte separating the padding (zeros) from the
|
|
236
|
+
// message
|
|
237
|
+
// TODO: It must be possible to do this in a better/smarter way?
|
|
238
|
+
var in_ps = 1;
|
|
239
|
+
var index = md.digestLength;
|
|
240
|
+
for(var j = md.digestLength; j < db.length; j++) {
|
|
241
|
+
var code = db.charCodeAt(j);
|
|
242
|
+
|
|
243
|
+
var is_0 = (code & 0x1) ^ 0x1;
|
|
244
|
+
|
|
245
|
+
// non-zero if not 0 or 1 in the ps section
|
|
246
|
+
var error_mask = in_ps ? 0xfffe : 0x0000;
|
|
247
|
+
error |= (code & error_mask);
|
|
248
|
+
|
|
249
|
+
// latch in_ps to zero after we find 0x1
|
|
250
|
+
in_ps = in_ps & is_0;
|
|
251
|
+
index += in_ps;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if(error || db.charCodeAt(index) !== 0x1) {
|
|
255
|
+
throw new Error('Invalid RSAES-OAEP padding.');
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return db.substring(index + 1);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
function rsa_mgf1(seed, maskLength, hash) {
|
|
262
|
+
// default to SHA-1 message digest
|
|
263
|
+
if(!hash) {
|
|
264
|
+
hash = forge.md.sha1.create();
|
|
265
|
+
}
|
|
266
|
+
var t = '';
|
|
267
|
+
var count = Math.ceil(maskLength / hash.digestLength);
|
|
268
|
+
for(var i = 0; i < count; ++i) {
|
|
269
|
+
var c = String.fromCharCode(
|
|
270
|
+
(i >> 24) & 0xFF, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF);
|
|
271
|
+
hash.start();
|
|
272
|
+
hash.update(seed + c);
|
|
273
|
+
t += hash.digest().getBytes();
|
|
274
|
+
}
|
|
275
|
+
return t.substring(0, maskLength);
|
|
276
|
+
}
|