@protontech/openpgp 4.10.5 → 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 +41080 -41565
  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 -61067
  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 -40024
  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 -224
  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 -363
  88. package/src/key/index.js +0 -32
  89. package/src/key/key.js +0 -890
  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 -156
  109. package/src/packet/public_subkey.js +0 -44
  110. package/src/packet/secret_key.js +0 -448
  111. package/src/packet/secret_subkey.js +0 -41
  112. package/src/packet/signature.js +0 -782
  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 -88
  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 -3402
  163. package/test/general/keyring.js +0 -336
  164. package/test/general/oid.js +0 -39
  165. package/test/general/openpgp.js +0 -2542
  166. package/test/general/packet.js +0 -937
  167. package/test/general/signature.js +0 -1665
  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,232 +0,0 @@
1
- /* eslint-disable callback-return */
2
- /**
3
- * @requires web-stream-tools
4
- * @requires packet/all_packets
5
- * @requires packet/packet
6
- * @requires config
7
- * @requires enums
8
- * @requires util
9
- */
10
-
11
- import stream from 'web-stream-tools';
12
- import * as packets from './all_packets';
13
- import packetParser from './packet';
14
- import config from '../config';
15
- import enums from '../enums';
16
- import util from '../util';
17
-
18
- /**
19
- * This class represents a list of openpgp packets.
20
- * Take care when iterating over it - the packets themselves
21
- * are stored as numerical indices.
22
- * @memberof module:packet
23
- * @constructor
24
- * @extends Array
25
- */
26
- function List() {
27
- /**
28
- * The number of packets contained within the list.
29
- * @readonly
30
- * @type {Integer}
31
- */
32
- this.length = 0;
33
- }
34
-
35
- List.prototype = [];
36
-
37
- /**
38
- * Reads a stream of binary data and interprents it as a list of packets.
39
- * @param {Uint8Array | ReadableStream<Uint8Array>} A Uint8Array of bytes.
40
- */
41
- List.prototype.read = async function (bytes, streaming) {
42
- this.stream = stream.transformPair(bytes, async (readable, writable) => {
43
- const writer = stream.getWriter(writable);
44
- try {
45
- while (true) {
46
- await writer.ready;
47
- const done = await packetParser.read(readable, streaming, async parsed => {
48
- try {
49
- const tag = enums.read(enums.packet, parsed.tag);
50
- const packet = packets.newPacketFromTag(tag);
51
- packet.packets = new List();
52
- packet.fromStream = util.isStream(parsed.packet);
53
- await packet.read(parsed.packet, streaming);
54
- await writer.write(packet);
55
- } catch (e) {
56
- if (!config.tolerant || packetParser.supportsStreaming(parsed.tag)) {
57
- // The packets that support streaming are the ones that contain
58
- // message data. Those are also the ones we want to be more strict
59
- // about and throw on parse errors for.
60
- await writer.abort(e);
61
- }
62
- util.print_debug_error(e);
63
- }
64
- });
65
- if (done) {
66
- await writer.ready;
67
- await writer.close();
68
- return;
69
- }
70
- }
71
- } catch (e) {
72
- await writer.abort(e);
73
- }
74
- });
75
-
76
- // Wait until first few packets have been read
77
- const reader = stream.getReader(this.stream);
78
- while (true) {
79
- const { done, value } = await reader.read();
80
- if (!done) {
81
- this.push(value);
82
- } else {
83
- this.stream = null;
84
- }
85
- if (done || packetParser.supportsStreaming(value.tag)) {
86
- break;
87
- }
88
- }
89
- reader.releaseLock();
90
- };
91
-
92
- /**
93
- * Creates a binary representation of openpgp objects contained within the
94
- * class instance.
95
- * @returns {Uint8Array} A Uint8Array containing valid openpgp packets.
96
- */
97
- List.prototype.write = function () {
98
- const arr = [];
99
-
100
- for (let i = 0; i < this.length; i++) {
101
- const packetbytes = this[i].write();
102
- if (util.isStream(packetbytes) && packetParser.supportsStreaming(this[i].tag)) {
103
- let buffer = [];
104
- let bufferLength = 0;
105
- const minLength = 512;
106
- arr.push(packetParser.writeTag(this[i].tag));
107
- arr.push(stream.transform(packetbytes, value => {
108
- buffer.push(value);
109
- bufferLength += value.length;
110
- if (bufferLength >= minLength) {
111
- const powerOf2 = Math.min(Math.log(bufferLength) / Math.LN2 | 0, 30);
112
- const chunkSize = 2 ** powerOf2;
113
- const bufferConcat = util.concat([packetParser.writePartialLength(powerOf2)].concat(buffer));
114
- buffer = [bufferConcat.subarray(1 + chunkSize)];
115
- bufferLength = buffer[0].length;
116
- return bufferConcat.subarray(0, 1 + chunkSize);
117
- }
118
- }, () => util.concat([packetParser.writeSimpleLength(bufferLength)].concat(buffer))));
119
- } else {
120
- if (util.isStream(packetbytes)) {
121
- let length = 0;
122
- arr.push(stream.transform(stream.clone(packetbytes), value => {
123
- length += value.length;
124
- }, () => packetParser.writeHeader(this[i].tag, length)));
125
- } else {
126
- arr.push(packetParser.writeHeader(this[i].tag, packetbytes.length));
127
- }
128
- arr.push(packetbytes);
129
- }
130
- }
131
-
132
- return util.concat(arr);
133
- };
134
-
135
- /**
136
- * Adds a packet to the list. This is the only supported method of doing so;
137
- * writing to packetlist[i] directly will result in an error.
138
- * @param {Object} packet Packet to push
139
- */
140
- List.prototype.push = function (packet) {
141
- if (!packet) {
142
- return;
143
- }
144
-
145
- packet.packets = packet.packets || new List();
146
-
147
- this[this.length] = packet;
148
- this.length++;
149
- };
150
-
151
- /**
152
- * Creates a new PacketList with all packets from the given types
153
- */
154
- List.prototype.filterByTag = function (...args) {
155
- const filtered = new List();
156
-
157
- const handle = tag => packetType => tag === packetType;
158
-
159
- for (let i = 0; i < this.length; i++) {
160
- if (args.some(handle(this[i].tag))) {
161
- filtered.push(this[i]);
162
- }
163
- }
164
-
165
- return filtered;
166
- };
167
-
168
- /**
169
- * Traverses packet tree and returns first matching packet
170
- * @param {module:enums.packet} type The packet type
171
- * @returns {module:packet/packet|undefined}
172
- */
173
- List.prototype.findPacket = function (type) {
174
- return this.find(packet => packet.tag === type);
175
- };
176
-
177
- /**
178
- * Returns array of found indices by tag
179
- */
180
- List.prototype.indexOfTag = function (...args) {
181
- const tagIndex = [];
182
- const that = this;
183
-
184
- const handle = tag => packetType => tag === packetType;
185
-
186
- for (let i = 0; i < this.length; i++) {
187
- if (args.some(handle(that[i].tag))) {
188
- tagIndex.push(i);
189
- }
190
- }
191
- return tagIndex;
192
- };
193
-
194
- /**
195
- * Concatenates packetlist or array of packets
196
- */
197
- List.prototype.concat = function (packetlist) {
198
- if (packetlist) {
199
- for (let i = 0; i < packetlist.length; i++) {
200
- this.push(packetlist[i]);
201
- }
202
- }
203
- return this;
204
- };
205
-
206
- /**
207
- * Allocate a new packetlist from structured packetlist clone
208
- * See {@link https://w3c.github.io/html/infrastructure.html#safe-passing-of-structured-data}
209
- * @param {Object} packetClone packetlist clone
210
- * @returns {Object} new packetlist object with data from packetlist clone
211
- */
212
- List.fromStructuredClone = function(packetlistClone) {
213
- const packetlist = new List();
214
- for (let i = 0; i < packetlistClone.length; i++) {
215
- const packet = packets.fromStructuredClone(packetlistClone[i]);
216
- packetlist.push(packet);
217
- if (packet.embeddedSignature) {
218
- packet.embeddedSignature = packets.fromStructuredClone(packet.embeddedSignature);
219
- }
220
- if (packet.packets.length !== 0) {
221
- packet.packets = this.fromStructuredClone(packet.packets);
222
- } else {
223
- packet.packets = new List();
224
- }
225
- }
226
- if (packetlistClone.stream) {
227
- packetlist.stream = stream.transform(packetlistClone.stream, packet => packets.fromStructuredClone(packet));
228
- }
229
- return packetlist;
230
- };
231
-
232
- export default List;
@@ -1,280 +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/keyid
20
- * @requires type/mpi
21
- * @requires config
22
- * @requires crypto
23
- * @requires enums
24
- * @requires util
25
- */
26
-
27
- import { Sha1 } from 'asmcrypto.js/dist_es5/hash/sha1/sha1';
28
- import { Sha256 } from 'asmcrypto.js/dist_es5/hash/sha256/sha256';
29
- import type_keyid from '../type/keyid';
30
- import type_mpi from '../type/mpi';
31
- import config from '../config';
32
- import crypto from '../crypto';
33
- import enums from '../enums';
34
- import util from '../util';
35
-
36
- /**
37
- * Implementation of the Key Material Packet (Tag 5,6,7,14)
38
- *
39
- * {@link https://tools.ietf.org/html/rfc4880#section-5.5|RFC4480 5.5}:
40
- * A key material packet contains all the information about a public or
41
- * private key. There are four variants of this packet type, and two
42
- * major versions.
43
- *
44
- * A Public-Key packet starts a series of packets that forms an OpenPGP
45
- * key (sometimes called an OpenPGP certificate).
46
- * @memberof module:packet
47
- * @constructor
48
- */
49
- function PublicKey(date = new Date()) {
50
- /**
51
- * Packet type
52
- * @type {module:enums.packet}
53
- */
54
- this.tag = enums.packet.publicKey;
55
- /**
56
- * Packet version
57
- * @type {Integer}
58
- */
59
- this.version = config.v5_keys ? 5 : 4;
60
- /**
61
- * Key creation date.
62
- * @type {Date}
63
- */
64
- this.created = util.normalizeDate(date);
65
- /**
66
- * Public key algorithm.
67
- * @type {String}
68
- */
69
- this.algorithm = null;
70
- /**
71
- * Algorithm specific params
72
- * @type {Array<Object>}
73
- */
74
- this.params = [];
75
- /**
76
- * Time until expiration in days (V3 only)
77
- * @type {Integer}
78
- */
79
- this.expirationTimeV3 = 0;
80
- /**
81
- * Fingerprint in lowercase hex
82
- * @type {String}
83
- */
84
- this.fingerprint = null;
85
- /**
86
- * Keyid
87
- * @type {module:type/keyid}
88
- */
89
- this.keyid = null;
90
- }
91
-
92
- /**
93
- * Internal Parser for public keys as specified in {@link https://tools.ietf.org/html/rfc4880#section-5.5.2|RFC 4880 section 5.5.2 Public-Key Packet Formats}
94
- * called by read_tag&lt;num&gt;
95
- * @param {Uint8Array} bytes Input array to read the packet from
96
- * @returns {Object} This object with attributes set by the parser
97
- */
98
- PublicKey.prototype.read = function (bytes) {
99
- let pos = 0;
100
- // A one-octet version number (3, 4 or 5).
101
- this.version = bytes[pos++];
102
-
103
- if (this.version === 4 || this.version === 5) {
104
- // - A four-octet number denoting the time that the key was created.
105
- this.created = util.readDate(bytes.subarray(pos, pos + 4));
106
- pos += 4;
107
-
108
- // - A one-octet number denoting the public-key algorithm of this key.
109
- this.algorithm = enums.read(enums.publicKey, bytes[pos++]);
110
- const algo = enums.write(enums.publicKey, this.algorithm);
111
-
112
- if (this.version === 5) {
113
- // - A four-octet scalar octet count for the following key material.
114
- pos += 4;
115
- }
116
-
117
- // - A series of values comprising the key material. This is
118
- // algorithm-specific and described in section XXXX.
119
- const types = crypto.getPubKeyParamTypes(algo);
120
- this.params = crypto.constructParams(types);
121
-
122
- for (let i = 0; i < types.length && pos < bytes.length; i++) {
123
- pos += this.params[i].read(bytes.subarray(pos, bytes.length));
124
- if (pos > bytes.length) {
125
- throw new Error('Error reading MPI @:' + pos);
126
- }
127
- }
128
-
129
- return pos;
130
- }
131
- throw new Error('Version ' + this.version + ' of the key packet is unsupported.');
132
- };
133
-
134
- /**
135
- * Alias of read()
136
- * @see module:packet.PublicKey#read
137
- */
138
- PublicKey.prototype.readPublicKey = PublicKey.prototype.read;
139
-
140
- /**
141
- * Same as write_private_key, but has less information because of
142
- * public key.
143
- * @returns {Uint8Array} OpenPGP packet body contents,
144
- */
145
- PublicKey.prototype.write = function () {
146
- const arr = [];
147
- // Version
148
- arr.push(new Uint8Array([this.version]));
149
- arr.push(util.writeDate(this.created));
150
- // A one-octet number denoting the public-key algorithm of this key
151
- const algo = enums.write(enums.publicKey, this.algorithm);
152
- arr.push(new Uint8Array([algo]));
153
-
154
- const paramCount = crypto.getPubKeyParamTypes(algo).length;
155
- const params = util.concatUint8Array(this.params.slice(0, paramCount).map(param => param.write()));
156
- if (this.version === 5) {
157
- // A four-octet scalar octet count for the following key material
158
- arr.push(util.writeNumber(params.length, 4));
159
- }
160
- // Algorithm-specific params
161
- arr.push(params);
162
- return util.concatUint8Array(arr);
163
- };
164
-
165
- /**
166
- * Alias of write()
167
- * @see module:packet.PublicKey#write
168
- */
169
- PublicKey.prototype.writePublicKey = PublicKey.prototype.write;
170
-
171
- /**
172
- * Write packet in order to be hashed; either for a signature or a fingerprint.
173
- */
174
- PublicKey.prototype.writeForHash = function (version) {
175
- const bytes = this.writePublicKey();
176
-
177
- if (version === 5) {
178
- return util.concatUint8Array([new Uint8Array([0x9A]), util.writeNumber(bytes.length, 4), bytes]);
179
- }
180
- return util.concatUint8Array([new Uint8Array([0x99]), util.writeNumber(bytes.length, 2), bytes]);
181
- };
182
-
183
- /**
184
- * Check whether secret-key data is available in decrypted form. Returns null for public keys.
185
- * @returns {Boolean|null}
186
- */
187
- PublicKey.prototype.isDecrypted = function() {
188
- return null;
189
- };
190
-
191
- /**
192
- * Returns the creation time of the key
193
- * @returns {Date}
194
- */
195
- PublicKey.prototype.getCreationTime = function() {
196
- return this.created;
197
- };
198
-
199
- /**
200
- * Calculates the key id of the key
201
- * @returns {module:type/keyid} A 8 byte key id
202
- */
203
- PublicKey.prototype.getKeyId = function () {
204
- if (this.keyid) {
205
- return this.keyid;
206
- }
207
- this.keyid = new type_keyid();
208
- if (this.version === 5) {
209
- this.keyid.read(util.hex_to_Uint8Array(this.getFingerprint()).subarray(0, 8));
210
- } else if (this.version === 4) {
211
- this.keyid.read(util.hex_to_Uint8Array(this.getFingerprint()).subarray(12, 20));
212
- }
213
- return this.keyid;
214
- };
215
-
216
- /**
217
- * Calculates the fingerprint of the key
218
- * @returns {Uint8Array} A Uint8Array containing the fingerprint
219
- */
220
- PublicKey.prototype.getFingerprintBytes = function () {
221
- if (this.fingerprint) {
222
- return this.fingerprint;
223
- }
224
- const toHash = this.writeForHash(this.version);
225
- if (this.version === 5) {
226
- this.fingerprint = Sha256.bytes(toHash);
227
- } else if (this.version === 4) {
228
- this.fingerprint = Sha1.bytes(toHash);
229
- }
230
- return this.fingerprint;
231
- };
232
-
233
- /**
234
- * Calculates the fingerprint of the key
235
- * @returns {String} A string containing the fingerprint in lowercase hex
236
- */
237
- PublicKey.prototype.getFingerprint = function() {
238
- return util.Uint8Array_to_hex(this.getFingerprintBytes());
239
- };
240
-
241
- /**
242
- * Calculates whether two keys have the same fingerprint without actually calculating the fingerprint
243
- * @returns {Boolean} Whether the two keys have the same version and public key data
244
- */
245
- PublicKey.prototype.hasSameFingerprintAs = function(other) {
246
- return this.version === other.version && util.equalsUint8Array(this.writePublicKey(), other.writePublicKey());
247
- };
248
-
249
- /**
250
- * Returns algorithm information
251
- * @returns {Object} An object of the form {algorithm: String, rsaBits:int, curve:String}
252
- */
253
- PublicKey.prototype.getAlgorithmInfo = function () {
254
- const result = {};
255
- result.algorithm = this.algorithm;
256
- if (this.params[0] instanceof type_mpi) {
257
- result.rsaBits = this.params[0].byteLength() * 8;
258
- result.bits = result.rsaBits; // Deprecated.
259
- } else {
260
- result.curve = this.params[0].getName();
261
- }
262
- return result;
263
- };
264
-
265
- /**
266
- * Fix custom types after cloning
267
- */
268
- PublicKey.prototype.postCloneTypeFix = function() {
269
- const algo = enums.write(enums.publicKey, this.algorithm);
270
- const types = crypto.getPubKeyParamTypes(algo);
271
- for (let i = 0; i < types.length; i++) {
272
- const param = this.params[i];
273
- this.params[i] = types[i].fromClone(param);
274
- }
275
- if (this.keyid) {
276
- this.keyid = type_keyid.fromClone(this.keyid);
277
- }
278
- };
279
-
280
- export default PublicKey;
@@ -1,156 +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/keyid
20
- * @requires type/mpi
21
- * @requires crypto
22
- * @requires enums
23
- * @requires util
24
- */
25
-
26
- import type_keyid from '../type/keyid';
27
- import crypto from '../crypto';
28
- import enums from '../enums';
29
- import util from '../util';
30
-
31
- /**
32
- * Public-Key Encrypted Session Key Packets (Tag 1)
33
- *
34
- * {@link https://tools.ietf.org/html/rfc4880#section-5.1|RFC4880 5.1}:
35
- * A Public-Key Encrypted Session Key packet holds the session key
36
- * used to encrypt a message. Zero or more Public-Key Encrypted Session Key
37
- * packets and/or Symmetric-Key Encrypted Session Key packets may precede a
38
- * Symmetrically Encrypted Data Packet, which holds an encrypted message. The
39
- * message is encrypted with the session key, and the session key is itself
40
- * encrypted and stored in the Encrypted Session Key packet(s). The
41
- * Symmetrically Encrypted Data Packet is preceded by one Public-Key Encrypted
42
- * Session Key packet for each OpenPGP key to which the message is encrypted.
43
- * The recipient of the message finds a session key that is encrypted to their
44
- * public key, decrypts the session key, and then uses the session key to
45
- * decrypt the message.
46
- * @memberof module:packet
47
- * @constructor
48
- */
49
- function PublicKeyEncryptedSessionKey() {
50
- this.tag = enums.packet.publicKeyEncryptedSessionKey;
51
- this.version = 3;
52
-
53
- this.publicKeyId = new type_keyid();
54
- this.publicKeyAlgorithm = null;
55
-
56
- this.sessionKey = null;
57
- this.sessionKeyAlgorithm = null;
58
-
59
- /** @type {Array<module:type/mpi>} */
60
- this.encrypted = [];
61
- }
62
-
63
- /**
64
- * Parsing function for a publickey encrypted session key packet (tag 1).
65
- *
66
- * @param {Uint8Array} input Payload of a tag 1 packet
67
- * @param {Integer} position Position to start reading from the input string
68
- * @param {Integer} len Length of the packet or the remaining length of
69
- * input at position
70
- * @returns {module:packet.PublicKeyEncryptedSessionKey} Object representation
71
- */
72
- PublicKeyEncryptedSessionKey.prototype.read = function (bytes) {
73
- this.version = bytes[0];
74
- this.publicKeyId.read(bytes.subarray(1, bytes.length));
75
- this.publicKeyAlgorithm = enums.read(enums.publicKey, bytes[9]);
76
-
77
- let i = 10;
78
-
79
- const algo = enums.write(enums.publicKey, this.publicKeyAlgorithm);
80
- const types = crypto.getEncSessionKeyParamTypes(algo);
81
- this.encrypted = crypto.constructParams(types);
82
-
83
- for (let j = 0; j < types.length; j++) {
84
- i += this.encrypted[j].read(bytes.subarray(i, bytes.length));
85
- }
86
- };
87
-
88
- /**
89
- * Create a string representation of a tag 1 packet
90
- *
91
- * @returns {Uint8Array} The Uint8Array representation
92
- */
93
- PublicKeyEncryptedSessionKey.prototype.write = function () {
94
- const arr = [new Uint8Array([this.version]), this.publicKeyId.write(), new Uint8Array([enums.write(enums.publicKey, this.publicKeyAlgorithm)])];
95
-
96
- for (let i = 0; i < this.encrypted.length; i++) {
97
- arr.push(this.encrypted[i].write());
98
- }
99
-
100
- return util.concatUint8Array(arr);
101
- };
102
-
103
- /**
104
- * Encrypt session key packet
105
- * @param {module:packet.PublicKey} key Public key
106
- * @returns {Promise<Boolean>}
107
- * @async
108
- */
109
- PublicKeyEncryptedSessionKey.prototype.encrypt = async function (key) {
110
- let data = String.fromCharCode(enums.write(enums.symmetric, this.sessionKeyAlgorithm));
111
-
112
- data += util.Uint8Array_to_str(this.sessionKey);
113
- data += util.Uint8Array_to_str(util.write_checksum(this.sessionKey));
114
- const algo = enums.write(enums.publicKey, this.publicKeyAlgorithm);
115
- this.encrypted = await crypto.publicKeyEncrypt(
116
- algo, key.params, data, key.getFingerprintBytes());
117
- return true;
118
- };
119
-
120
- /**
121
- * Decrypts the session key (only for public key encrypted session key
122
- * packets (tag 1)
123
- *
124
- * @param {module:packet.SecretKey} key
125
- * Private key with secret params unlocked
126
- * @returns {Promise<Boolean>}
127
- * @async
128
- */
129
- PublicKeyEncryptedSessionKey.prototype.decrypt = async function (key) {
130
- const algo = enums.write(enums.publicKey, this.publicKeyAlgorithm);
131
- const decoded = await crypto.publicKeyDecrypt(algo, key.params, this.encrypted, key.getFingerprintBytes());
132
- const checksum = util.str_to_Uint8Array(decoded.substr(decoded.length - 2));
133
- key = util.str_to_Uint8Array(decoded.substring(1, decoded.length - 2));
134
-
135
- if (!util.equalsUint8Array(checksum, util.write_checksum(key))) {
136
- throw new Error('Decryption error');
137
- } else {
138
- this.sessionKey = key;
139
- this.sessionKeyAlgorithm = enums.read(enums.symmetric, decoded.charCodeAt(0));
140
- }
141
- return true;
142
- };
143
-
144
- /**
145
- * Fix custom types after cloning
146
- */
147
- PublicKeyEncryptedSessionKey.prototype.postCloneTypeFix = function() {
148
- this.publicKeyId = type_keyid.fromClone(this.publicKeyId);
149
- const algo = enums.write(enums.publicKey, this.publicKeyAlgorithm);
150
- const types = crypto.getEncSessionKeyParamTypes(algo);
151
- for (let i = 0; i < this.encrypted.length; i++) {
152
- this.encrypted[i] = types[i].fromClone(this.encrypted[i]);
153
- }
154
- };
155
-
156
- export default PublicKeyEncryptedSessionKey;
@@ -1,44 +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 packet/public_key
20
- * @requires enums
21
- */
22
-
23
- import PublicKey from './public_key';
24
- import enums from '../enums';
25
-
26
- /**
27
- * A Public-Subkey packet (tag 14) has exactly the same format as a
28
- * Public-Key packet, but denotes a subkey. One or more subkeys may be
29
- * associated with a top-level key. By convention, the top-level key
30
- * provides signature services, and the subkeys provide encryption
31
- * services.
32
- * @memberof module:packet
33
- * @constructor
34
- * @extends module:packet.PublicKey
35
- */
36
- function PublicSubkey() {
37
- PublicKey.call(this);
38
- this.tag = enums.packet.publicSubkey;
39
- }
40
-
41
- PublicSubkey.prototype = new PublicKey();
42
- PublicSubkey.prototype.constructor = PublicSubkey;
43
-
44
- export default PublicSubkey;