@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
package/src/key/subkey.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @requires enums
|
|
3
|
-
* @requires key/helper
|
|
4
|
-
* @requires packet
|
|
5
|
-
* @module key/SubKey
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import enums from '../enums';
|
|
9
|
-
import * as helper from './helper';
|
|
10
|
-
import packet from '../packet';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @class
|
|
14
|
-
* @classdesc Class that represents a subkey packet and the relevant signatures.
|
|
15
|
-
* @borrows module:packet.PublicSubkey#getKeyId as SubKey#getKeyId
|
|
16
|
-
* @borrows module:packet.PublicSubkey#getFingerprint as SubKey#getFingerprint
|
|
17
|
-
* @borrows module:packet.PublicSubkey#hasSameFingerprintAs as SubKey#hasSameFingerprintAs
|
|
18
|
-
* @borrows module:packet.PublicSubkey#getAlgorithmInfo as SubKey#getAlgorithmInfo
|
|
19
|
-
* @borrows module:packet.PublicSubkey#getCreationTime as SubKey#getCreationTime
|
|
20
|
-
* @borrows module:packet.PublicSubkey#isDecrypted as SubKey#isDecrypted
|
|
21
|
-
*/
|
|
22
|
-
export default function SubKey(subKeyPacket) {
|
|
23
|
-
if (!(this instanceof SubKey)) {
|
|
24
|
-
return new SubKey(subKeyPacket);
|
|
25
|
-
}
|
|
26
|
-
this.keyPacket = subKeyPacket;
|
|
27
|
-
this.bindingSignatures = [];
|
|
28
|
-
this.revocationSignatures = [];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Transforms structured subkey data to packetlist
|
|
33
|
-
* @returns {module:packet.List}
|
|
34
|
-
*/
|
|
35
|
-
SubKey.prototype.toPacketlist = function() {
|
|
36
|
-
const packetlist = new packet.List();
|
|
37
|
-
packetlist.push(this.keyPacket);
|
|
38
|
-
packetlist.concat(this.revocationSignatures);
|
|
39
|
-
packetlist.concat(this.bindingSignatures);
|
|
40
|
-
return packetlist;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Checks if a binding signature of a subkey is revoked
|
|
45
|
-
* @param {module:packet.SecretKey|
|
|
46
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
47
|
-
* @param {module:packet.Signature} signature The binding signature to verify
|
|
48
|
-
* @param {module:packet.PublicSubkey|
|
|
49
|
-
* module:packet.SecretSubkey|
|
|
50
|
-
* module:packet.PublicKey|
|
|
51
|
-
* module:packet.SecretKey} key, optional The key to verify the signature
|
|
52
|
-
* @param {Date} date Use the given date instead of the current time
|
|
53
|
-
* @returns {Promise<Boolean>} True if the binding signature is revoked
|
|
54
|
-
* @async
|
|
55
|
-
*/
|
|
56
|
-
SubKey.prototype.isRevoked = async function(primaryKey, signature, key, date = new Date()) {
|
|
57
|
-
return helper.isDataRevoked(
|
|
58
|
-
primaryKey, enums.signature.subkey_revocation, {
|
|
59
|
-
key: primaryKey,
|
|
60
|
-
bind: this.keyPacket
|
|
61
|
-
}, this.revocationSignatures, signature, key, date
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Verify subkey. Checks for revocation signatures, expiration time
|
|
68
|
-
* and valid binding signature. Throws if the subkey is invalid.
|
|
69
|
-
* @param {module:packet.SecretKey|
|
|
70
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
71
|
-
* @param {Date} date Use the given date instead of the current time
|
|
72
|
-
* @returns {Promise<true>} The status of the subkey
|
|
73
|
-
* @async
|
|
74
|
-
*/
|
|
75
|
-
SubKey.prototype.verify = async function(primaryKey, date = new Date()) {
|
|
76
|
-
const dataToVerify = { key: primaryKey, bind: this.keyPacket };
|
|
77
|
-
// check subkey binding signatures
|
|
78
|
-
const bindingSignature = await helper.getLatestValidSignature(this.bindingSignatures, primaryKey, enums.signature.subkey_binding, dataToVerify, date);
|
|
79
|
-
// check binding signature is not revoked
|
|
80
|
-
if (bindingSignature.revoked || await this.isRevoked(primaryKey, bindingSignature, null, date)) {
|
|
81
|
-
throw new Error('Subkey is revoked');
|
|
82
|
-
}
|
|
83
|
-
// check for expiration time
|
|
84
|
-
if (helper.isDataExpired(this.keyPacket, bindingSignature, date)) {
|
|
85
|
-
throw new Error('Subkey is expired');
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Returns the expiration time of the subkey or Infinity if key does not expire
|
|
91
|
-
* Returns null if the subkey is invalid.
|
|
92
|
-
* @param {module:packet.SecretKey|
|
|
93
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
94
|
-
* @param {Date} date Use the given date instead of the current time
|
|
95
|
-
* @returns {Promise<Date | Infinity | null>}
|
|
96
|
-
* @async
|
|
97
|
-
*/
|
|
98
|
-
SubKey.prototype.getExpirationTime = async function(primaryKey, date = new Date()) {
|
|
99
|
-
const dataToVerify = { key: primaryKey, bind: this.keyPacket };
|
|
100
|
-
let bindingSignature;
|
|
101
|
-
try {
|
|
102
|
-
bindingSignature = await helper.getLatestValidSignature(this.bindingSignatures, primaryKey, enums.signature.subkey_binding, dataToVerify, date);
|
|
103
|
-
} catch (e) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
const keyExpiry = helper.getExpirationTime(this.keyPacket, bindingSignature);
|
|
107
|
-
const sigExpiry = bindingSignature.getExpirationTime();
|
|
108
|
-
return keyExpiry < sigExpiry ? keyExpiry : sigExpiry;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Update subkey with new components from specified subkey
|
|
113
|
-
* @param {module:key~SubKey} subKey Source subkey to merge
|
|
114
|
-
* @param {module:packet.SecretKey|
|
|
115
|
-
module:packet.SecretSubkey} primaryKey primary key used for validation
|
|
116
|
-
* @returns {Promise<undefined>}
|
|
117
|
-
* @async
|
|
118
|
-
*/
|
|
119
|
-
SubKey.prototype.update = async function(subKey, primaryKey) {
|
|
120
|
-
if (!this.hasSameFingerprintAs(subKey)) {
|
|
121
|
-
throw new Error('SubKey update method: fingerprints of subkeys not equal');
|
|
122
|
-
}
|
|
123
|
-
// key packet
|
|
124
|
-
if (this.keyPacket.tag === enums.packet.publicSubkey &&
|
|
125
|
-
subKey.keyPacket.tag === enums.packet.secretSubkey) {
|
|
126
|
-
this.keyPacket = subKey.keyPacket;
|
|
127
|
-
}
|
|
128
|
-
// update missing binding signatures
|
|
129
|
-
const that = this;
|
|
130
|
-
const dataToVerify = { key: primaryKey, bind: that.keyPacket };
|
|
131
|
-
await helper.mergeSignatures(subKey, this, 'bindingSignatures', async function(srcBindSig) {
|
|
132
|
-
for (let i = 0; i < that.bindingSignatures.length; i++) {
|
|
133
|
-
if (that.bindingSignatures[i].issuerKeyId.equals(srcBindSig.issuerKeyId)) {
|
|
134
|
-
if (srcBindSig.created > that.bindingSignatures[i].created) {
|
|
135
|
-
that.bindingSignatures[i] = srcBindSig;
|
|
136
|
-
}
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
try {
|
|
141
|
-
return srcBindSig.verified || await srcBindSig.verify(primaryKey, enums.signature.subkey_binding, dataToVerify);
|
|
142
|
-
} catch (e) {
|
|
143
|
-
return false;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
// revocation signatures
|
|
147
|
-
await helper.mergeSignatures(subKey, this, 'revocationSignatures', function(srcRevSig) {
|
|
148
|
-
return helper.isDataRevoked(primaryKey, enums.signature.subkey_revocation, dataToVerify, [srcRevSig]);
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Revokes the subkey
|
|
154
|
-
* @param {module:packet.SecretKey} primaryKey decrypted private primary key for revocation
|
|
155
|
-
* @param {Object} reasonForRevocation optional, object indicating the reason for revocation
|
|
156
|
-
* @param {module:enums.reasonForRevocation} reasonForRevocation.flag optional, flag indicating the reason for revocation
|
|
157
|
-
* @param {String} reasonForRevocation.string optional, string explaining the reason for revocation
|
|
158
|
-
* @param {Date} date optional, override the creationtime of the revocation signature
|
|
159
|
-
* @returns {Promise<module:key~SubKey>} new subkey with revocation signature
|
|
160
|
-
* @async
|
|
161
|
-
*/
|
|
162
|
-
SubKey.prototype.revoke = async function(primaryKey, {
|
|
163
|
-
flag: reasonForRevocationFlag = enums.reasonForRevocation.no_reason,
|
|
164
|
-
string: reasonForRevocationString = ''
|
|
165
|
-
} = {}, date = new Date()) {
|
|
166
|
-
const dataToSign = { key: primaryKey, bind: this.keyPacket };
|
|
167
|
-
const subKey = new SubKey(this.keyPacket);
|
|
168
|
-
subKey.revocationSignatures.push(await helper.createSignaturePacket(dataToSign, null, primaryKey, {
|
|
169
|
-
signatureType: enums.signature.subkey_revocation,
|
|
170
|
-
reasonForRevocationFlag: enums.write(enums.reasonForRevocation, reasonForRevocationFlag),
|
|
171
|
-
reasonForRevocationString
|
|
172
|
-
}, date));
|
|
173
|
-
await subKey.update(this, primaryKey);
|
|
174
|
-
return subKey;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
['getKeyId', 'getFingerprint', 'getAlgorithmInfo', 'getCreationTime', 'isDecrypted'].forEach(name => {
|
|
178
|
-
SubKey.prototype[name] =
|
|
179
|
-
function() {
|
|
180
|
-
return this.keyPacket[name]();
|
|
181
|
-
};
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
SubKey.prototype.hasSameFingerprintAs =
|
|
185
|
-
function(other) {
|
|
186
|
-
return this.keyPacket.hasSameFingerprintAs(other.keyPacket || other);
|
|
187
|
-
};
|
package/src/key/user.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @requires enums
|
|
3
|
-
* @requires util
|
|
4
|
-
* @requires packet
|
|
5
|
-
* @requires key/helper
|
|
6
|
-
* @module key/User
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import enums from '../enums';
|
|
10
|
-
import util from '../util';
|
|
11
|
-
import packet from '../packet';
|
|
12
|
-
import { mergeSignatures, isDataRevoked, createSignaturePacket } from './helper';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @class
|
|
16
|
-
* @classdesc Class that represents an user ID or attribute packet and the relevant signatures.
|
|
17
|
-
*/
|
|
18
|
-
export default function User(userPacket) {
|
|
19
|
-
if (!(this instanceof User)) {
|
|
20
|
-
return new User(userPacket);
|
|
21
|
-
}
|
|
22
|
-
this.userId = userPacket.tag === enums.packet.userid ? userPacket : null;
|
|
23
|
-
this.userAttribute = userPacket.tag === enums.packet.userAttribute ? userPacket : null;
|
|
24
|
-
this.selfCertifications = [];
|
|
25
|
-
this.otherCertifications = [];
|
|
26
|
-
this.revocationSignatures = [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Transforms structured user data to packetlist
|
|
31
|
-
* @returns {module:packet.List}
|
|
32
|
-
*/
|
|
33
|
-
User.prototype.toPacketlist = function() {
|
|
34
|
-
const packetlist = new packet.List();
|
|
35
|
-
packetlist.push(this.userId || this.userAttribute);
|
|
36
|
-
packetlist.concat(this.revocationSignatures);
|
|
37
|
-
packetlist.concat(this.selfCertifications);
|
|
38
|
-
packetlist.concat(this.otherCertifications);
|
|
39
|
-
return packetlist;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Signs user
|
|
44
|
-
* @param {module:packet.SecretKey|
|
|
45
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
46
|
-
* @param {Array<module:key.Key>} privateKeys Decrypted private keys for signing
|
|
47
|
-
* @returns {Promise<module:key.Key>} New user with new certificate signatures
|
|
48
|
-
* @async
|
|
49
|
-
*/
|
|
50
|
-
User.prototype.sign = async function(primaryKey, privateKeys) {
|
|
51
|
-
const dataToSign = {
|
|
52
|
-
userId: this.userId,
|
|
53
|
-
userAttribute: this.userAttribute,
|
|
54
|
-
key: primaryKey
|
|
55
|
-
};
|
|
56
|
-
const user = new User(dataToSign.userId || dataToSign.userAttribute);
|
|
57
|
-
user.otherCertifications = await Promise.all(privateKeys.map(async function(privateKey) {
|
|
58
|
-
if (privateKey.isPublic()) {
|
|
59
|
-
throw new Error('Need private key for signing');
|
|
60
|
-
}
|
|
61
|
-
if (privateKey.hasSameFingerprintAs(primaryKey)) {
|
|
62
|
-
throw new Error('Not implemented for self signing');
|
|
63
|
-
}
|
|
64
|
-
const signingKey = await privateKey.getSigningKey();
|
|
65
|
-
return createSignaturePacket(dataToSign, privateKey, signingKey.keyPacket, {
|
|
66
|
-
// Most OpenPGP implementations use generic certification (0x10)
|
|
67
|
-
signatureType: enums.signature.cert_generic,
|
|
68
|
-
keyFlags: [enums.keyFlags.certify_keys | enums.keyFlags.sign_data]
|
|
69
|
-
});
|
|
70
|
-
}));
|
|
71
|
-
await user.update(this, primaryKey);
|
|
72
|
-
return user;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Checks if a given certificate of the user is revoked
|
|
77
|
-
* @param {module:packet.SecretKey|
|
|
78
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
79
|
-
* @param {module:packet.Signature} certificate The certificate to verify
|
|
80
|
-
* @param {module:packet.PublicSubkey|
|
|
81
|
-
* module:packet.SecretSubkey|
|
|
82
|
-
* module:packet.PublicKey|
|
|
83
|
-
* module:packet.SecretKey} key, optional The key to verify the signature
|
|
84
|
-
* @param {Date} date Use the given date instead of the current time
|
|
85
|
-
* @returns {Promise<Boolean>} True if the certificate is revoked
|
|
86
|
-
* @async
|
|
87
|
-
*/
|
|
88
|
-
User.prototype.isRevoked = async function(primaryKey, certificate, key, date = new Date()) {
|
|
89
|
-
return isDataRevoked(
|
|
90
|
-
primaryKey, enums.signature.cert_revocation, {
|
|
91
|
-
key: primaryKey,
|
|
92
|
-
userId: this.userId,
|
|
93
|
-
userAttribute: this.userAttribute
|
|
94
|
-
}, this.revocationSignatures, certificate, key, date
|
|
95
|
-
);
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Verifies the user certificate. Throws if the user certificate is invalid.
|
|
101
|
-
* @param {module:packet.SecretKey|
|
|
102
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
103
|
-
* @param {module:packet.Signature} certificate A certificate of this user
|
|
104
|
-
* @param {Array<module:key.Key>} keys Array of keys to verify certificate signatures
|
|
105
|
-
* @param {Date} date Use the given date instead of the current time
|
|
106
|
-
* @returns {Promise<true>} status of the certificate
|
|
107
|
-
* @async
|
|
108
|
-
*/
|
|
109
|
-
User.prototype.verifyCertificate = async function(primaryKey, certificate, keys, date = new Date()) {
|
|
110
|
-
const that = this;
|
|
111
|
-
const keyid = certificate.issuerKeyId;
|
|
112
|
-
const dataToVerify = {
|
|
113
|
-
userId: this.userId,
|
|
114
|
-
userAttribute: this.userAttribute,
|
|
115
|
-
key: primaryKey
|
|
116
|
-
};
|
|
117
|
-
const results = await Promise.all(keys.map(async function(key) {
|
|
118
|
-
if (!key.getKeyIds().some(id => id.equals(keyid))) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
const signingKey = await key.getSigningKey(keyid, date);
|
|
122
|
-
if (certificate.revoked || await that.isRevoked(primaryKey, certificate, signingKey.keyPacket, date)) {
|
|
123
|
-
throw new Error('User certificate is revoked');
|
|
124
|
-
}
|
|
125
|
-
try {
|
|
126
|
-
certificate.verified || await certificate.verify(signingKey.keyPacket, enums.signature.cert_generic, dataToVerify);
|
|
127
|
-
} catch (e) {
|
|
128
|
-
throw util.wrapError('User certificate is invalid', e);
|
|
129
|
-
}
|
|
130
|
-
if (certificate.isExpired(date)) {
|
|
131
|
-
throw new Error('User certificate is expired');
|
|
132
|
-
}
|
|
133
|
-
return true;
|
|
134
|
-
}));
|
|
135
|
-
return results.find(result => result !== null) || null;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Verifies all user certificates
|
|
140
|
-
* @param {module:packet.SecretKey|
|
|
141
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
142
|
-
* @param {Array<module:key.Key>} keys Array of keys to verify certificate signatures
|
|
143
|
-
* @param {Date} date Use the given date instead of the current time
|
|
144
|
-
* @returns {Promise<Array<{keyid: module:type/keyid,
|
|
145
|
-
* valid: Boolean}>>} List of signer's keyid and validity of signature
|
|
146
|
-
* @async
|
|
147
|
-
*/
|
|
148
|
-
User.prototype.verifyAllCertifications = async function(primaryKey, keys, date = new Date()) {
|
|
149
|
-
const that = this;
|
|
150
|
-
const certifications = this.selfCertifications.concat(this.otherCertifications);
|
|
151
|
-
return Promise.all(certifications.map(async function(certification) {
|
|
152
|
-
return {
|
|
153
|
-
keyid: certification.issuerKeyId,
|
|
154
|
-
valid: await that.verifyCertificate(primaryKey, certification, keys, date).catch(() => false)
|
|
155
|
-
};
|
|
156
|
-
}));
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Verify User. Checks for existence of self signatures, revocation signatures
|
|
161
|
-
* and validity of self signature. Throws when there are no valid self signatures.
|
|
162
|
-
* @param {module:packet.SecretKey|
|
|
163
|
-
* module:packet.PublicKey} primaryKey The primary key packet
|
|
164
|
-
* @param {Date} date Use the given date instead of the current time
|
|
165
|
-
* @returns {Promise<true>} Status of user
|
|
166
|
-
* @async
|
|
167
|
-
*/
|
|
168
|
-
User.prototype.verify = async function(primaryKey, date = new Date()) {
|
|
169
|
-
if (!this.selfCertifications.length) {
|
|
170
|
-
throw new Error('No self-certifications');
|
|
171
|
-
}
|
|
172
|
-
const that = this;
|
|
173
|
-
const dataToVerify = {
|
|
174
|
-
userId: this.userId,
|
|
175
|
-
userAttribute: this.userAttribute,
|
|
176
|
-
key: primaryKey
|
|
177
|
-
};
|
|
178
|
-
// TODO replace when Promise.some or Promise.any are implemented
|
|
179
|
-
let exception;
|
|
180
|
-
for (let i = this.selfCertifications.length - 1; i >= 0; i--) {
|
|
181
|
-
try {
|
|
182
|
-
const selfCertification = this.selfCertifications[i];
|
|
183
|
-
if (selfCertification.revoked || await that.isRevoked(primaryKey, selfCertification, undefined, date)) {
|
|
184
|
-
throw new Error('Self-certification is revoked');
|
|
185
|
-
}
|
|
186
|
-
try {
|
|
187
|
-
selfCertification.verified || await selfCertification.verify(primaryKey, enums.signature.cert_generic, dataToVerify);
|
|
188
|
-
} catch (e) {
|
|
189
|
-
throw util.wrapError('Self-certification is invalid', e);
|
|
190
|
-
}
|
|
191
|
-
if (selfCertification.isExpired(date)) {
|
|
192
|
-
throw new Error('Self-certification is expired');
|
|
193
|
-
}
|
|
194
|
-
return true;
|
|
195
|
-
} catch (e) {
|
|
196
|
-
exception = e;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
throw exception;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Update user with new components from specified user
|
|
204
|
-
* @param {module:key.User} user Source user to merge
|
|
205
|
-
* @param {module:packet.SecretKey|
|
|
206
|
-
* module:packet.SecretSubkey} primaryKey primary key used for validation
|
|
207
|
-
* @returns {Promise<undefined>}
|
|
208
|
-
* @async
|
|
209
|
-
*/
|
|
210
|
-
User.prototype.update = async function(user, primaryKey) {
|
|
211
|
-
const dataToVerify = {
|
|
212
|
-
userId: this.userId,
|
|
213
|
-
userAttribute: this.userAttribute,
|
|
214
|
-
key: primaryKey
|
|
215
|
-
};
|
|
216
|
-
// self signatures
|
|
217
|
-
await mergeSignatures(user, this, 'selfCertifications', async function(srcSelfSig) {
|
|
218
|
-
try {
|
|
219
|
-
return srcSelfSig.verified || srcSelfSig.verify(primaryKey, enums.signature.cert_generic, dataToVerify);
|
|
220
|
-
} catch (e) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
// other signatures
|
|
225
|
-
await mergeSignatures(user, this, 'otherCertifications');
|
|
226
|
-
// revocation signatures
|
|
227
|
-
await mergeSignatures(user, this, 'revocationSignatures', function(srcRevSig) {
|
|
228
|
-
return isDataRevoked(primaryKey, enums.signature.cert_revocation, dataToVerify, [srcRevSig]);
|
|
229
|
-
});
|
|
230
|
-
};
|
package/src/keyring/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Functions dealing with storage of the keyring.
|
|
3
|
-
* @see module:keyring/keyring
|
|
4
|
-
* @see module:keyring/localstore
|
|
5
|
-
* @module keyring
|
|
6
|
-
*/
|
|
7
|
-
import Keyring from './keyring.js';
|
|
8
|
-
import localstore from './localstore.js';
|
|
9
|
-
|
|
10
|
-
Keyring.localstore = localstore;
|
|
11
|
-
|
|
12
|
-
export default Keyring;
|
package/src/keyring/keyring.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2011 Recurity Labs GmbH
|
|
3
|
-
//
|
|
4
|
-
// This library is free software; you can redistribute it and/or
|
|
5
|
-
// modify it under the terms of the GNU Lesser General Public
|
|
6
|
-
// License as published by the Free Software Foundation; either
|
|
7
|
-
// version 3.0 of the License, or (at your option) any later version.
|
|
8
|
-
//
|
|
9
|
-
// This library is distributed in the hope that it will be useful,
|
|
10
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
-
// Lesser General Public License for more details.
|
|
13
|
-
//
|
|
14
|
-
// You should have received a copy of the GNU Lesser General Public
|
|
15
|
-
// License along with this library; if not, write to the Free Software
|
|
16
|
-
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @fileoverview Provides the Keyring class
|
|
20
|
-
* @requires key
|
|
21
|
-
* @requires keyring/localstore
|
|
22
|
-
* @module keyring/keyring
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { readArmored } from '../key';
|
|
26
|
-
import LocalStore from './localstore';
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Initialization routine for the keyring.
|
|
30
|
-
* @constructor
|
|
31
|
-
* @param {keyring/localstore} [storeHandler] class implementing loadPublic(), loadPrivate(), storePublic(), and storePrivate() methods
|
|
32
|
-
*/
|
|
33
|
-
function Keyring(storeHandler) {
|
|
34
|
-
this.storeHandler = storeHandler || new LocalStore();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Calls the storeHandler to load the keys
|
|
39
|
-
* @async
|
|
40
|
-
*/
|
|
41
|
-
Keyring.prototype.load = async function () {
|
|
42
|
-
this.publicKeys = new KeyArray(await this.storeHandler.loadPublic());
|
|
43
|
-
this.privateKeys = new KeyArray(await this.storeHandler.loadPrivate());
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Calls the storeHandler to save the keys
|
|
48
|
-
* @async
|
|
49
|
-
*/
|
|
50
|
-
Keyring.prototype.store = async function () {
|
|
51
|
-
await Promise.all([
|
|
52
|
-
this.storeHandler.storePublic(this.publicKeys.keys),
|
|
53
|
-
this.storeHandler.storePrivate(this.privateKeys.keys)
|
|
54
|
-
]);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Clear the keyring - erase all the keys
|
|
59
|
-
*/
|
|
60
|
-
Keyring.prototype.clear = function() {
|
|
61
|
-
this.publicKeys.keys = [];
|
|
62
|
-
this.privateKeys.keys = [];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Searches the keyring for keys having the specified key id
|
|
67
|
-
* @param {String} keyId provided as string of lowercase hex number
|
|
68
|
-
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
|
69
|
-
* @param {Boolean} deep if true search also in subkeys
|
|
70
|
-
* @returns {Array<module:key.Key>|null} keys found or null
|
|
71
|
-
*/
|
|
72
|
-
Keyring.prototype.getKeysForId = function (keyId, deep) {
|
|
73
|
-
let result = [];
|
|
74
|
-
result = result.concat(this.publicKeys.getForId(keyId, deep) || []);
|
|
75
|
-
result = result.concat(this.privateKeys.getForId(keyId, deep) || []);
|
|
76
|
-
return result.length ? result : null;
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Removes keys having the specified key id from the keyring
|
|
81
|
-
* @param {String} keyId provided as string of lowercase hex number
|
|
82
|
-
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
|
83
|
-
* @returns {Array<module:key.Key>|null} keys found or null
|
|
84
|
-
*/
|
|
85
|
-
Keyring.prototype.removeKeysForId = function (keyId) {
|
|
86
|
-
let result = [];
|
|
87
|
-
result = result.concat(this.publicKeys.removeForId(keyId) || []);
|
|
88
|
-
result = result.concat(this.privateKeys.removeForId(keyId) || []);
|
|
89
|
-
return result.length ? result : null;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get all public and private keys
|
|
94
|
-
* @returns {Array<module:key.Key>} all keys
|
|
95
|
-
*/
|
|
96
|
-
Keyring.prototype.getAllKeys = function () {
|
|
97
|
-
return this.publicKeys.keys.concat(this.privateKeys.keys);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Array of keys
|
|
102
|
-
* @param {Array<module:key.Key>} keys The keys to store in this array
|
|
103
|
-
*/
|
|
104
|
-
function KeyArray(keys) {
|
|
105
|
-
this.keys = keys;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Searches all keys in the KeyArray matching the address or address part of the user ids
|
|
110
|
-
* @param {String} email email address to search for
|
|
111
|
-
* @returns {Array<module:key.Key>} The public keys associated with provided email address.
|
|
112
|
-
*/
|
|
113
|
-
KeyArray.prototype.getForAddress = function(email) {
|
|
114
|
-
const results = [];
|
|
115
|
-
for (let i = 0; i < this.keys.length; i++) {
|
|
116
|
-
if (emailCheck(email, this.keys[i])) {
|
|
117
|
-
results.push(this.keys[i]);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return results;
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Checks a key to see if it matches the specified email address
|
|
125
|
-
* @private
|
|
126
|
-
* @param {String} email email address to search for
|
|
127
|
-
* @param {module:key.Key} key The key to be checked.
|
|
128
|
-
* @returns {Boolean} True if the email address is defined in the specified key
|
|
129
|
-
*/
|
|
130
|
-
function emailCheck(email, key) {
|
|
131
|
-
email = email.toLowerCase();
|
|
132
|
-
// escape email before using in regular expression
|
|
133
|
-
const emailEsc = email.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
134
|
-
const emailRegex = new RegExp('<' + emailEsc + '>');
|
|
135
|
-
const userIds = key.getUserIds();
|
|
136
|
-
for (let i = 0; i < userIds.length; i++) {
|
|
137
|
-
const userId = userIds[i].toLowerCase();
|
|
138
|
-
if (email === userId || emailRegex.test(userId)) {
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Checks a key to see if it matches the specified keyid
|
|
147
|
-
* @private
|
|
148
|
-
* @param {String} keyId provided as string of lowercase hex number
|
|
149
|
-
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
|
150
|
-
* @param {module:key.Key|module:key.SubKey} key The key to be checked
|
|
151
|
-
* @returns {Boolean} True if key has the specified keyid
|
|
152
|
-
*/
|
|
153
|
-
function keyIdCheck(keyId, key) {
|
|
154
|
-
if (keyId.length === 16) {
|
|
155
|
-
return keyId === key.getKeyId().toHex();
|
|
156
|
-
}
|
|
157
|
-
return keyId === key.getFingerprint();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Searches the KeyArray for a key having the specified key id
|
|
162
|
-
* @param {String} keyId provided as string of lowercase hex number
|
|
163
|
-
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
|
164
|
-
* @param {Boolean} deep if true search also in subkeys
|
|
165
|
-
* @returns {module:key.Key|null} key found or null
|
|
166
|
-
*/
|
|
167
|
-
KeyArray.prototype.getForId = function (keyId, deep) {
|
|
168
|
-
for (let i = 0; i < this.keys.length; i++) {
|
|
169
|
-
if (keyIdCheck(keyId, this.keys[i])) {
|
|
170
|
-
return this.keys[i];
|
|
171
|
-
}
|
|
172
|
-
if (deep && this.keys[i].subKeys.length) {
|
|
173
|
-
for (let j = 0; j < this.keys[i].subKeys.length; j++) {
|
|
174
|
-
if (keyIdCheck(keyId, this.keys[i].subKeys[j])) {
|
|
175
|
-
return this.keys[i];
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return null;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Imports a key from an ascii armored message
|
|
185
|
-
* @param {String} armored message to read the keys/key from
|
|
186
|
-
* @returns {Promise<Array<Error>|null>} array of error objects or null
|
|
187
|
-
* @async
|
|
188
|
-
*/
|
|
189
|
-
KeyArray.prototype.importKey = async function (armored) {
|
|
190
|
-
const imported = await readArmored(armored);
|
|
191
|
-
for (let i = 0; i < imported.keys.length; i++) {
|
|
192
|
-
const key = imported.keys[i];
|
|
193
|
-
// check if key already in key array
|
|
194
|
-
const keyidHex = key.getKeyId().toHex();
|
|
195
|
-
const keyFound = this.getForId(keyidHex);
|
|
196
|
-
if (keyFound) {
|
|
197
|
-
await keyFound.update(key);
|
|
198
|
-
} else {
|
|
199
|
-
this.push(key);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return imported.err ? imported.err : null;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Add key to KeyArray
|
|
207
|
-
* @param {module:key.Key} key The key that will be added to the keyring
|
|
208
|
-
* @returns {Number} The new length of the KeyArray
|
|
209
|
-
*/
|
|
210
|
-
KeyArray.prototype.push = function (key) {
|
|
211
|
-
return this.keys.push(key);
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Removes a key with the specified keyid from the keyring
|
|
216
|
-
* @param {String} keyId provided as string of lowercase hex number
|
|
217
|
-
* withouth 0x prefix (can be 16-character key ID or fingerprint)
|
|
218
|
-
* @returns {module:key.Key|null} The key object which has been removed or null
|
|
219
|
-
*/
|
|
220
|
-
KeyArray.prototype.removeForId = function (keyId) {
|
|
221
|
-
for (let i = 0; i < this.keys.length; i++) {
|
|
222
|
-
if (keyIdCheck(keyId, this.keys[i])) {
|
|
223
|
-
return this.keys.splice(i, 1)[0];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return null;
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
export default Keyring;
|