@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.
Files changed (159) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/app-path-routes-manifest.json +5 -5
  3. package/.next/standalone/.next/build-manifest.json +2 -2
  4. package/.next/standalone/.next/prerender-manifest.json +3 -3
  5. package/.next/standalone/.next/server/app/(dashboard)/mitm/page_client-reference-manifest.js +1 -1
  6. package/.next/standalone/.next/server/app/(dashboard)/page_client-reference-manifest.js +1 -1
  7. package/.next/standalone/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.html +2 -2
  9. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  13. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  14. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  15. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  16. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  17. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.rsc +3 -3
  19. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +3 -3
  20. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  21. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +3 -3
  22. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  23. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  24. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  25. package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/alias/route.js +2 -2
  26. package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/alias/route_client-reference-manifest.js +1 -1
  27. package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/console-logs/route_client-reference-manifest.js +1 -1
  28. package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/route.js +1 -1
  29. package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/route_client-reference-manifest.js +1 -1
  30. package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/settings/route.js +2 -2
  31. package/.next/standalone/.next/server/app/api/cli-tools/antigravity-mitm/settings/route_client-reference-manifest.js +1 -1
  32. package/.next/standalone/.next/server/app/api/cli-tools/claude-settings/route.js +2 -2
  33. package/.next/standalone/.next/server/app/api/cli-tools/claude-settings/route_client-reference-manifest.js +1 -1
  34. package/.next/standalone/.next/server/app/api/cli-tools/codex-settings/route.js +2 -2
  35. package/.next/standalone/.next/server/app/api/cli-tools/codex-settings/route_client-reference-manifest.js +1 -1
  36. package/.next/standalone/.next/server/app/api/cli-tools/copilot-settings/route.js +2 -2
  37. package/.next/standalone/.next/server/app/api/cli-tools/copilot-settings/route_client-reference-manifest.js +1 -1
  38. package/.next/standalone/.next/server/app/api/cli-tools/droid-settings/route.js +1 -1
  39. package/.next/standalone/.next/server/app/api/cli-tools/droid-settings/route_client-reference-manifest.js +1 -1
  40. package/.next/standalone/.next/server/app/api/cli-tools/openclaw-settings/route.js +1 -1
  41. package/.next/standalone/.next/server/app/api/cli-tools/openclaw-settings/route_client-reference-manifest.js +1 -1
  42. package/.next/standalone/.next/server/app/api/cli-tools/opencode-settings/route.js +1 -1
  43. package/.next/standalone/.next/server/app/api/cli-tools/opencode-settings/route_client-reference-manifest.js +1 -1
  44. package/.next/standalone/.next/server/app/api/keys/[id]/route_client-reference-manifest.js +1 -1
  45. package/.next/standalone/.next/server/app/api/keys/route_client-reference-manifest.js +1 -1
  46. package/.next/standalone/.next/server/app/api/locale/route.js +2 -2
  47. package/.next/standalone/.next/server/app/api/locale/route_client-reference-manifest.js +1 -1
  48. package/.next/standalone/.next/server/app/api/models/alias/route_client-reference-manifest.js +1 -1
  49. package/.next/standalone/.next/server/app/api/models/route_client-reference-manifest.js +1 -1
  50. package/.next/standalone/.next/server/app/api/providers/route_client-reference-manifest.js +1 -1
  51. package/.next/standalone/.next/server/app/api/settings/route_client-reference-manifest.js +1 -1
  52. package/.next/standalone/.next/server/app/api/version/route_client-reference-manifest.js +1 -1
  53. package/.next/standalone/.next/server/app/index.html +1 -1
  54. package/.next/standalone/.next/server/app/index.rsc +4 -4
  55. package/.next/standalone/.next/server/app/index.segments/!KGRhc2hib2FyZCk/__PAGE__.segment.rsc +1 -1
  56. package/.next/standalone/.next/server/app/index.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
  57. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +4 -4
  58. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  59. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +3 -3
  60. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  61. package/.next/standalone/.next/server/app/mitm.html +1 -1
  62. package/.next/standalone/.next/server/app/mitm.rsc +5 -5
  63. package/.next/standalone/.next/server/app/mitm.segments/!KGRhc2hib2FyZCk/mitm/__PAGE__.segment.rsc +2 -2
  64. package/.next/standalone/.next/server/app/mitm.segments/!KGRhc2hib2FyZCk/mitm.segment.rsc +1 -1
  65. package/.next/standalone/.next/server/app/mitm.segments/!KGRhc2hib2FyZCk.segment.rsc +2 -2
  66. package/.next/standalone/.next/server/app/mitm.segments/_full.segment.rsc +5 -5
  67. package/.next/standalone/.next/server/app/mitm.segments/_head.segment.rsc +1 -1
  68. package/.next/standalone/.next/server/app/mitm.segments/_index.segment.rsc +3 -3
  69. package/.next/standalone/.next/server/app/mitm.segments/_tree.segment.rsc +1 -1
  70. package/.next/standalone/.next/server/app-paths-manifest.json +5 -5
  71. package/.next/standalone/.next/server/chunks/411.js +1 -1
  72. package/.next/standalone/.next/server/middleware.js +2 -2
  73. package/.next/standalone/.next/server/pages/404.html +1 -1
  74. package/.next/standalone/.next/server/pages/500.html +2 -2
  75. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  76. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  77. package/.next/standalone/.next/static/chunks/{702-90a93bbee38dba8f.js → 702-0864796c00fc702e.js} +1 -1
  78. package/.next/standalone/node_modules/node-forge/LICENSE +331 -0
  79. package/.next/standalone/node_modules/node-forge/README.md +2071 -0
  80. package/.next/standalone/node_modules/node-forge/dist/forge.all.min.js +2 -0
  81. package/.next/standalone/node_modules/node-forge/dist/forge.all.min.js.map +1 -0
  82. package/.next/standalone/node_modules/node-forge/dist/forge.min.js +2 -0
  83. package/.next/standalone/node_modules/node-forge/dist/forge.min.js.map +1 -0
  84. package/.next/standalone/node_modules/node-forge/dist/prime.worker.min.js +2 -0
  85. package/.next/standalone/node_modules/node-forge/dist/prime.worker.min.js.map +1 -0
  86. package/.next/standalone/node_modules/node-forge/flash/swf/SocketPool.swf +0 -0
  87. package/.next/standalone/node_modules/node-forge/lib/aes.js +1091 -0
  88. package/.next/standalone/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
  89. package/.next/standalone/node_modules/node-forge/lib/asn1-validator.js +91 -0
  90. package/.next/standalone/node_modules/node-forge/lib/asn1.js +1503 -0
  91. package/.next/standalone/node_modules/node-forge/lib/baseN.js +186 -0
  92. package/.next/standalone/node_modules/node-forge/lib/cipher.js +230 -0
  93. package/.next/standalone/node_modules/node-forge/lib/cipherModes.js +999 -0
  94. package/.next/standalone/node_modules/node-forge/lib/des.js +496 -0
  95. package/.next/standalone/node_modules/node-forge/lib/ed25519.js +1072 -0
  96. package/.next/standalone/node_modules/node-forge/lib/forge.js +13 -0
  97. package/.next/standalone/node_modules/node-forge/lib/form.js +149 -0
  98. package/.next/standalone/node_modules/node-forge/lib/hmac.js +146 -0
  99. package/.next/standalone/node_modules/node-forge/lib/http.js +1346 -0
  100. package/.next/standalone/node_modules/node-forge/lib/index.all.js +16 -0
  101. package/.next/standalone/node_modules/node-forge/lib/index.js +33 -0
  102. package/.next/standalone/node_modules/node-forge/lib/jsbn.js +1264 -0
  103. package/.next/standalone/node_modules/node-forge/lib/kem.js +168 -0
  104. package/.next/standalone/node_modules/node-forge/lib/log.js +319 -0
  105. package/.next/standalone/node_modules/node-forge/lib/md.all.js +13 -0
  106. package/.next/standalone/node_modules/node-forge/lib/md.js +11 -0
  107. package/.next/standalone/node_modules/node-forge/lib/md5.js +289 -0
  108. package/.next/standalone/node_modules/node-forge/lib/mgf.js +12 -0
  109. package/.next/standalone/node_modules/node-forge/lib/mgf1.js +57 -0
  110. package/.next/standalone/node_modules/node-forge/lib/oids.js +179 -0
  111. package/.next/standalone/node_modules/node-forge/lib/pbe.js +1023 -0
  112. package/.next/standalone/node_modules/node-forge/lib/pbkdf2.js +211 -0
  113. package/.next/standalone/node_modules/node-forge/lib/pem.js +237 -0
  114. package/.next/standalone/node_modules/node-forge/lib/pkcs1.js +276 -0
  115. package/.next/standalone/node_modules/node-forge/lib/pkcs12.js +1078 -0
  116. package/.next/standalone/node_modules/node-forge/lib/pkcs7.js +1260 -0
  117. package/.next/standalone/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
  118. package/.next/standalone/node_modules/node-forge/lib/pki.js +102 -0
  119. package/.next/standalone/node_modules/node-forge/lib/prime.js +297 -0
  120. package/.next/standalone/node_modules/node-forge/lib/prime.worker.js +168 -0
  121. package/.next/standalone/node_modules/node-forge/lib/prng.js +419 -0
  122. package/.next/standalone/node_modules/node-forge/lib/pss.js +241 -0
  123. package/.next/standalone/node_modules/node-forge/lib/random.js +191 -0
  124. package/.next/standalone/node_modules/node-forge/lib/rc2.js +410 -0
  125. package/.next/standalone/node_modules/node-forge/lib/rsa.js +1949 -0
  126. package/.next/standalone/node_modules/node-forge/lib/sha1.js +319 -0
  127. package/.next/standalone/node_modules/node-forge/lib/sha256.js +327 -0
  128. package/.next/standalone/node_modules/node-forge/lib/sha512.js +561 -0
  129. package/.next/standalone/node_modules/node-forge/lib/socket.js +287 -0
  130. package/.next/standalone/node_modules/node-forge/lib/ssh.js +236 -0
  131. package/.next/standalone/node_modules/node-forge/lib/tls.js +4282 -0
  132. package/.next/standalone/node_modules/node-forge/lib/tlssocket.js +249 -0
  133. package/.next/standalone/node_modules/node-forge/lib/util.js +2652 -0
  134. package/.next/standalone/node_modules/node-forge/lib/x509.js +3242 -0
  135. package/.next/standalone/node_modules/node-forge/lib/xhr.js +738 -0
  136. package/.next/standalone/node_modules/node-forge/package.json +123 -0
  137. package/.next/standalone/node_modules/node-machine-id/.babelrc +26 -0
  138. package/.next/standalone/node_modules/node-machine-id/.eslintignore +2 -0
  139. package/.next/standalone/node_modules/node-machine-id/.eslintrc +140 -0
  140. package/.next/standalone/node_modules/node-machine-id/.flowconfig +9 -0
  141. package/.next/standalone/node_modules/node-machine-id/LICENSE +21 -0
  142. package/.next/standalone/node_modules/node-machine-id/README.md +84 -0
  143. package/.next/standalone/node_modules/node-machine-id/dist/index.js +1 -0
  144. package/.next/standalone/node_modules/node-machine-id/index.js +80 -0
  145. package/.next/standalone/node_modules/node-machine-id/package.json +74 -0
  146. package/.next/standalone/node_modules/node-machine-id/tests/index.js +45 -0
  147. package/.next/standalone/node_modules/node-machine-id/types/index.d.ts +17 -0
  148. package/.next/standalone/node_modules/node-machine-id/webpack.config.babel.js +59 -0
  149. package/.next/standalone/package.json +1 -1
  150. package/.next/standalone/src/mitm/cert/generate.js +32 -0
  151. package/.next/standalone/src/mitm/cert/install.js +176 -0
  152. package/.next/standalone/src/mitm/cert/rootCA.js +173 -0
  153. package/.next/standalone/src/mitm/dns/dnsConfig.js +216 -0
  154. package/.next/standalone/src/mitm/logger.js +8 -0
  155. package/.next/standalone/src/mitm/manager.js +603 -0
  156. package/.next/standalone/src/mitm/paths.js +16 -0
  157. package/package.json +1 -1
  158. /package/.next/standalone/.next/static/{Ws7kclTEFgfHRwd7pk9Ly → DkVxg6bby4SUixuq1vdO8}/_buildManifest.js +0 -0
  159. /package/.next/standalone/.next/static/{Ws7kclTEFgfHRwd7pk9Ly → DkVxg6bby4SUixuq1vdO8}/_ssgManifest.js +0 -0
@@ -0,0 +1,282 @@
1
+ /**
2
+ * A Javascript implementation of AES Cipher Suites for TLS.
3
+ *
4
+ * @author Dave Longley
5
+ *
6
+ * Copyright (c) 2009-2015 Digital Bazaar, Inc.
7
+ *
8
+ */
9
+ var forge = require('./forge');
10
+ require('./aes');
11
+ require('./tls');
12
+
13
+ var tls = module.exports = forge.tls;
14
+
15
+ /**
16
+ * Supported cipher suites.
17
+ */
18
+ tls.CipherSuites['TLS_RSA_WITH_AES_128_CBC_SHA'] = {
19
+ id: [0x00, 0x2f],
20
+ name: 'TLS_RSA_WITH_AES_128_CBC_SHA',
21
+ initSecurityParameters: function(sp) {
22
+ sp.bulk_cipher_algorithm = tls.BulkCipherAlgorithm.aes;
23
+ sp.cipher_type = tls.CipherType.block;
24
+ sp.enc_key_length = 16;
25
+ sp.block_length = 16;
26
+ sp.fixed_iv_length = 16;
27
+ sp.record_iv_length = 16;
28
+ sp.mac_algorithm = tls.MACAlgorithm.hmac_sha1;
29
+ sp.mac_length = 20;
30
+ sp.mac_key_length = 20;
31
+ },
32
+ initConnectionState: initConnectionState
33
+ };
34
+ tls.CipherSuites['TLS_RSA_WITH_AES_256_CBC_SHA'] = {
35
+ id: [0x00, 0x35],
36
+ name: 'TLS_RSA_WITH_AES_256_CBC_SHA',
37
+ initSecurityParameters: function(sp) {
38
+ sp.bulk_cipher_algorithm = tls.BulkCipherAlgorithm.aes;
39
+ sp.cipher_type = tls.CipherType.block;
40
+ sp.enc_key_length = 32;
41
+ sp.block_length = 16;
42
+ sp.fixed_iv_length = 16;
43
+ sp.record_iv_length = 16;
44
+ sp.mac_algorithm = tls.MACAlgorithm.hmac_sha1;
45
+ sp.mac_length = 20;
46
+ sp.mac_key_length = 20;
47
+ },
48
+ initConnectionState: initConnectionState
49
+ };
50
+
51
+ function initConnectionState(state, c, sp) {
52
+ var client = (c.entity === forge.tls.ConnectionEnd.client);
53
+
54
+ // cipher setup
55
+ state.read.cipherState = {
56
+ init: false,
57
+ cipher: forge.cipher.createDecipher('AES-CBC', client ?
58
+ sp.keys.server_write_key : sp.keys.client_write_key),
59
+ iv: client ? sp.keys.server_write_IV : sp.keys.client_write_IV
60
+ };
61
+ state.write.cipherState = {
62
+ init: false,
63
+ cipher: forge.cipher.createCipher('AES-CBC', client ?
64
+ sp.keys.client_write_key : sp.keys.server_write_key),
65
+ iv: client ? sp.keys.client_write_IV : sp.keys.server_write_IV
66
+ };
67
+ state.read.cipherFunction = decrypt_aes_cbc_sha1;
68
+ state.write.cipherFunction = encrypt_aes_cbc_sha1;
69
+
70
+ // MAC setup
71
+ state.read.macLength = state.write.macLength = sp.mac_length;
72
+ state.read.macFunction = state.write.macFunction = tls.hmac_sha1;
73
+ }
74
+
75
+ /**
76
+ * Encrypts the TLSCompressed record into a TLSCipherText record using AES
77
+ * in CBC mode.
78
+ *
79
+ * @param record the TLSCompressed record to encrypt.
80
+ * @param s the ConnectionState to use.
81
+ *
82
+ * @return true on success, false on failure.
83
+ */
84
+ function encrypt_aes_cbc_sha1(record, s) {
85
+ var rval = false;
86
+
87
+ // append MAC to fragment, update sequence number
88
+ var mac = s.macFunction(s.macKey, s.sequenceNumber, record);
89
+ record.fragment.putBytes(mac);
90
+ s.updateSequenceNumber();
91
+
92
+ // TLS 1.1+ use an explicit IV every time to protect against CBC attacks
93
+ var iv;
94
+ if(record.version.minor === tls.Versions.TLS_1_0.minor) {
95
+ // use the pre-generated IV when initializing for TLS 1.0, otherwise use
96
+ // the residue from the previous encryption
97
+ iv = s.cipherState.init ? null : s.cipherState.iv;
98
+ } else {
99
+ iv = forge.random.getBytesSync(16);
100
+ }
101
+
102
+ s.cipherState.init = true;
103
+
104
+ // start cipher
105
+ var cipher = s.cipherState.cipher;
106
+ cipher.start({iv: iv});
107
+
108
+ // TLS 1.1+ write IV into output
109
+ if(record.version.minor >= tls.Versions.TLS_1_1.minor) {
110
+ cipher.output.putBytes(iv);
111
+ }
112
+
113
+ // do encryption (default padding is appropriate)
114
+ cipher.update(record.fragment);
115
+ if(cipher.finish(encrypt_aes_cbc_sha1_padding)) {
116
+ // set record fragment to encrypted output
117
+ record.fragment = cipher.output;
118
+ record.length = record.fragment.length();
119
+ rval = true;
120
+ }
121
+
122
+ return rval;
123
+ }
124
+
125
+ /**
126
+ * Handles padding for aes_cbc_sha1 in encrypt mode.
127
+ *
128
+ * @param blockSize the block size.
129
+ * @param input the input buffer.
130
+ * @param decrypt true in decrypt mode, false in encrypt mode.
131
+ *
132
+ * @return true on success, false on failure.
133
+ */
134
+ function encrypt_aes_cbc_sha1_padding(blockSize, input, decrypt) {
135
+ /* The encrypted data length (TLSCiphertext.length) is one more than the sum
136
+ of SecurityParameters.block_length, TLSCompressed.length,
137
+ SecurityParameters.mac_length, and padding_length.
138
+
139
+ The padding may be any length up to 255 bytes long, as long as it results in
140
+ the TLSCiphertext.length being an integral multiple of the block length.
141
+ Lengths longer than necessary might be desirable to frustrate attacks on a
142
+ protocol based on analysis of the lengths of exchanged messages. Each uint8
143
+ in the padding data vector must be filled with the padding length value.
144
+
145
+ The padding length should be such that the total size of the
146
+ GenericBlockCipher structure is a multiple of the cipher's block length.
147
+ Legal values range from zero to 255, inclusive. This length specifies the
148
+ length of the padding field exclusive of the padding_length field itself.
149
+
150
+ This is slightly different from PKCS#7 because the padding value is 1
151
+ less than the actual number of padding bytes if you include the
152
+ padding_length uint8 itself as a padding byte. */
153
+ if(!decrypt) {
154
+ // get the number of padding bytes required to reach the blockSize and
155
+ // subtract 1 for the padding value (to make room for the padding_length
156
+ // uint8)
157
+ var padding = blockSize - (input.length() % blockSize);
158
+ input.fillWithByte(padding - 1, padding);
159
+ }
160
+ return true;
161
+ }
162
+
163
+ /**
164
+ * Handles padding for aes_cbc_sha1 in decrypt mode.
165
+ *
166
+ * @param blockSize the block size.
167
+ * @param output the output buffer.
168
+ * @param decrypt true in decrypt mode, false in encrypt mode.
169
+ *
170
+ * @return true on success, false on failure.
171
+ */
172
+ function decrypt_aes_cbc_sha1_padding(blockSize, output, decrypt) {
173
+ var rval = true;
174
+ if(decrypt) {
175
+ /* The last byte in the output specifies the number of padding bytes not
176
+ including itself. Each of the padding bytes has the same value as that
177
+ last byte (known as the padding_length). Here we check all padding
178
+ bytes to ensure they have the value of padding_length even if one of
179
+ them is bad in order to ward-off timing attacks. */
180
+ var len = output.length();
181
+ var paddingLength = output.last();
182
+ for(var i = len - 1 - paddingLength; i < len - 1; ++i) {
183
+ rval = rval && (output.at(i) == paddingLength);
184
+ }
185
+ if(rval) {
186
+ // trim off padding bytes and last padding length byte
187
+ output.truncate(paddingLength + 1);
188
+ }
189
+ }
190
+ return rval;
191
+ }
192
+
193
+ /**
194
+ * Decrypts a TLSCipherText record into a TLSCompressed record using
195
+ * AES in CBC mode.
196
+ *
197
+ * @param record the TLSCipherText record to decrypt.
198
+ * @param s the ConnectionState to use.
199
+ *
200
+ * @return true on success, false on failure.
201
+ */
202
+ function decrypt_aes_cbc_sha1(record, s) {
203
+ var rval = false;
204
+
205
+ var iv;
206
+ if(record.version.minor === tls.Versions.TLS_1_0.minor) {
207
+ // use pre-generated IV when initializing for TLS 1.0, otherwise use the
208
+ // residue from the previous decryption
209
+ iv = s.cipherState.init ? null : s.cipherState.iv;
210
+ } else {
211
+ // TLS 1.1+ use an explicit IV every time to protect against CBC attacks
212
+ // that is appended to the record fragment
213
+ iv = record.fragment.getBytes(16);
214
+ }
215
+
216
+ s.cipherState.init = true;
217
+
218
+ // start cipher
219
+ var cipher = s.cipherState.cipher;
220
+ cipher.start({iv: iv});
221
+
222
+ // do decryption
223
+ cipher.update(record.fragment);
224
+ rval = cipher.finish(decrypt_aes_cbc_sha1_padding);
225
+
226
+ // even if decryption fails, keep going to minimize timing attacks
227
+
228
+ // decrypted data:
229
+ // first (len - 20) bytes = application data
230
+ // last 20 bytes = MAC
231
+ var macLen = s.macLength;
232
+
233
+ // create a random MAC to check against should the mac length check fail
234
+ // Note: do this regardless of the failure to keep timing consistent
235
+ var mac = forge.random.getBytesSync(macLen);
236
+
237
+ // get fragment and mac
238
+ var len = cipher.output.length();
239
+ if(len >= macLen) {
240
+ record.fragment = cipher.output.getBytes(len - macLen);
241
+ mac = cipher.output.getBytes(macLen);
242
+ } else {
243
+ // bad data, but get bytes anyway to try to keep timing consistent
244
+ record.fragment = cipher.output.getBytes();
245
+ }
246
+ record.fragment = forge.util.createBuffer(record.fragment);
247
+ record.length = record.fragment.length();
248
+
249
+ // see if data integrity checks out, update sequence number
250
+ var mac2 = s.macFunction(s.macKey, s.sequenceNumber, record);
251
+ s.updateSequenceNumber();
252
+ rval = compareMacs(s.macKey, mac, mac2) && rval;
253
+ return rval;
254
+ }
255
+
256
+ /**
257
+ * Safely compare two MACs. This function will compare two MACs in a way
258
+ * that protects against timing attacks.
259
+ *
260
+ * TODO: Expose elsewhere as a utility API.
261
+ *
262
+ * See: https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/
263
+ *
264
+ * @param key the MAC key to use.
265
+ * @param mac1 as a binary-encoded string of bytes.
266
+ * @param mac2 as a binary-encoded string of bytes.
267
+ *
268
+ * @return true if the MACs are the same, false if not.
269
+ */
270
+ function compareMacs(key, mac1, mac2) {
271
+ var hmac = forge.hmac.create();
272
+
273
+ hmac.start('SHA1', key);
274
+ hmac.update(mac1);
275
+ mac1 = hmac.digest().getBytes();
276
+
277
+ hmac.start(null, null);
278
+ hmac.update(mac2);
279
+ mac2 = hmac.digest().getBytes();
280
+
281
+ return mac1 === mac2;
282
+ }
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Copyright (c) 2019 Digital Bazaar, Inc.
3
+ */
4
+
5
+ var forge = require('./forge');
6
+ require('./asn1');
7
+ var asn1 = forge.asn1;
8
+
9
+ exports.privateKeyValidator = {
10
+ // PrivateKeyInfo
11
+ name: 'PrivateKeyInfo',
12
+ tagClass: asn1.Class.UNIVERSAL,
13
+ type: asn1.Type.SEQUENCE,
14
+ constructed: true,
15
+ value: [{
16
+ // Version (INTEGER)
17
+ name: 'PrivateKeyInfo.version',
18
+ tagClass: asn1.Class.UNIVERSAL,
19
+ type: asn1.Type.INTEGER,
20
+ constructed: false,
21
+ capture: 'privateKeyVersion'
22
+ }, {
23
+ // privateKeyAlgorithm
24
+ name: 'PrivateKeyInfo.privateKeyAlgorithm',
25
+ tagClass: asn1.Class.UNIVERSAL,
26
+ type: asn1.Type.SEQUENCE,
27
+ constructed: true,
28
+ value: [{
29
+ name: 'AlgorithmIdentifier.algorithm',
30
+ tagClass: asn1.Class.UNIVERSAL,
31
+ type: asn1.Type.OID,
32
+ constructed: false,
33
+ capture: 'privateKeyOid'
34
+ }]
35
+ }, {
36
+ // PrivateKey
37
+ name: 'PrivateKeyInfo',
38
+ tagClass: asn1.Class.UNIVERSAL,
39
+ type: asn1.Type.OCTETSTRING,
40
+ constructed: false,
41
+ capture: 'privateKey'
42
+ }]
43
+ };
44
+
45
+ exports.publicKeyValidator = {
46
+ name: 'SubjectPublicKeyInfo',
47
+ tagClass: asn1.Class.UNIVERSAL,
48
+ type: asn1.Type.SEQUENCE,
49
+ constructed: true,
50
+ captureAsn1: 'subjectPublicKeyInfo',
51
+ value: [{
52
+ name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
53
+ tagClass: asn1.Class.UNIVERSAL,
54
+ type: asn1.Type.SEQUENCE,
55
+ constructed: true,
56
+ value: [{
57
+ name: 'AlgorithmIdentifier.algorithm',
58
+ tagClass: asn1.Class.UNIVERSAL,
59
+ type: asn1.Type.OID,
60
+ constructed: false,
61
+ capture: 'publicKeyOid'
62
+ }]
63
+ },
64
+ // capture group for ed25519PublicKey
65
+ {
66
+ tagClass: asn1.Class.UNIVERSAL,
67
+ type: asn1.Type.BITSTRING,
68
+ constructed: false,
69
+ composed: true,
70
+ captureBitStringValue: 'ed25519PublicKey'
71
+ }
72
+ // FIXME: this is capture group for rsaPublicKey, use it in this API or
73
+ // discard?
74
+ /* {
75
+ // subjectPublicKey
76
+ name: 'SubjectPublicKeyInfo.subjectPublicKey',
77
+ tagClass: asn1.Class.UNIVERSAL,
78
+ type: asn1.Type.BITSTRING,
79
+ constructed: false,
80
+ value: [{
81
+ // RSAPublicKey
82
+ name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey',
83
+ tagClass: asn1.Class.UNIVERSAL,
84
+ type: asn1.Type.SEQUENCE,
85
+ constructed: true,
86
+ optional: true,
87
+ captureAsn1: 'rsaPublicKey'
88
+ }]
89
+ } */
90
+ ]
91
+ };