@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,150 +0,0 @@
1
- // Modified by ProtonTech AG
2
-
3
- // Adapted from https://github.com/artjomb/cryptojs-extension/blob/8c61d159/test/eax.js
4
-
5
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
6
-
7
- const chai = require('chai');
8
- chai.use(require('chai-as-promised'));
9
-
10
- const expect = chai.expect;
11
-
12
- function testAESEAX() {
13
- it('Passes all test vectors', async function() {
14
- const vectors = [
15
- // From http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf ...
16
- {
17
- msg: "",
18
- key: "233952DEE4D5ED5F9B9C6D6FF80FF478",
19
- nonce: "62EC67F9C3A4A407FCB2A8C49031A8B3",
20
- header: "6BFB914FD07EAE6B",
21
- ct: "E037830E8389F27B025A2D6527E79D01"
22
- },
23
- {
24
- msg: "F7FB",
25
- key: "91945D3F4DCBEE0BF45EF52255F095A4",
26
- nonce: "BECAF043B0A23D843194BA972C66DEBD",
27
- header: "FA3BFD4806EB53FA",
28
- ct: "19DD5C4C9331049D0BDAB0277408F67967E5"
29
- },
30
- {
31
- msg: "1A47CB4933",
32
- key: "01F74AD64077F2E704C0F60ADA3DD523",
33
- nonce: "70C3DB4F0D26368400A10ED05D2BFF5E",
34
- header: "234A3463C1264AC6",
35
- ct: "D851D5BAE03A59F238A23E39199DC9266626C40F80"
36
- },
37
- {
38
- msg: "481C9E39B1",
39
- key: "D07CF6CBB7F313BDDE66B727AFD3C5E8",
40
- nonce: "8408DFFF3C1A2B1292DC199E46B7D617",
41
- header: "33CCE2EABFF5A79D",
42
- ct: "632A9D131AD4C168A4225D8E1FF755939974A7BEDE"
43
- },
44
- {
45
- msg: "40D0C07DA5E4",
46
- key: "35B6D0580005BBC12B0587124557D2C2",
47
- nonce: "FDB6B06676EEDC5C61D74276E1F8E816",
48
- header: "AEB96EAEBE2970E9",
49
- ct: "071DFE16C675CB0677E536F73AFE6A14B74EE49844DD"
50
- },
51
- {
52
- msg: "4DE3B35C3FC039245BD1FB7D",
53
- key: "BD8E6E11475E60B268784C38C62FEB22",
54
- nonce: "6EAC5C93072D8E8513F750935E46DA1B",
55
- header: "D4482D1CA78DCE0F",
56
- ct: "835BB4F15D743E350E728414ABB8644FD6CCB86947C5E10590210A4F"
57
- },
58
- {
59
- msg: "8B0A79306C9CE7ED99DAE4F87F8DD61636",
60
- key: "7C77D6E813BED5AC98BAA417477A2E7D",
61
- nonce: "1A8C98DCD73D38393B2BF1569DEEFC19",
62
- header: "65D2017990D62528",
63
- ct: "02083E3979DA014812F59F11D52630DA30137327D10649B0AA6E1C181DB617D7F2"
64
- },
65
- {
66
- msg: "1BDA122BCE8A8DBAF1877D962B8592DD2D56",
67
- key: "5FFF20CAFAB119CA2FC73549E20F5B0D",
68
- nonce: "DDE59B97D722156D4D9AFF2BC7559826",
69
- header: "54B9F04E6A09189A",
70
- ct: "2EC47B2C4954A489AFC7BA4897EDCDAE8CC33B60450599BD02C96382902AEF7F832A"
71
- },
72
- {
73
- msg: "6CF36720872B8513F6EAB1A8A44438D5EF11",
74
- key: "A4A4782BCFFD3EC5E7EF6D8C34A56123",
75
- nonce: "B781FCF2F75FA5A8DE97A9CA48E522EC",
76
- header: "899A175897561D7E",
77
- ct: "0DE18FD0FDD91E7AF19F1D8EE8733938B1E8E7F6D2231618102FDB7FE55FF1991700"
78
- },
79
- {
80
- msg: "CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7",
81
- key: "8395FCF1E95BEBD697BD010BC766AAC3",
82
- nonce: "22E7ADD93CFC6393C57EC0B3C17D6B44",
83
- header: "126735FCC320D25A",
84
- ct: "CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E"
85
- }
86
- ];
87
-
88
- const cipher = 'aes128';
89
-
90
- await Promise.all(vectors.map(async vec => {
91
- const keyBytes = openpgp.util.hex_to_Uint8Array(vec.key);
92
- const msgBytes = openpgp.util.hex_to_Uint8Array(vec.msg);
93
- const nonceBytes = openpgp.util.hex_to_Uint8Array(vec.nonce);
94
- const headerBytes = openpgp.util.hex_to_Uint8Array(vec.header);
95
- const ctBytes = openpgp.util.hex_to_Uint8Array(vec.ct);
96
-
97
- const eax = await openpgp.crypto.eax(cipher, keyBytes);
98
-
99
- // encryption test
100
- let ct = await eax.encrypt(msgBytes, nonceBytes, headerBytes);
101
- expect(openpgp.util.Uint8Array_to_hex(ct)).to.equal(vec.ct.toLowerCase());
102
-
103
- // decryption test with verification
104
- let pt = await eax.decrypt(ctBytes, nonceBytes, headerBytes);
105
- expect(openpgp.util.Uint8Array_to_hex(pt)).to.equal(vec.msg.toLowerCase());
106
-
107
- // tampering detection test
108
- ct = await eax.encrypt(msgBytes, nonceBytes, headerBytes);
109
- ct[2] ^= 8;
110
- pt = eax.decrypt(ct, nonceBytes, headerBytes);
111
- await expect(pt).to.eventually.be.rejectedWith('Authentication tag mismatch');
112
-
113
- // testing without additional data
114
- ct = await eax.encrypt(msgBytes, nonceBytes, new Uint8Array());
115
- pt = await eax.decrypt(ct, nonceBytes, new Uint8Array());
116
- expect(openpgp.util.Uint8Array_to_hex(pt)).to.equal(vec.msg.toLowerCase());
117
-
118
- // testing with multiple additional data
119
- ct = await eax.encrypt(msgBytes, nonceBytes, openpgp.util.concatUint8Array([headerBytes, headerBytes, headerBytes]));
120
- pt = await eax.decrypt(ct, nonceBytes, openpgp.util.concatUint8Array([headerBytes, headerBytes, headerBytes]));
121
- expect(openpgp.util.Uint8Array_to_hex(pt)).to.equal(vec.msg.toLowerCase());
122
- }));
123
- });
124
- }
125
-
126
- describe('Symmetric AES-EAX (native)', function() {
127
- let use_nativeVal;
128
- beforeEach(function() {
129
- use_nativeVal = openpgp.config.use_native;
130
- openpgp.config.use_native = true;
131
- });
132
- afterEach(function() {
133
- openpgp.config.use_native = use_nativeVal;
134
- });
135
-
136
- testAESEAX();
137
- });
138
-
139
- describe('Symmetric AES-EAX (asm.js fallback)', function() {
140
- let use_nativeVal;
141
- beforeEach(function() {
142
- use_nativeVal = openpgp.config.use_native;
143
- openpgp.config.use_native = false;
144
- });
145
- afterEach(function() {
146
- openpgp.config.use_native = use_nativeVal;
147
- });
148
-
149
- testAESEAX();
150
- });
@@ -1,359 +0,0 @@
1
- const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
2
- const chai = require('chai');
3
- const elliptic_data = require('./elliptic_data');
4
-
5
- chai.use(require('chai-as-promised'));
6
-
7
- const expect = chai.expect;
8
- const key_data = elliptic_data.key_data;
9
- /* eslint-disable no-invalid-this */
10
- describe('ECDH key exchange @lightweight', function () {
11
- const elliptic_curves = openpgp.crypto.publicKey.elliptic;
12
- const decrypt_message = function (oid, hash, cipher, priv, pub, ephemeral, data, fingerprint) {
13
- if (openpgp.util.isString(data)) {
14
- data = openpgp.util.str_to_Uint8Array(data);
15
- } else {
16
- data = new Uint8Array(data);
17
- }
18
- return Promise.resolve().then(() => {
19
- const curve = new elliptic_curves.Curve(oid);
20
- return elliptic_curves.ecdh.decrypt(
21
- new openpgp.OID(curve.oid),
22
- new openpgp.KDFParams({ cipher, hash }),
23
- new Uint8Array(ephemeral),
24
- data,
25
- new Uint8Array(pub),
26
- new Uint8Array(priv),
27
- new Uint8Array(fingerprint)
28
- );
29
- });
30
- };
31
- const secp256k1_value = new Uint8Array([
32
- 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
33
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
36
- ]);
37
- const secp256k1_point = new Uint8Array([
38
- 0x04,
39
- 0x79, 0xBE, 0x66, 0x7E, 0xF9, 0xDC, 0xBB, 0xAC,
40
- 0x55, 0xA0, 0x62, 0x95, 0xCE, 0x87, 0x0B, 0x07,
41
- 0x02, 0x9B, 0xFC, 0xDB, 0x2D, 0xCE, 0x28, 0xD9,
42
- 0x59, 0xF2, 0x81, 0x5B, 0x16, 0xF8, 0x17, 0x98,
43
- 0x48, 0x3A, 0xDA, 0x77, 0x26, 0xA3, 0xC4, 0x65,
44
- 0x5D, 0xA4, 0xFB, 0xFC, 0x0E, 0x11, 0x08, 0xA8,
45
- 0xFD, 0x17, 0xB4, 0x48, 0xA6, 0x85, 0x54, 0x19,
46
- 0x9C, 0x47, 0xD0, 0x8F, 0xFB, 0x10, 0xD4, 0xB8
47
- ]);
48
- const secp256k1_invalid_point = new Uint8Array([
49
- 0x04,
50
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
52
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
57
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
58
- ]);
59
- const secp256k1_data = new Uint8Array([
60
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
62
- ]);
63
-
64
- it('Invalid curve oid', function (done) {
65
- expect(decrypt_message(
66
- '', 2, 7, [], [], [], [], []
67
- )).to.be.rejectedWith(Error, /Not valid curve/).notify(done);
68
- });
69
- it('Invalid ephemeral key', function (done) {
70
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
71
- this.skip();
72
- }
73
- expect(decrypt_message(
74
- 'secp256k1', 2, 7, [], [], [], [], []
75
- )).to.be.rejectedWith(Error, /Private key is not valid for specified curve|Unknown point format/).notify(done);
76
- });
77
- it('Invalid elliptic public key', function (done) {
78
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
79
- this.skip();
80
- }
81
- expect(decrypt_message(
82
- 'secp256k1', 2, 7, secp256k1_value, secp256k1_point, secp256k1_invalid_point, secp256k1_data, []
83
- )).to.be.rejectedWith(Error, /Public key is not valid for specified curve|Failed to translate Buffer to a EC_POINT|Invalid elliptic public key/).notify(done);
84
- });
85
- it('Invalid key data integrity', function (done) {
86
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
87
- this.skip();
88
- }
89
- expect(decrypt_message(
90
- 'secp256k1', 2, 7, secp256k1_value, secp256k1_point, secp256k1_point, secp256k1_data, []
91
- )).to.be.rejectedWith(Error, /Key Data Integrity failed/).notify(done);
92
- });
93
-
94
- const Q1 = new Uint8Array([
95
- 64,
96
- 48, 226, 162, 114, 194, 194, 67, 214,
97
- 199, 10, 173, 22, 216, 240, 197, 202,
98
- 114, 49, 127, 107, 152, 58, 119, 48,
99
- 234, 194, 192, 66, 53, 165, 137, 93
100
- ]);
101
- const d1 = new Uint8Array([
102
- 65, 200, 132, 198, 77, 86, 126, 196,
103
- 247, 169, 156, 201, 32, 52, 3, 198,
104
- 127, 144, 139, 47, 153, 239, 64, 235,
105
- 61, 7, 17, 214, 64, 211, 215, 80
106
- ]);
107
- const Q2 = new Uint8Array([
108
- 64,
109
- 154, 115, 36, 108, 33, 153, 64, 184,
110
- 25, 139, 67, 25, 178, 194, 227, 53,
111
- 254, 40, 101, 213, 28, 121, 154, 62,
112
- 27, 99, 92, 126, 33, 223, 122, 91
113
- ]);
114
- const d2 = new Uint8Array([
115
- 123, 99, 163, 24, 201, 87, 0, 9,
116
- 204, 21, 154, 5, 5, 5, 127, 157,
117
- 237, 95, 76, 117, 89, 250, 64, 178,
118
- 72, 69, 69, 58, 89, 228, 113, 112
119
- ]);
120
- const fingerprint1 = new Uint8Array([
121
- 177, 183,
122
- 116, 123, 76, 133, 245, 212, 151, 243, 236,
123
- 71, 245, 86, 3, 168, 101, 74, 209, 105
124
- ]);
125
- const fingerprint2 = new Uint8Array([
126
- 177, 83,
127
- 123, 123, 76, 133, 245, 212, 151, 243, 236,
128
- 71, 245, 86, 3, 168, 101, 74, 209, 105
129
- ]);
130
- async function genPublicEphemeralKey(curve, Q, fingerprint) {
131
- const curveObj = new openpgp.crypto.publicKey.elliptic.Curve(curve);
132
- const oid = new openpgp.OID(curveObj.oid);
133
- const { publicKey: V, sharedKey } = await openpgp.crypto.publicKey.elliptic.ecdh.genPublicEphemeralKey(
134
- curveObj, Q
135
- );
136
- let cipher_algo = curveObj.cipher;
137
- const hash_algo = curveObj.hash;
138
- const kdfParams = new openpgp.KDFParams({ cipher: cipher_algo, hash: hash_algo });
139
- const param = openpgp.crypto.publicKey.elliptic.ecdh.buildEcdhParam(
140
- openpgp.enums.publicKey.ecdh, oid, kdfParams, fingerprint
141
- );
142
- cipher_algo = openpgp.enums.read(openpgp.enums.symmetric, cipher_algo);
143
- const Z = await openpgp.crypto.publicKey.elliptic.ecdh.kdf(
144
- hash_algo, sharedKey, openpgp.crypto.cipher[cipher_algo].keySize, param, curveObj, false
145
- );
146
- return { V, Z };
147
- }
148
-
149
- async function genPrivateEphemeralKey(curve, V, Q, d, fingerprint) {
150
- const curveObj = new openpgp.crypto.publicKey.elliptic.Curve(curve);
151
- const oid = new openpgp.OID(curveObj.oid);
152
- const { sharedKey } = await openpgp.crypto.publicKey.elliptic.ecdh.genPrivateEphemeralKey(
153
- curveObj, V, Q, d
154
- );
155
- let cipher_algo = curveObj.cipher;
156
- const hash_algo = curveObj.hash;
157
- const kdfParams = new openpgp.KDFParams({ cipher: cipher_algo, hash: hash_algo });
158
- const param = openpgp.crypto.publicKey.elliptic.ecdh.buildEcdhParam(
159
- openpgp.enums.publicKey.ecdh, oid, kdfParams, fingerprint
160
- );
161
- cipher_algo = openpgp.enums.read(openpgp.enums.symmetric, cipher_algo);
162
- const Z = await openpgp.crypto.publicKey.elliptic.ecdh.kdf(
163
- hash_algo, sharedKey, openpgp.crypto.cipher[cipher_algo].keySize, param, curveObj, false
164
- );
165
- return Z;
166
- }
167
-
168
- async function genPrivateEphemeralKeySpecific(fun, curve, V, Q, d, fingerprint) {
169
- const curveObj = new openpgp.crypto.publicKey.elliptic.Curve(curve);
170
- const oid = new openpgp.OID(curveObj.oid);
171
- let result;
172
- switch (fun) {
173
- case 'webPrivateEphemeralKey': {
174
- result = await openpgp.crypto.publicKey.elliptic.ecdh[fun](
175
- curveObj, V, Q, d
176
- );
177
- break;
178
- }
179
- case 'nodePrivateEphemeralKey':
180
- case 'ellipticPrivateEphemeralKey': {
181
- result = await openpgp.crypto.publicKey.elliptic.ecdh[fun](
182
- curveObj, V, d
183
- );
184
- break;
185
- }
186
- }
187
- const sharedKey = result.sharedKey;
188
- let cipher_algo = curveObj.cipher;
189
- const hash_algo = curveObj.hash;
190
- const kdfParams = new openpgp.KDFParams({ cipher: cipher_algo, hash: hash_algo });
191
- const param = openpgp.crypto.publicKey.elliptic.ecdh.buildEcdhParam(
192
- openpgp.enums.publicKey.ecdh, oid, kdfParams, fingerprint
193
- );
194
- cipher_algo = openpgp.enums.read(openpgp.enums.symmetric, cipher_algo);
195
- const Z = await openpgp.crypto.publicKey.elliptic.ecdh.kdf(
196
- hash_algo, sharedKey, openpgp.crypto.cipher[cipher_algo].keySize, param, curveObj, false
197
- );
198
- return Z;
199
- }
200
-
201
- describe('ECDHE key generation', function () {
202
- it('Invalid curve', function (done) {
203
- if (!openpgp.config.use_indutny_elliptic && !openpgp.util.getNodeCrypto()) {
204
- this.skip();
205
- }
206
- expect(genPublicEphemeralKey("secp256k1", Q1, fingerprint1)
207
- ).to.be.rejectedWith(Error, /Public key is not valid for specified curve|Failed to translate Buffer to a EC_POINT|Unknown point format/).notify(done);
208
- });
209
- it('Invalid public part of ephemeral key and private key', async function () {
210
- const ECDHE_VZ1 = await genPublicEphemeralKey("curve25519", Q1, fingerprint1);
211
- const ECDHE_Z12 = await genPrivateEphemeralKey("curve25519", ECDHE_VZ1.V, Q2, d2, fingerprint1);
212
- expect(Array.from(ECDHE_Z12).join(' ') === Array.from(ECDHE_VZ1.Z).join(' ')).to.be.false;
213
- });
214
- it('Invalid fingerprint', async function () {
215
- const ECDHE_VZ2 = await genPublicEphemeralKey("curve25519", Q2, fingerprint1);
216
- const ECDHE_Z2 = await genPrivateEphemeralKey("curve25519", ECDHE_VZ2.V, Q2, d2, fingerprint2);
217
- expect(Array.from(ECDHE_Z2).join(' ') === Array.from(ECDHE_VZ2.Z).join(' ')).to.be.false;
218
- });
219
- it('Different keys', async function () {
220
- const ECDHE_VZ1 = await genPublicEphemeralKey("curve25519", Q1, fingerprint1);
221
- const ECDHE_VZ2 = await genPublicEphemeralKey("curve25519", Q2, fingerprint1);
222
- const ECDHE_Z1 = await genPrivateEphemeralKey("curve25519", ECDHE_VZ1.V, Q1, d1, fingerprint1);
223
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_VZ2.Z).join(' ')).to.be.false;
224
- });
225
- it('Successful exchange curve25519', async function () {
226
- const ECDHE_VZ1 = await genPublicEphemeralKey("curve25519", Q1, fingerprint1);
227
- const ECDHE_Z1 = await genPrivateEphemeralKey("curve25519", ECDHE_VZ1.V, Q1, d1, fingerprint1);
228
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_VZ1.Z).join(' ')).to.be.true;
229
- });
230
- it('Successful exchange NIST P256', async function () {
231
- const ECDHE_VZ1 = await genPublicEphemeralKey("p256", key_data.p256.pub, fingerprint1);
232
- const ECDHE_Z1 = await genPrivateEphemeralKey("p256", ECDHE_VZ1.V, key_data.p256.pub, key_data.p256.priv, fingerprint1);
233
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_VZ1.Z).join(' ')).to.be.true;
234
- });
235
- it('Successful exchange NIST P384', async function () {
236
- const ECDHE_VZ1 = await genPublicEphemeralKey("p384", key_data.p384.pub, fingerprint1);
237
- const ECDHE_Z1 = await genPrivateEphemeralKey("p384", ECDHE_VZ1.V, key_data.p384.pub, key_data.p384.priv, fingerprint1);
238
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_VZ1.Z).join(' ')).to.be.true;
239
- });
240
- it('Successful exchange NIST P521', async function () {
241
- const ECDHE_VZ1 = await genPublicEphemeralKey("p521", key_data.p521.pub, fingerprint1);
242
- const ECDHE_Z1 = await genPrivateEphemeralKey("p521", ECDHE_VZ1.V, key_data.p521.pub, key_data.p521.priv, fingerprint1);
243
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_VZ1.Z).join(' ')).to.be.true;
244
- });
245
-
246
- it('Comparing keys derived using webCrypto and elliptic', async function () {
247
- const names = ["p256", "p384", "p521"];
248
- if (!openpgp.util.getWebCrypto() || !openpgp.config.use_indutny_elliptic) {
249
- // eslint-disable-next-line no-invalid-this
250
- this.skip();
251
- }
252
- return Promise.all(names.map(async function (name) {
253
- const curve = new elliptic_curves.Curve(name);
254
- try {
255
- await window.crypto.subtle.generateKey({
256
- name: "ECDSA",
257
- namedCurve: curve.web.web
258
- }, false, ["sign", "verify"]);
259
- } catch (err) {
260
- openpgp.util.print_debug_error(err);
261
- return;
262
- }
263
- const ECDHE_VZ1 = await genPublicEphemeralKey(name, key_data[name].pub, fingerprint1);
264
- const ECDHE_Z1 = await genPrivateEphemeralKeySpecific('ellipticPrivateEphemeralKey', name, ECDHE_VZ1.V, key_data[name].pub, key_data[name].priv, fingerprint1);
265
- const ECDHE_Z2 = await genPrivateEphemeralKeySpecific('webPrivateEphemeralKey', name, ECDHE_VZ1.V, key_data[name].pub, key_data[name].priv, fingerprint1);
266
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_VZ1.Z).join(' ')).to.be.true;
267
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_Z2).join(' ')).to.be.true;
268
- }));
269
- });
270
- it('Comparing keys derived using nodeCrypto and elliptic', async function () {
271
- const names = ["p256", "p384", "p521"];
272
- if (!openpgp.util.getNodeCrypto() || !openpgp.config.use_indutny_elliptic) {
273
- // eslint-disable-next-line no-invalid-this
274
- this.skip();
275
- }
276
- return Promise.all(names.map(async function (name) {
277
- const ECDHE_VZ1 = await genPublicEphemeralKey(name, key_data[name].pub, fingerprint1);
278
- const ECDHE_Z1 = await genPrivateEphemeralKeySpecific('ellipticPrivateEphemeralKey', name, ECDHE_VZ1.V, key_data[name].pub, key_data[name].priv, fingerprint1);
279
- const ECDHE_Z2 = await genPrivateEphemeralKeySpecific('nodePrivateEphemeralKey', name, ECDHE_VZ1.V, key_data[name].pub, key_data[name].priv, fingerprint1);
280
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_VZ1.Z).join(' ')).to.be.true;
281
- expect(Array.from(ECDHE_Z1).join(' ') === Array.from(ECDHE_Z2).join(' ')).to.be.true;
282
- }));
283
- });
284
- });
285
- });
286
-
287
- describe('KDF parameters', function () {
288
- const fingerprint = new Uint8Array([
289
- 177, 183, 116, 123, 76, 133, 245, 212, 151, 243,
290
- 236, 71, 245, 86, 3, 168, 101, 74, 209, 105
291
- ]);
292
-
293
- it('Valid serialization', async function () {
294
- const cipher = openpgp.enums.symmetric.aes256;
295
- const hash = openpgp.enums.hash.sha256;
296
-
297
- const v1 = new openpgp.KDFParams({ cipher, hash });
298
- const v1Copy = new openpgp.KDFParams({});
299
- v1Copy.read(v1.write());
300
- expect(v1Copy).to.deep.equal(v1);
301
-
302
- const v1Flags0x0 = new openpgp.KDFParams({
303
- cipher,
304
- hash,
305
- flags: 0x0 // discarded
306
- });
307
- const v1Flags0x0Copy = new openpgp.KDFParams({});
308
- v1Flags0x0Copy.read(v1Flags0x0.write());
309
- v1Flags0x0.flags = undefined;
310
- expect(v1Flags0x0Copy).to.deep.equal(v1Flags0x0);
311
-
312
- const v2Flags0x3 = new openpgp.KDFParams({
313
- cipher,
314
- hash,
315
- version: 2,
316
- flags: 0x3,
317
- replacementFingerprint: fingerprint,
318
- replacementKDFParams: new Uint8Array([3, 1, cipher, hash])
319
- });
320
- const v2Flags0x3Copy = new openpgp.KDFParams();
321
- v2Flags0x3Copy.read(v2Flags0x3.write());
322
- expect(v2Flags0x3Copy).to.deep.equal(v2Flags0x3);
323
-
324
- const v2Flags0x0 = new openpgp.KDFParams({
325
- cipher,
326
- hash,
327
- version: 2,
328
- flags: 0x0
329
- });
330
- const v2Flags0x0Copy = new openpgp.KDFParams({});
331
- v2Flags0x0Copy.read(v2Flags0x0.write());
332
-
333
- expect(v2Flags0x0Copy).to.deep.equal(v2Flags0x0);
334
-
335
- const v2Flags0x1 = new openpgp.KDFParams({
336
- cipher,
337
- hash,
338
- version: 2,
339
- flags: 0x1,
340
- replacementFingerprint: fingerprint
341
- });
342
- const v2Flags0x1Copy = new openpgp.KDFParams();
343
- v2Flags0x1Copy.read(v2Flags0x1.write());
344
- v2Flags0x1.replacementKDFParams = null;
345
- expect(v2Flags0x1Copy).to.deep.equal(v2Flags0x1);
346
-
347
- const v2Flags0x2 = new openpgp.KDFParams({
348
- cipher,
349
- hash,
350
- version: 2,
351
- flags: 0x2,
352
- replacementKDFParams: new Uint8Array([3, 1, cipher, hash])
353
- });
354
- const v2Flags0x2Copy = new openpgp.KDFParams();
355
- v2Flags0x2Copy.read(v2Flags0x2.write());
356
- v2Flags0x2.replacementFingerprint = null;
357
- expect(v2Flags0x2Copy).to.deep.equal(v2Flags0x2);
358
- });
359
- });