@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.
Files changed (173) hide show
  1. package/README.md +311 -239
  2. package/dist/lightweight/bn.interface.min.mjs +3 -0
  3. package/dist/lightweight/bn.interface.min.mjs.map +1 -0
  4. package/dist/lightweight/bn.interface.mjs +340 -0
  5. package/dist/lightweight/bn.min.mjs +3 -0
  6. package/dist/lightweight/bn.min.mjs.map +1 -0
  7. package/dist/lightweight/bn.mjs +3434 -0
  8. package/dist/lightweight/elliptic.min.mjs +3 -0
  9. package/dist/lightweight/elliptic.min.mjs.map +1 -0
  10. package/dist/lightweight/elliptic.mjs +4313 -0
  11. package/dist/lightweight/openpgp.min.mjs +3 -0
  12. package/dist/lightweight/openpgp.min.mjs.map +1 -0
  13. package/dist/lightweight/openpgp.mjs +31375 -0
  14. package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
  15. package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
  16. package/dist/lightweight/ponyfill.es6.mjs +3831 -0
  17. package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
  18. package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
  19. package/dist/lightweight/web-streams-adapter.mjs +561 -0
  20. package/dist/node/openpgp.js +43943 -0
  21. package/dist/node/openpgp.min.js +17 -0
  22. package/dist/node/openpgp.min.js.map +1 -0
  23. package/dist/node/openpgp.min.mjs +17 -0
  24. package/dist/node/openpgp.min.mjs.map +1 -0
  25. package/dist/node/openpgp.mjs +43880 -0
  26. package/dist/openpgp.js +41077 -41609
  27. package/dist/openpgp.min.js +17 -2
  28. package/dist/openpgp.min.js.map +1 -0
  29. package/dist/openpgp.min.mjs +17 -0
  30. package/dist/openpgp.min.mjs.map +1 -0
  31. package/dist/openpgp.mjs +43868 -0
  32. package/lightweight/package.json +5 -0
  33. package/openpgp.d.ts +889 -0
  34. package/package.json +63 -57
  35. package/dist/compat/openpgp.js +0 -61152
  36. package/dist/compat/openpgp.min.js +0 -2
  37. package/dist/compat/openpgp.worker.js +0 -173
  38. package/dist/compat/openpgp.worker.min.js +0 -2
  39. package/dist/lightweight/elliptic.min.js +0 -5
  40. package/dist/lightweight/openpgp.js +0 -40071
  41. package/dist/lightweight/openpgp.min.js +0 -2
  42. package/dist/lightweight/openpgp.worker.js +0 -173
  43. package/dist/lightweight/openpgp.worker.min.js +0 -2
  44. package/dist/openpgp.worker.js +0 -173
  45. package/dist/openpgp.worker.min.js +0 -2
  46. package/src/cleartext.js +0 -220
  47. package/src/config/config.js +0 -232
  48. package/src/config/index.js +0 -7
  49. package/src/config/localStorage.js +0 -35
  50. package/src/crypto/aes_kw.js +0 -153
  51. package/src/crypto/cfb.js +0 -169
  52. package/src/crypto/cipher/aes.js +0 -27
  53. package/src/crypto/cipher/blowfish.js +0 -398
  54. package/src/crypto/cipher/cast5.js +0 -610
  55. package/src/crypto/cipher/des.js +0 -476
  56. package/src/crypto/cipher/index.js +0 -91
  57. package/src/crypto/cipher/twofish.js +0 -346
  58. package/src/crypto/cmac.js +0 -98
  59. package/src/crypto/crypto.js +0 -394
  60. package/src/crypto/eax.js +0 -172
  61. package/src/crypto/gcm.js +0 -141
  62. package/src/crypto/hash/index.js +0 -163
  63. package/src/crypto/hash/md5.js +0 -205
  64. package/src/crypto/index.js +0 -57
  65. package/src/crypto/ocb.js +0 -274
  66. package/src/crypto/pkcs1.js +0 -170
  67. package/src/crypto/pkcs5.js +0 -55
  68. package/src/crypto/public_key/dsa.js +0 -188
  69. package/src/crypto/public_key/elgamal.js +0 -137
  70. package/src/crypto/public_key/elliptic/curves.js +0 -385
  71. package/src/crypto/public_key/elliptic/ecdh.js +0 -414
  72. package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
  73. package/src/crypto/public_key/elliptic/eddsa.js +0 -119
  74. package/src/crypto/public_key/elliptic/index.js +0 -34
  75. package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
  76. package/src/crypto/public_key/index.js +0 -28
  77. package/src/crypto/public_key/prime.js +0 -275
  78. package/src/crypto/public_key/rsa.js +0 -597
  79. package/src/crypto/random.js +0 -145
  80. package/src/crypto/signature.js +0 -137
  81. package/src/encoding/armor.js +0 -433
  82. package/src/encoding/base64.js +0 -96
  83. package/src/enums.js +0 -493
  84. package/src/hkp.js +0 -89
  85. package/src/index.js +0 -161
  86. package/src/key/factory.js +0 -326
  87. package/src/key/helper.js +0 -378
  88. package/src/key/index.js +0 -32
  89. package/src/key/key.js +0 -888
  90. package/src/key/subkey.js +0 -187
  91. package/src/key/user.js +0 -230
  92. package/src/keyring/index.js +0 -12
  93. package/src/keyring/keyring.js +0 -229
  94. package/src/keyring/localstore.js +0 -119
  95. package/src/lightweight_helper.js +0 -26
  96. package/src/message.js +0 -825
  97. package/src/openpgp.js +0 -717
  98. package/src/packet/all_packets.js +0 -116
  99. package/src/packet/clone.js +0 -189
  100. package/src/packet/compressed.js +0 -194
  101. package/src/packet/index.js +0 -20
  102. package/src/packet/literal.js +0 -168
  103. package/src/packet/marker.js +0 -62
  104. package/src/packet/one_pass_signature.js +0 -156
  105. package/src/packet/packet.js +0 -300
  106. package/src/packet/packetlist.js +0 -232
  107. package/src/packet/public_key.js +0 -280
  108. package/src/packet/public_key_encrypted_session_key.js +0 -161
  109. package/src/packet/public_subkey.js +0 -44
  110. package/src/packet/secret_key.js +0 -468
  111. package/src/packet/secret_subkey.js +0 -41
  112. package/src/packet/signature.js +0 -786
  113. package/src/packet/sym_encrypted_aead_protected.js +0 -189
  114. package/src/packet/sym_encrypted_integrity_protected.js +0 -139
  115. package/src/packet/sym_encrypted_session_key.js +0 -204
  116. package/src/packet/symmetrically_encrypted.js +0 -118
  117. package/src/packet/trust.js +0 -35
  118. package/src/packet/user_attribute.js +0 -94
  119. package/src/packet/userid.js +0 -87
  120. package/src/polyfills.js +0 -64
  121. package/src/signature.js +0 -73
  122. package/src/type/ecdh_symkey.js +0 -69
  123. package/src/type/kdf_params.js +0 -114
  124. package/src/type/keyid.js +0 -110
  125. package/src/type/mpi.js +0 -138
  126. package/src/type/oid.js +0 -110
  127. package/src/type/s2k.js +0 -203
  128. package/src/util.js +0 -836
  129. package/src/wkd.js +0 -84
  130. package/src/worker/async_proxy.js +0 -190
  131. package/src/worker/worker.js +0 -167
  132. package/test/crypto/aes_kw.js +0 -57
  133. package/test/crypto/cipher/aes.js +0 -86
  134. package/test/crypto/cipher/blowfish.js +0 -58
  135. package/test/crypto/cipher/cast5.js +0 -25
  136. package/test/crypto/cipher/des.js +0 -143
  137. package/test/crypto/cipher/index.js +0 -7
  138. package/test/crypto/cipher/twofish.js +0 -71
  139. package/test/crypto/crypto.js +0 -383
  140. package/test/crypto/eax.js +0 -150
  141. package/test/crypto/ecdh.js +0 -359
  142. package/test/crypto/elliptic.js +0 -251
  143. package/test/crypto/elliptic_data.js +0 -102
  144. package/test/crypto/hash/index.js +0 -5
  145. package/test/crypto/hash/md5.js +0 -16
  146. package/test/crypto/hash/ripemd.js +0 -14
  147. package/test/crypto/hash/sha.js +0 -20
  148. package/test/crypto/index.js +0 -14
  149. package/test/crypto/ocb.js +0 -183
  150. package/test/crypto/pkcs5.js +0 -39
  151. package/test/crypto/random.js +0 -79
  152. package/test/crypto/rsa.js +0 -180
  153. package/test/crypto/validate.js +0 -387
  154. package/test/general/armor.js +0 -408
  155. package/test/general/brainpool.js +0 -360
  156. package/test/general/decompression.js +0 -60
  157. package/test/general/ecc_nist.js +0 -115
  158. package/test/general/ecc_secp256k1.js +0 -242
  159. package/test/general/forwarding.js +0 -43
  160. package/test/general/hkp.js +0 -165
  161. package/test/general/index.js +0 -20
  162. package/test/general/key.js +0 -3491
  163. package/test/general/keyring.js +0 -336
  164. package/test/general/oid.js +0 -39
  165. package/test/general/openpgp.js +0 -2577
  166. package/test/general/packet.js +0 -950
  167. package/test/general/signature.js +0 -1715
  168. package/test/general/streaming.js +0 -944
  169. package/test/general/testInputs.js +0 -18
  170. package/test/general/util.js +0 -183
  171. package/test/general/wkd.js +0 -48
  172. package/test/general/x25519.js +0 -556
  173. package/test/unittests.js +0 -64
@@ -1,189 +0,0 @@
1
- // OpenPGP.js - An OpenPGP implementation in javascript
2
- // Copyright (C) 2016 Tankred Hase
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
- * @requires web-stream-tools
20
- * @requires config
21
- * @requires crypto
22
- * @requires enums
23
- * @requires util
24
- */
25
-
26
- import stream from 'web-stream-tools';
27
- import config from '../config';
28
- import crypto from '../crypto';
29
- import enums from '../enums';
30
- import util from '../util';
31
-
32
- const VERSION = 1; // A one-octet version number of the data packet.
33
-
34
- /**
35
- * Implementation of the Symmetrically Encrypted Authenticated Encryption with
36
- * Additional Data (AEAD) Protected Data Packet
37
- *
38
- * {@link https://tools.ietf.org/html/draft-ford-openpgp-format-00#section-2.1}:
39
- * AEAD Protected Data Packet
40
- * @memberof module:packet
41
- * @constructor
42
- */
43
- function SymEncryptedAEADProtected() {
44
- this.tag = enums.packet.symEncryptedAEADProtected;
45
- this.version = VERSION;
46
- this.cipherAlgo = null;
47
- this.aeadAlgorithm = 'eax';
48
- this.aeadAlgo = null;
49
- this.chunkSizeByte = null;
50
- this.iv = null;
51
- this.encrypted = null;
52
- this.packets = null;
53
- }
54
-
55
- export default SymEncryptedAEADProtected;
56
-
57
- /**
58
- * Parse an encrypted payload of bytes in the order: version, IV, ciphertext (see specification)
59
- * @param {Uint8Array | ReadableStream<Uint8Array>} bytes
60
- */
61
- SymEncryptedAEADProtected.prototype.read = async function (bytes) {
62
- await stream.parse(bytes, async reader => {
63
- if (await reader.readByte() !== VERSION) { // The only currently defined value is 1.
64
- throw new Error('Invalid packet version.');
65
- }
66
- this.cipherAlgo = await reader.readByte();
67
- this.aeadAlgo = await reader.readByte();
68
- this.chunkSizeByte = await reader.readByte();
69
- const mode = crypto[enums.read(enums.aead, this.aeadAlgo)];
70
- this.iv = await reader.readBytes(mode.ivLength);
71
- this.encrypted = reader.remainder();
72
- });
73
- };
74
-
75
- /**
76
- * Write the encrypted payload of bytes in the order: version, IV, ciphertext (see specification)
77
- * @returns {Uint8Array | ReadableStream<Uint8Array>} The encrypted payload
78
- */
79
- SymEncryptedAEADProtected.prototype.write = function () {
80
- return util.concat([new Uint8Array([this.version, this.cipherAlgo, this.aeadAlgo, this.chunkSizeByte]), this.iv, this.encrypted]);
81
- };
82
-
83
- /**
84
- * Decrypt the encrypted payload.
85
- * @param {String} sessionKeyAlgorithm The session key's cipher algorithm e.g. 'aes128'
86
- * @param {Uint8Array} key The session key used to encrypt the payload
87
- * @param {Boolean} streaming Whether the top-level function will return a stream
88
- * @returns {Boolean}
89
- * @async
90
- */
91
- SymEncryptedAEADProtected.prototype.decrypt = async function (sessionKeyAlgorithm, key, streaming) {
92
- await this.packets.read(await this.crypt('decrypt', key, stream.clone(this.encrypted), streaming), streaming);
93
- return true;
94
- };
95
-
96
- /**
97
- * Encrypt the packet list payload.
98
- * @param {String} sessionKeyAlgorithm The session key's cipher algorithm e.g. 'aes128'
99
- * @param {Uint8Array} key The session key used to encrypt the payload
100
- * @param {Boolean} streaming Whether the top-level function will return a stream
101
- * @async
102
- */
103
- SymEncryptedAEADProtected.prototype.encrypt = async function (sessionKeyAlgorithm, key, streaming) {
104
- this.cipherAlgo = enums.write(enums.symmetric, sessionKeyAlgorithm);
105
- this.aeadAlgo = enums.write(enums.aead, this.aeadAlgorithm);
106
- const mode = crypto[enums.read(enums.aead, this.aeadAlgo)];
107
- this.iv = await crypto.random.getRandomBytes(mode.ivLength); // generate new random IV
108
- this.chunkSizeByte = config.aead_chunk_size_byte;
109
- const data = this.packets.write();
110
- this.encrypted = await this.crypt('encrypt', key, data, streaming);
111
- };
112
-
113
- /**
114
- * En/decrypt the payload.
115
- * @param {encrypt|decrypt} fn Whether to encrypt or decrypt
116
- * @param {Uint8Array} key The session key used to en/decrypt the payload
117
- * @param {Uint8Array | ReadableStream<Uint8Array>} data The data to en/decrypt
118
- * @param {Boolean} streaming Whether the top-level function will return a stream
119
- * @returns {Uint8Array | ReadableStream<Uint8Array>}
120
- * @async
121
- */
122
- SymEncryptedAEADProtected.prototype.crypt = async function (fn, key, data, streaming) {
123
- const cipher = enums.read(enums.symmetric, this.cipherAlgo);
124
- const mode = crypto[enums.read(enums.aead, this.aeadAlgo)];
125
- const modeInstance = await mode(cipher, key);
126
- const tagLengthIfDecrypting = fn === 'decrypt' ? mode.tagLength : 0;
127
- const tagLengthIfEncrypting = fn === 'encrypt' ? mode.tagLength : 0;
128
- const chunkSize = 2 ** (this.chunkSizeByte + 6) + tagLengthIfDecrypting; // ((uint64_t)1 << (c + 6))
129
- const adataBuffer = new ArrayBuffer(21);
130
- const adataArray = new Uint8Array(adataBuffer, 0, 13);
131
- const adataTagArray = new Uint8Array(adataBuffer);
132
- const adataView = new DataView(adataBuffer);
133
- const chunkIndexArray = new Uint8Array(adataBuffer, 5, 8);
134
- adataArray.set([0xC0 | this.tag, this.version, this.cipherAlgo, this.aeadAlgo, this.chunkSizeByte], 0);
135
- let chunkIndex = 0;
136
- let latestPromise = Promise.resolve();
137
- let cryptedBytes = 0;
138
- let queuedBytes = 0;
139
- const iv = this.iv;
140
- return stream.transformPair(data, async (readable, writable) => {
141
- const reader = stream.getReader(readable);
142
- const buffer = new TransformStream({}, {
143
- highWaterMark: streaming ? util.getHardwareConcurrency() * 2 ** (this.chunkSizeByte + 6) : Infinity,
144
- size: array => array.length
145
- });
146
- stream.pipe(buffer.readable, writable);
147
- const writer = stream.getWriter(buffer.writable);
148
- try {
149
- while (true) {
150
- let chunk = await reader.readBytes(chunkSize + tagLengthIfDecrypting) || new Uint8Array();
151
- const finalChunk = chunk.subarray(chunk.length - tagLengthIfDecrypting);
152
- chunk = chunk.subarray(0, chunk.length - tagLengthIfDecrypting);
153
- let cryptedPromise;
154
- let done;
155
- if (!chunkIndex || chunk.length) {
156
- reader.unshift(finalChunk);
157
- cryptedPromise = modeInstance[fn](chunk, mode.getNonce(iv, chunkIndexArray), adataArray);
158
- queuedBytes += chunk.length - tagLengthIfDecrypting + tagLengthIfEncrypting;
159
- } else {
160
- // After the last chunk, we either encrypt a final, empty
161
- // data chunk to get the final authentication tag or
162
- // validate that final authentication tag.
163
- adataView.setInt32(13 + 4, cryptedBytes); // Should be setInt64(13, ...)
164
- cryptedPromise = modeInstance[fn](finalChunk, mode.getNonce(iv, chunkIndexArray), adataTagArray);
165
- queuedBytes += tagLengthIfEncrypting;
166
- done = true;
167
- }
168
- cryptedBytes += chunk.length - tagLengthIfDecrypting;
169
- // eslint-disable-next-line no-loop-func
170
- latestPromise = latestPromise.then(() => cryptedPromise).then(async crypted => {
171
- await writer.ready;
172
- await writer.write(crypted);
173
- queuedBytes -= crypted.length;
174
- }).catch(err => writer.abort(err));
175
- if (done || queuedBytes > writer.desiredSize) {
176
- await latestPromise; // Respect backpressure
177
- }
178
- if (!done) {
179
- adataView.setInt32(5 + 4, ++chunkIndex); // Should be setInt64(5, ...)
180
- } else {
181
- await writer.close();
182
- break;
183
- }
184
- }
185
- } catch (e) {
186
- await writer.abort(e);
187
- }
188
- });
189
- };
@@ -1,139 +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
- * @requires asmcrypto.js
20
- * @requires web-stream-tools
21
- * @requires config
22
- * @requires crypto
23
- * @requires enums
24
- * @requires util
25
- */
26
-
27
- import stream from 'web-stream-tools';
28
- import config from '../config';
29
- import crypto from '../crypto';
30
- import enums from '../enums';
31
- import util from '../util';
32
-
33
- const VERSION = 1; // A one-octet version number of the data packet.
34
-
35
- /**
36
- * Implementation of the Sym. Encrypted Integrity Protected Data Packet (Tag 18)
37
- *
38
- * {@link https://tools.ietf.org/html/rfc4880#section-5.13|RFC4880 5.13}:
39
- * The Symmetrically Encrypted Integrity Protected Data packet is
40
- * a variant of the Symmetrically Encrypted Data packet. It is a new feature
41
- * created for OpenPGP that addresses the problem of detecting a modification to
42
- * encrypted data. It is used in combination with a Modification Detection Code
43
- * packet.
44
- * @memberof module:packet
45
- * @constructor
46
- */
47
- function SymEncryptedIntegrityProtected() {
48
- this.tag = enums.packet.symEncryptedIntegrityProtected;
49
- this.version = VERSION;
50
- /** The encrypted payload. */
51
- this.encrypted = null; // string
52
- /**
53
- * If after decrypting the packet this is set to true,
54
- * a modification has been detected and thus the contents
55
- * should be discarded.
56
- * @type {Boolean}
57
- */
58
- this.modification = false;
59
- this.packets = null;
60
- }
61
-
62
- SymEncryptedIntegrityProtected.prototype.read = async function (bytes) {
63
- await stream.parse(bytes, async reader => {
64
-
65
- // - A one-octet version number. The only currently defined value is 1.
66
- if (await reader.readByte() !== VERSION) {
67
- throw new Error('Invalid packet version.');
68
- }
69
-
70
- // - Encrypted data, the output of the selected symmetric-key cipher
71
- // operating in Cipher Feedback mode with shift amount equal to the
72
- // block size of the cipher (CFB-n where n is the block size).
73
- this.encrypted = reader.remainder();
74
- });
75
- };
76
-
77
- SymEncryptedIntegrityProtected.prototype.write = function () {
78
- return util.concat([new Uint8Array([VERSION]), this.encrypted]);
79
- };
80
-
81
- /**
82
- * Encrypt the payload in the packet.
83
- * @param {String} sessionKeyAlgorithm The selected symmetric encryption algorithm to be used e.g. 'aes128'
84
- * @param {Uint8Array} key The key of cipher blocksize length to be used
85
- * @param {Boolean} streaming Whether to set this.encrypted to a stream
86
- * @returns {Promise<Boolean>}
87
- * @async
88
- */
89
- SymEncryptedIntegrityProtected.prototype.encrypt = async function (sessionKeyAlgorithm, key, streaming) {
90
- let bytes = this.packets.write();
91
- if (!streaming) bytes = await stream.readToEnd(bytes);
92
- const prefix = await crypto.getPrefixRandom(sessionKeyAlgorithm);
93
- const mdc = new Uint8Array([0xD3, 0x14]); // modification detection code packet
94
-
95
- const tohash = util.concat([prefix, bytes, mdc]);
96
- const hash = await crypto.hash.sha1(stream.passiveClone(tohash));
97
- const plaintext = util.concat([tohash, hash]);
98
-
99
- this.encrypted = await crypto.cfb.encrypt(sessionKeyAlgorithm, key, plaintext, new Uint8Array(crypto.cipher[sessionKeyAlgorithm].blockSize));
100
- return true;
101
- };
102
-
103
- /**
104
- * Decrypts the encrypted data contained in the packet.
105
- * @param {String} sessionKeyAlgorithm The selected symmetric encryption algorithm to be used e.g. 'aes128'
106
- * @param {Uint8Array} key The key of cipher blocksize length to be used
107
- * @param {Boolean} streaming Whether to read this.encrypted as a stream
108
- * @returns {Promise<Boolean>}
109
- * @async
110
- */
111
- SymEncryptedIntegrityProtected.prototype.decrypt = async function (sessionKeyAlgorithm, key, streaming) {
112
- let encrypted = stream.clone(this.encrypted);
113
- if (!streaming) encrypted = await stream.readToEnd(encrypted);
114
- const decrypted = await crypto.cfb.decrypt(sessionKeyAlgorithm, key, encrypted, new Uint8Array(crypto.cipher[sessionKeyAlgorithm].blockSize));
115
-
116
- // there must be a modification detection code packet as the
117
- // last packet and everything gets hashed except the hash itself
118
- const realHash = stream.slice(stream.passiveClone(decrypted), -20);
119
- const tohash = stream.slice(decrypted, 0, -20);
120
- const verifyHash = Promise.all([
121
- stream.readToEnd(await crypto.hash.sha1(stream.passiveClone(tohash))),
122
- stream.readToEnd(realHash)
123
- ]).then(([hash, mdc]) => {
124
- if (!util.equalsUint8Array(hash, mdc)) {
125
- throw new Error('Modification detected.');
126
- }
127
- return new Uint8Array();
128
- });
129
- const bytes = stream.slice(tohash, crypto.cipher[sessionKeyAlgorithm].blockSize + 2); // Remove random prefix
130
- let packetbytes = stream.slice(bytes, 0, -2); // Remove MDC packet
131
- packetbytes = stream.concat([packetbytes, stream.fromAsync(() => verifyHash)]);
132
- if (!util.isStream(encrypted) || !config.allow_unauthenticated_stream) {
133
- packetbytes = await stream.readToEnd(packetbytes);
134
- }
135
- await this.packets.read(packetbytes, streaming);
136
- return true;
137
- };
138
-
139
- export default SymEncryptedIntegrityProtected;
@@ -1,204 +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
- * @requires type/s2k
20
- * @requires config
21
- * @requires crypto
22
- * @requires enums
23
- * @requires util
24
- */
25
-
26
- import type_s2k from '../type/s2k';
27
- import config from '../config';
28
- import crypto from '../crypto';
29
- import enums from '../enums';
30
- import util from '../util';
31
-
32
- /**
33
- * Public-Key Encrypted Session Key Packets (Tag 1)
34
- *
35
- * {@link https://tools.ietf.org/html/rfc4880#section-5.1|RFC4880 5.1}:
36
- * A Public-Key Encrypted Session Key packet holds the session key
37
- * used to encrypt a message. Zero or more Public-Key Encrypted Session Key
38
- * packets and/or Symmetric-Key Encrypted Session Key packets may precede a
39
- * Symmetrically Encrypted Data Packet, which holds an encrypted message. The
40
- * message is encrypted with the session key, and the session key is itself
41
- * encrypted and stored in the Encrypted Session Key packet(s). The
42
- * Symmetrically Encrypted Data Packet is preceded by one Public-Key Encrypted
43
- * Session Key packet for each OpenPGP key to which the message is encrypted.
44
- * The recipient of the message finds a session key that is encrypted to their
45
- * public key, decrypts the session key, and then uses the session key to
46
- * decrypt the message.
47
- * @memberof module:packet
48
- * @constructor
49
- */
50
- function SymEncryptedSessionKey() {
51
- this.tag = enums.packet.symEncryptedSessionKey;
52
- this.version = config.aead_protect ? 5 : 4;
53
- this.sessionKey = null;
54
- this.sessionKeyEncryptionAlgorithm = null;
55
- this.sessionKeyAlgorithm = 'aes256';
56
- this.aeadAlgorithm = enums.read(enums.aead, config.aead_mode);
57
- this.encrypted = null;
58
- this.s2k = null;
59
- this.iv = null;
60
- }
61
-
62
- /**
63
- * Parsing function for a symmetric encrypted session key packet (tag 3).
64
- *
65
- * @param {Uint8Array} input Payload of a tag 1 packet
66
- * @param {Integer} position Position to start reading from the input string
67
- * @param {Integer} len
68
- * Length of the packet or the remaining length of
69
- * input at position
70
- * @returns {module:packet.SymEncryptedSessionKey} Object representation
71
- */
72
- SymEncryptedSessionKey.prototype.read = function(bytes) {
73
- let offset = 0;
74
-
75
- // A one-octet version number. The only currently defined version is 4.
76
- this.version = bytes[offset++];
77
-
78
- // A one-octet number describing the symmetric algorithm used.
79
- const algo = enums.read(enums.symmetric, bytes[offset++]);
80
-
81
- if (this.version === 5) {
82
- // A one-octet AEAD algorithm.
83
- this.aeadAlgorithm = enums.read(enums.aead, bytes[offset++]);
84
- }
85
-
86
- // A string-to-key (S2K) specifier, length as defined above.
87
- this.s2k = new type_s2k();
88
- offset += this.s2k.read(bytes.subarray(offset, bytes.length));
89
-
90
- if (this.version === 5) {
91
- const mode = crypto[this.aeadAlgorithm];
92
-
93
- // A starting initialization vector of size specified by the AEAD
94
- // algorithm.
95
- this.iv = bytes.subarray(offset, offset += mode.ivLength);
96
- }
97
-
98
- // The encrypted session key itself, which is decrypted with the
99
- // string-to-key object. This is optional in version 4.
100
- if (this.version === 5 || offset < bytes.length) {
101
- this.encrypted = bytes.subarray(offset, bytes.length);
102
- this.sessionKeyEncryptionAlgorithm = algo;
103
- } else {
104
- this.sessionKeyAlgorithm = algo;
105
- }
106
- };
107
-
108
- SymEncryptedSessionKey.prototype.write = function() {
109
- const algo = this.encrypted === null ?
110
- this.sessionKeyAlgorithm :
111
- this.sessionKeyEncryptionAlgorithm;
112
-
113
- let bytes;
114
-
115
- if (this.version === 5) {
116
- bytes = util.concatUint8Array([new Uint8Array([this.version, enums.write(enums.symmetric, algo), enums.write(enums.aead, this.aeadAlgorithm)]), this.s2k.write(), this.iv, this.encrypted]);
117
- } else {
118
- bytes = util.concatUint8Array([new Uint8Array([this.version, enums.write(enums.symmetric, algo)]), this.s2k.write()]);
119
-
120
- if (this.encrypted !== null) {
121
- bytes = util.concatUint8Array([bytes, this.encrypted]);
122
- }
123
- }
124
-
125
- return bytes;
126
- };
127
-
128
- /**
129
- * Decrypts the session key
130
- * @param {String} passphrase The passphrase in string form
131
- * @returns {Promise<Boolean>}
132
- * @async
133
- */
134
- SymEncryptedSessionKey.prototype.decrypt = async function(passphrase) {
135
- const algo = this.sessionKeyEncryptionAlgorithm !== null ?
136
- this.sessionKeyEncryptionAlgorithm :
137
- this.sessionKeyAlgorithm;
138
-
139
- const length = crypto.cipher[algo].keySize;
140
- const key = await this.s2k.produce_key(passphrase, length);
141
-
142
- if (this.version === 5) {
143
- const mode = crypto[this.aeadAlgorithm];
144
- const adata = new Uint8Array([0xC0 | this.tag, this.version, enums.write(enums.symmetric, this.sessionKeyEncryptionAlgorithm), enums.write(enums.aead, this.aeadAlgorithm)]);
145
- const modeInstance = await mode(algo, key);
146
- this.sessionKey = await modeInstance.decrypt(this.encrypted, this.iv, adata);
147
- } else if (this.encrypted !== null) {
148
- const decrypted = await crypto.cfb.decrypt(algo, key, this.encrypted, new Uint8Array(crypto.cipher[algo].blockSize));
149
-
150
- this.sessionKeyAlgorithm = enums.read(enums.symmetric, decrypted[0]);
151
- this.sessionKey = decrypted.subarray(1, decrypted.length);
152
- } else {
153
- this.sessionKey = key;
154
- }
155
-
156
- return true;
157
- };
158
-
159
- /**
160
- * Encrypts the session key
161
- * @param {String} passphrase The passphrase in string form
162
- * @returns {Promise<Boolean>}
163
- * @async
164
- */
165
- SymEncryptedSessionKey.prototype.encrypt = async function(passphrase) {
166
- const algo = this.sessionKeyEncryptionAlgorithm !== null ?
167
- this.sessionKeyEncryptionAlgorithm :
168
- this.sessionKeyAlgorithm;
169
-
170
- this.sessionKeyEncryptionAlgorithm = algo;
171
-
172
- this.s2k = new type_s2k();
173
- this.s2k.salt = await crypto.random.getRandomBytes(8);
174
-
175
- const length = crypto.cipher[algo].keySize;
176
- const key = await this.s2k.produce_key(passphrase, length);
177
-
178
- if (this.sessionKey === null) {
179
- this.sessionKey = await crypto.generateSessionKey(this.sessionKeyAlgorithm);
180
- }
181
-
182
- if (this.version === 5) {
183
- const mode = crypto[this.aeadAlgorithm];
184
- this.iv = await crypto.random.getRandomBytes(mode.ivLength); // generate new random IV
185
- const adata = new Uint8Array([0xC0 | this.tag, this.version, enums.write(enums.symmetric, this.sessionKeyEncryptionAlgorithm), enums.write(enums.aead, this.aeadAlgorithm)]);
186
- const modeInstance = await mode(algo, key);
187
- this.encrypted = await modeInstance.encrypt(this.sessionKey, this.iv, adata);
188
- } else {
189
- const algo_enum = new Uint8Array([enums.write(enums.symmetric, this.sessionKeyAlgorithm)]);
190
- const private_key = util.concatUint8Array([algo_enum, this.sessionKey]);
191
- this.encrypted = await crypto.cfb.encrypt(algo, key, private_key, new Uint8Array(crypto.cipher[algo].blockSize));
192
- }
193
-
194
- return true;
195
- };
196
-
197
- /**
198
- * Fix custom types after cloning
199
- */
200
- SymEncryptedSessionKey.prototype.postCloneTypeFix = function() {
201
- this.s2k = type_s2k.fromClone(this.s2k);
202
- };
203
-
204
- export default SymEncryptedSessionKey;
@@ -1,118 +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
- * @requires web-stream-tools
20
- * @requires config
21
- * @requires crypto
22
- * @requires enums
23
- * @requires util
24
- */
25
-
26
- import stream from 'web-stream-tools';
27
- import config from '../config';
28
- import crypto from '../crypto';
29
- import enums from '../enums';
30
- import util from '../util';
31
-
32
- /**
33
- * Implementation of the Symmetrically Encrypted Data Packet (Tag 9)
34
- *
35
- * {@link https://tools.ietf.org/html/rfc4880#section-5.7|RFC4880 5.7}:
36
- * The Symmetrically Encrypted Data packet contains data encrypted with a
37
- * symmetric-key algorithm. When it has been decrypted, it contains other
38
- * packets (usually a literal data packet or compressed data packet, but in
39
- * theory other Symmetrically Encrypted Data packets or sequences of packets
40
- * that form whole OpenPGP messages).
41
- * @memberof module:packet
42
- * @constructor
43
- */
44
- function SymmetricallyEncrypted() {
45
- /**
46
- * Packet type
47
- * @type {module:enums.packet}
48
- */
49
- this.tag = enums.packet.symmetricallyEncrypted;
50
- /**
51
- * Encrypted secret-key data
52
- */
53
- this.encrypted = null;
54
- /**
55
- * Decrypted packets contained within.
56
- * @type {module:packet.List}
57
- */
58
- this.packets = null;
59
- /**
60
- * When true, decrypt fails if message is not integrity protected
61
- * @see module:config.ignore_mdc_error
62
- */
63
- this.ignore_mdc_error = config.ignore_mdc_error;
64
- }
65
-
66
- SymmetricallyEncrypted.prototype.read = function (bytes) {
67
- this.encrypted = bytes;
68
- };
69
-
70
- SymmetricallyEncrypted.prototype.write = function () {
71
- return this.encrypted;
72
- };
73
-
74
- /**
75
- * Decrypt the symmetrically-encrypted packet data
76
- * See {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2} for algorithms.
77
- * @param {module:enums.symmetric} sessionKeyAlgorithm Symmetric key algorithm to use
78
- * @param {Uint8Array} key The key of cipher blocksize length to be used
79
- * @returns {Promise<Boolean>}
80
- * @async
81
- */
82
- SymmetricallyEncrypted.prototype.decrypt = async function (sessionKeyAlgorithm, key) {
83
- // If MDC errors are not being ignored, all missing MDC packets in symmetrically encrypted data should throw an error
84
- if (!this.ignore_mdc_error) {
85
- throw new Error('Decryption failed due to missing MDC.');
86
- }
87
-
88
- this.encrypted = await stream.readToEnd(this.encrypted);
89
- const decrypted = await crypto.cfb.decrypt(sessionKeyAlgorithm, key,
90
- this.encrypted.subarray(crypto.cipher[sessionKeyAlgorithm].blockSize + 2),
91
- this.encrypted.subarray(2, crypto.cipher[sessionKeyAlgorithm].blockSize + 2)
92
- );
93
-
94
- await this.packets.read(decrypted);
95
-
96
- return true;
97
- };
98
-
99
- /**
100
- * Encrypt the symmetrically-encrypted packet data
101
- * See {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC 4880 9.2} for algorithms.
102
- * @param {module:enums.symmetric} sessionKeyAlgorithm Symmetric key algorithm to use
103
- * @param {Uint8Array} key The key of cipher blocksize length to be used
104
- * @returns {Promise<Boolean>}
105
- * @async
106
- */
107
- SymmetricallyEncrypted.prototype.encrypt = async function (algo, key) {
108
- const data = this.packets.write();
109
-
110
- const prefix = await crypto.getPrefixRandom(algo);
111
- const FRE = await crypto.cfb.encrypt(algo, key, prefix, new Uint8Array(crypto.cipher[algo].blockSize));
112
- const ciphertext = await crypto.cfb.encrypt(algo, key, data, FRE.subarray(2));
113
- this.encrypted = util.concat([FRE, ciphertext]);
114
-
115
- return true;
116
- };
117
-
118
- export default SymmetricallyEncrypted;
@@ -1,35 +0,0 @@
1
- /**
2
- * @requires enums
3
- */
4
-
5
- import enums from '../enums';
6
-
7
- /**
8
- * Implementation of the Trust Packet (Tag 12)
9
- *
10
- * {@link https://tools.ietf.org/html/rfc4880#section-5.10|RFC4880 5.10}:
11
- * The Trust packet is used only within keyrings and is not normally
12
- * exported. Trust packets contain data that record the user's
13
- * specifications of which key holders are trustworthy introducers,
14
- * along with other information that implementing software uses for
15
- * trust information. The format of Trust packets is defined by a given
16
- * implementation.
17
- *
18
- * Trust packets SHOULD NOT be emitted to output streams that are
19
- * transferred to other users, and they SHOULD be ignored on any input
20
- * other than local keyring files.
21
- * @memberof module:packet
22
- * @constructor
23
- */
24
- function Trust() {
25
- this.tag = enums.packet.trust;
26
- }
27
-
28
- /**
29
- * Parsing function for a trust packet (tag 12).
30
- * Currently not implemented as we ignore trust packets
31
- * @param {String} byptes payload of a tag 12 packet
32
- */
33
- Trust.prototype.read = function () {}; // TODO
34
-
35
- export default Trust;