@protontech/openpgp 4.10.8 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +41077 -41609
- 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 -61152
- 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 -40071
- 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 -232
- 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 -378
- package/src/key/index.js +0 -32
- package/src/key/key.js +0 -888
- 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 -161
- package/src/packet/public_subkey.js +0 -44
- package/src/packet/secret_key.js +0 -468
- package/src/packet/secret_subkey.js +0 -41
- package/src/packet/signature.js +0 -786
- 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 -84
- 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 -3491
- package/test/general/keyring.js +0 -336
- package/test/general/oid.js +0 -39
- package/test/general/openpgp.js +0 -2577
- package/test/general/packet.js +0 -950
- package/test/general/signature.js +0 -1715
- 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
package/src/index.js
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/newline-after-import, import/first */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Export high level api as default.
|
|
5
|
-
* Usage:
|
|
6
|
-
*
|
|
7
|
-
* import openpgp from 'openpgp.js'
|
|
8
|
-
* openpgp.encryptMessage(keys, text)
|
|
9
|
-
*/
|
|
10
|
-
import * as openpgp from './openpgp';
|
|
11
|
-
export default openpgp;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Export each high level api function separately.
|
|
15
|
-
* Usage:
|
|
16
|
-
*
|
|
17
|
-
* import { encryptMessage } from 'openpgp.js'
|
|
18
|
-
* encryptMessage(keys, text)
|
|
19
|
-
*/
|
|
20
|
-
export {
|
|
21
|
-
encrypt, decrypt, sign, verify,
|
|
22
|
-
generateKey, reformatKey, revokeKey, decryptKey,
|
|
23
|
-
encryptSessionKey, decryptSessionKeys,
|
|
24
|
-
initWorker, getWorker, destroyWorker
|
|
25
|
-
} from './openpgp';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @see module:key
|
|
29
|
-
* @name module:openpgp.key
|
|
30
|
-
*/
|
|
31
|
-
import * as keyMod from './key';
|
|
32
|
-
export const key = keyMod;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @see module:signature
|
|
36
|
-
* @name module:openpgp.signature
|
|
37
|
-
*/
|
|
38
|
-
import * as signatureMod from './signature';
|
|
39
|
-
export const signature = signatureMod;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @see module:message
|
|
43
|
-
* @name module:openpgp.message
|
|
44
|
-
*/
|
|
45
|
-
import * as messageMod from './message';
|
|
46
|
-
export const message = messageMod;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @see module:cleartext
|
|
50
|
-
* @name module:openpgp.cleartext
|
|
51
|
-
*/
|
|
52
|
-
import * as cleartextMod from './cleartext';
|
|
53
|
-
export const cleartext = cleartextMod;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @see module:util
|
|
57
|
-
* @name module:openpgp.util
|
|
58
|
-
*/
|
|
59
|
-
export { default as util } from './util';
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @see module:packet
|
|
63
|
-
* @name module:openpgp.packet
|
|
64
|
-
*/
|
|
65
|
-
export { default as packet } from './packet';
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @see module:type/mpi
|
|
69
|
-
* @name module:openpgp.MPI
|
|
70
|
-
*/
|
|
71
|
-
export { default as MPI } from './type/mpi';
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @see module:type/s2k
|
|
75
|
-
* @name module:openpgp.S2K
|
|
76
|
-
*/
|
|
77
|
-
export { default as S2K } from './type/s2k';
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @see module:type/keyid
|
|
81
|
-
* @name module:openpgp.Keyid
|
|
82
|
-
*/
|
|
83
|
-
export { default as Keyid } from './type/keyid';
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @see module:type/ecdh_symkey
|
|
87
|
-
* @name module:openpgp.ECDHSymmetricKey
|
|
88
|
-
*/
|
|
89
|
-
export { default as ECDHSymmetricKey } from './type/ecdh_symkey';
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @see module:type/kdf_params
|
|
93
|
-
* @name module:openpgp.KDFParams
|
|
94
|
-
*/
|
|
95
|
-
export { default as KDFParams } from './type/kdf_params';
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @see module:type/oid
|
|
99
|
-
* @name module:openpgp.OID
|
|
100
|
-
*/
|
|
101
|
-
export { default as OID } from './type/oid';
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @see streams
|
|
105
|
-
* @name module:openpgp.stream
|
|
106
|
-
*/
|
|
107
|
-
export { default as stream } from 'web-stream-tools';
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @see module:encoding/armor
|
|
111
|
-
* @name module:openpgp.armor
|
|
112
|
-
*/
|
|
113
|
-
export { default as armor } from './encoding/armor';
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @see module:enums
|
|
117
|
-
* @name module:openpgp.enums
|
|
118
|
-
*/
|
|
119
|
-
export { default as enums } from './enums';
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @see module:config/config
|
|
123
|
-
* @name module:openpgp.config
|
|
124
|
-
*/
|
|
125
|
-
export { default as config } from './config/config';
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @see module:crypto
|
|
129
|
-
* @name module:openpgp.crypto
|
|
130
|
-
*/
|
|
131
|
-
export { default as crypto } from './crypto';
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @see module:keyring
|
|
135
|
-
* @name module:openpgp.Keyring
|
|
136
|
-
*/
|
|
137
|
-
export { default as Keyring } from './keyring';
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @see module:worker/async_proxy
|
|
141
|
-
* @name module:openpgp.AsyncProxy
|
|
142
|
-
*/
|
|
143
|
-
export { default as AsyncProxy } from './worker/async_proxy';
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @see module:hkp
|
|
147
|
-
* @name module:openpgp.HKP
|
|
148
|
-
*/
|
|
149
|
-
export { default as HKP } from './hkp';
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @see module:wkd
|
|
153
|
-
* @name module:openpgp.WKD
|
|
154
|
-
*/
|
|
155
|
-
export { default as WKD } from './wkd';
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* @see module:lightweight
|
|
159
|
-
*/
|
|
160
|
-
import * as lightweightMod from './lightweight_helper';
|
|
161
|
-
export const lightweight = lightweightMod;
|
package/src/key/factory.js
DELETED
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2015-2016 Decentral
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @fileoverview Provides factory methods for key creation
|
|
20
|
-
* @requires packet
|
|
21
|
-
* @requires key/Key
|
|
22
|
-
* @requires key/helper
|
|
23
|
-
* @requires enums
|
|
24
|
-
* @requires util
|
|
25
|
-
* @requires config
|
|
26
|
-
* @requires armor
|
|
27
|
-
* @module key/factory
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
import packet from '../packet';
|
|
31
|
-
import Key from './key';
|
|
32
|
-
import * as helper from './helper';
|
|
33
|
-
import enums from '../enums';
|
|
34
|
-
import util from '../util';
|
|
35
|
-
import config from '../config';
|
|
36
|
-
import armor from '../encoding/armor';
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Generates a new OpenPGP key. Supports RSA and ECC keys.
|
|
40
|
-
* Primary and subkey will be of same type.
|
|
41
|
-
* @param {module:enums.publicKey} [options.keyType=module:enums.publicKey.rsa_encrypt_sign]
|
|
42
|
-
* To indicate what type of key to make.
|
|
43
|
-
* RSA is 1. See {@link https://tools.ietf.org/html/rfc4880#section-9.1}
|
|
44
|
-
* @param {Integer} options.numBits number of bits for the key creation.
|
|
45
|
-
* @param {String|Array<String>} options.userIds
|
|
46
|
-
* Assumes already in form of "User Name <username@email.com>"
|
|
47
|
-
* If array is used, the first userId is set as primary user Id
|
|
48
|
-
* @param {String} options.passphrase The passphrase used to encrypt the resulting private key
|
|
49
|
-
* @param {Number} [options.keyExpirationTime=0]
|
|
50
|
-
* The number of seconds after the key creation time that the key expires
|
|
51
|
-
* @param {String} curve (optional) elliptic curve for ECC keys
|
|
52
|
-
* @param {Date} date Override the creation date of the key and the key signatures
|
|
53
|
-
* @param {Array<Object>} subkeys (optional) options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}]
|
|
54
|
-
* sign parameter defaults to false, and indicates whether the subkey should sign rather than encrypt
|
|
55
|
-
* @returns {Promise<module:key.Key>}
|
|
56
|
-
* @async
|
|
57
|
-
* @static
|
|
58
|
-
*/
|
|
59
|
-
export async function generate(options) {
|
|
60
|
-
options.sign = true; // primary key is always a signing key
|
|
61
|
-
options = helper.sanitizeKeyOptions(options);
|
|
62
|
-
options.subkeys = options.subkeys.map(function(subkey, index) { return helper.sanitizeKeyOptions(options.subkeys[index], options); });
|
|
63
|
-
|
|
64
|
-
let promises = [helper.generateSecretKey(options)];
|
|
65
|
-
promises = promises.concat(options.subkeys.map(helper.generateSecretSubkey));
|
|
66
|
-
return Promise.all(promises).then(packets => wrapKeyObject(packets[0], packets.slice(1), options));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Reformats and signs an OpenPGP key with a given User ID. Currently only supports RSA keys.
|
|
71
|
-
* @param {module:key.Key} options.privateKey The private key to reformat
|
|
72
|
-
* @param {module:enums.publicKey} [options.keyType=module:enums.publicKey.rsa_encrypt_sign]
|
|
73
|
-
* @param {String|Array<String>} options.userIds
|
|
74
|
-
* Assumes already in form of "User Name <username@email.com>"
|
|
75
|
-
* If array is used, the first userId is set as primary user Id
|
|
76
|
-
* @param {String} options.passphrase The passphrase used to encrypt the resulting private key
|
|
77
|
-
* @param {Number} [options.keyExpirationTime=0]
|
|
78
|
-
* The number of seconds after the key creation time that the key expires
|
|
79
|
-
* @param {Date} date Override the creation date of the key and the key signatures
|
|
80
|
-
* @param {Array<Object>} subkeys (optional) options for each subkey, default to main key options. e.g. [{sign: true, passphrase: '123'}]
|
|
81
|
-
*
|
|
82
|
-
* @returns {Promise<module:key.Key>}
|
|
83
|
-
* @async
|
|
84
|
-
* @static
|
|
85
|
-
*/
|
|
86
|
-
export async function reformat(options) {
|
|
87
|
-
options = sanitize(options);
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const isDecrypted = options.privateKey.getKeys().every(key => key.isDecrypted());
|
|
91
|
-
if (!isDecrypted) {
|
|
92
|
-
await options.privateKey.decrypt();
|
|
93
|
-
}
|
|
94
|
-
} catch (err) {
|
|
95
|
-
throw new Error('Key not decrypted');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const packetlist = options.privateKey.toPacketlist();
|
|
99
|
-
let secretKeyPacket;
|
|
100
|
-
const secretSubkeyPackets = [];
|
|
101
|
-
for (let i = 0; i < packetlist.length; i++) {
|
|
102
|
-
if (packetlist[i].tag === enums.packet.secretKey) {
|
|
103
|
-
secretKeyPacket = packetlist[i];
|
|
104
|
-
} else if (packetlist[i].tag === enums.packet.secretSubkey) {
|
|
105
|
-
secretSubkeyPackets.push(packetlist[i]);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
if (!secretKeyPacket) {
|
|
109
|
-
throw new Error('Key does not contain a secret key packet');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (!options.subkeys) {
|
|
113
|
-
options.subkeys = await Promise.all(secretSubkeyPackets.map(async secretSubkeyPacket => ({
|
|
114
|
-
sign: await options.privateKey.getSigningKey(secretSubkeyPacket.getKeyId(), null).catch(() => {}) &&
|
|
115
|
-
!await options.privateKey.getEncryptionKey(secretSubkeyPacket.getKeyId(), null).catch(() => {})
|
|
116
|
-
})));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (options.subkeys.length !== secretSubkeyPackets.length) {
|
|
120
|
-
throw new Error('Number of subkey options does not match number of subkeys');
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
options.subkeys = options.subkeys.map(function(subkey, index) { return sanitize(options.subkeys[index], options); });
|
|
124
|
-
|
|
125
|
-
return wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options);
|
|
126
|
-
|
|
127
|
-
function sanitize(options, subkeyDefaults = {}) {
|
|
128
|
-
options.keyExpirationTime = options.keyExpirationTime || subkeyDefaults.keyExpirationTime;
|
|
129
|
-
options.passphrase = util.isString(options.passphrase) ? options.passphrase : subkeyDefaults.passphrase;
|
|
130
|
-
options.date = options.date || subkeyDefaults.date;
|
|
131
|
-
|
|
132
|
-
return options;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options) {
|
|
138
|
-
// set passphrase protection
|
|
139
|
-
if (options.passphrase) {
|
|
140
|
-
await secretKeyPacket.encrypt(options.passphrase);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
await Promise.all(secretSubkeyPackets.map(async function(secretSubkeyPacket, index) {
|
|
144
|
-
const subkeyPassphrase = options.subkeys[index].passphrase;
|
|
145
|
-
if (subkeyPassphrase) {
|
|
146
|
-
await secretSubkeyPacket.encrypt(subkeyPassphrase);
|
|
147
|
-
}
|
|
148
|
-
}));
|
|
149
|
-
|
|
150
|
-
const packetlist = new packet.List();
|
|
151
|
-
|
|
152
|
-
packetlist.push(secretKeyPacket);
|
|
153
|
-
|
|
154
|
-
await Promise.all(options.userIds.map(async function(userId, index) {
|
|
155
|
-
function createdPreferredAlgos(algos, configAlgo) {
|
|
156
|
-
if (configAlgo) { // Not `uncompressed` / `plaintext`
|
|
157
|
-
const configIndex = algos.indexOf(configAlgo);
|
|
158
|
-
if (configIndex >= 1) { // If it is included and not in first place,
|
|
159
|
-
algos.splice(configIndex, 1); // remove it.
|
|
160
|
-
}
|
|
161
|
-
if (configIndex !== 0) { // If it was included and not in first place, or wasn't included,
|
|
162
|
-
algos.unshift(configAlgo); // add it to the front.
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return algos;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const userIdPacket = new packet.Userid();
|
|
169
|
-
userIdPacket.format(userId);
|
|
170
|
-
|
|
171
|
-
const dataToSign = {};
|
|
172
|
-
dataToSign.userId = userIdPacket;
|
|
173
|
-
dataToSign.key = secretKeyPacket;
|
|
174
|
-
const signaturePacket = new packet.Signature(options.date);
|
|
175
|
-
signaturePacket.signatureType = enums.signature.cert_generic;
|
|
176
|
-
signaturePacket.publicKeyAlgorithm = secretKeyPacket.algorithm;
|
|
177
|
-
signaturePacket.hashAlgorithm = await helper.getPreferredHashAlgo(null, secretKeyPacket);
|
|
178
|
-
signaturePacket.keyFlags = [enums.keyFlags.certify_keys | enums.keyFlags.sign_data];
|
|
179
|
-
signaturePacket.preferredSymmetricAlgorithms = createdPreferredAlgos([
|
|
180
|
-
// prefer aes256, aes128, then aes192 (no WebCrypto support: https://www.chromium.org/blink/webcrypto#TOC-AES-support)
|
|
181
|
-
enums.symmetric.aes256,
|
|
182
|
-
enums.symmetric.aes128,
|
|
183
|
-
enums.symmetric.aes192,
|
|
184
|
-
enums.symmetric.cast5,
|
|
185
|
-
enums.symmetric.tripledes
|
|
186
|
-
], config.encryption_cipher);
|
|
187
|
-
if (config.aead_protect) {
|
|
188
|
-
signaturePacket.preferredAeadAlgorithms = createdPreferredAlgos([
|
|
189
|
-
enums.aead.eax,
|
|
190
|
-
enums.aead.ocb
|
|
191
|
-
], config.aead_mode);
|
|
192
|
-
}
|
|
193
|
-
signaturePacket.preferredHashAlgorithms = createdPreferredAlgos([
|
|
194
|
-
// prefer fast asm.js implementations (SHA-256). SHA-1 will not be secure much longer...move to bottom of list
|
|
195
|
-
enums.hash.sha256,
|
|
196
|
-
enums.hash.sha512,
|
|
197
|
-
enums.hash.sha1
|
|
198
|
-
], config.prefer_hash_algorithm);
|
|
199
|
-
signaturePacket.preferredCompressionAlgorithms = createdPreferredAlgos([
|
|
200
|
-
enums.compression.zlib,
|
|
201
|
-
enums.compression.zip,
|
|
202
|
-
enums.compression.uncompressed
|
|
203
|
-
], config.compression);
|
|
204
|
-
if (index === 0) {
|
|
205
|
-
signaturePacket.isPrimaryUserID = true;
|
|
206
|
-
}
|
|
207
|
-
if (config.integrity_protect) {
|
|
208
|
-
signaturePacket.features = [0];
|
|
209
|
-
signaturePacket.features[0] |= enums.features.modification_detection;
|
|
210
|
-
}
|
|
211
|
-
if (config.aead_protect) {
|
|
212
|
-
signaturePacket.features || (signaturePacket.features = [0]);
|
|
213
|
-
signaturePacket.features[0] |= enums.features.aead;
|
|
214
|
-
}
|
|
215
|
-
if (config.v5_keys) {
|
|
216
|
-
signaturePacket.features || (signaturePacket.features = [0]);
|
|
217
|
-
signaturePacket.features[0] |= enums.features.v5_keys;
|
|
218
|
-
}
|
|
219
|
-
if (options.keyExpirationTime > 0) {
|
|
220
|
-
signaturePacket.keyExpirationTime = options.keyExpirationTime;
|
|
221
|
-
signaturePacket.keyNeverExpires = false;
|
|
222
|
-
}
|
|
223
|
-
await signaturePacket.sign(secretKeyPacket, dataToSign);
|
|
224
|
-
|
|
225
|
-
return { userIdPacket, signaturePacket };
|
|
226
|
-
})).then(list => {
|
|
227
|
-
list.forEach(({ userIdPacket, signaturePacket }) => {
|
|
228
|
-
packetlist.push(userIdPacket);
|
|
229
|
-
packetlist.push(signaturePacket);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
await Promise.all(secretSubkeyPackets.map(async function(secretSubkeyPacket, index) {
|
|
234
|
-
const subkeyOptions = options.subkeys[index];
|
|
235
|
-
const subkeySignaturePacket = await helper.createBindingSignature(secretSubkeyPacket, secretKeyPacket, subkeyOptions);
|
|
236
|
-
return { secretSubkeyPacket, subkeySignaturePacket };
|
|
237
|
-
})).then(packets => {
|
|
238
|
-
packets.forEach(({ secretSubkeyPacket, subkeySignaturePacket }) => {
|
|
239
|
-
packetlist.push(secretSubkeyPacket);
|
|
240
|
-
packetlist.push(subkeySignaturePacket);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// Add revocation signature packet for creating a revocation certificate.
|
|
245
|
-
// This packet should be removed before returning the key.
|
|
246
|
-
const dataToSign = { key: secretKeyPacket };
|
|
247
|
-
packetlist.push(await helper.createSignaturePacket(dataToSign, null, secretKeyPacket, {
|
|
248
|
-
signatureType: enums.signature.key_revocation,
|
|
249
|
-
reasonForRevocationFlag: enums.reasonForRevocation.no_reason,
|
|
250
|
-
reasonForRevocationString: ''
|
|
251
|
-
}, options.date));
|
|
252
|
-
|
|
253
|
-
// set passphrase protection
|
|
254
|
-
if (options.passphrase) {
|
|
255
|
-
secretKeyPacket.clearPrivateParams();
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
await Promise.all(secretSubkeyPackets.map(async function(secretSubkeyPacket, index) {
|
|
259
|
-
const subkeyPassphrase = options.subkeys[index].passphrase;
|
|
260
|
-
if (subkeyPassphrase) {
|
|
261
|
-
secretSubkeyPacket.clearPrivateParams();
|
|
262
|
-
}
|
|
263
|
-
}));
|
|
264
|
-
|
|
265
|
-
return new Key(packetlist);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Reads an unarmored OpenPGP key list and returns one or multiple key objects
|
|
270
|
-
* @param {Uint8Array} data to be parsed
|
|
271
|
-
* @returns {Promise<{keys: Array<module:key.Key>,
|
|
272
|
-
* err: (Array<Error>|null)}>} result object with key and error arrays
|
|
273
|
-
* @async
|
|
274
|
-
* @static
|
|
275
|
-
*/
|
|
276
|
-
export async function read(data) {
|
|
277
|
-
const result = {};
|
|
278
|
-
result.keys = [];
|
|
279
|
-
const err = [];
|
|
280
|
-
try {
|
|
281
|
-
const packetlist = new packet.List();
|
|
282
|
-
await packetlist.read(data);
|
|
283
|
-
const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey);
|
|
284
|
-
if (keyIndex.length === 0) {
|
|
285
|
-
throw new Error('No key packet found');
|
|
286
|
-
}
|
|
287
|
-
for (let i = 0; i < keyIndex.length; i++) {
|
|
288
|
-
const oneKeyList = packetlist.slice(keyIndex[i], keyIndex[i + 1]);
|
|
289
|
-
try {
|
|
290
|
-
const newKey = new Key(oneKeyList);
|
|
291
|
-
result.keys.push(newKey);
|
|
292
|
-
} catch (e) {
|
|
293
|
-
err.push(e);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
} catch (e) {
|
|
297
|
-
err.push(e);
|
|
298
|
-
}
|
|
299
|
-
if (err.length) {
|
|
300
|
-
result.err = err;
|
|
301
|
-
}
|
|
302
|
-
return result;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Reads an OpenPGP armored text and returns one or multiple key objects
|
|
308
|
-
* @param {String | ReadableStream<String>} armoredText text to be parsed
|
|
309
|
-
* @returns {Promise<{keys: Array<module:key.Key>,
|
|
310
|
-
* err: (Array<Error>|null)}>} result object with key and error arrays
|
|
311
|
-
* @async
|
|
312
|
-
* @static
|
|
313
|
-
*/
|
|
314
|
-
export async function readArmored(armoredText) {
|
|
315
|
-
try {
|
|
316
|
-
const input = await armor.decode(armoredText);
|
|
317
|
-
if (!(input.type === enums.armor.public_key || input.type === enums.armor.private_key)) {
|
|
318
|
-
throw new Error('Armored text not of type key');
|
|
319
|
-
}
|
|
320
|
-
return read(input.data);
|
|
321
|
-
} catch (e) {
|
|
322
|
-
const result = { keys: [], err: [] };
|
|
323
|
-
result.err.push(e);
|
|
324
|
-
return result;
|
|
325
|
-
}
|
|
326
|
-
}
|