@protontech/openpgp 4.10.6 → 5.4.0

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 +31379 -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 +43947 -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 +43884 -0
  26. package/dist/openpgp.js +41082 -41563
  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 +43872 -0
  32. package/lightweight/package.json +5 -0
  33. package/openpgp.d.ts +890 -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,79 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
2
-
3
- const chai = require('chai');
4
-
5
- const { expect } = chai;
6
-
7
- describe('Random Buffer', function() {
8
- let randomBuffer;
9
-
10
- before(function() {
11
- randomBuffer = new openpgp.crypto.random.randomBuffer.constructor();
12
- expect(randomBuffer).to.exist;
13
- });
14
-
15
- it('Throw error if not initialized', async function () {
16
- expect(randomBuffer.set.bind(randomBuffer)).to.throw('RandomBuffer is not initialized');
17
- await expect(randomBuffer.get(new Uint8Array(1))).to.eventually.be.rejectedWith('RandomBuffer is not initialized');
18
- });
19
-
20
- it('Initialization', function () {
21
- randomBuffer.init(5);
22
- expect(randomBuffer.buffer).to.exist;
23
- expect(randomBuffer.buffer).to.have.length(5);
24
- expect(randomBuffer.size).to.equal(0);
25
- });
26
-
27
- function equal(buf, arr) {
28
- for (let i = 0; i < buf.length; i++) {
29
- if (buf[i] !== arr[i]) {
30
- return false;
31
- }
32
- }
33
- return true;
34
- }
35
-
36
- it('Set Method', function () {
37
- randomBuffer.init(5);
38
- let buf = new Uint32Array(2);
39
- expect(randomBuffer.set.bind(randomBuffer, buf)).to.throw('Invalid type: buf not an Uint8Array');
40
- buf = new Uint8Array(2);
41
- buf[0] = 1; buf[1] = 2;
42
- randomBuffer.set(buf);
43
- expect(equal(randomBuffer.buffer, [1,2,0,0,0])).to.be.true;
44
- expect(randomBuffer.size).to.equal(2);
45
- randomBuffer.set(buf);
46
- expect(equal(randomBuffer.buffer, [1,2,1,2,0])).to.be.true;
47
- expect(randomBuffer.size).to.equal(4);
48
- randomBuffer.set(buf);
49
- expect(equal(randomBuffer.buffer, [1,2,1,2,1])).to.be.true;
50
- expect(randomBuffer.size).to.equal(5);
51
- randomBuffer.init(1);
52
- buf = new Uint8Array(2);
53
- buf[0] = 1; buf[1] = 2;
54
- randomBuffer.set(buf);
55
- expect(buf).to.to.have.property('0', 1);
56
- expect(randomBuffer.size).to.equal(1);
57
- });
58
-
59
- it('Get Method', async function () {
60
- randomBuffer.init(5);
61
- let buf = new Uint8Array(5);
62
- buf[0] = 1; buf[1] = 2; buf[2] = 5; buf[3] = 7; buf[4] = 8;
63
- randomBuffer.set(buf);
64
- buf = new Uint32Array(2);
65
- await expect(randomBuffer.get(buf)).to.eventually.be.rejectedWith('Invalid type: buf not an Uint8Array');
66
- buf = new Uint8Array(2);
67
- randomBuffer.get(buf);
68
- expect(equal(randomBuffer.buffer, [1,2,5,0,0])).to.be.true;
69
- expect(randomBuffer.size).to.equal(3);
70
- expect(buf).to.to.have.property('0', 8);
71
- expect(buf).to.to.have.property('1', 7);
72
- randomBuffer.get(buf);
73
- expect(buf).to.to.have.property('0', 5);
74
- expect(buf).to.to.have.property('1', 2);
75
- expect(equal(randomBuffer.buffer, [1,0,0,0,0])).to.be.true;
76
- expect(randomBuffer.size).to.equal(1);
77
- await expect(randomBuffer.get(buf)).to.eventually.be.rejectedWith('Random number buffer depleted');
78
- });
79
- });
@@ -1,180 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
2
- const chai = require('chai');
3
-
4
- chai.use(require('chai-as-promised'));
5
-
6
- const expect = chai.expect;
7
-
8
- /* eslint-disable no-unused-expressions */
9
- /* eslint-disable no-invalid-this */
10
- const native = openpgp.util.getWebCrypto() || openpgp.util.getNodeCrypto();
11
- (!native ? describe.skip : describe)('basic RSA cryptography with native crypto', function () {
12
- it('generate rsa key', async function() {
13
- const bits = openpgp.util.getWebCryptoAll() ? 2048 : 1024;
14
- const keyObject = await openpgp.crypto.publicKey.rsa.generate(bits, "10001");
15
- expect(keyObject.n).to.exist;
16
- expect(keyObject.e).to.exist;
17
- expect(keyObject.d).to.exist;
18
- expect(keyObject.p).to.exist;
19
- expect(keyObject.q).to.exist;
20
- expect(keyObject.u).to.exist;
21
- });
22
-
23
- it('sign and verify using generated key params', async function() {
24
- const bits = openpgp.util.getWebCryptoAll() ? 2048 : 1024;
25
- const keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, bits);
26
- const message = await openpgp.crypto.random.getRandomBytes(64);
27
- const hash_algo = openpgp.enums.write(openpgp.enums.hash, 'sha256');
28
- const hashed = await openpgp.crypto.hash.digest(hash_algo, message);
29
- const n = keyParams[0].toUint8Array();
30
- const e = keyParams[1].toUint8Array();
31
- const d = keyParams[2].toUint8Array();
32
- const p = keyParams[3].toUint8Array();
33
- const q = keyParams[4].toUint8Array();
34
- const u = keyParams[5].toUint8Array();
35
- const signature = await openpgp.crypto.publicKey.rsa.sign(hash_algo, message, n, e, d, p, q, u, hashed);
36
- expect(signature).to.exist;
37
- const verify = await openpgp.crypto.publicKey.rsa.verify(hash_algo, message, signature, n, e, hashed);
38
- expect(verify).to.be.true;
39
- });
40
-
41
- it('encrypt and decrypt using generated key params', async function() {
42
- const bits = openpgp.util.getWebCryptoAll() ? 2048 : 1024;
43
- const keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, bits);
44
- const n = keyParams[0].toUint8Array();
45
- const e = keyParams[1].toUint8Array();
46
- const d = keyParams[2].toUint8Array();
47
- const p = keyParams[3].toUint8Array();
48
- const q = keyParams[4].toUint8Array();
49
- const u = keyParams[5].toUint8Array();
50
- const message = openpgp.util.Uint8Array_to_str(await openpgp.crypto.generateSessionKey('aes256'));
51
- const encrypted = await openpgp.crypto.publicKey.rsa.encrypt(openpgp.util.str_to_Uint8Array(message), n, e);
52
- const result = new openpgp.MPI(encrypted);
53
- const decrypted = await openpgp.crypto.publicKey.rsa.decrypt(result.toUint8Array(), n, e, d, p, q, u);
54
- expect(decrypted).to.be.equal(message);
55
- });
56
-
57
- it('decrypt nodeCrypto by bnCrypto and vice versa', async function() {
58
- if (!openpgp.util.getNodeCrypto()) {
59
- this.skip();
60
- }
61
- const bits = 1024;
62
- const keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, bits);
63
- const n = keyParams[0].toUint8Array();
64
- const e = keyParams[1].toUint8Array();
65
- const d = keyParams[2].toUint8Array();
66
- const p = keyParams[3].toUint8Array();
67
- const q = keyParams[4].toUint8Array();
68
- const u = keyParams[5].toUint8Array();
69
- const message = openpgp.util.Uint8Array_to_str(await openpgp.crypto.generateSessionKey('aes256'));
70
- const encryptedBn = await openpgp.crypto.publicKey.rsa.bnEncrypt(openpgp.util.str_to_Uint8Array(message), n, e);
71
- const resultBN = new openpgp.MPI(encryptedBn);
72
- const decrypted1 = await openpgp.crypto.publicKey.rsa.nodeDecrypt(resultBN.toUint8Array(), n, e, d, p, q, u);
73
- expect(decrypted1).to.be.equal(message);
74
- const encryptedNode = await openpgp.crypto.publicKey.rsa.nodeEncrypt(openpgp.util.str_to_Uint8Array(message), n, e);
75
- const resultNode = new openpgp.MPI(encryptedNode);
76
- const decrypted2 = await openpgp.crypto.publicKey.rsa.bnDecrypt(resultNode.toUint8Array(), n, e, d, p, q, u);
77
- expect(decrypted2).to.be.equal(message);
78
- });
79
-
80
- it('compare webCrypto and bn math sign', async function() {
81
- if (!openpgp.util.getWebCrypto()) {
82
- this.skip();
83
- }
84
- const bits = openpgp.util.getWebCrypto() ? 2048 : 1024;
85
- const keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, bits);
86
- const n = keyParams[0].toUint8Array();
87
- const e = keyParams[1].toUint8Array();
88
- const d = keyParams[2].toUint8Array();
89
- const p = keyParams[3].toUint8Array();
90
- const q = keyParams[4].toUint8Array();
91
- const u = keyParams[5].toUint8Array();
92
- const message = await openpgp.crypto.random.getRandomBytes(64);
93
- const hashName = 'sha256';
94
- const hash_algo = openpgp.enums.write(openpgp.enums.hash, hashName);
95
- const hashed = await openpgp.crypto.hash.digest(hash_algo, message);
96
- let signatureWeb;
97
- try {
98
- signatureWeb = await openpgp.crypto.publicKey.rsa.webSign('SHA-256', message, n, e, d, p, q, u, hashed);
99
- } catch (error) {
100
- openpgp.util.print_debug_error('web crypto error');
101
- this.skip();
102
- }
103
- const signatureBN = await openpgp.crypto.publicKey.rsa.bnSign(hash_algo, n, d, hashed);
104
- expect(openpgp.util.Uint8Array_to_hex(signatureWeb)).to.be.equal(openpgp.util.Uint8Array_to_hex(signatureBN));
105
- });
106
-
107
- it('compare webCrypto and bn math verify', async function() {
108
- if (!openpgp.util.getWebCrypto()) {
109
- this.skip();
110
- }
111
- const bits = openpgp.util.getWebCrypto() ? 2048 : 1024;
112
- const keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, bits);
113
- const n = keyParams[0].toUint8Array();
114
- const e = keyParams[1].toUint8Array();
115
- const d = keyParams[2].toUint8Array();
116
- const p = keyParams[3].toUint8Array();
117
- const q = keyParams[4].toUint8Array();
118
- const u = keyParams[5].toUint8Array();
119
- const message = await openpgp.crypto.random.getRandomBytes(64);
120
- const hashName = 'sha256';
121
- const hash_algo = openpgp.enums.write(openpgp.enums.hash, hashName);
122
- const hashed = await openpgp.crypto.hash.digest(hash_algo, message);
123
- let verifyWeb;
124
- let signature;
125
- try {
126
- signature = await openpgp.crypto.publicKey.rsa.webSign('SHA-256', message, n, e, d, p, q, u, hashed);
127
- verifyWeb = await openpgp.crypto.publicKey.rsa.webVerify('SHA-256', message, signature, n, e);
128
- } catch (error) {
129
- openpgp.util.print_debug_error('web crypto error');
130
- this.skip();
131
- }
132
- const verifyBN = await openpgp.crypto.publicKey.rsa.bnVerify(hash_algo, signature, n, e, hashed);
133
- expect(verifyWeb).to.be.true;
134
- expect(verifyBN).to.be.true;
135
- });
136
-
137
- it('compare nodeCrypto and bn math sign', async function() {
138
- if (!openpgp.util.getNodeCrypto()) {
139
- this.skip();
140
- }
141
- const bits = 1024;
142
- const keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, bits);
143
- const n = keyParams[0].toUint8Array();
144
- const e = keyParams[1].toUint8Array();
145
- const d = keyParams[2].toUint8Array();
146
- const p = keyParams[3].toUint8Array();
147
- const q = keyParams[4].toUint8Array();
148
- const u = keyParams[5].toUint8Array();
149
- const message = await openpgp.crypto.random.getRandomBytes(64);
150
- const hashName = 'sha256';
151
- const hash_algo = openpgp.enums.write(openpgp.enums.hash, hashName);
152
- const hashed = await openpgp.crypto.hash.digest(hash_algo, message);
153
- const signatureNode = await openpgp.crypto.publicKey.rsa.nodeSign(hash_algo, message, n, e, d, p, q, u);
154
- const signatureBN = await openpgp.crypto.publicKey.rsa.bnSign(hash_algo, n, d, hashed);
155
- expect(openpgp.util.Uint8Array_to_hex(signatureNode)).to.be.equal(openpgp.util.Uint8Array_to_hex(signatureBN));
156
- });
157
-
158
- it('compare nodeCrypto and bn math verify', async function() {
159
- if (!openpgp.util.getNodeCrypto()) {
160
- this.skip();
161
- }
162
- const bits = openpgp.util.getWebCrypto() ? 2048 : 1024;
163
- const keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, bits);
164
- const n = keyParams[0].toUint8Array();
165
- const e = keyParams[1].toUint8Array();
166
- const d = keyParams[2].toUint8Array();
167
- const p = keyParams[3].toUint8Array();
168
- const q = keyParams[4].toUint8Array();
169
- const u = keyParams[5].toUint8Array();
170
- const message = await openpgp.crypto.random.getRandomBytes(64);
171
- const hashName = 'sha256';
172
- const hash_algo = openpgp.enums.write(openpgp.enums.hash, hashName);
173
- const hashed = await openpgp.crypto.hash.digest(hash_algo, message);
174
- const signatureNode = await openpgp.crypto.publicKey.rsa.nodeSign(hash_algo, message, n, e, d, p, q, u);
175
- const verifyNode = await openpgp.crypto.publicKey.rsa.nodeVerify(hash_algo, message, signatureNode, n, e);
176
- const verifyBN = await openpgp.crypto.publicKey.rsa.bnVerify(hash_algo, signatureNode, n, e, hashed);
177
- expect(verifyNode).to.be.true;
178
- expect(verifyBN).to.be.true;
179
- });
180
- });
@@ -1,387 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
2
- const chai = require('chai');
3
- const BN = require('bn.js');
4
-
5
- chai.use(require('chai-as-promised'));
6
-
7
- const expect = chai.expect;
8
- const armoredDSAKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
9
-
10
- lQNTBF69PO8RCACHP4KLQcYOPGsGV9owTZvxnvHvvrY8W0v8xDUL3y6CLc05srF1
11
- kQp/81iUfP5g57BEiDpJV95kMh+ulBthIOGnuMCkodJjuBICB4K6BtFTV4Fw1Q5S
12
- S7aLC9beCaMvvGHXsK6MbknYl+IVJY7Zmml1qUSrBIQFGp5kqdhIX4o+OrzZ1zYj
13
- ALicqzD7Zx2VRjGNQv7UKv4CkBOC8ncdnq/4/OQeOYFzVbCOf+sJhTgz6yxjHJVC
14
- fLk7w8l2v1zV11VJuc8cQiQ9g8tjbKgLMsbyzy7gl4m9MSCdinG36XZuPibZrSm0
15
- H8gKAdd1FT84a3/qU2rtLLR0y8tCxBj89Xx/AQCv7CDmwoU+/yGpBVVl1mh0ZUkA
16
- /VJUhnJfv5MIOIi3AQf8CS9HrEmYJg/A3z0DcvcwIu/9gqpRLTqH1iT5o4BCg2j+
17
- Cog2ExYkQl1OEPkEQ1lKJSnD8MDwO3BlkJ4cD0VSKxlnwd9dsu9m2+F8T+K1hoA7
18
- PfH89TjD5HrEaGAYIdivLYSwoTNOO+fY8FoVC0RR9pFNOmjiTU5PZZedOxAql5Os
19
- Hp2bYhky0G9trjo8Mt6CGhvgA3dAKyONftLQr9HSM0GKacFV+nRd9TGCPNZidKU8
20
- MDa/SB/08y1bBGX5FK5wwiZ6H5qD8VAUobH3kwKlrg0nL00/EqtYHJqvJ2gkT5/v
21
- h8+z4R4TuYiy4kKF2FLPd5OjdA31IVDoVgCwF0WHLgf/X9AiTr/DPs/5dIYN1+hf
22
- UJwqjzr3dlokRwx3CVDcOVsdkWRwb8cvxubbsIorvUrF02IhYjHJMjIHT/zFt2zA
23
- +VPzO4zabUlawWVepPEwrCtXgvn9aXqjhAYbilG3UZamhfstGUmbmvWVDadALwby
24
- EO8u2pfLhI2lep63V/+KtUOLhfk8jKRSvxvxlYAvMi7sK8kB+lYy17XKN+IMYgf8
25
- gMFV6XGKpdmMSV3jOvat8cI6vnRO0i+g3jANP3PfrFEivat/rVgxo67r4rxezfFn
26
- J29qwB9rgbRgMBGsbDvIlQNV/NWFvHy2uQAEKn5eX4CoLsCZoR2VfK3BwBCxhYDp
27
- /wAA/0GSmI9MlMnLadFNlcX2Bm4i15quZAGF8JxwHbj1dhdUEYq0E1Rlc3QgPHRl
28
- c3RAdGVzdC5pbz6IlAQTEQgAPBYhBAq6lCI5EfrbHP1qZCxnOy/rlEGVBQJevTzv
29
- AhsDBQsJCAcCAyICAQYVCgkICwIEFgIDAQIeBwIXgAAKCRAsZzsv65RBlUPoAP9Q
30
- aTCWpHWZkvZzC8VU64O76fHp31rLWlcZFttuDNLyeAEAhOxkQHk6GR88R+EF5mrn
31
- clr63t9Q4wreqOlO0NR5/9k=
32
- =UW2O
33
- -----END PGP PRIVATE KEY BLOCK-----
34
- `;
35
-
36
- const armoredElGamalKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
37
-
38
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- muMbqY8GlV5RmSlIRF4ctPVtfrTF6KYrkgFC3ChlWdaqrmTAfaXlwp58oZb834jv
52
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- PNtW7NG89KhF4CiXTqxQO6jEha+lnZfFFMkKZsBrm++rESQ7zzsYLne180LJhHmr
63
- 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
- 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
- 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
- GwWHvG1+gKJygl6PJpifKwkh6oIzqmXl0Xm+oohmGfbQRlMwbIc6BbZAyPNXmFEa
67
- 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
- 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
- 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
- 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
- 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
- O/oyRu0zeX+qySgJyNtOJ2rJ3V52VrwSPUAA/26s21WNs8M6Ryse7sEYcqAmk5QQ
73
- vqBGKJzmO5q3cECw
74
- =X9kJ
75
- -----END PGP PRIVATE KEY BLOCK-----`;
76
-
77
- describe('EdDSA parameter validation', function() {
78
- let keyParams;
79
- before(async () => {
80
- keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.eddsa, null, 'ed25519');
81
- });
82
-
83
- it('EdDSA params should be valid', async function() {
84
- const { oid, Q, seed } = openpgp.crypto.publicKey.elliptic.eddsa.parseParams(keyParams);
85
- const valid = await openpgp.crypto.publicKey.elliptic.eddsa.validateParams(oid, Q, seed);
86
- expect(valid).to.be.true;
87
- });
88
-
89
- it('detect invalid edDSA Q', async function() {
90
- const { oid, Q, seed } = openpgp.crypto.publicKey.elliptic.eddsa.parseParams(keyParams);
91
-
92
-
93
- Q[0]++;
94
- let valid = await openpgp.crypto.publicKey.elliptic.eddsa.validateParams(oid, Q, seed);
95
- expect(valid).to.be.false;
96
-
97
- const infQ = new Uint8Array(Q.length);
98
- valid = await openpgp.crypto.publicKey.elliptic.ecdh.validateParams(oid, infQ, seed);
99
- expect(valid).to.be.false;
100
- });
101
- });
102
-
103
- describe('ECC curve validation', function() {
104
- it('EdDSA params are not valid for ECDH', async function() {
105
- const keyParams = await openpgp.crypto.generateParams(
106
- openpgp.enums.publicKey.eddsa,
107
- null,
108
- 'ed25519'
109
- );
110
- const { oid, Q, seed } = openpgp.crypto.publicKey.elliptic.eddsa.parseParams(keyParams);
111
- const valid = await openpgp.crypto.publicKey.elliptic.ecdsa.validateParams(oid, Q, seed);
112
- expect(valid).to.be.false;
113
- });
114
-
115
- it('EdDSA params are not valid for EcDSA', async function() {
116
- const keyParams = await openpgp.crypto.generateParams(
117
- openpgp.enums.publicKey.eddsa,
118
- null,
119
- 'ed25519'
120
- );
121
- const { oid, Q, seed } = openpgp.crypto.publicKey.elliptic.eddsa.parseParams(keyParams);
122
- const valid = await openpgp.crypto.publicKey.elliptic.ecdsa.validateParams(oid, Q, seed);
123
- expect(valid).to.be.false;
124
- });
125
-
126
- it('x25519 params are not valid for EcDSA', async function() {
127
- const keyParams = await openpgp.crypto.generateParams(
128
- openpgp.enums.publicKey.ecdsa,
129
- null,
130
- 'curve25519'
131
- );
132
- const { oid, Q, d } = openpgp.crypto.publicKey.elliptic.ecdsa.parseParams(keyParams);
133
- const valid = await openpgp.crypto.publicKey.elliptic.ecdsa.validateParams(oid, Q, d);
134
- expect(valid).to.be.false;
135
- });
136
-
137
- it('EcDSA params are not valid for EdDSA', async function() {
138
- const keyParams = await openpgp.crypto.generateParams(
139
- openpgp.enums.publicKey.ecdsa, null, 'p256'
140
- );
141
- const { oid, Q, d } = openpgp.crypto.publicKey.elliptic.ecdsa.parseParams(keyParams);
142
- const valid = await openpgp.crypto.publicKey.elliptic.eddsa.validateParams(oid, Q, d);
143
- expect(valid).to.be.false;
144
- });
145
-
146
- it('x25519 params are not valid for EdDSA', async function() {
147
- const keyParams = await openpgp.crypto.generateParams(
148
- openpgp.enums.publicKey.ecdsa, null, 'curve25519'
149
- );
150
- const { oid, Q, d } = openpgp.crypto.publicKey.elliptic.ecdsa.parseParams(keyParams);
151
- const valid = await openpgp.crypto.publicKey.elliptic.eddsa.validateParams(oid, Q, d);
152
- expect(valid).to.be.false;
153
- });
154
- });
155
-
156
-
157
- const curves = ['curve25519', 'p256', 'p384', 'p521', 'secp256k1', 'brainpoolP256r1', 'brainpoolP384r1', 'brainpoolP512r1'];
158
- curves.forEach(curve => {
159
- describe(`ECC ${curve} parameter validation`, () => {
160
- let keyParams;
161
- before(async () => {
162
- // we generate also ecdh params as ecdsa ones since we do not need the kdf params
163
- keyParams = await openpgp.crypto.generateParams(
164
- openpgp.enums.publicKey.ecdsa, null, curve
165
- );
166
- });
167
-
168
- if (curve !== 'curve25519') {
169
- it(`EcDSA ${curve} params should be valid`, async function() {
170
- const { oid, Q, d } = openpgp.crypto.publicKey.elliptic.ecdsa.parseParams(keyParams);
171
- const valid = await openpgp.crypto.publicKey.elliptic.ecdsa.validateParams(oid, Q, d);
172
- expect(valid).to.be.true;
173
- });
174
-
175
- it('detect invalid EcDSA Q', async function() {
176
- const { oid, Q, d } = openpgp.crypto.publicKey.elliptic.ecdsa.parseParams(keyParams);
177
-
178
- Q[16]++;
179
- let valid = await openpgp.crypto.publicKey.elliptic.ecdsa.validateParams(oid, Q, d);
180
- expect(valid).to.be.false;
181
-
182
- const infQ = new Uint8Array(Q.length);
183
- valid = await openpgp.crypto.publicKey.elliptic.ecdsa.validateParams(oid, infQ, d);
184
- expect(valid).to.be.false;
185
- });
186
- }
187
-
188
- it(`ECDH ${curve} params should be valid`, async function() {
189
- const { oid, Q, d } = openpgp.crypto.publicKey.elliptic.ecdsa.parseParams(keyParams);
190
- const valid = await openpgp.crypto.publicKey.elliptic.ecdh.validateParams(oid, Q, d);
191
- expect(valid).to.be.true;
192
- });
193
-
194
- it('detect invalid ECDH Q', async function() {
195
- const { oid, Q, d } = openpgp.crypto.publicKey.elliptic.ecdsa.parseParams(keyParams);
196
-
197
- Q[16]++;
198
- let valid = await openpgp.crypto.publicKey.elliptic.ecdh.validateParams(oid, Q, d);
199
- expect(valid).to.be.false;
200
-
201
- const infQ = new Uint8Array(Q.length);
202
- valid = await openpgp.crypto.publicKey.elliptic.ecdh.validateParams(oid, infQ, d);
203
- expect(valid).to.be.false;
204
- });
205
- });
206
- });
207
-
208
- describe('RSA parameter validation', function() {
209
- let keyParams;
210
- before(async () => {
211
- keyParams = await openpgp.crypto.generateParams(openpgp.enums.publicKey.rsa_sign, 2048);
212
- });
213
-
214
- it('generated RSA params are valid', async function() {
215
- const n = keyParams[0].toUint8Array();
216
- const e = keyParams[1].toUint8Array();
217
- const d = keyParams[2].toUint8Array();
218
- const p = keyParams[3].toUint8Array();
219
- const q = keyParams[4].toUint8Array();
220
- const u = keyParams[5].toUint8Array();
221
- const valid = await openpgp.crypto.publicKey.rsa.validateParams(n, e, d, p, q, u);
222
- expect(valid).to.be.true;
223
- });
224
-
225
- it('detect invalid RSA n', async function() {
226
- const n = keyParams[0].toUint8Array();
227
- const e = keyParams[1].toUint8Array();
228
- const d = keyParams[2].toUint8Array();
229
- const p = keyParams[3].toUint8Array();
230
- const q = keyParams[4].toUint8Array();
231
- const u = keyParams[5].toUint8Array();
232
-
233
- n[0]++;
234
- const valid = await openpgp.crypto.publicKey.rsa.validateParams(n, e, d, p, q, u);
235
- expect(valid).to.be.false;
236
- });
237
-
238
- it('detect invalid RSA e', async function() {
239
- const n = keyParams[0].toUint8Array();
240
- const e = keyParams[1].toUint8Array();
241
- const d = keyParams[2].toUint8Array();
242
- const p = keyParams[3].toUint8Array();
243
- const q = keyParams[4].toUint8Array();
244
- const u = keyParams[5].toUint8Array();
245
-
246
- e[0]++;
247
- const valid = await openpgp.crypto.publicKey.rsa.validateParams(n, e, d, p, q, u);
248
- expect(valid).to.be.false;
249
- });
250
- });
251
-
252
- describe('DSA parameter validation', function() {
253
- let dsaKey;
254
- before(async () => {
255
- dsaKey = (await openpgp.key.readArmored(armoredDSAKey)).keys[0];
256
- });
257
-
258
- it('DSA params should be valid', async function() {
259
- const params = dsaKey.keyPacket.params;
260
- const p = params[0].toUint8Array();
261
- const q = params[1].toUint8Array();
262
- const g = params[2].toUint8Array();
263
- const y = params[3].toUint8Array();
264
- const x = params[4].toUint8Array();
265
- const valid = await openpgp.crypto.publicKey.dsa.validateParams(p, q, g, y, x);
266
- expect(valid).to.be.true;
267
- });
268
-
269
- it('detect invalid DSA p', async function() {
270
- const params = dsaKey.keyPacket.params;
271
- const p = params[0].toUint8Array();
272
- const q = params[1].toUint8Array();
273
- const g = params[2].toUint8Array();
274
- const y = params[3].toUint8Array();
275
- const x = params[4].toUint8Array();
276
-
277
- p[0]++;
278
- const valid = await openpgp.crypto.publicKey.dsa.validateParams(p, q, g, y, x);
279
-
280
- expect(valid).to.be.false;
281
- });
282
-
283
- it('detect invalid DSA y', async function() {
284
- const params = dsaKey.keyPacket.params;
285
- const p = params[0].toUint8Array();
286
- const q = params[1].toUint8Array();
287
- const g = params[2].toUint8Array();
288
- const y = params[3].toUint8Array();
289
- const x = params[4].toUint8Array();
290
-
291
- y[0]++;
292
- const valid = await openpgp.crypto.publicKey.dsa.validateParams(p, q, g, y, x);
293
-
294
- expect(valid).to.be.false;
295
- });
296
-
297
- it('detect invalid DSA g', async function() {
298
- const params = dsaKey.keyPacket.params;
299
- const p = params[0].toUint8Array();
300
- const q = params[1].toUint8Array();
301
- const g = params[2].toUint8Array();
302
- const y = params[3].toUint8Array();
303
- const x = params[4].toUint8Array();
304
-
305
- g[0]++;
306
- let valid = await openpgp.crypto.publicKey.dsa.validateParams(p, q, g, y, x);
307
- expect(valid).to.be.false;
308
-
309
- const gOne = new Uint8Array([1]);
310
- valid = await openpgp.crypto.publicKey.dsa.validateParams(p, q, gOne, y, x);
311
- expect(valid).to.be.false;
312
- });
313
- });
314
-
315
- describe('ElGamal parameter validation', function() {
316
- let egKey;
317
- before(async () => {
318
- egKey = (await openpgp.key.readArmored(armoredElGamalKey)).keys[0].subKeys[0];
319
- });
320
-
321
- it('params should be valid', async function() {
322
- const params = egKey.keyPacket.params;
323
- const p = params[0].toUint8Array();
324
- const g = params[1].toUint8Array();
325
- const y = params[2].toUint8Array();
326
- const x = params[3].toUint8Array();
327
-
328
- const valid = await openpgp.crypto.publicKey.elgamal.validateParams(p, g, y, x);
329
- expect(valid).to.be.true;
330
- });
331
-
332
- it('detect invalid p', async function() {
333
- const params = egKey.keyPacket.params;
334
- const p = params[0].toUint8Array();
335
- const g = params[1].toUint8Array();
336
- const y = params[2].toUint8Array();
337
- const x = params[3].toUint8Array();
338
- p[0]++;
339
- const valid = await openpgp.crypto.publicKey.elgamal.validateParams(p, g, y, x);
340
-
341
- expect(valid).to.be.false;
342
- });
343
-
344
- it('detect invalid y', async function() {
345
- const params = egKey.keyPacket.params;
346
- const p = params[0].toUint8Array();
347
- const g = params[1].toUint8Array();
348
- const y = params[2].toUint8Array();
349
- const x = params[3].toUint8Array();
350
-
351
- y[0]++;
352
- const valid = await openpgp.crypto.publicKey.elgamal.validateParams(p, g, y, x);
353
-
354
- expect(valid).to.be.false;
355
- });
356
-
357
- it('detect invalid g', async function() {
358
- const params = egKey.keyPacket.params;
359
- const p = params[0].toUint8Array();
360
- const g = params[1].toUint8Array();
361
- const y = params[2].toUint8Array();
362
- const x = params[3].toUint8Array();
363
-
364
- g[0]++;
365
- let valid = await openpgp.crypto.publicKey.elgamal.validateParams(p, g, y, x);
366
- expect(valid).to.be.false;
367
-
368
- const gOne = new Uint8Array([1]);
369
- valid = await openpgp.crypto.publicKey.elgamal.validateParams(p, gOne, y, x);
370
- expect(valid).to.be.false;
371
- });
372
-
373
- it('detect g with small order', async function() {
374
- const params = egKey.keyPacket.params;
375
- const p = params[0].toUint8Array();
376
- const g = params[1].toUint8Array();
377
- const y = params[2].toUint8Array();
378
- const x = params[3].toUint8Array();
379
-
380
- const pBN = new BN(p);
381
- const gModP = new BN(g).toRed(new BN.red(pBN));
382
- // g**(p-1)/2 has order 2
383
- const gOrd2 = gModP.redPow(pBN.subn(1).shrn(1));
384
- const valid = await openpgp.crypto.publicKey.elgamal.validateParams(p, gOrd2.toArrayLike(Uint8Array, 'be'), y, x);
385
- expect(valid).to.be.false;
386
- });
387
- });