@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.
- package/README.md +311 -239
- package/dist/lightweight/bn.interface.min.mjs +3 -0
- package/dist/lightweight/bn.interface.min.mjs.map +1 -0
- package/dist/lightweight/bn.interface.mjs +340 -0
- package/dist/lightweight/bn.min.mjs +3 -0
- package/dist/lightweight/bn.min.mjs.map +1 -0
- package/dist/lightweight/bn.mjs +3434 -0
- package/dist/lightweight/elliptic.min.mjs +3 -0
- package/dist/lightweight/elliptic.min.mjs.map +1 -0
- package/dist/lightweight/elliptic.mjs +4313 -0
- package/dist/lightweight/openpgp.min.mjs +3 -0
- package/dist/lightweight/openpgp.min.mjs.map +1 -0
- package/dist/lightweight/openpgp.mjs +31375 -0
- package/dist/lightweight/ponyfill.es6.min.mjs +3 -0
- package/dist/lightweight/ponyfill.es6.min.mjs.map +1 -0
- package/dist/lightweight/ponyfill.es6.mjs +3831 -0
- package/dist/lightweight/web-streams-adapter.min.mjs +17 -0
- package/dist/lightweight/web-streams-adapter.min.mjs.map +1 -0
- package/dist/lightweight/web-streams-adapter.mjs +561 -0
- package/dist/node/openpgp.js +43943 -0
- package/dist/node/openpgp.min.js +17 -0
- package/dist/node/openpgp.min.js.map +1 -0
- package/dist/node/openpgp.min.mjs +17 -0
- package/dist/node/openpgp.min.mjs.map +1 -0
- package/dist/node/openpgp.mjs +43880 -0
- package/dist/openpgp.js +41080 -41565
- package/dist/openpgp.min.js +17 -2
- package/dist/openpgp.min.js.map +1 -0
- package/dist/openpgp.min.mjs +17 -0
- package/dist/openpgp.min.mjs.map +1 -0
- package/dist/openpgp.mjs +43868 -0
- package/lightweight/package.json +5 -0
- package/openpgp.d.ts +889 -0
- package/package.json +63 -57
- package/dist/compat/openpgp.js +0 -61067
- package/dist/compat/openpgp.min.js +0 -2
- package/dist/compat/openpgp.worker.js +0 -173
- package/dist/compat/openpgp.worker.min.js +0 -2
- package/dist/lightweight/elliptic.min.js +0 -5
- package/dist/lightweight/openpgp.js +0 -40024
- package/dist/lightweight/openpgp.min.js +0 -2
- package/dist/lightweight/openpgp.worker.js +0 -173
- package/dist/lightweight/openpgp.worker.min.js +0 -2
- package/dist/openpgp.worker.js +0 -173
- package/dist/openpgp.worker.min.js +0 -2
- package/src/cleartext.js +0 -220
- package/src/config/config.js +0 -224
- package/src/config/index.js +0 -7
- package/src/config/localStorage.js +0 -35
- package/src/crypto/aes_kw.js +0 -153
- package/src/crypto/cfb.js +0 -169
- package/src/crypto/cipher/aes.js +0 -27
- package/src/crypto/cipher/blowfish.js +0 -398
- package/src/crypto/cipher/cast5.js +0 -610
- package/src/crypto/cipher/des.js +0 -476
- package/src/crypto/cipher/index.js +0 -91
- package/src/crypto/cipher/twofish.js +0 -346
- package/src/crypto/cmac.js +0 -98
- package/src/crypto/crypto.js +0 -394
- package/src/crypto/eax.js +0 -172
- package/src/crypto/gcm.js +0 -141
- package/src/crypto/hash/index.js +0 -163
- package/src/crypto/hash/md5.js +0 -205
- package/src/crypto/index.js +0 -57
- package/src/crypto/ocb.js +0 -274
- package/src/crypto/pkcs1.js +0 -170
- package/src/crypto/pkcs5.js +0 -55
- package/src/crypto/public_key/dsa.js +0 -188
- package/src/crypto/public_key/elgamal.js +0 -137
- package/src/crypto/public_key/elliptic/curves.js +0 -385
- package/src/crypto/public_key/elliptic/ecdh.js +0 -414
- package/src/crypto/public_key/elliptic/ecdsa.js +0 -348
- package/src/crypto/public_key/elliptic/eddsa.js +0 -119
- package/src/crypto/public_key/elliptic/index.js +0 -34
- package/src/crypto/public_key/elliptic/indutnyKey.js +0 -85
- package/src/crypto/public_key/index.js +0 -28
- package/src/crypto/public_key/prime.js +0 -275
- package/src/crypto/public_key/rsa.js +0 -597
- package/src/crypto/random.js +0 -145
- package/src/crypto/signature.js +0 -137
- package/src/encoding/armor.js +0 -433
- package/src/encoding/base64.js +0 -96
- package/src/enums.js +0 -493
- package/src/hkp.js +0 -89
- package/src/index.js +0 -161
- package/src/key/factory.js +0 -326
- package/src/key/helper.js +0 -363
- package/src/key/index.js +0 -32
- package/src/key/key.js +0 -890
- package/src/key/subkey.js +0 -187
- package/src/key/user.js +0 -230
- package/src/keyring/index.js +0 -12
- package/src/keyring/keyring.js +0 -229
- package/src/keyring/localstore.js +0 -119
- package/src/lightweight_helper.js +0 -26
- package/src/message.js +0 -825
- package/src/openpgp.js +0 -717
- package/src/packet/all_packets.js +0 -116
- package/src/packet/clone.js +0 -189
- package/src/packet/compressed.js +0 -194
- package/src/packet/index.js +0 -20
- package/src/packet/literal.js +0 -168
- package/src/packet/marker.js +0 -62
- package/src/packet/one_pass_signature.js +0 -156
- package/src/packet/packet.js +0 -300
- package/src/packet/packetlist.js +0 -232
- package/src/packet/public_key.js +0 -280
- package/src/packet/public_key_encrypted_session_key.js +0 -156
- package/src/packet/public_subkey.js +0 -44
- package/src/packet/secret_key.js +0 -448
- package/src/packet/secret_subkey.js +0 -41
- package/src/packet/signature.js +0 -782
- package/src/packet/sym_encrypted_aead_protected.js +0 -189
- package/src/packet/sym_encrypted_integrity_protected.js +0 -139
- package/src/packet/sym_encrypted_session_key.js +0 -204
- package/src/packet/symmetrically_encrypted.js +0 -118
- package/src/packet/trust.js +0 -35
- package/src/packet/user_attribute.js +0 -94
- package/src/packet/userid.js +0 -87
- package/src/polyfills.js +0 -64
- package/src/signature.js +0 -73
- package/src/type/ecdh_symkey.js +0 -69
- package/src/type/kdf_params.js +0 -114
- package/src/type/keyid.js +0 -110
- package/src/type/mpi.js +0 -138
- package/src/type/oid.js +0 -110
- package/src/type/s2k.js +0 -203
- package/src/util.js +0 -836
- package/src/wkd.js +0 -88
- package/src/worker/async_proxy.js +0 -190
- package/src/worker/worker.js +0 -167
- package/test/crypto/aes_kw.js +0 -57
- package/test/crypto/cipher/aes.js +0 -86
- package/test/crypto/cipher/blowfish.js +0 -58
- package/test/crypto/cipher/cast5.js +0 -25
- package/test/crypto/cipher/des.js +0 -143
- package/test/crypto/cipher/index.js +0 -7
- package/test/crypto/cipher/twofish.js +0 -71
- package/test/crypto/crypto.js +0 -383
- package/test/crypto/eax.js +0 -150
- package/test/crypto/ecdh.js +0 -359
- package/test/crypto/elliptic.js +0 -251
- package/test/crypto/elliptic_data.js +0 -102
- package/test/crypto/hash/index.js +0 -5
- package/test/crypto/hash/md5.js +0 -16
- package/test/crypto/hash/ripemd.js +0 -14
- package/test/crypto/hash/sha.js +0 -20
- package/test/crypto/index.js +0 -14
- package/test/crypto/ocb.js +0 -183
- package/test/crypto/pkcs5.js +0 -39
- package/test/crypto/random.js +0 -79
- package/test/crypto/rsa.js +0 -180
- package/test/crypto/validate.js +0 -387
- package/test/general/armor.js +0 -408
- package/test/general/brainpool.js +0 -360
- package/test/general/decompression.js +0 -60
- package/test/general/ecc_nist.js +0 -115
- package/test/general/ecc_secp256k1.js +0 -242
- package/test/general/forwarding.js +0 -43
- package/test/general/hkp.js +0 -165
- package/test/general/index.js +0 -20
- package/test/general/key.js +0 -3402
- package/test/general/keyring.js +0 -336
- package/test/general/oid.js +0 -39
- package/test/general/openpgp.js +0 -2542
- package/test/general/packet.js +0 -937
- package/test/general/signature.js +0 -1665
- package/test/general/streaming.js +0 -944
- package/test/general/testInputs.js +0 -18
- package/test/general/util.js +0 -183
- package/test/general/wkd.js +0 -48
- package/test/general/x25519.js +0 -556
- package/test/unittests.js +0 -64
|
@@ -1,944 +0,0 @@
|
|
|
1
|
-
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../../dist/openpgp');
|
|
2
|
-
|
|
3
|
-
const stub = require('sinon/lib/sinon/stub');
|
|
4
|
-
const chai = require('chai');
|
|
5
|
-
chai.use(require('chai-as-promised'));
|
|
6
|
-
const input = require('./testInputs.js');
|
|
7
|
-
|
|
8
|
-
const { expect } = chai;
|
|
9
|
-
|
|
10
|
-
const { stream, util } = openpgp;
|
|
11
|
-
|
|
12
|
-
const pub_key =
|
|
13
|
-
['-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
|
14
|
-
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
|
15
|
-
'',
|
|
16
|
-
'mI0EUmEvTgEEANyWtQQMOybQ9JltDqmaX0WnNPJeLILIM36sw6zL0nfTQ5zXSS3+',
|
|
17
|
-
'fIF6P29lJFxpblWk02PSID5zX/DYU9/zjM2xPO8Oa4xo0cVTOTLj++Ri5mtr//f5',
|
|
18
|
-
'GLsIXxFrBJhD/ghFsL3Op0GXOeLJ9A5bsOn8th7x6JucNKuaRB6bQbSPABEBAAG0',
|
|
19
|
-
'JFRlc3QgTWNUZXN0aW5ndG9uIDx0ZXN0QGV4YW1wbGUuY29tPoi5BBMBAgAjBQJS',
|
|
20
|
-
'YS9OAhsvBwsJCAcDAgEGFQgCCQoLBBYCAwECHgECF4AACgkQSmNhOk1uQJQwDAP6',
|
|
21
|
-
'AgrTyqkRlJVqz2pb46TfbDM2TDF7o9CBnBzIGoxBhlRwpqALz7z2kxBDmwpQa+ki',
|
|
22
|
-
'Bq3jZN/UosY9y8bhwMAlnrDY9jP1gdCo+H0sD48CdXybblNwaYpwqC8VSpDdTndf',
|
|
23
|
-
'9j2wE/weihGp/DAdy/2kyBCaiOY1sjhUfJ1GogF49rC4jQRSYS9OAQQA6R/PtBFa',
|
|
24
|
-
'JaT4jq10yqASk4sqwVMsc6HcifM5lSdxzExFP74naUMMyEsKHP53QxTF0Grqusag',
|
|
25
|
-
'Qg/ZtgT0CN1HUM152y7ACOdp1giKjpMzOTQClqCoclyvWOFB+L/SwGEIJf7LSCEr',
|
|
26
|
-
'woBuJifJc8xAVr0XX0JthoW+uP91eTQ3XpsAEQEAAYkBPQQYAQIACQUCUmEvTgIb',
|
|
27
|
-
'LgCoCRBKY2E6TW5AlJ0gBBkBAgAGBQJSYS9OAAoJEOCE90RsICyXuqIEANmmiRCA',
|
|
28
|
-
'SF7YK7PvFkieJNwzeK0V3F2lGX+uu6Y3Q/Zxdtwc4xR+me/CSBmsURyXTO29OWhP',
|
|
29
|
-
'GLszPH9zSJU9BdDi6v0yNprmFPX/1Ng0Abn/sCkwetvjxC1YIvTLFwtUL/7v6NS2',
|
|
30
|
-
'bZpsUxRTg9+cSrMWWSNjiY9qUKajm1tuzPDZXAUEAMNmAN3xXN/Kjyvj2OK2ck0X',
|
|
31
|
-
'W748sl/tc3qiKPMJ+0AkMF7Pjhmh9nxqE9+QCEl7qinFqqBLjuzgUhBU4QlwX1GD',
|
|
32
|
-
'AtNTq6ihLMD5v1d82ZC7tNatdlDMGWnIdvEMCv2GZcuIqDQ9rXWs49e7tq1NncLY',
|
|
33
|
-
'hz3tYjKhoFTKEIq3y3Pp',
|
|
34
|
-
'=h/aX',
|
|
35
|
-
'-----END PGP PUBLIC KEY BLOCK-----'].join('\n');
|
|
36
|
-
|
|
37
|
-
const priv_key =
|
|
38
|
-
['-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
|
39
|
-
'Version: GnuPG v2.0.19 (GNU/Linux)',
|
|
40
|
-
'',
|
|
41
|
-
'lQH+BFJhL04BBADclrUEDDsm0PSZbQ6pml9FpzTyXiyCyDN+rMOsy9J300Oc10kt',
|
|
42
|
-
'/nyBej9vZSRcaW5VpNNj0iA+c1/w2FPf84zNsTzvDmuMaNHFUzky4/vkYuZra//3',
|
|
43
|
-
'+Ri7CF8RawSYQ/4IRbC9zqdBlzniyfQOW7Dp/LYe8eibnDSrmkQem0G0jwARAQAB',
|
|
44
|
-
'/gMDAu7L//czBpE40p1ZqO8K3k7UejemjsQqc7kOqnlDYd1Z6/3NEA/UM30Siipr',
|
|
45
|
-
'KjdIFY5+hp0hcs6EiiNq0PDfm/W2j+7HfrZ5kpeQVxDek4irezYZrl7JS2xezaLv',
|
|
46
|
-
'k0Fv/6fxasnFtjOM6Qbstu67s5Gpl9y06ZxbP3VpT62+Xeibn/swWrfiJjuGEEhM',
|
|
47
|
-
'bgnsMpHtzAz/L8y6KSzViG/05hBaqrvk3/GeEA6nE+o0+0a6r0LYLTemmq6FbaA1',
|
|
48
|
-
'PHo+x7k7oFcBFUUeSzgx78GckuPwqr2mNfeF+IuSRnrlpZl3kcbHASPAOfEkyMXS',
|
|
49
|
-
'sWGE7grCAjbyQyM3OEXTSyqnehvGS/1RdB6kDDxGwgE/QFbwNyEh6K4eaaAThW2j',
|
|
50
|
-
'IEEI0WEnRkPi9fXyxhFsCLSI1XhqTaq7iDNqJTxE+AX2b9ZuZXAxI3Tc/7++vEyL',
|
|
51
|
-
'3p18N/MB2kt1Wb1azmXWL2EKlT1BZ5yDaJuBQ8BhphM3tCRUZXN0IE1jVGVzdGlu',
|
|
52
|
-
'Z3RvbiA8dGVzdEBleGFtcGxlLmNvbT6IuQQTAQIAIwUCUmEvTgIbLwcLCQgHAwIB',
|
|
53
|
-
'BhUIAgkKCwQWAgMBAh4BAheAAAoJEEpjYTpNbkCUMAwD+gIK08qpEZSVas9qW+Ok',
|
|
54
|
-
'32wzNkwxe6PQgZwcyBqMQYZUcKagC8+89pMQQ5sKUGvpIgat42Tf1KLGPcvG4cDA',
|
|
55
|
-
'JZ6w2PYz9YHQqPh9LA+PAnV8m25TcGmKcKgvFUqQ3U53X/Y9sBP8HooRqfwwHcv9',
|
|
56
|
-
'pMgQmojmNbI4VHydRqIBePawnQH+BFJhL04BBADpH8+0EVolpPiOrXTKoBKTiyrB',
|
|
57
|
-
'UyxzodyJ8zmVJ3HMTEU/vidpQwzISwoc/ndDFMXQauq6xqBCD9m2BPQI3UdQzXnb',
|
|
58
|
-
'LsAI52nWCIqOkzM5NAKWoKhyXK9Y4UH4v9LAYQgl/stIISvCgG4mJ8lzzEBWvRdf',
|
|
59
|
-
'Qm2Ghb64/3V5NDdemwARAQAB/gMDAu7L//czBpE40iPcpLzL7GwBbWFhSWgSLy53',
|
|
60
|
-
'Md99Kxw3cApWCok2E8R9/4VS0490xKZIa5y2I/K8thVhqk96Z8Kbt7MRMC1WLHgC',
|
|
61
|
-
'qJvkeQCI6PrFM0PUIPLHAQtDJYKtaLXxYuexcAdKzZj3FHdtLNWCooK6n3vJlL1c',
|
|
62
|
-
'WjZcHJ1PH7USlj1jup4XfxsbziuysRUSyXkjn92GZLm+64vCIiwhqAYoizF2NHHG',
|
|
63
|
-
'hRTN4gQzxrxgkeVchl+ag7DkQUDANIIVI+A63JeLJgWJiH1fbYlwESByHW+zBFNt',
|
|
64
|
-
'qStjfIOhjrfNIc3RvsggbDdWQLcbxmLZj4sB0ydPSgRKoaUdRHJY0S4vp9ouKOtl',
|
|
65
|
-
'2au/P1BP3bhD0fDXl91oeheYth+MSmsJFDg/vZJzCJhFaQ9dp+2EnjN5auNCNbaI',
|
|
66
|
-
'beFJRHFf9cha8p3hh+AK54NRCT++B2MXYf+TPwqX88jYMBv8kk8vYUgo8128r1zQ',
|
|
67
|
-
'EzjviQE9BBgBAgAJBQJSYS9OAhsuAKgJEEpjYTpNbkCUnSAEGQECAAYFAlJhL04A',
|
|
68
|
-
'CgkQ4IT3RGwgLJe6ogQA2aaJEIBIXtgrs+8WSJ4k3DN4rRXcXaUZf667pjdD9nF2',
|
|
69
|
-
'3BzjFH6Z78JIGaxRHJdM7b05aE8YuzM8f3NIlT0F0OLq/TI2muYU9f/U2DQBuf+w',
|
|
70
|
-
'KTB62+PELVgi9MsXC1Qv/u/o1LZtmmxTFFOD35xKsxZZI2OJj2pQpqObW27M8Nlc',
|
|
71
|
-
'BQQAw2YA3fFc38qPK+PY4rZyTRdbvjyyX+1zeqIo8wn7QCQwXs+OGaH2fGoT35AI',
|
|
72
|
-
'SXuqKcWqoEuO7OBSEFThCXBfUYMC01OrqKEswPm/V3zZkLu01q12UMwZach28QwK',
|
|
73
|
-
'/YZly4ioND2tdazj17u2rU2dwtiHPe1iMqGgVMoQirfLc+k=',
|
|
74
|
-
'=lw5e',
|
|
75
|
-
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
|
76
|
-
|
|
77
|
-
const passphrase = 'hello world';
|
|
78
|
-
|
|
79
|
-
const brainpoolPub = [
|
|
80
|
-
'-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
|
81
|
-
'',
|
|
82
|
-
'mHMEWq8ruRMJKyQDAwIIAQELAwMEhi/66JLo1vMhpytb1bYvBhd/aKHde2Zwke7r',
|
|
83
|
-
'zWFTYBZQl/DUrpMrVAhkQhk5G3kqFWf98O/DpvVmY6EDr3IjmODWowNvGfC4Avc9',
|
|
84
|
-
'rYRgV8GbMBUVLIS+ytS1YNpAKW4vtBlidW5ueSA8YnVubnlAYnVubnkuYnVubnk+',
|
|
85
|
-
'iLAEExMKADgWIQSLliWLcmzBLxv2/X36PWTJvPM4vAUCWq8ruQIbAwULCQgHAwUV',
|
|
86
|
-
'CgkICwUWAgMBAAIeAQIXgAAKCRD6PWTJvPM4vIcVAYCIO41QylZkb9W4FP+kd3bz',
|
|
87
|
-
'b73xxwojWpCiw1bWV9Xe/dKA23DtCYhlmhF/Twjh9lkBfihHXs/negGMnqbA8TQF',
|
|
88
|
-
'U1IvBflDcA7yj677lgLkze/yd5hg/ZVx7M8XyUzcEm9xi7h3BFqvK7kSCSskAwMC',
|
|
89
|
-
'CAEBCwMDBCkGskA01sBvG/B1bl0EN+yxF6xPn74WQoAMm7K4n1PlZ1u8RWg+BJVG',
|
|
90
|
-
'Kna/88ZGcT5BZSUvRrYWgqb4/SPAPea5C1p6UYd+C0C0dVf0FaGv5z0gCtc/+kwF',
|
|
91
|
-
'3sLGLZh3rAMBCQmImAQYEwoAIBYhBIuWJYtybMEvG/b9ffo9ZMm88zi8BQJaryu5',
|
|
92
|
-
'AhsMAAoJEPo9ZMm88zi8w1QBfR4k1d5ElME3ef7viE+Mud4qGv1ra56pKa86hS9+',
|
|
93
|
-
'l262twTxe1hk08/FySeJW08P3wF/WrhCrE9UDD6FQiZk1lqekhd9bf84v6i5Smbi',
|
|
94
|
-
'oml1QWkiI6BtbLD39Su6zQKR7u+Y',
|
|
95
|
-
'=wB7z',
|
|
96
|
-
'-----END PGP PUBLIC KEY BLOCK-----'
|
|
97
|
-
].join('\n');
|
|
98
|
-
|
|
99
|
-
const brainpoolPriv = [
|
|
100
|
-
'-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
|
101
|
-
'',
|
|
102
|
-
'lNYEWq8ruRMJKyQDAwIIAQELAwMEhi/66JLo1vMhpytb1bYvBhd/aKHde2Zwke7r',
|
|
103
|
-
'zWFTYBZQl/DUrpMrVAhkQhk5G3kqFWf98O/DpvVmY6EDr3IjmODWowNvGfC4Avc9',
|
|
104
|
-
'rYRgV8GbMBUVLIS+ytS1YNpAKW4v/gcDAtyjmSfDquSq5ffphtkwJ56Zz5jc+jSm',
|
|
105
|
-
'yZaPgmnPOwcgYhWy1g7BcBKYFPNKZlajnV4Rut2VUWkELwWrRmchX4ENJoAKZob0',
|
|
106
|
-
'l/zjgOPug3FtEGirOPmvi7nOkjDEFNJwtBlidW5ueSA8YnVubnlAYnVubnkuYnVu',
|
|
107
|
-
'bnk+iLAEExMKADgWIQSLliWLcmzBLxv2/X36PWTJvPM4vAUCWq8ruQIbAwULCQgH',
|
|
108
|
-
'AwUVCgkICwUWAgMBAAIeAQIXgAAKCRD6PWTJvPM4vIcVAYCIO41QylZkb9W4FP+k',
|
|
109
|
-
'd3bzb73xxwojWpCiw1bWV9Xe/dKA23DtCYhlmhF/Twjh9lkBfihHXs/negGMnqbA',
|
|
110
|
-
'8TQFU1IvBflDcA7yj677lgLkze/yd5hg/ZVx7M8XyUzcEm9xi5zaBFqvK7kSCSsk',
|
|
111
|
-
'AwMCCAEBCwMDBCkGskA01sBvG/B1bl0EN+yxF6xPn74WQoAMm7K4n1PlZ1u8RWg+',
|
|
112
|
-
'BJVGKna/88ZGcT5BZSUvRrYWgqb4/SPAPea5C1p6UYd+C0C0dVf0FaGv5z0gCtc/',
|
|
113
|
-
'+kwF3sLGLZh3rAMBCQn+BwMC6RvzFHWyKqPlVqrm6+j797Y9vHdZW1zixtmEK0Wg',
|
|
114
|
-
'lvQRpZF8AbpSzk/XolsoeQyic1e18C6ubFZFw7cI7ekINiRu/OXOvBnTbc5TdbDi',
|
|
115
|
-
'kKTuOkL+lEwWrUTEwdshbJ+ImAQYEwoAIBYhBIuWJYtybMEvG/b9ffo9ZMm88zi8',
|
|
116
|
-
'BQJaryu5AhsMAAoJEPo9ZMm88zi8w1QBfR4k1d5ElME3ef7viE+Mud4qGv1ra56p',
|
|
117
|
-
'Ka86hS9+l262twTxe1hk08/FySeJW08P3wF/WrhCrE9UDD6FQiZk1lqekhd9bf84',
|
|
118
|
-
'v6i5Smbioml1QWkiI6BtbLD39Su6zQKR7u+Y',
|
|
119
|
-
'=uGZP',
|
|
120
|
-
'-----END PGP PRIVATE KEY BLOCK-----'
|
|
121
|
-
].join('\n');
|
|
122
|
-
|
|
123
|
-
const brainpoolPass = '321';
|
|
124
|
-
|
|
125
|
-
const xPub = [
|
|
126
|
-
'-----BEGIN PGP PUBLIC KEY BLOCK-----',
|
|
127
|
-
'',
|
|
128
|
-
'mDMEWkN+5BYJKwYBBAHaRw8BAQdAIGqj23Kp273IPkgjwA7ue5MDIRAfWLYRqnFy',
|
|
129
|
-
'c2AFMcC0EUxpZ2h0IDxsaWdodEBzdW4+iJAEExYIADgWIQSGS0GuVELT3Rs0woce',
|
|
130
|
-
'zfAmwCRYMAUCWkN+5AIbAwULCQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRAezfAm',
|
|
131
|
-
'wCRYMLteAQCFZcl8kBxCH86wmqpc2+KtEA8l/hsfh7jd+JWuyFuuRAD7BOix8Vo1',
|
|
132
|
-
'P/hv8qUYwSn3IRXPeGXucoWVoKGgxRd+zAO4OARaQ37kEgorBgEEAZdVAQUBAQdA',
|
|
133
|
-
'L1KkHCFxtK1CgvZlInT/y6OQeCfXiYzd/i452t2ZR2ADAQgHiHgEGBYIACAWIQSG',
|
|
134
|
-
'S0GuVELT3Rs0wocezfAmwCRYMAUCWkN+5AIbDAAKCRAezfAmwCRYMJ71AQDmoQTg',
|
|
135
|
-
'36pfjrl82srS6XPRJxl3r/6lpWGaNij0VptB2wEA2V10ifOhnwILCw1qBle6On7a',
|
|
136
|
-
'Ba257lrFM+cOSMaEsgo=',
|
|
137
|
-
'=D8HS',
|
|
138
|
-
'-----END PGP PUBLIC KEY BLOCK-----'
|
|
139
|
-
].join('\n');
|
|
140
|
-
|
|
141
|
-
const xPriv = [
|
|
142
|
-
'-----BEGIN PGP PRIVATE KEY BLOCK-----',
|
|
143
|
-
'',
|
|
144
|
-
'lIYEWkN+5BYJKwYBBAHaRw8BAQdAIGqj23Kp273IPkgjwA7ue5MDIRAfWLYRqnFy',
|
|
145
|
-
'c2AFMcD+BwMCeaL+cNXzgI7uJQ7HBv53TAXO3y5uyJQMonkFtQtldL8YDbNP3pbd',
|
|
146
|
-
'3zzo9fxU12bWAJyFwBlBWJqkrxZN+0jt0ElsG3kp+V67MESJkrRhKrQRTGlnaHQg',
|
|
147
|
-
'PGxpZ2h0QHN1bj6IkAQTFggAOBYhBIZLQa5UQtPdGzTChx7N8CbAJFgwBQJaQ37k',
|
|
148
|
-
'AhsDBQsJCAcCBhUICQoLAgQWAgMBAh4BAheAAAoJEB7N8CbAJFgwu14BAIVlyXyQ',
|
|
149
|
-
'HEIfzrCaqlzb4q0QDyX+Gx+HuN34la7IW65EAPsE6LHxWjU/+G/ypRjBKfchFc94',
|
|
150
|
-
'Ze5yhZWgoaDFF37MA5yLBFpDfuQSCisGAQQBl1UBBQEBB0AvUqQcIXG0rUKC9mUi',
|
|
151
|
-
'dP/Lo5B4J9eJjN3+Ljna3ZlHYAMBCAf+BwMCvyW2D5Yx6dbujE3yHi1XQ9MbhOY5',
|
|
152
|
-
'XRFFgYIUYzzi1qmaL+8Gr9zODsUdeO60XHnMXOmqVa6/sdx32TWo5s3sgS19kRUM',
|
|
153
|
-
'D+pbxS/aZnxvrYh4BBgWCAAgFiEEhktBrlRC090bNMKHHs3wJsAkWDAFAlpDfuQC',
|
|
154
|
-
'GwwACgkQHs3wJsAkWDCe9QEA5qEE4N+qX465fNrK0ulz0ScZd6/+paVhmjYo9Fab',
|
|
155
|
-
'QdsBANlddInzoZ8CCwsNagZXujp+2gWtue5axTPnDkjGhLIK',
|
|
156
|
-
'=wo91',
|
|
157
|
-
'-----END PGP PRIVATE KEY BLOCK-----'
|
|
158
|
-
].join('\n');
|
|
159
|
-
|
|
160
|
-
const xPass = 'sun';
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
let privKey, pubKey, plaintext, data, i, canceled, expectedType, dataArrived;
|
|
164
|
-
|
|
165
|
-
function tests() {
|
|
166
|
-
it('Encrypt small message', async function() {
|
|
167
|
-
dataArrived(); // Do not wait until data arrived.
|
|
168
|
-
const data = new ReadableStream({
|
|
169
|
-
async start(controller) {
|
|
170
|
-
controller.enqueue(util.str_to_Uint8Array('hello '));
|
|
171
|
-
controller.enqueue(util.str_to_Uint8Array('world'));
|
|
172
|
-
controller.close();
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
const encrypted = await openpgp.encrypt({
|
|
176
|
-
message: openpgp.message.fromBinary(data),
|
|
177
|
-
passwords: ['test'],
|
|
178
|
-
});
|
|
179
|
-
const msgAsciiArmored = await openpgp.stream.readToEnd(encrypted.data);
|
|
180
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
181
|
-
const decrypted = await openpgp.decrypt({
|
|
182
|
-
passwords: ['test'],
|
|
183
|
-
message
|
|
184
|
-
});
|
|
185
|
-
expect(decrypted.data).to.equal('hello world');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('Encrypt larger message', async function() {
|
|
189
|
-
const encrypted = await openpgp.encrypt({
|
|
190
|
-
message: openpgp.message.fromBinary(data),
|
|
191
|
-
passwords: ['test'],
|
|
192
|
-
});
|
|
193
|
-
const reader = openpgp.stream.getReader(encrypted.data);
|
|
194
|
-
expect(await reader.peekBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
|
|
195
|
-
dataArrived();
|
|
196
|
-
reader.releaseLock();
|
|
197
|
-
const msgAsciiArmored = await openpgp.stream.readToEnd(encrypted.data);
|
|
198
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
199
|
-
const decrypted = await openpgp.decrypt({
|
|
200
|
-
passwords: ['test'],
|
|
201
|
-
message,
|
|
202
|
-
format: 'binary'
|
|
203
|
-
});
|
|
204
|
-
expect(decrypted.data).to.deep.equal(util.concatUint8Array(plaintext));
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it('Input stream should be canceled when canceling encrypted stream', async function() {
|
|
208
|
-
const encrypted = await openpgp.encrypt({
|
|
209
|
-
message: openpgp.message.fromBinary(data),
|
|
210
|
-
passwords: ['test'],
|
|
211
|
-
});
|
|
212
|
-
const reader = openpgp.stream.getReader(encrypted.data);
|
|
213
|
-
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
|
|
214
|
-
dataArrived();
|
|
215
|
-
reader.releaseLock();
|
|
216
|
-
await openpgp.stream.cancel(encrypted.data);
|
|
217
|
-
expect(canceled).to.be.true;
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('Sign: Input stream should be canceled when canceling encrypted stream', async function() {
|
|
221
|
-
const signed = await openpgp.sign({
|
|
222
|
-
message: openpgp.message.fromBinary(data),
|
|
223
|
-
privateKeys: privKey
|
|
224
|
-
});
|
|
225
|
-
const reader = openpgp.stream.getReader(signed.data);
|
|
226
|
-
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
|
|
227
|
-
dataArrived();
|
|
228
|
-
reader.releaseLock();
|
|
229
|
-
await openpgp.stream.cancel(signed.data);
|
|
230
|
-
expect(canceled).to.be.true;
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('Encrypt and decrypt larger message roundtrip', async function() {
|
|
234
|
-
const encrypted = await openpgp.encrypt({
|
|
235
|
-
message: openpgp.message.fromBinary(data),
|
|
236
|
-
passwords: ['test'],
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
const msgAsciiArmored = encrypted.data;
|
|
240
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
241
|
-
setTimeout(dataArrived, 3000); // Do not wait until data arrived, but wait a bit to check that it doesn't arrive early.
|
|
242
|
-
const decrypted = await openpgp.decrypt({
|
|
243
|
-
passwords: ['test'],
|
|
244
|
-
message,
|
|
245
|
-
format: 'binary'
|
|
246
|
-
});
|
|
247
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
248
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
249
|
-
expect(await reader.peekBytes(1024)).to.deep.equal(plaintext[0]);
|
|
250
|
-
if (i <= 10) throw new Error('Data arrived early.');
|
|
251
|
-
expect(await reader.readToEnd()).to.deep.equal(util.concatUint8Array(plaintext));
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('Encrypt and decrypt larger message roundtrip (allow_unauthenticated_stream=true)', async function() {
|
|
255
|
-
let allow_unauthenticated_streamValue = openpgp.config.allow_unauthenticated_stream;
|
|
256
|
-
openpgp.config.allow_unauthenticated_stream = true;
|
|
257
|
-
try {
|
|
258
|
-
const encrypted = await openpgp.encrypt({
|
|
259
|
-
message: openpgp.message.fromBinary(data),
|
|
260
|
-
passwords: ['test'],
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
const msgAsciiArmored = encrypted.data;
|
|
264
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
265
|
-
const decrypted = await openpgp.decrypt({
|
|
266
|
-
passwords: ['test'],
|
|
267
|
-
message,
|
|
268
|
-
format: 'binary'
|
|
269
|
-
});
|
|
270
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
271
|
-
expect(util.isStream(decrypted.signatures)).to.be.false;
|
|
272
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
273
|
-
expect(await reader.peekBytes(1024)).to.deep.equal(plaintext[0]);
|
|
274
|
-
dataArrived();
|
|
275
|
-
expect(await reader.readToEnd()).to.deep.equal(util.concatUint8Array(plaintext));
|
|
276
|
-
expect(decrypted.signatures).to.exist.and.have.length(0);
|
|
277
|
-
} finally {
|
|
278
|
-
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it('Encrypt and decrypt larger message roundtrip using public keys (allow_unauthenticated_stream=true)', async function() {
|
|
283
|
-
let allow_unauthenticated_streamValue = openpgp.config.allow_unauthenticated_stream;
|
|
284
|
-
openpgp.config.allow_unauthenticated_stream = true;
|
|
285
|
-
try {
|
|
286
|
-
const encrypted = await openpgp.encrypt({
|
|
287
|
-
message: openpgp.message.fromBinary(data),
|
|
288
|
-
publicKeys: pubKey,
|
|
289
|
-
privateKeys: privKey
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
const msgAsciiArmored = encrypted.data;
|
|
293
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
294
|
-
const decrypted = await openpgp.decrypt({
|
|
295
|
-
publicKeys: pubKey,
|
|
296
|
-
privateKeys: privKey,
|
|
297
|
-
message,
|
|
298
|
-
format: 'binary'
|
|
299
|
-
});
|
|
300
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
301
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
302
|
-
expect(await reader.peekBytes(1024)).to.deep.equal(plaintext[0]);
|
|
303
|
-
dataArrived();
|
|
304
|
-
expect(await reader.readToEnd()).to.deep.equal(util.concatUint8Array(plaintext));
|
|
305
|
-
} finally {
|
|
306
|
-
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('Encrypt and decrypt larger message roundtrip using curve x25519 (allow_unauthenticated_stream=true)', async function() {
|
|
311
|
-
let allow_unauthenticated_streamValue = openpgp.config.allow_unauthenticated_stream;
|
|
312
|
-
openpgp.config.allow_unauthenticated_stream = true;
|
|
313
|
-
const priv = (await openpgp.key.readArmored(xPriv)).keys[0];
|
|
314
|
-
const pub = (await openpgp.key.readArmored(xPub)).keys[0];
|
|
315
|
-
await priv.decrypt(xPass);
|
|
316
|
-
try {
|
|
317
|
-
const encrypted = await openpgp.encrypt({
|
|
318
|
-
message: openpgp.message.fromBinary(data),
|
|
319
|
-
publicKeys: pub,
|
|
320
|
-
privateKeys: priv
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
const msgAsciiArmored = encrypted.data;
|
|
324
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
325
|
-
const decrypted = await openpgp.decrypt({
|
|
326
|
-
publicKeys: pub,
|
|
327
|
-
privateKeys: priv,
|
|
328
|
-
message,
|
|
329
|
-
format: 'binary'
|
|
330
|
-
});
|
|
331
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
332
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
333
|
-
expect(await reader.peekBytes(1024)).to.deep.equal(plaintext[0]);
|
|
334
|
-
dataArrived();
|
|
335
|
-
expect(await reader.readToEnd()).to.deep.equal(util.concatUint8Array(plaintext));
|
|
336
|
-
} finally {
|
|
337
|
-
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('Encrypt and decrypt larger message roundtrip using curve brainpool (allow_unauthenticated_stream=true)', async function() {
|
|
342
|
-
let allow_unauthenticated_streamValue = openpgp.config.allow_unauthenticated_stream;
|
|
343
|
-
openpgp.config.allow_unauthenticated_stream = true;
|
|
344
|
-
const priv = (await openpgp.key.readArmored(brainpoolPriv)).keys[0];
|
|
345
|
-
const pub = (await openpgp.key.readArmored(brainpoolPub)).keys[0];
|
|
346
|
-
await priv.decrypt(brainpoolPass);
|
|
347
|
-
try {
|
|
348
|
-
const encrypted = await openpgp.encrypt({
|
|
349
|
-
message: openpgp.message.fromBinary(data),
|
|
350
|
-
publicKeys: pub,
|
|
351
|
-
privateKeys: priv
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
const msgAsciiArmored = encrypted.data;
|
|
355
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
356
|
-
const decrypted = await openpgp.decrypt({
|
|
357
|
-
publicKeys: pub,
|
|
358
|
-
privateKeys: priv,
|
|
359
|
-
message,
|
|
360
|
-
format: 'binary'
|
|
361
|
-
});
|
|
362
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
363
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
364
|
-
expect(await reader.peekBytes(1024)).to.deep.equal(plaintext[0]);
|
|
365
|
-
dataArrived();
|
|
366
|
-
expect(await reader.readToEnd()).to.deep.equal(util.concatUint8Array(plaintext));
|
|
367
|
-
} finally {
|
|
368
|
-
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
it('Detect MDC modifications (allow_unauthenticated_stream=true)', async function() {
|
|
373
|
-
let allow_unauthenticated_streamValue = openpgp.config.allow_unauthenticated_stream;
|
|
374
|
-
openpgp.config.allow_unauthenticated_stream = true;
|
|
375
|
-
try {
|
|
376
|
-
const encrypted = await openpgp.encrypt({
|
|
377
|
-
message: openpgp.message.fromBinary(data),
|
|
378
|
-
passwords: ['test'],
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
const msgAsciiArmored = encrypted.data;
|
|
382
|
-
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
|
383
|
-
value += '';
|
|
384
|
-
if (value === '=' || value.length === 6) return; // Remove checksum
|
|
385
|
-
const newlineIndex = value.indexOf('\r\n', 500);
|
|
386
|
-
if (value.length > 1000) return value.slice(0, newlineIndex - 1) + (value[newlineIndex - 1] === 'a' ? 'b' : 'a') + value.slice(newlineIndex);
|
|
387
|
-
return value;
|
|
388
|
-
}));
|
|
389
|
-
const decrypted = await openpgp.decrypt({
|
|
390
|
-
passwords: ['test'],
|
|
391
|
-
message,
|
|
392
|
-
streaming: expectedType,
|
|
393
|
-
format: 'binary'
|
|
394
|
-
});
|
|
395
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
396
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
397
|
-
expect(await reader.peekBytes(1024)).not.to.deep.equal(plaintext[0]);
|
|
398
|
-
dataArrived();
|
|
399
|
-
await expect(reader.readToEnd()).to.be.rejectedWith('Modification detected.');
|
|
400
|
-
expect(decrypted.signatures).to.exist.and.have.length(0);
|
|
401
|
-
} finally {
|
|
402
|
-
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it('Detect armor checksum error (allow_unauthenticated_stream=true)', async function() {
|
|
407
|
-
let allow_unauthenticated_streamValue = openpgp.config.allow_unauthenticated_stream;
|
|
408
|
-
openpgp.config.allow_unauthenticated_stream = true;
|
|
409
|
-
try {
|
|
410
|
-
const encrypted = await openpgp.encrypt({
|
|
411
|
-
message: openpgp.message.fromBinary(data),
|
|
412
|
-
publicKeys: pubKey,
|
|
413
|
-
privateKeys: privKey
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
const msgAsciiArmored = encrypted.data;
|
|
417
|
-
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
|
418
|
-
value += '';
|
|
419
|
-
const newlineIndex = value.indexOf('\r\n', 500);
|
|
420
|
-
if (value.length > 1000) return value.slice(0, newlineIndex - 1) + (value[newlineIndex - 1] === 'a' ? 'b' : 'a') + value.slice(newlineIndex);
|
|
421
|
-
return value;
|
|
422
|
-
}));
|
|
423
|
-
const decrypted = await openpgp.decrypt({
|
|
424
|
-
publicKeys: pubKey,
|
|
425
|
-
privateKeys: privKey,
|
|
426
|
-
message,
|
|
427
|
-
streaming: expectedType,
|
|
428
|
-
format: 'binary'
|
|
429
|
-
});
|
|
430
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
431
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
432
|
-
expect(await reader.peekBytes(1024)).not.to.deep.equal(plaintext[0]);
|
|
433
|
-
dataArrived();
|
|
434
|
-
await expect(reader.readToEnd()).to.be.rejectedWith('Ascii armor integrity check on message failed');
|
|
435
|
-
expect(decrypted.signatures).to.exist.and.have.length(1);
|
|
436
|
-
} finally {
|
|
437
|
-
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
|
|
438
|
-
}
|
|
439
|
-
});
|
|
440
|
-
|
|
441
|
-
it('Detect armor checksum error when not passing public keys (allow_unauthenticated_stream=true)', async function() {
|
|
442
|
-
let allow_unauthenticated_streamValue = openpgp.config.allow_unauthenticated_stream;
|
|
443
|
-
openpgp.config.allow_unauthenticated_stream = true;
|
|
444
|
-
try {
|
|
445
|
-
const encrypted = await openpgp.encrypt({
|
|
446
|
-
message: openpgp.message.fromBinary(data),
|
|
447
|
-
publicKeys: pubKey,
|
|
448
|
-
privateKeys: privKey
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
const msgAsciiArmored = encrypted.data;
|
|
452
|
-
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
|
453
|
-
value += '';
|
|
454
|
-
const newlineIndex = value.indexOf('\r\n', 500);
|
|
455
|
-
if (value.length > 1000) return value.slice(0, newlineIndex - 1) + (value[newlineIndex - 1] === 'a' ? 'b' : 'a') + value.slice(newlineIndex);
|
|
456
|
-
return value;
|
|
457
|
-
}));
|
|
458
|
-
const decrypted = await openpgp.decrypt({
|
|
459
|
-
privateKeys: privKey,
|
|
460
|
-
message,
|
|
461
|
-
streaming: expectedType,
|
|
462
|
-
format: 'binary'
|
|
463
|
-
});
|
|
464
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
465
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
466
|
-
expect(await reader.peekBytes(1024)).not.to.deep.equal(plaintext[0]);
|
|
467
|
-
dataArrived();
|
|
468
|
-
await expect(reader.readToEnd()).to.be.rejectedWith('Ascii armor integrity check on message failed');
|
|
469
|
-
expect(decrypted.signatures).to.exist.and.have.length(1);
|
|
470
|
-
expect(await decrypted.signatures[0].verified).to.be.null;
|
|
471
|
-
} finally {
|
|
472
|
-
openpgp.config.allow_unauthenticated_stream = allow_unauthenticated_streamValue;
|
|
473
|
-
}
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
it('Sign/verify: Detect armor checksum error', async function() {
|
|
477
|
-
const signed = await openpgp.sign({
|
|
478
|
-
message: openpgp.message.fromBinary(data),
|
|
479
|
-
privateKeys: privKey
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
const msgAsciiArmored = signed.data;
|
|
483
|
-
const message = await openpgp.message.readArmored(openpgp.stream.transform(msgAsciiArmored, value => {
|
|
484
|
-
value += '';
|
|
485
|
-
const newlineIndex = value.indexOf('\r\n', 500);
|
|
486
|
-
if (value.length > 1000) return value.slice(0, newlineIndex - 1) + (value[newlineIndex - 1] === 'a' ? 'b' : 'a') + value.slice(newlineIndex);
|
|
487
|
-
return value;
|
|
488
|
-
}));
|
|
489
|
-
const verified = await openpgp.verify({
|
|
490
|
-
publicKeys: pubKey,
|
|
491
|
-
message,
|
|
492
|
-
streaming: expectedType
|
|
493
|
-
});
|
|
494
|
-
expect(util.isStream(verified.data)).to.equal(expectedType);
|
|
495
|
-
const reader = openpgp.stream.getReader(verified.data);
|
|
496
|
-
expect(await reader.peekBytes(1024)).not.to.deep.equal(plaintext[0]);
|
|
497
|
-
dataArrived();
|
|
498
|
-
await expect(reader.readToEnd()).to.be.rejectedWith('Ascii armor integrity check on message failed');
|
|
499
|
-
expect(verified.signatures).to.exist.and.have.length(1);
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
it('Encrypt and decrypt larger message roundtrip (AEAD)', async function() {
|
|
503
|
-
let aead_protectValue = openpgp.config.aead_protect;
|
|
504
|
-
let aead_chunk_size_byteValue = openpgp.config.aead_chunk_size_byte;
|
|
505
|
-
openpgp.config.aead_protect = true;
|
|
506
|
-
openpgp.config.aead_chunk_size_byte = 4;
|
|
507
|
-
try {
|
|
508
|
-
const encrypted = await openpgp.encrypt({
|
|
509
|
-
message: openpgp.message.fromBinary(data),
|
|
510
|
-
passwords: ['test'],
|
|
511
|
-
});
|
|
512
|
-
|
|
513
|
-
const msgAsciiArmored = encrypted.data;
|
|
514
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
515
|
-
const decrypted = await openpgp.decrypt({
|
|
516
|
-
passwords: ['test'],
|
|
517
|
-
message,
|
|
518
|
-
format: 'binary'
|
|
519
|
-
});
|
|
520
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
521
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
522
|
-
expect(await reader.peekBytes(1024)).to.deep.equal(plaintext[0]);
|
|
523
|
-
dataArrived();
|
|
524
|
-
expect(await reader.readToEnd()).to.deep.equal(util.concatUint8Array(plaintext));
|
|
525
|
-
} finally {
|
|
526
|
-
openpgp.config.aead_protect = aead_protectValue;
|
|
527
|
-
openpgp.config.aead_chunk_size_byte = aead_chunk_size_byteValue;
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
it('Encrypt and decrypt larger text message roundtrip (AEAD)', async function() {
|
|
532
|
-
let aead_protectValue = openpgp.config.aead_protect;
|
|
533
|
-
let aead_chunk_size_byteValue = openpgp.config.aead_chunk_size_byte;
|
|
534
|
-
openpgp.config.aead_protect = true;
|
|
535
|
-
openpgp.config.aead_chunk_size_byte = 0;
|
|
536
|
-
try {
|
|
537
|
-
let plaintext = [];
|
|
538
|
-
let i = 0;
|
|
539
|
-
const data = new ReadableStream({
|
|
540
|
-
async pull(controller) {
|
|
541
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
542
|
-
if (i++ < 10) {
|
|
543
|
-
let randomData = input.createSomeMessage();
|
|
544
|
-
controller.enqueue(randomData);
|
|
545
|
-
plaintext.push(randomData);
|
|
546
|
-
} else {
|
|
547
|
-
controller.close();
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
});
|
|
551
|
-
const encrypted = await openpgp.encrypt({
|
|
552
|
-
message: openpgp.message.fromText(data),
|
|
553
|
-
streaming: expectedType,
|
|
554
|
-
passwords: ['test'],
|
|
555
|
-
});
|
|
556
|
-
|
|
557
|
-
const msgAsciiArmored = encrypted.data;
|
|
558
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
559
|
-
const decrypted = await openpgp.decrypt({
|
|
560
|
-
passwords: ['test'],
|
|
561
|
-
message
|
|
562
|
-
});
|
|
563
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
564
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
565
|
-
expect((await reader.peekBytes(plaintext[0].length * 4)).toString('utf8').substr(0, plaintext[0].length)).to.equal(plaintext[0]);
|
|
566
|
-
dataArrived();
|
|
567
|
-
expect((await reader.readToEnd()).toString('utf8')).to.equal(util.concat(plaintext));
|
|
568
|
-
} finally {
|
|
569
|
-
openpgp.config.aead_protect = aead_protectValue;
|
|
570
|
-
openpgp.config.aead_chunk_size_byte = aead_chunk_size_byteValue;
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
it('stream.transformPair()', async function() {
|
|
575
|
-
dataArrived(); // Do not wait until data arrived.
|
|
576
|
-
const transformed = stream.transformPair(stream.slice(data, 0, 5000), async (readable, writable) => {
|
|
577
|
-
const reader = stream.getReader(readable);
|
|
578
|
-
const writer = stream.getWriter(writable);
|
|
579
|
-
try {
|
|
580
|
-
while (true) {
|
|
581
|
-
await writer.ready;
|
|
582
|
-
const { done, value } = await reader.read();
|
|
583
|
-
if (done) {
|
|
584
|
-
await writer.close();
|
|
585
|
-
break;
|
|
586
|
-
}
|
|
587
|
-
await writer.write(value);
|
|
588
|
-
}
|
|
589
|
-
} catch(e) {
|
|
590
|
-
await writer.abort(e);
|
|
591
|
-
}
|
|
592
|
-
});
|
|
593
|
-
await new Promise(resolve => setTimeout(resolve));
|
|
594
|
-
await stream.cancel(transformed);
|
|
595
|
-
expect(canceled).to.be.true;
|
|
596
|
-
});
|
|
597
|
-
|
|
598
|
-
it('Input stream should be canceled when canceling decrypted stream (AEAD)', async function() {
|
|
599
|
-
let aead_protectValue = openpgp.config.aead_protect;
|
|
600
|
-
let aead_chunk_size_byteValue = openpgp.config.aead_chunk_size_byte;
|
|
601
|
-
openpgp.config.aead_protect = true;
|
|
602
|
-
openpgp.config.aead_chunk_size_byte = 4;
|
|
603
|
-
try {
|
|
604
|
-
const encrypted = await openpgp.encrypt({
|
|
605
|
-
message: openpgp.message.fromBinary(data),
|
|
606
|
-
passwords: ['test'],
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
const msgAsciiArmored = encrypted.data;
|
|
610
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
611
|
-
const decrypted = await openpgp.decrypt({
|
|
612
|
-
passwords: ['test'],
|
|
613
|
-
message,
|
|
614
|
-
format: 'binary'
|
|
615
|
-
});
|
|
616
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
617
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
618
|
-
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
|
|
619
|
-
dataArrived();
|
|
620
|
-
reader.releaseLock();
|
|
621
|
-
await openpgp.stream.cancel(decrypted.data, new Error('canceled by test'));
|
|
622
|
-
expect(canceled).to.be.true;
|
|
623
|
-
} finally {
|
|
624
|
-
openpgp.config.aead_protect = aead_protectValue;
|
|
625
|
-
openpgp.config.aead_chunk_size_byte = aead_chunk_size_byteValue;
|
|
626
|
-
}
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
it('Sign/verify: Input stream should be canceled when canceling verified stream', async function() {
|
|
630
|
-
const signed = await openpgp.sign({
|
|
631
|
-
message: openpgp.message.fromBinary(data),
|
|
632
|
-
privateKeys: privKey
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
const msgAsciiArmored = signed.data;
|
|
636
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
637
|
-
const verified = await openpgp.verify({
|
|
638
|
-
publicKeys: pubKey,
|
|
639
|
-
message
|
|
640
|
-
});
|
|
641
|
-
expect(util.isStream(verified.data)).to.equal(expectedType);
|
|
642
|
-
const reader = openpgp.stream.getReader(verified.data);
|
|
643
|
-
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
|
|
644
|
-
dataArrived();
|
|
645
|
-
reader.releaseLock();
|
|
646
|
-
await openpgp.stream.cancel(verified.data, new Error('canceled by test'));
|
|
647
|
-
expect(canceled).to.be.true;
|
|
648
|
-
expect(verified.signatures).to.exist.and.have.length(1);
|
|
649
|
-
await expect(verified.signatures[0].verified).to.be.rejectedWith('canceled');
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
it("Don't pull entire input stream when we're not pulling encrypted stream", async function() {
|
|
653
|
-
const encrypted = await openpgp.encrypt({
|
|
654
|
-
message: openpgp.message.fromBinary(data),
|
|
655
|
-
passwords: ['test'],
|
|
656
|
-
});
|
|
657
|
-
const reader = openpgp.stream.getReader(encrypted.data);
|
|
658
|
-
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
|
|
659
|
-
dataArrived();
|
|
660
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
661
|
-
expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 100);
|
|
662
|
-
});
|
|
663
|
-
|
|
664
|
-
it("Sign: Don't pull entire input stream when we're not pulling signed stream", async function() {
|
|
665
|
-
const signed = await openpgp.sign({
|
|
666
|
-
message: openpgp.message.fromBinary(data),
|
|
667
|
-
privateKeys: privKey
|
|
668
|
-
});
|
|
669
|
-
const reader = openpgp.stream.getReader(signed.data);
|
|
670
|
-
expect(await reader.readBytes(1024)).to.match(/^-----BEGIN PGP MESSAGE-----\r\n/);
|
|
671
|
-
dataArrived();
|
|
672
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
673
|
-
expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 100);
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
it("Don't pull entire input stream when we're not pulling decrypted stream (AEAD)", async function() {
|
|
677
|
-
let aead_protectValue = openpgp.config.aead_protect;
|
|
678
|
-
let aead_chunk_size_byteValue = openpgp.config.aead_chunk_size_byte;
|
|
679
|
-
openpgp.config.aead_protect = true;
|
|
680
|
-
openpgp.config.aead_chunk_size_byte = 4;
|
|
681
|
-
let coresStub = stub(openpgp.util, 'getHardwareConcurrency');
|
|
682
|
-
coresStub.returns(1);
|
|
683
|
-
try {
|
|
684
|
-
const encrypted = await openpgp.encrypt({
|
|
685
|
-
message: openpgp.message.fromBinary(data),
|
|
686
|
-
passwords: ['test'],
|
|
687
|
-
});
|
|
688
|
-
const msgAsciiArmored = encrypted.data;
|
|
689
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
690
|
-
const decrypted = await openpgp.decrypt({
|
|
691
|
-
passwords: ['test'],
|
|
692
|
-
message,
|
|
693
|
-
format: 'binary'
|
|
694
|
-
});
|
|
695
|
-
expect(util.isStream(decrypted.data)).to.equal(expectedType);
|
|
696
|
-
const reader = openpgp.stream.getReader(decrypted.data);
|
|
697
|
-
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
|
|
698
|
-
dataArrived();
|
|
699
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
700
|
-
expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 100);
|
|
701
|
-
} finally {
|
|
702
|
-
openpgp.config.aead_protect = aead_protectValue;
|
|
703
|
-
openpgp.config.aead_chunk_size_byte = aead_chunk_size_byteValue;
|
|
704
|
-
coresStub.restore();
|
|
705
|
-
}
|
|
706
|
-
});
|
|
707
|
-
|
|
708
|
-
it("Sign/verify: Don't pull entire input stream when we're not pulling verified stream", async function() {
|
|
709
|
-
const signed = await openpgp.sign({
|
|
710
|
-
message: openpgp.message.fromBinary(data),
|
|
711
|
-
privateKeys: privKey
|
|
712
|
-
});
|
|
713
|
-
const msgAsciiArmored = signed.data;
|
|
714
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
715
|
-
const verified = await openpgp.verify({
|
|
716
|
-
publicKeys: pubKey,
|
|
717
|
-
message
|
|
718
|
-
});
|
|
719
|
-
expect(util.isStream(verified.data)).to.equal(expectedType);
|
|
720
|
-
const reader = openpgp.stream.getReader(verified.data);
|
|
721
|
-
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
|
|
722
|
-
dataArrived();
|
|
723
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
724
|
-
expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 100);
|
|
725
|
-
});
|
|
726
|
-
|
|
727
|
-
it('Detached sign small message', async function() {
|
|
728
|
-
dataArrived(); // Do not wait until data arrived.
|
|
729
|
-
const data = new ReadableStream({
|
|
730
|
-
async start(controller) {
|
|
731
|
-
controller.enqueue(util.str_to_Uint8Array('hello '));
|
|
732
|
-
controller.enqueue(util.str_to_Uint8Array('world'));
|
|
733
|
-
controller.close();
|
|
734
|
-
}
|
|
735
|
-
});
|
|
736
|
-
const signed = await openpgp.sign({
|
|
737
|
-
message: openpgp.message.fromBinary(data),
|
|
738
|
-
privateKeys: privKey,
|
|
739
|
-
detached: true,
|
|
740
|
-
streaming: expectedType
|
|
741
|
-
});
|
|
742
|
-
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
|
743
|
-
const signature = await openpgp.message.readArmored(sigArmored);
|
|
744
|
-
const verified = await openpgp.verify({
|
|
745
|
-
signature,
|
|
746
|
-
publicKeys: pubKey,
|
|
747
|
-
message: openpgp.message.fromText('hello world')
|
|
748
|
-
});
|
|
749
|
-
expect(openpgp.util.decode_utf8(verified.data)).to.equal('hello world');
|
|
750
|
-
expect(verified.signatures).to.exist.and.have.length(1);
|
|
751
|
-
expect(verified.signatures[0].valid).to.be.true;
|
|
752
|
-
});
|
|
753
|
-
|
|
754
|
-
it('Detached sign small message (not streaming)', async function() {
|
|
755
|
-
dataArrived(); // Do not wait until data arrived.
|
|
756
|
-
const data = new ReadableStream({
|
|
757
|
-
async start(controller) {
|
|
758
|
-
controller.enqueue(util.str_to_Uint8Array('hello '));
|
|
759
|
-
controller.enqueue(util.str_to_Uint8Array('world'));
|
|
760
|
-
controller.close();
|
|
761
|
-
}
|
|
762
|
-
});
|
|
763
|
-
const signed = await openpgp.sign({
|
|
764
|
-
message: openpgp.message.fromBinary(data),
|
|
765
|
-
privateKeys: privKey,
|
|
766
|
-
detached: true,
|
|
767
|
-
streaming: false,
|
|
768
|
-
});
|
|
769
|
-
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
|
770
|
-
const signature = await openpgp.message.readArmored(sigArmored);
|
|
771
|
-
const verified = await openpgp.verify({
|
|
772
|
-
signature,
|
|
773
|
-
publicKeys: pubKey,
|
|
774
|
-
message: openpgp.message.fromText('hello world')
|
|
775
|
-
});
|
|
776
|
-
expect(openpgp.util.decode_utf8(verified.data)).to.equal('hello world');
|
|
777
|
-
expect(verified.signatures).to.exist.and.have.length(1);
|
|
778
|
-
expect(verified.signatures[0].valid).to.be.true;
|
|
779
|
-
});
|
|
780
|
-
|
|
781
|
-
it('Detached sign small message using brainpool curve keys', async function() {
|
|
782
|
-
dataArrived(); // Do not wait until data arrived.
|
|
783
|
-
const data = new ReadableStream({
|
|
784
|
-
async start(controller) {
|
|
785
|
-
controller.enqueue(util.str_to_Uint8Array('hello '));
|
|
786
|
-
controller.enqueue(util.str_to_Uint8Array('world'));
|
|
787
|
-
controller.close();
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
const priv = (await openpgp.key.readArmored(brainpoolPriv)).keys[0];
|
|
791
|
-
const pub = (await openpgp.key.readArmored(brainpoolPub)).keys[0];
|
|
792
|
-
await priv.decrypt(brainpoolPass);
|
|
793
|
-
const signed = await openpgp.sign({
|
|
794
|
-
message: openpgp.message.fromBinary(data),
|
|
795
|
-
privateKeys: priv,
|
|
796
|
-
detached: true,
|
|
797
|
-
streaming: expectedType
|
|
798
|
-
});
|
|
799
|
-
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
|
800
|
-
const signature = await openpgp.message.readArmored(sigArmored);
|
|
801
|
-
const verified = await openpgp.verify({
|
|
802
|
-
signature,
|
|
803
|
-
publicKeys: pub,
|
|
804
|
-
message: openpgp.message.fromText('hello world')
|
|
805
|
-
});
|
|
806
|
-
expect(openpgp.util.decode_utf8(verified.data)).to.equal('hello world');
|
|
807
|
-
expect(verified.signatures).to.exist.and.have.length(1);
|
|
808
|
-
expect(verified.signatures[0].valid).to.be.true;
|
|
809
|
-
});
|
|
810
|
-
|
|
811
|
-
it('Detached sign small message using x25519 curve keys', async function() {
|
|
812
|
-
dataArrived(); // Do not wait until data arrived.
|
|
813
|
-
const data = new ReadableStream({
|
|
814
|
-
async start(controller) {
|
|
815
|
-
controller.enqueue(util.str_to_Uint8Array('hello '));
|
|
816
|
-
controller.enqueue(util.str_to_Uint8Array('world'));
|
|
817
|
-
controller.close();
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
const priv = (await openpgp.key.readArmored(xPriv)).keys[0];
|
|
821
|
-
const pub = (await openpgp.key.readArmored(xPub)).keys[0];
|
|
822
|
-
await priv.decrypt(xPass);
|
|
823
|
-
const signed = await openpgp.sign({
|
|
824
|
-
message: openpgp.message.fromBinary(data),
|
|
825
|
-
privateKeys: priv,
|
|
826
|
-
detached: true,
|
|
827
|
-
streaming: expectedType
|
|
828
|
-
});
|
|
829
|
-
const sigArmored = await openpgp.stream.readToEnd(signed.signature);
|
|
830
|
-
const signature = await openpgp.message.readArmored(sigArmored);
|
|
831
|
-
const verified = await openpgp.verify({
|
|
832
|
-
signature,
|
|
833
|
-
publicKeys: pub,
|
|
834
|
-
message: openpgp.message.fromText('hello world')
|
|
835
|
-
});
|
|
836
|
-
expect(openpgp.util.decode_utf8(verified.data)).to.equal('hello world');
|
|
837
|
-
expect(verified.signatures).to.exist.and.have.length(1);
|
|
838
|
-
expect(verified.signatures[0].valid).to.be.true;
|
|
839
|
-
});
|
|
840
|
-
|
|
841
|
-
it("Detached sign is expected to pull entire input stream when we're not pulling signed stream", async function() {
|
|
842
|
-
const signed = await openpgp.sign({
|
|
843
|
-
message: openpgp.message.fromBinary(data),
|
|
844
|
-
privateKeys: privKey,
|
|
845
|
-
detached: true
|
|
846
|
-
});
|
|
847
|
-
const reader = openpgp.stream.getReader(signed.signature);
|
|
848
|
-
expect((await reader.readBytes(31)).toString('utf8')).to.equal('-----BEGIN PGP SIGNATURE-----\r\n');
|
|
849
|
-
dataArrived();
|
|
850
|
-
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
851
|
-
expect(i).to.be.greaterThan(100);
|
|
852
|
-
});
|
|
853
|
-
|
|
854
|
-
it('Detached sign: Input stream should be canceled when canceling signed stream', async function() {
|
|
855
|
-
const signed = await openpgp.sign({
|
|
856
|
-
message: openpgp.message.fromBinary(data),
|
|
857
|
-
privateKeys: privKey,
|
|
858
|
-
detached: true
|
|
859
|
-
});
|
|
860
|
-
const reader = openpgp.stream.getReader(signed.signature);
|
|
861
|
-
expect((await reader.readBytes(31)).toString('utf8')).to.equal('-----BEGIN PGP SIGNATURE-----\r\n');
|
|
862
|
-
dataArrived();
|
|
863
|
-
reader.releaseLock();
|
|
864
|
-
await openpgp.stream.cancel(signed.signature, new Error('canceled by test'));
|
|
865
|
-
expect(canceled).to.be.true;
|
|
866
|
-
});
|
|
867
|
-
|
|
868
|
-
if (openpgp.util.detectNode()) {
|
|
869
|
-
const fs = util.nodeRequire('fs');
|
|
870
|
-
|
|
871
|
-
it('Node: Encrypt and decrypt binary message roundtrip', async function() {
|
|
872
|
-
dataArrived(); // Do not wait until data arrived.
|
|
873
|
-
let plaintext = fs.readFileSync(__filename);
|
|
874
|
-
const data = fs.createReadStream(__filename);
|
|
875
|
-
const encrypted = await openpgp.encrypt({
|
|
876
|
-
message: openpgp.message.fromBinary(data),
|
|
877
|
-
passwords: ['test'],
|
|
878
|
-
});
|
|
879
|
-
|
|
880
|
-
const msgAsciiArmored = encrypted.data;
|
|
881
|
-
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
|
882
|
-
const decrypted = await openpgp.decrypt({
|
|
883
|
-
passwords: ['test'],
|
|
884
|
-
message,
|
|
885
|
-
format: 'binary'
|
|
886
|
-
});
|
|
887
|
-
expect(util.isStream(decrypted.data)).to.equal('node');
|
|
888
|
-
expect(await openpgp.stream.readToEnd(decrypted.data)).to.deep.equal(plaintext);
|
|
889
|
-
});
|
|
890
|
-
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
describe('Streaming', function() {
|
|
895
|
-
let currentTest = 0;
|
|
896
|
-
|
|
897
|
-
before(async function() {
|
|
898
|
-
pubKey = (await openpgp.key.readArmored(pub_key)).keys[0];
|
|
899
|
-
privKey = (await openpgp.key.readArmored(priv_key)).keys[0];
|
|
900
|
-
await privKey.decrypt(passphrase);
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
beforeEach(function() {
|
|
904
|
-
let test = ++currentTest;
|
|
905
|
-
|
|
906
|
-
let dataArrivedPromise = new Promise(resolve => {
|
|
907
|
-
dataArrived = resolve;
|
|
908
|
-
});
|
|
909
|
-
plaintext = [];
|
|
910
|
-
i = 0;
|
|
911
|
-
canceled = false;
|
|
912
|
-
data = new ReadableStream({
|
|
913
|
-
async pull(controller) {
|
|
914
|
-
await new Promise(setTimeout);
|
|
915
|
-
if (test === currentTest && i++ < 100) {
|
|
916
|
-
if (i === 4) await dataArrivedPromise;
|
|
917
|
-
let randomBytes = await openpgp.crypto.random.getRandomBytes(1024);
|
|
918
|
-
controller.enqueue(randomBytes);
|
|
919
|
-
plaintext.push(randomBytes);
|
|
920
|
-
} else {
|
|
921
|
-
controller.close();
|
|
922
|
-
}
|
|
923
|
-
},
|
|
924
|
-
cancel() {
|
|
925
|
-
canceled = true;
|
|
926
|
-
}
|
|
927
|
-
});
|
|
928
|
-
});
|
|
929
|
-
|
|
930
|
-
tryTests('WhatWG Streams', tests, {
|
|
931
|
-
if: true,
|
|
932
|
-
beforeEach: function() {
|
|
933
|
-
expectedType = 'web';
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
|
|
937
|
-
tryTests('Node Streams', tests, {
|
|
938
|
-
if: openpgp.util.detectNode(),
|
|
939
|
-
beforeEach: function() {
|
|
940
|
-
data = openpgp.stream.webToNode(data);
|
|
941
|
-
expectedType = 'node';
|
|
942
|
-
}
|
|
943
|
-
});
|
|
944
|
-
});
|