@protontech/openpgp 4.10.8 → 5.3.1
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/README.md +311 -239
- package/dist/lightweight/bn.interface.min.mjs +3 -0
- package/dist/lightweight/bn.interface.min.mjs.map +1 -0
- package/dist/lightweight/bn.interface.mjs +340 -0
- package/dist/lightweight/bn.min.mjs +3 -0
- package/dist/lightweight/bn.min.mjs.map +1 -0
- package/dist/lightweight/bn.mjs +3434 -0
- package/dist/lightweight/elliptic.min.mjs +3 -0
- package/dist/lightweight/elliptic.min.mjs.map +1 -0
- package/dist/lightweight/elliptic.mjs +4313 -0
- package/dist/lightweight/openpgp.min.mjs +3 -0
- package/dist/lightweight/openpgp.min.mjs.map +1 -0
- package/dist/lightweight/openpgp.mjs +31375 -0
- package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
- package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
- package/dist/lightweight/ponyfill.es6.mjs +3831 -0
- package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
- package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
- package/dist/lightweight/web-streams-adapter.mjs +561 -0
- package/dist/node/openpgp.js +43943 -0
- package/dist/node/openpgp.min.js +17 -0
- package/dist/node/openpgp.min.js.map +1 -0
- package/dist/node/openpgp.min.mjs +17 -0
- package/dist/node/openpgp.min.mjs.map +1 -0
- package/dist/node/openpgp.mjs +43880 -0
- package/dist/openpgp.js +41077 -41609
- package/dist/openpgp.min.js +17 -2
- package/dist/openpgp.min.js.map +1 -0
- package/dist/openpgp.min.mjs +17 -0
- package/dist/openpgp.min.mjs.map +1 -0
- package/dist/openpgp.mjs +43868 -0
- package/lightweight/package.json +5 -0
- package/openpgp.d.ts +889 -0
- package/package.json +63 -57
- package/dist/compat/openpgp.js +0 -61152
- package/dist/compat/openpgp.min.js +0 -2
- package/dist/compat/openpgp.worker.js +0 -173
- package/dist/compat/openpgp.worker.min.js +0 -2
- package/dist/lightweight/elliptic.min.js +0 -5
- package/dist/lightweight/openpgp.js +0 -40071
- package/dist/lightweight/openpgp.min.js +0 -2
- package/dist/lightweight/openpgp.worker.js +0 -173
- package/dist/lightweight/openpgp.worker.min.js +0 -2
- package/dist/openpgp.worker.js +0 -173
- package/dist/openpgp.worker.min.js +0 -2
- package/src/cleartext.js +0 -220
- package/src/config/config.js +0 -232
- package/src/config/index.js +0 -7
- package/src/config/localStorage.js +0 -35
- package/src/crypto/aes_kw.js +0 -153
- package/src/crypto/cfb.js +0 -169
- package/src/crypto/cipher/aes.js +0 -27
- package/src/crypto/cipher/blowfish.js +0 -398
- package/src/crypto/cipher/cast5.js +0 -610
- package/src/crypto/cipher/des.js +0 -476
- package/src/crypto/cipher/index.js +0 -91
- package/src/crypto/cipher/twofish.js +0 -346
- package/src/crypto/cmac.js +0 -98
- package/src/crypto/crypto.js +0 -394
- package/src/crypto/eax.js +0 -172
- package/src/crypto/gcm.js +0 -141
- package/src/crypto/hash/index.js +0 -163
- package/src/crypto/hash/md5.js +0 -205
- package/src/crypto/index.js +0 -57
- package/src/crypto/ocb.js +0 -274
- package/src/crypto/pkcs1.js +0 -170
- package/src/crypto/pkcs5.js +0 -55
- package/src/crypto/public_key/dsa.js +0 -188
- package/src/crypto/public_key/elgamal.js +0 -137
- package/src/crypto/public_key/elliptic/curves.js +0 -385
- package/src/crypto/public_key/elliptic/ecdh.js +0 -414
- package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
- package/src/crypto/public_key/elliptic/eddsa.js +0 -119
- package/src/crypto/public_key/elliptic/index.js +0 -34
- package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
- package/src/crypto/public_key/index.js +0 -28
- package/src/crypto/public_key/prime.js +0 -275
- package/src/crypto/public_key/rsa.js +0 -597
- package/src/crypto/random.js +0 -145
- package/src/crypto/signature.js +0 -137
- package/src/encoding/armor.js +0 -433
- package/src/encoding/base64.js +0 -96
- package/src/enums.js +0 -493
- package/src/hkp.js +0 -89
- package/src/index.js +0 -161
- package/src/key/factory.js +0 -326
- package/src/key/helper.js +0 -378
- package/src/key/index.js +0 -32
- package/src/key/key.js +0 -888
- package/src/key/subkey.js +0 -187
- package/src/key/user.js +0 -230
- package/src/keyring/index.js +0 -12
- package/src/keyring/keyring.js +0 -229
- package/src/keyring/localstore.js +0 -119
- package/src/lightweight_helper.js +0 -26
- package/src/message.js +0 -825
- package/src/openpgp.js +0 -717
- package/src/packet/all_packets.js +0 -116
- package/src/packet/clone.js +0 -189
- package/src/packet/compressed.js +0 -194
- package/src/packet/index.js +0 -20
- package/src/packet/literal.js +0 -168
- package/src/packet/marker.js +0 -62
- package/src/packet/one_pass_signature.js +0 -156
- package/src/packet/packet.js +0 -300
- package/src/packet/packetlist.js +0 -232
- package/src/packet/public_key.js +0 -280
- package/src/packet/public_key_encrypted_session_key.js +0 -161
- package/src/packet/public_subkey.js +0 -44
- package/src/packet/secret_key.js +0 -468
- package/src/packet/secret_subkey.js +0 -41
- package/src/packet/signature.js +0 -786
- package/src/packet/sym_encrypted_aead_protected.js +0 -189
- package/src/packet/sym_encrypted_integrity_protected.js +0 -139
- package/src/packet/sym_encrypted_session_key.js +0 -204
- package/src/packet/symmetrically_encrypted.js +0 -118
- package/src/packet/trust.js +0 -35
- package/src/packet/user_attribute.js +0 -94
- package/src/packet/userid.js +0 -87
- package/src/polyfills.js +0 -64
- package/src/signature.js +0 -73
- package/src/type/ecdh_symkey.js +0 -69
- package/src/type/kdf_params.js +0 -114
- package/src/type/keyid.js +0 -110
- package/src/type/mpi.js +0 -138
- package/src/type/oid.js +0 -110
- package/src/type/s2k.js +0 -203
- package/src/util.js +0 -836
- package/src/wkd.js +0 -84
- package/src/worker/async_proxy.js +0 -190
- package/src/worker/worker.js +0 -167
- package/test/crypto/aes_kw.js +0 -57
- package/test/crypto/cipher/aes.js +0 -86
- package/test/crypto/cipher/blowfish.js +0 -58
- package/test/crypto/cipher/cast5.js +0 -25
- package/test/crypto/cipher/des.js +0 -143
- package/test/crypto/cipher/index.js +0 -7
- package/test/crypto/cipher/twofish.js +0 -71
- package/test/crypto/crypto.js +0 -383
- package/test/crypto/eax.js +0 -150
- package/test/crypto/ecdh.js +0 -359
- package/test/crypto/elliptic.js +0 -251
- package/test/crypto/elliptic_data.js +0 -102
- package/test/crypto/hash/index.js +0 -5
- package/test/crypto/hash/md5.js +0 -16
- package/test/crypto/hash/ripemd.js +0 -14
- package/test/crypto/hash/sha.js +0 -20
- package/test/crypto/index.js +0 -14
- package/test/crypto/ocb.js +0 -183
- package/test/crypto/pkcs5.js +0 -39
- package/test/crypto/random.js +0 -79
- package/test/crypto/rsa.js +0 -180
- package/test/crypto/validate.js +0 -387
- package/test/general/armor.js +0 -408
- package/test/general/brainpool.js +0 -360
- package/test/general/decompression.js +0 -60
- package/test/general/ecc_nist.js +0 -115
- package/test/general/ecc_secp256k1.js +0 -242
- package/test/general/forwarding.js +0 -43
- package/test/general/hkp.js +0 -165
- package/test/general/index.js +0 -20
- package/test/general/key.js +0 -3491
- package/test/general/keyring.js +0 -336
- package/test/general/oid.js +0 -39
- package/test/general/openpgp.js +0 -2577
- package/test/general/packet.js +0 -950
- package/test/general/signature.js +0 -1715
- package/test/general/streaming.js +0 -944
- package/test/general/testInputs.js +0 -18
- package/test/general/util.js +0 -183
- package/test/general/wkd.js +0 -48
- package/test/general/x25519.js +0 -556
- package/test/unittests.js +0 -64
package/src/config/config.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2011 Recurity Labs GmbH
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Global configuration values.
|
|
20
|
-
* @requires enums
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import enums from '../enums';
|
|
24
|
-
|
|
25
|
-
export default {
|
|
26
|
-
/**
|
|
27
|
-
* @memberof module:config
|
|
28
|
-
* @property {Integer} prefer_hash_algorithm Default hash algorithm {@link module:enums.hash}
|
|
29
|
-
*/
|
|
30
|
-
prefer_hash_algorithm: enums.hash.sha256,
|
|
31
|
-
/**
|
|
32
|
-
* @memberof module:config
|
|
33
|
-
* @property {Integer} encryption_cipher Default encryption cipher {@link module:enums.symmetric}
|
|
34
|
-
*/
|
|
35
|
-
encryption_cipher: enums.symmetric.aes256,
|
|
36
|
-
/**
|
|
37
|
-
* @memberof module:config
|
|
38
|
-
* @property {Integer} compression Default compression algorithm {@link module:enums.compression}
|
|
39
|
-
*/
|
|
40
|
-
compression: enums.compression.uncompressed,
|
|
41
|
-
/**
|
|
42
|
-
* @memberof module:config
|
|
43
|
-
* @property {Integer} deflate_level Default zip/zlib compression level, between 1 and 9
|
|
44
|
-
*/
|
|
45
|
-
deflate_level: 6,
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Use Authenticated Encryption with Additional Data (AEAD) protection for symmetric encryption.
|
|
49
|
-
* **NOT INTEROPERABLE WITH OTHER OPENPGP IMPLEMENTATIONS**
|
|
50
|
-
* **FUTURE OPENPGP.JS VERSIONS MAY BREAK COMPATIBILITY WHEN USING THIS OPTION**
|
|
51
|
-
* @see {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-07|RFC4880bis-07}
|
|
52
|
-
* @memberof module:config
|
|
53
|
-
* @property {Boolean} aead_protect
|
|
54
|
-
*/
|
|
55
|
-
aead_protect: false,
|
|
56
|
-
/**
|
|
57
|
-
* Default Authenticated Encryption with Additional Data (AEAD) encryption mode
|
|
58
|
-
* Only has an effect when aead_protect is set to true.
|
|
59
|
-
* @memberof module:config
|
|
60
|
-
* @property {Integer} aead_mode Default AEAD mode {@link module:enums.aead}
|
|
61
|
-
*/
|
|
62
|
-
aead_mode: enums.aead.eax,
|
|
63
|
-
/**
|
|
64
|
-
* Chunk Size Byte for Authenticated Encryption with Additional Data (AEAD) mode
|
|
65
|
-
* Only has an effect when aead_protect is set to true.
|
|
66
|
-
* Must be an integer value from 0 to 56.
|
|
67
|
-
* @memberof module:config
|
|
68
|
-
* @property {Integer} aead_chunk_size_byte
|
|
69
|
-
*/
|
|
70
|
-
aead_chunk_size_byte: 12,
|
|
71
|
-
/**
|
|
72
|
-
* Use V5 keys.
|
|
73
|
-
* **NOT INTEROPERABLE WITH OTHER OPENPGP IMPLEMENTATIONS**
|
|
74
|
-
* **FUTURE OPENPGP.JS VERSIONS MAY BREAK COMPATIBILITY WHEN USING THIS OPTION**
|
|
75
|
-
* @memberof module:config
|
|
76
|
-
* @property {Boolean} v5_keys
|
|
77
|
-
*/
|
|
78
|
-
v5_keys: false,
|
|
79
|
-
/**
|
|
80
|
-
* {@link https://tools.ietf.org/html/rfc4880#section-3.7.1.3|RFC4880 3.7.1.3}:
|
|
81
|
-
* Iteration Count Byte for S2K (String to Key)
|
|
82
|
-
* @memberof module:config
|
|
83
|
-
* @property {Integer} s2k_iteration_count_byte
|
|
84
|
-
*/
|
|
85
|
-
s2k_iteration_count_byte: 224,
|
|
86
|
-
/** Use integrity protection for symmetric encryption
|
|
87
|
-
* @memberof module:config
|
|
88
|
-
* @property {Boolean} integrity_protect
|
|
89
|
-
*/
|
|
90
|
-
integrity_protect: true,
|
|
91
|
-
/**
|
|
92
|
-
* @memberof module:config
|
|
93
|
-
* @property {Boolean} ignore_mdc_error Fail on decrypt if message is not integrity protected
|
|
94
|
-
*/
|
|
95
|
-
ignore_mdc_error: false,
|
|
96
|
-
/**
|
|
97
|
-
* @memberof module:config
|
|
98
|
-
* @property {Boolean} allow_unauthenticated_stream Stream unauthenticated data before integrity has been checked
|
|
99
|
-
*/
|
|
100
|
-
allow_unauthenticated_stream: false,
|
|
101
|
-
/**
|
|
102
|
-
* @memberof module:config
|
|
103
|
-
* @property {Boolean} checksum_required Do not throw error when armor is missing a checksum
|
|
104
|
-
*/
|
|
105
|
-
checksum_required: false,
|
|
106
|
-
/**
|
|
107
|
-
* @memberof module:config
|
|
108
|
-
* @property {Boolean} rsa_blinding
|
|
109
|
-
*/
|
|
110
|
-
rsa_blinding: true,
|
|
111
|
-
/**
|
|
112
|
-
* Work-around for rare GPG decryption bug when encrypting with multiple passwords.
|
|
113
|
-
* **Slower and slightly less secure**
|
|
114
|
-
* @memberof module:config
|
|
115
|
-
* @property {Boolean} password_collision_check
|
|
116
|
-
*/
|
|
117
|
-
password_collision_check: false,
|
|
118
|
-
/**
|
|
119
|
-
* @memberof module:config
|
|
120
|
-
* @property {Boolean} revocations_expire If true, expired revocation signatures are ignored
|
|
121
|
-
*/
|
|
122
|
-
revocations_expire: false,
|
|
123
|
-
/**
|
|
124
|
-
* Allow decryption using RSA keys without `encrypt` flag.
|
|
125
|
-
* This setting is potentially insecure, but it is needed to get around an old openpgpjs bug
|
|
126
|
-
* where key flags were ignored when selecting a key for encryption.
|
|
127
|
-
* @memberof module:config
|
|
128
|
-
* @property {Boolean} allow_insecure_decryption_with_signing_keys
|
|
129
|
-
*/
|
|
130
|
-
allow_insecure_decryption_with_signing_keys: false,
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @memberof module:config
|
|
134
|
-
* @property {Boolean} use_native Use native Node.js crypto/zlib and WebCrypto APIs when available
|
|
135
|
-
*/
|
|
136
|
-
use_native: true,
|
|
137
|
-
/**
|
|
138
|
-
* @memberof module:config
|
|
139
|
-
* @property {Integer} min_bytes_for_web_crypto The minimum amount of bytes for which to use native WebCrypto APIs when available
|
|
140
|
-
*/
|
|
141
|
-
min_bytes_for_web_crypto: 1000,
|
|
142
|
-
/**
|
|
143
|
-
* @memberof module:config
|
|
144
|
-
* @property {Boolean} Use transferable objects between the Web Worker and main thread
|
|
145
|
-
*/
|
|
146
|
-
zero_copy: false,
|
|
147
|
-
/**
|
|
148
|
-
* @memberof module:config
|
|
149
|
-
* @property {Boolean} debug If enabled, debug messages will be printed
|
|
150
|
-
*/
|
|
151
|
-
debug: false,
|
|
152
|
-
/**
|
|
153
|
-
* @memberof module:config
|
|
154
|
-
* @property {Boolean} tolerant Ignore unsupported/unrecognizable packets instead of throwing an error
|
|
155
|
-
*/
|
|
156
|
-
tolerant: true,
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* @memberof module:config
|
|
160
|
-
* @property {Boolean} show_version Whether to include {@link module:config/config.versionstring} in armored messages
|
|
161
|
-
*/
|
|
162
|
-
show_version: true,
|
|
163
|
-
/**
|
|
164
|
-
* @memberof module:config
|
|
165
|
-
* @property {Boolean} show_comment Whether to include {@link module:config/config.commentstring} in armored messages
|
|
166
|
-
*/
|
|
167
|
-
show_comment: true,
|
|
168
|
-
/**
|
|
169
|
-
* @memberof module:config
|
|
170
|
-
* @property {String} versionstring A version string to be included in armored messages
|
|
171
|
-
*/
|
|
172
|
-
versionstring: "OpenPGP.js VERSION",
|
|
173
|
-
/**
|
|
174
|
-
* @memberof module:config
|
|
175
|
-
* @property {String} commentstring A comment string to be included in armored messages
|
|
176
|
-
*/
|
|
177
|
-
commentstring: "https://openpgpjs.org",
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* @memberof module:config
|
|
181
|
-
* @property {String} keyserver
|
|
182
|
-
*/
|
|
183
|
-
keyserver: "https://keyserver.ubuntu.com",
|
|
184
|
-
/**
|
|
185
|
-
* @memberof module:config
|
|
186
|
-
* @property {String} node_store
|
|
187
|
-
*/
|
|
188
|
-
node_store: "./openpgp.store",
|
|
189
|
-
/**
|
|
190
|
-
* Max userid string length (used for parsing)
|
|
191
|
-
* @memberof module:config
|
|
192
|
-
* @property {Integer} max_userid_length
|
|
193
|
-
*/
|
|
194
|
-
max_userid_length: 1024 * 5,
|
|
195
|
-
/**
|
|
196
|
-
* Contains notatations that are considered "known". Known notations do not trigger
|
|
197
|
-
* validation error when the notation is marked as critical.
|
|
198
|
-
* @memberof module:config
|
|
199
|
-
* @property {Array} known_notations
|
|
200
|
-
*/
|
|
201
|
-
known_notations: ["preferred-email-encoding@pgp.com", "pka-address@gnupg.org"],
|
|
202
|
-
/**
|
|
203
|
-
* @memberof module:config
|
|
204
|
-
* @property {Boolean} use_indutny_elliptic Whether to use the indutny/elliptic library. When false, certain curves will not be supported.
|
|
205
|
-
*/
|
|
206
|
-
use_indutny_elliptic: true,
|
|
207
|
-
/**
|
|
208
|
-
* @memberof module:config
|
|
209
|
-
* @property {Boolean} external_indutny_elliptic Whether to lazily load the indutny/elliptic library from an external path on demand.
|
|
210
|
-
*/
|
|
211
|
-
external_indutny_elliptic: false,
|
|
212
|
-
/**
|
|
213
|
-
* @memberof module:config
|
|
214
|
-
* @property {String} indutny_elliptic_path The path to load the indutny/elliptic library from. Only has an effect if `config.external_indutny_elliptic` is true.
|
|
215
|
-
*/
|
|
216
|
-
indutny_elliptic_path: './elliptic.min.js',
|
|
217
|
-
/**
|
|
218
|
-
* @memberof module:config
|
|
219
|
-
* @property {Object} indutny_elliptic_fetch_options Options object to pass to `fetch` when loading the indutny/elliptic library. Only has an effect if `config.external_indutny_elliptic` is true.
|
|
220
|
-
*/
|
|
221
|
-
indutny_elliptic_fetch_options: {},
|
|
222
|
-
/**
|
|
223
|
-
* @memberof module:config
|
|
224
|
-
* @property {Set<Integer>} reject_hash_algorithms Reject insecure hash algorithms {@link module:enums.hash}
|
|
225
|
-
*/
|
|
226
|
-
reject_hash_algorithms: new global.Set([enums.hash.md5, enums.hash.ripemd]),
|
|
227
|
-
/**
|
|
228
|
-
* @memberof module:config
|
|
229
|
-
* @property {Set<Integer>} reject_message_hash_algorithms Reject insecure message hash algorithms {@link module:enums.hash}
|
|
230
|
-
*/
|
|
231
|
-
reject_message_hash_algorithms: new global.Set([enums.hash.md5, enums.hash.ripemd, enums.hash.sha1])
|
|
232
|
-
};
|
package/src/config/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Provides functions for storing and retrieving configuration from HTML5 local storage.
|
|
3
|
-
* @module config/localStorage
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* This object is used for storing and retrieving configuration from HTML5 local storage.
|
|
8
|
-
* @constructor
|
|
9
|
-
*/
|
|
10
|
-
function LocalStorage() {}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Reads the config out of the HTML5 local storage
|
|
14
|
-
* and initializes the object config.
|
|
15
|
-
* if config is null the default config will be used
|
|
16
|
-
*/
|
|
17
|
-
LocalStorage.prototype.read = function () {
|
|
18
|
-
const raw = global.localStorage.getItem("config");
|
|
19
|
-
const cf = (raw === null ? null : JSON.parse(raw));
|
|
20
|
-
if (cf === null) {
|
|
21
|
-
this.config = this.default_config;
|
|
22
|
-
this.write();
|
|
23
|
-
} else {
|
|
24
|
-
this.config = cf;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Writes the config to HTML5 local storage
|
|
30
|
-
*/
|
|
31
|
-
LocalStorage.prototype.write = function () {
|
|
32
|
-
global.localStorage.setItem("config", JSON.stringify(this.config));
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default LocalStorage;
|
package/src/crypto/aes_kw.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2015-2016 Decentral
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @fileoverview Implementation of RFC 3394 AES Key Wrap & Key Unwrap funcions
|
|
20
|
-
* @see module:crypto/public_key/elliptic/ecdh
|
|
21
|
-
* @requires crypto/cipher
|
|
22
|
-
* @requires util
|
|
23
|
-
* @module crypto/aes_kw
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
import cipher from './cipher';
|
|
27
|
-
import util from '../util';
|
|
28
|
-
|
|
29
|
-
function wrap(key, data) {
|
|
30
|
-
const aes = new cipher["aes" + (key.length * 8)](key);
|
|
31
|
-
const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
|
|
32
|
-
const P = unpack(data);
|
|
33
|
-
let A = IV;
|
|
34
|
-
const R = P;
|
|
35
|
-
const n = P.length / 2;
|
|
36
|
-
const t = new Uint32Array([0, 0]);
|
|
37
|
-
let B = new Uint32Array(4);
|
|
38
|
-
for (let j = 0; j <= 5; ++j) {
|
|
39
|
-
for (let i = 0; i < n; ++i) {
|
|
40
|
-
t[1] = n * j + (1 + i);
|
|
41
|
-
// B = A
|
|
42
|
-
B[0] = A[0];
|
|
43
|
-
B[1] = A[1];
|
|
44
|
-
// B = A || R[i]
|
|
45
|
-
B[2] = R[2 * i];
|
|
46
|
-
B[3] = R[2 * i + 1];
|
|
47
|
-
// B = AES(K, B)
|
|
48
|
-
B = unpack(aes.encrypt(pack(B)));
|
|
49
|
-
// A = MSB(64, B) ^ t
|
|
50
|
-
A = B.subarray(0, 2);
|
|
51
|
-
A[0] ^= t[0];
|
|
52
|
-
A[1] ^= t[1];
|
|
53
|
-
// R[i] = LSB(64, B)
|
|
54
|
-
R[2 * i] = B[2];
|
|
55
|
-
R[2 * i + 1] = B[3];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return pack(A, R);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function unwrap(key, data) {
|
|
62
|
-
const aes = new cipher["aes" + (key.length * 8)](key);
|
|
63
|
-
const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]);
|
|
64
|
-
const C = unpack(data);
|
|
65
|
-
let A = C.subarray(0, 2);
|
|
66
|
-
const R = C.subarray(2);
|
|
67
|
-
const n = C.length / 2 - 1;
|
|
68
|
-
const t = new Uint32Array([0, 0]);
|
|
69
|
-
let B = new Uint32Array(4);
|
|
70
|
-
for (let j = 5; j >= 0; --j) {
|
|
71
|
-
for (let i = n - 1; i >= 0; --i) {
|
|
72
|
-
t[1] = n * j + (i + 1);
|
|
73
|
-
// B = A ^ t
|
|
74
|
-
B[0] = A[0] ^ t[0];
|
|
75
|
-
B[1] = A[1] ^ t[1];
|
|
76
|
-
// B = (A ^ t) || R[i]
|
|
77
|
-
B[2] = R[2 * i];
|
|
78
|
-
B[3] = R[2 * i + 1];
|
|
79
|
-
// B = AES-1(B)
|
|
80
|
-
B = unpack(aes.decrypt(pack(B)));
|
|
81
|
-
// A = MSB(64, B)
|
|
82
|
-
A = B.subarray(0, 2);
|
|
83
|
-
// R[i] = LSB(64, B)
|
|
84
|
-
R[2 * i] = B[2];
|
|
85
|
-
R[2 * i + 1] = B[3];
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
if (A[0] === IV[0] && A[1] === IV[1]) {
|
|
89
|
-
return pack(R);
|
|
90
|
-
}
|
|
91
|
-
throw new Error("Key Data Integrity failed");
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function createArrayBuffer(data) {
|
|
95
|
-
if (util.isString(data)) {
|
|
96
|
-
const { length } = data;
|
|
97
|
-
const buffer = new ArrayBuffer(length);
|
|
98
|
-
const view = new Uint8Array(buffer);
|
|
99
|
-
for (let j = 0; j < length; ++j) {
|
|
100
|
-
view[j] = data.charCodeAt(j);
|
|
101
|
-
}
|
|
102
|
-
return buffer;
|
|
103
|
-
}
|
|
104
|
-
return new Uint8Array(data).buffer;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function unpack(data) {
|
|
108
|
-
const { length } = data;
|
|
109
|
-
const buffer = createArrayBuffer(data);
|
|
110
|
-
const view = new DataView(buffer);
|
|
111
|
-
const arr = new Uint32Array(length / 4);
|
|
112
|
-
for (let i = 0; i < length / 4; ++i) {
|
|
113
|
-
arr[i] = view.getUint32(4 * i);
|
|
114
|
-
}
|
|
115
|
-
return arr;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function pack() {
|
|
119
|
-
let length = 0;
|
|
120
|
-
for (let k = 0; k < arguments.length; ++k) {
|
|
121
|
-
length += 4 * arguments[k].length;
|
|
122
|
-
}
|
|
123
|
-
const buffer = new ArrayBuffer(length);
|
|
124
|
-
const view = new DataView(buffer);
|
|
125
|
-
let offset = 0;
|
|
126
|
-
for (let i = 0; i < arguments.length; ++i) {
|
|
127
|
-
for (let j = 0; j < arguments[i].length; ++j) {
|
|
128
|
-
view.setUint32(offset + 4 * j, arguments[i][j]);
|
|
129
|
-
}
|
|
130
|
-
offset += 4 * arguments[i].length;
|
|
131
|
-
}
|
|
132
|
-
return new Uint8Array(buffer);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export default {
|
|
136
|
-
/**
|
|
137
|
-
* AES key wrap
|
|
138
|
-
* @function
|
|
139
|
-
* @param {String} key
|
|
140
|
-
* @param {String} data
|
|
141
|
-
* @returns {Uint8Array}
|
|
142
|
-
*/
|
|
143
|
-
wrap,
|
|
144
|
-
/**
|
|
145
|
-
* AES key unwrap
|
|
146
|
-
* @function
|
|
147
|
-
* @param {String} key
|
|
148
|
-
* @param {String} data
|
|
149
|
-
* @returns {Uint8Array}
|
|
150
|
-
* @throws {Error}
|
|
151
|
-
*/
|
|
152
|
-
unwrap
|
|
153
|
-
};
|
package/src/crypto/cfb.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
// Modified by ProtonTech AG
|
|
2
|
-
|
|
3
|
-
// Modified by Recurity Labs GmbH
|
|
4
|
-
|
|
5
|
-
// modified version of https://www.hanewin.net/encrypt/PGdecode.js:
|
|
6
|
-
|
|
7
|
-
/* OpenPGP encryption using RSA/AES
|
|
8
|
-
* Copyright 2005-2006 Herbert Hanewinkel, www.haneWIN.de
|
|
9
|
-
* version 2.0, check www.haneWIN.de for the latest version
|
|
10
|
-
|
|
11
|
-
* This software is provided as-is, without express or implied warranty.
|
|
12
|
-
* Permission to use, copy, modify, distribute or sell this software, with or
|
|
13
|
-
* without fee, for any purpose and by any individual or organization, is hereby
|
|
14
|
-
* granted, provided that the above copyright notice and this paragraph appear
|
|
15
|
-
* in all copies. Distribution as a part of an application or binary must
|
|
16
|
-
* include the above copyright notice in the documentation and/or other
|
|
17
|
-
* materials provided with the application or distribution.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @requires web-stream-tools
|
|
22
|
-
* @requires crypto/cipher
|
|
23
|
-
* @requires util
|
|
24
|
-
* @module crypto/cfb
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { AES_CFB } from 'asmcrypto.js/dist_es5/aes/cfb';
|
|
28
|
-
|
|
29
|
-
import stream from 'web-stream-tools';
|
|
30
|
-
import cipher from './cipher';
|
|
31
|
-
import config from '../config';
|
|
32
|
-
import util from '../util';
|
|
33
|
-
|
|
34
|
-
const webCrypto = util.getWebCrypto();
|
|
35
|
-
const nodeCrypto = util.getNodeCrypto();
|
|
36
|
-
const Buffer = util.getNodeBuffer();
|
|
37
|
-
|
|
38
|
-
const knownAlgos = nodeCrypto ? nodeCrypto.getCiphers() : [];
|
|
39
|
-
const nodeAlgos = {
|
|
40
|
-
idea: knownAlgos.includes('idea-cfb') ? 'idea-cfb' : undefined, /* Unused, not implemented */
|
|
41
|
-
'3des': knownAlgos.includes('des-ede3-cfb') ? 'des-ede3-cfb' : undefined,
|
|
42
|
-
tripledes: knownAlgos.includes('des-ede3-cfb') ? 'des-ede3-cfb' : undefined,
|
|
43
|
-
cast5: knownAlgos.includes('cast5-cfb') ? 'cast5-cfb' : undefined,
|
|
44
|
-
blowfish: knownAlgos.includes('bf-cfb') ? 'bf-cfb' : undefined,
|
|
45
|
-
aes128: knownAlgos.includes('aes-128-cfb') ? 'aes-128-cfb' : undefined,
|
|
46
|
-
aes192: knownAlgos.includes('aes-192-cfb') ? 'aes-192-cfb' : undefined,
|
|
47
|
-
aes256: knownAlgos.includes('aes-256-cfb') ? 'aes-256-cfb' : undefined
|
|
48
|
-
/* twofish is not implemented in OpenSSL */
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default {
|
|
52
|
-
encrypt: function(algo, key, plaintext, iv) {
|
|
53
|
-
if (util.getNodeCrypto() && nodeAlgos[algo]) { // Node crypto library.
|
|
54
|
-
return nodeEncrypt(algo, key, plaintext, iv);
|
|
55
|
-
}
|
|
56
|
-
if (algo.substr(0, 3) === 'aes') {
|
|
57
|
-
return aesEncrypt(algo, key, plaintext, iv);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const cipherfn = new cipher[algo](key);
|
|
61
|
-
const block_size = cipherfn.blockSize;
|
|
62
|
-
|
|
63
|
-
const blockc = iv.slice();
|
|
64
|
-
let pt = new Uint8Array();
|
|
65
|
-
const process = chunk => {
|
|
66
|
-
if (chunk) {
|
|
67
|
-
pt = util.concatUint8Array([pt, chunk]);
|
|
68
|
-
}
|
|
69
|
-
const ciphertext = new Uint8Array(pt.length);
|
|
70
|
-
let i;
|
|
71
|
-
let j = 0;
|
|
72
|
-
while (chunk ? pt.length >= block_size : pt.length) {
|
|
73
|
-
const encblock = cipherfn.encrypt(blockc);
|
|
74
|
-
for (i = 0; i < block_size; i++) {
|
|
75
|
-
blockc[i] = pt[i] ^ encblock[i];
|
|
76
|
-
ciphertext[j++] = blockc[i];
|
|
77
|
-
}
|
|
78
|
-
pt = pt.subarray(block_size);
|
|
79
|
-
}
|
|
80
|
-
return ciphertext.subarray(0, j);
|
|
81
|
-
};
|
|
82
|
-
return stream.transform(plaintext, process, process);
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
decrypt: async function(algo, key, ciphertext, iv) {
|
|
86
|
-
if (util.getNodeCrypto() && nodeAlgos[algo]) { // Node crypto library.
|
|
87
|
-
return nodeDecrypt(algo, key, ciphertext, iv);
|
|
88
|
-
}
|
|
89
|
-
if (algo.substr(0, 3) === 'aes') {
|
|
90
|
-
return aesDecrypt(algo, key, ciphertext, iv);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const cipherfn = new cipher[algo](key);
|
|
94
|
-
const block_size = cipherfn.blockSize;
|
|
95
|
-
|
|
96
|
-
let blockp = iv;
|
|
97
|
-
let ct = new Uint8Array();
|
|
98
|
-
const process = chunk => {
|
|
99
|
-
if (chunk) {
|
|
100
|
-
ct = util.concatUint8Array([ct, chunk]);
|
|
101
|
-
}
|
|
102
|
-
const plaintext = new Uint8Array(ct.length);
|
|
103
|
-
let i;
|
|
104
|
-
let j = 0;
|
|
105
|
-
while (chunk ? ct.length >= block_size : ct.length) {
|
|
106
|
-
const decblock = cipherfn.encrypt(blockp);
|
|
107
|
-
blockp = ct;
|
|
108
|
-
for (i = 0; i < block_size; i++) {
|
|
109
|
-
plaintext[j++] = blockp[i] ^ decblock[i];
|
|
110
|
-
}
|
|
111
|
-
ct = ct.subarray(block_size);
|
|
112
|
-
}
|
|
113
|
-
return plaintext.subarray(0, j);
|
|
114
|
-
};
|
|
115
|
-
return stream.transform(ciphertext, process, process);
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
function aesEncrypt(algo, key, pt, iv) {
|
|
120
|
-
if (
|
|
121
|
-
util.getWebCrypto() &&
|
|
122
|
-
key.length !== 24 && // Chrome doesn't support 192 bit keys, see https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
|
123
|
-
!util.isStream(pt) &&
|
|
124
|
-
pt.length >= 3000 * config.min_bytes_for_web_crypto // Default to a 3MB minimum. Chrome is pretty slow for small messages, see: https://bugs.chromium.org/p/chromium/issues/detail?id=701188#c2
|
|
125
|
-
) { // Web Crypto
|
|
126
|
-
return webEncrypt(algo, key, pt, iv);
|
|
127
|
-
}
|
|
128
|
-
// asm.js fallback
|
|
129
|
-
const cfb = new AES_CFB(key, iv);
|
|
130
|
-
return stream.transform(pt, value => cfb.AES_Encrypt_process(value), () => cfb.AES_Encrypt_finish());
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function aesDecrypt(algo, key, ct, iv) {
|
|
134
|
-
if (util.isStream(ct)) {
|
|
135
|
-
const cfb = new AES_CFB(key, iv);
|
|
136
|
-
return stream.transform(ct, value => cfb.AES_Decrypt_process(value), () => cfb.AES_Decrypt_finish());
|
|
137
|
-
}
|
|
138
|
-
return AES_CFB.decrypt(ct, key, iv);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function xorMut(a, b) {
|
|
142
|
-
for (let i = 0; i < a.length; i++) {
|
|
143
|
-
a[i] = a[i] ^ b[i];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async function webEncrypt(algo, key, pt, iv) {
|
|
148
|
-
const ALGO = 'AES-CBC';
|
|
149
|
-
const _key = await webCrypto.importKey('raw', key, { name: ALGO }, false, ['encrypt']);
|
|
150
|
-
const { blockSize } = cipher[algo];
|
|
151
|
-
const cbc_pt = util.concatUint8Array([new Uint8Array(blockSize), pt]);
|
|
152
|
-
const ct = new Uint8Array(await webCrypto.encrypt({ name: ALGO, iv }, _key, cbc_pt)).subarray(0, pt.length);
|
|
153
|
-
xorMut(ct, pt);
|
|
154
|
-
return ct;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function nodeEncrypt(algo, key, pt, iv) {
|
|
158
|
-
key = Buffer.from(key);
|
|
159
|
-
iv = Buffer.from(iv);
|
|
160
|
-
const cipherObj = new nodeCrypto.createCipheriv(nodeAlgos[algo], key, iv);
|
|
161
|
-
return stream.transform(pt, value => new Uint8Array(cipherObj.update(Buffer.from(value))));
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function nodeDecrypt(algo, key, ct, iv) {
|
|
165
|
-
key = Buffer.from(key);
|
|
166
|
-
iv = Buffer.from(iv);
|
|
167
|
-
const decipherObj = new nodeCrypto.createDecipheriv(nodeAlgos[algo], key, iv);
|
|
168
|
-
return stream.transform(ct, value => new Uint8Array(decipherObj.update(Buffer.from(value))));
|
|
169
|
-
}
|
package/src/crypto/cipher/aes.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @requires asmcrypto.js
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { AES_ECB } from 'asmcrypto.js/dist_es5/aes/ecb';
|
|
6
|
-
|
|
7
|
-
// TODO use webCrypto or nodeCrypto when possible.
|
|
8
|
-
function aes(length) {
|
|
9
|
-
const C = function(key) {
|
|
10
|
-
const aes_ecb = new AES_ECB(key);
|
|
11
|
-
|
|
12
|
-
this.encrypt = function(block) {
|
|
13
|
-
return aes_ecb.encrypt(block);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
this.decrypt = function(block) {
|
|
17
|
-
return aes_ecb.decrypt(block);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
C.blockSize = C.prototype.blockSize = 16;
|
|
22
|
-
C.keySize = C.prototype.keySize = length / 8;
|
|
23
|
-
|
|
24
|
-
return C;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default aes;
|