@protontech/openpgp 4.10.6 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +31379 -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 +43947 -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 +43884 -0
- package/dist/openpgp.js +41082 -41563
- 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 +43872 -0
- package/lightweight/package.json +5 -0
- package/openpgp.d.ts +890 -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,348 +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 Implementation of ECDSA following RFC6637 for Openpgpjs
|
|
20
|
-
* @requires bn.js
|
|
21
|
-
* @requires web-stream-tools
|
|
22
|
-
* @requires enums
|
|
23
|
-
* @requires util
|
|
24
|
-
* @requires crypto/public_key/elliptic/curves
|
|
25
|
-
* @module crypto/public_key/elliptic/ecdsa
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
import BN from 'bn.js';
|
|
29
|
-
import enums from '../../../enums';
|
|
30
|
-
import util from '../../../util';
|
|
31
|
-
import random from '../../random';
|
|
32
|
-
import hash from '../../hash';
|
|
33
|
-
import Curve, { webCurves, privateToJwk, rawPublicToJwk, validateStandardParams } from './curves';
|
|
34
|
-
import { getIndutnyCurve, keyFromPrivate, keyFromPublic } from './indutnyKey';
|
|
35
|
-
|
|
36
|
-
const webCrypto = util.getWebCrypto();
|
|
37
|
-
const nodeCrypto = util.getNodeCrypto();
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Sign a message using the provided key
|
|
41
|
-
* @param {module:type/oid} oid Elliptic curve object identifier
|
|
42
|
-
* @param {module:enums.hash} hash_algo Hash algorithm used to sign
|
|
43
|
-
* @param {Uint8Array} message Message to sign
|
|
44
|
-
* @param {Uint8Array} publicKey Public key
|
|
45
|
-
* @param {Uint8Array} privateKey Private key used to sign the message
|
|
46
|
-
* @param {Uint8Array} hashed The hashed message
|
|
47
|
-
* @returns {{r: Uint8Array,
|
|
48
|
-
* s: Uint8Array}} Signature of the message
|
|
49
|
-
* @async
|
|
50
|
-
*/
|
|
51
|
-
async function sign(oid, hash_algo, message, publicKey, privateKey, hashed) {
|
|
52
|
-
const curve = new Curve(oid);
|
|
53
|
-
if (message && !util.isStream(message)) {
|
|
54
|
-
const keyPair = { publicKey, privateKey };
|
|
55
|
-
switch (curve.type) {
|
|
56
|
-
case 'web': {
|
|
57
|
-
// If browser doesn't support a curve, we'll catch it
|
|
58
|
-
try {
|
|
59
|
-
// Need to await to make sure browser succeeds
|
|
60
|
-
return await webSign(curve, hash_algo, message, keyPair);
|
|
61
|
-
} catch (err) {
|
|
62
|
-
// We do not fallback if the error is related to key integrity
|
|
63
|
-
// Unfortunaley Safari does not support p521 and throws a DataError when using it
|
|
64
|
-
// So we need to always fallback for that curve
|
|
65
|
-
if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) {
|
|
66
|
-
throw err;
|
|
67
|
-
}
|
|
68
|
-
util.print_debug_error("Browser did not support verifying: " + err.message);
|
|
69
|
-
}
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case 'node': {
|
|
73
|
-
const signature = await nodeSign(curve, hash_algo, message, keyPair);
|
|
74
|
-
return {
|
|
75
|
-
r: signature.r.toArrayLike(Uint8Array),
|
|
76
|
-
s: signature.s.toArrayLike(Uint8Array)
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return ellipticSign(curve, hashed, privateKey);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Verifies if a signature is valid for a message
|
|
86
|
-
* @param {module:type/oid} oid Elliptic curve object identifier
|
|
87
|
-
* @param {module:enums.hash} hash_algo Hash algorithm used in the signature
|
|
88
|
-
* @param {{r: Uint8Array,
|
|
89
|
-
s: Uint8Array}} signature Signature to verify
|
|
90
|
-
* @param {Uint8Array} message Message to verify
|
|
91
|
-
* @param {Uint8Array} publicKey Public key used to verify the message
|
|
92
|
-
* @param {Uint8Array} hashed The hashed message
|
|
93
|
-
* @returns {Boolean}
|
|
94
|
-
* @async
|
|
95
|
-
*/
|
|
96
|
-
async function verify(oid, hash_algo, signature, message, publicKey, hashed) {
|
|
97
|
-
const curve = new Curve(oid);
|
|
98
|
-
if (message && !util.isStream(message)) {
|
|
99
|
-
switch (curve.type) {
|
|
100
|
-
case 'web':
|
|
101
|
-
try {
|
|
102
|
-
// Need to await to make sure browser succeeds
|
|
103
|
-
return await webVerify(curve, hash_algo, signature, message, publicKey);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
// We do not fallback if the error is related to key integrity
|
|
106
|
-
// Unfortunaley Safari does not support p521 and throws a DataError when using it
|
|
107
|
-
// So we need to always fallback for that curve
|
|
108
|
-
if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) {
|
|
109
|
-
throw err;
|
|
110
|
-
}
|
|
111
|
-
util.print_debug_error("Browser did not support verifying: " + err.message);
|
|
112
|
-
}
|
|
113
|
-
break;
|
|
114
|
-
case 'node':
|
|
115
|
-
return nodeVerify(curve, hash_algo, signature, message, publicKey);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
const digest = (typeof hash_algo === 'undefined') ? message : hashed;
|
|
119
|
-
return ellipticVerify(curve, signature, digest, publicKey);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Validate EcDSA parameters
|
|
124
|
-
* @param {module:type/oid} oid Elliptic curve object identifier
|
|
125
|
-
* @param {Uint8Array} Q EcDSA public point
|
|
126
|
-
* @param {Uint8Array} d EcDSA secret scalar
|
|
127
|
-
* @returns {Promise<Boolean>} whether params are valid
|
|
128
|
-
* @async
|
|
129
|
-
*/
|
|
130
|
-
async function validateParams(oid, Q, d) {
|
|
131
|
-
const curve = new Curve(oid);
|
|
132
|
-
// Reject curves x25519 and ed25519
|
|
133
|
-
if (curve.keyType !== enums.publicKey.ecdsa) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// To speed up the validation, we try to use node- or webcrypto when available
|
|
138
|
-
// and sign + verify a random message
|
|
139
|
-
switch (curve.type) {
|
|
140
|
-
case 'web':
|
|
141
|
-
case 'node': {
|
|
142
|
-
const message = await random.getRandomBytes(8);
|
|
143
|
-
const hashAlgo = enums.hash.sha256;
|
|
144
|
-
const hashed = await hash.digest(hashAlgo, message);
|
|
145
|
-
try {
|
|
146
|
-
const signature = await sign(oid, hashAlgo, message, Q, d, hashed);
|
|
147
|
-
return await verify(oid, hashAlgo, signature, message, Q, hashed);
|
|
148
|
-
} catch (err) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
default:
|
|
153
|
-
return validateStandardParams(enums.publicKey.ecdsa, oid, Q, d);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Parses MPI params and returns them as byte arrays of fixed length
|
|
159
|
-
* @param {Array} params key parameters
|
|
160
|
-
* @returns {Object} parameters in the form
|
|
161
|
-
* { oid, d: Uint8Array, Q: Uint8Array }
|
|
162
|
-
*/
|
|
163
|
-
function parseParams(params) {
|
|
164
|
-
if (params.length < 2 || params.length > 3) {
|
|
165
|
-
throw new Error('Unexpected number of parameters');
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const oid = params[0];
|
|
169
|
-
const curve = new Curve(oid);
|
|
170
|
-
const parsedParams = { oid };
|
|
171
|
-
// The public point never has leading zeros, as it is prefixed by 0x40 or 0x04
|
|
172
|
-
parsedParams.Q = params[1].toUint8Array();
|
|
173
|
-
if (params.length === 3) {
|
|
174
|
-
parsedParams.d = params[2].toUint8Array('be', curve.payloadSize);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return parsedParams;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
export default { sign, verify, ellipticVerify, ellipticSign, validateParams, parseParams };
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
//////////////////////////
|
|
185
|
-
// //
|
|
186
|
-
// Helper functions //
|
|
187
|
-
// //
|
|
188
|
-
//////////////////////////
|
|
189
|
-
|
|
190
|
-
async function ellipticSign(curve, hashed, privateKey) {
|
|
191
|
-
const indutnyCurve = await getIndutnyCurve(curve.name);
|
|
192
|
-
const key = keyFromPrivate(indutnyCurve, privateKey);
|
|
193
|
-
const signature = key.sign(hashed);
|
|
194
|
-
return {
|
|
195
|
-
r: signature.r.toArrayLike(Uint8Array),
|
|
196
|
-
s: signature.s.toArrayLike(Uint8Array)
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
async function ellipticVerify(curve, signature, digest, publicKey) {
|
|
201
|
-
const indutnyCurve = await getIndutnyCurve(curve.name);
|
|
202
|
-
const key = keyFromPublic(indutnyCurve, publicKey);
|
|
203
|
-
return key.verify(digest, signature);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
async function webSign(curve, hash_algo, message, keyPair) {
|
|
207
|
-
const len = curve.payloadSize;
|
|
208
|
-
const jwk = privateToJwk(curve.payloadSize, webCurves[curve.name], keyPair.publicKey, keyPair.privateKey);
|
|
209
|
-
const key = await webCrypto.importKey(
|
|
210
|
-
"jwk",
|
|
211
|
-
jwk,
|
|
212
|
-
{
|
|
213
|
-
"name": "ECDSA",
|
|
214
|
-
"namedCurve": webCurves[curve.name],
|
|
215
|
-
"hash": { name: enums.read(enums.webHash, curve.hash) }
|
|
216
|
-
},
|
|
217
|
-
false,
|
|
218
|
-
["sign"]
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const signature = new Uint8Array(await webCrypto.sign(
|
|
222
|
-
{
|
|
223
|
-
"name": 'ECDSA',
|
|
224
|
-
"namedCurve": webCurves[curve.name],
|
|
225
|
-
"hash": { name: enums.read(enums.webHash, hash_algo) }
|
|
226
|
-
},
|
|
227
|
-
key,
|
|
228
|
-
message
|
|
229
|
-
));
|
|
230
|
-
|
|
231
|
-
return {
|
|
232
|
-
r: signature.slice(0, len),
|
|
233
|
-
s: signature.slice(len, len << 1)
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
async function webVerify(curve, hash_algo, { r, s }, message, publicKey) {
|
|
238
|
-
const len = curve.payloadSize;
|
|
239
|
-
const jwk = rawPublicToJwk(curve.payloadSize, webCurves[curve.name], publicKey);
|
|
240
|
-
const key = await webCrypto.importKey(
|
|
241
|
-
"jwk",
|
|
242
|
-
jwk,
|
|
243
|
-
{
|
|
244
|
-
"name": "ECDSA",
|
|
245
|
-
"namedCurve": webCurves[curve.name],
|
|
246
|
-
"hash": { name: enums.read(enums.webHash, curve.hash) }
|
|
247
|
-
},
|
|
248
|
-
false,
|
|
249
|
-
["verify"]
|
|
250
|
-
);
|
|
251
|
-
|
|
252
|
-
const signature = util.concatUint8Array([
|
|
253
|
-
new Uint8Array(len - r.length), r,
|
|
254
|
-
new Uint8Array(len - s.length), s
|
|
255
|
-
]).buffer;
|
|
256
|
-
|
|
257
|
-
return webCrypto.verify(
|
|
258
|
-
{
|
|
259
|
-
"name": 'ECDSA',
|
|
260
|
-
"namedCurve": webCurves[curve.name],
|
|
261
|
-
"hash": { name: enums.read(enums.webHash, hash_algo) }
|
|
262
|
-
},
|
|
263
|
-
key,
|
|
264
|
-
signature,
|
|
265
|
-
message
|
|
266
|
-
);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
async function nodeSign(curve, hash_algo, message, keyPair) {
|
|
270
|
-
const sign = nodeCrypto.createSign(enums.read(enums.hash, hash_algo));
|
|
271
|
-
sign.write(message);
|
|
272
|
-
sign.end();
|
|
273
|
-
const key = ECPrivateKey.encode({
|
|
274
|
-
version: 1,
|
|
275
|
-
parameters: curve.oid,
|
|
276
|
-
privateKey: Array.from(keyPair.privateKey),
|
|
277
|
-
publicKey: { unused: 0, data: Array.from(keyPair.publicKey) }
|
|
278
|
-
}, 'pem', {
|
|
279
|
-
label: 'EC PRIVATE KEY'
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
return ECDSASignature.decode(sign.sign(key), 'der');
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
async function nodeVerify(curve, hash_algo, { r, s }, message, publicKey) {
|
|
286
|
-
const verify = nodeCrypto.createVerify(enums.read(enums.hash, hash_algo));
|
|
287
|
-
verify.write(message);
|
|
288
|
-
verify.end();
|
|
289
|
-
const key = SubjectPublicKeyInfo.encode({
|
|
290
|
-
algorithm: {
|
|
291
|
-
algorithm: [1, 2, 840, 10045, 2, 1],
|
|
292
|
-
parameters: curve.oid
|
|
293
|
-
},
|
|
294
|
-
subjectPublicKey: { unused: 0, data: Array.from(publicKey) }
|
|
295
|
-
}, 'pem', {
|
|
296
|
-
label: 'PUBLIC KEY'
|
|
297
|
-
});
|
|
298
|
-
const signature = ECDSASignature.encode({
|
|
299
|
-
r: new BN(r), s: new BN(s)
|
|
300
|
-
}, 'der');
|
|
301
|
-
|
|
302
|
-
try {
|
|
303
|
-
return verify.verify(key, signature);
|
|
304
|
-
} catch (err) {
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Originally written by Owen Smith https://github.com/omsmith
|
|
310
|
-
// Adapted on Feb 2018 from https://github.com/Brightspace/node-jwk-to-pem/
|
|
311
|
-
|
|
312
|
-
/* eslint-disable no-invalid-this */
|
|
313
|
-
|
|
314
|
-
const asn1 = nodeCrypto ? require('asn1.js') : undefined;
|
|
315
|
-
|
|
316
|
-
const ECDSASignature = nodeCrypto ?
|
|
317
|
-
asn1.define('ECDSASignature', function() {
|
|
318
|
-
this.seq().obj(
|
|
319
|
-
this.key('r').int(),
|
|
320
|
-
this.key('s').int()
|
|
321
|
-
);
|
|
322
|
-
}) : undefined;
|
|
323
|
-
|
|
324
|
-
const ECPrivateKey = nodeCrypto ?
|
|
325
|
-
asn1.define('ECPrivateKey', function() {
|
|
326
|
-
this.seq().obj(
|
|
327
|
-
this.key('version').int(),
|
|
328
|
-
this.key('privateKey').octstr(),
|
|
329
|
-
this.key('parameters').explicit(0).optional().any(),
|
|
330
|
-
this.key('publicKey').explicit(1).optional().bitstr()
|
|
331
|
-
);
|
|
332
|
-
}) : undefined;
|
|
333
|
-
|
|
334
|
-
const AlgorithmIdentifier = nodeCrypto ?
|
|
335
|
-
asn1.define('AlgorithmIdentifier', function() {
|
|
336
|
-
this.seq().obj(
|
|
337
|
-
this.key('algorithm').objid(),
|
|
338
|
-
this.key('parameters').optional().any()
|
|
339
|
-
);
|
|
340
|
-
}) : undefined;
|
|
341
|
-
|
|
342
|
-
const SubjectPublicKeyInfo = nodeCrypto ?
|
|
343
|
-
asn1.define('SubjectPublicKeyInfo', function() {
|
|
344
|
-
this.seq().obj(
|
|
345
|
-
this.key('algorithm').use(AlgorithmIdentifier),
|
|
346
|
-
this.key('subjectPublicKey').bitstr()
|
|
347
|
-
);
|
|
348
|
-
}) : undefined;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
2
|
-
// Copyright (C) 2018 Proton Technologies AG
|
|
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 Implementation of EdDSA following RFC4880bis-03 for OpenPGP
|
|
20
|
-
* @requires hash.js
|
|
21
|
-
* @requires tweetnacl
|
|
22
|
-
* @requires crypto/public_key/elliptic/curve
|
|
23
|
-
* @requires util
|
|
24
|
-
* @module crypto/public_key/elliptic/eddsa
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import sha512 from 'hash.js/lib/hash/sha/512';
|
|
28
|
-
import nacl from 'tweetnacl/nacl-fast-light.js';
|
|
29
|
-
import util from '../../../util';
|
|
30
|
-
|
|
31
|
-
nacl.hash = bytes => new Uint8Array(sha512().update(bytes).digest());
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Sign a message using the provided key
|
|
35
|
-
* @param {module:type/oid} oid Elliptic curve object identifier
|
|
36
|
-
* @param {module:enums.hash} hash_algo Hash algorithm used to sign
|
|
37
|
-
* @param {Uint8Array} message Message to sign
|
|
38
|
-
* @param {Uint8Array} publicKey Public key
|
|
39
|
-
* @param {Uint8Array} privateKey Private key used to sign the message
|
|
40
|
-
* @param {Uint8Array} hashed The hashed message
|
|
41
|
-
* @returns {{R: Uint8Array,
|
|
42
|
-
* S: Uint8Array}} Signature of the message
|
|
43
|
-
* @async
|
|
44
|
-
*/
|
|
45
|
-
async function sign(oid, hash_algo, message, publicKey, privateKey, hashed) {
|
|
46
|
-
const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
|
|
47
|
-
const signature = nacl.sign.detached(hashed, secretKey);
|
|
48
|
-
// EdDSA signature params are returned in little-endian format
|
|
49
|
-
return {
|
|
50
|
-
R: signature.subarray(0, 32),
|
|
51
|
-
S: signature.subarray(32)
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Verifies if a signature is valid for a message
|
|
57
|
-
* @param {module:type/oid} oid Elliptic curve object identifier
|
|
58
|
-
* @param {module:enums.hash} hash_algo Hash algorithm used in the signature
|
|
59
|
-
* @param {{R: Uint8Array,
|
|
60
|
-
S: Uint8Array}} signature Signature to verify the message
|
|
61
|
-
* @param {Uint8Array} m Message to verify
|
|
62
|
-
* @param {Uint8Array} publicKey Public key used to verify the message
|
|
63
|
-
* @param {Uint8Array} hashed The hashed message
|
|
64
|
-
* @returns {Boolean}
|
|
65
|
-
* @async
|
|
66
|
-
*/
|
|
67
|
-
async function verify(oid, hash_algo, { R, S }, m, publicKey, hashed) {
|
|
68
|
-
const signature = util.concatUint8Array([R, S]);
|
|
69
|
-
return nacl.sign.detached.verify(hashed, signature, publicKey.subarray(1));
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Validate EdDSA parameters
|
|
74
|
-
* @param {module:type/oid} oid Elliptic curve object identifier
|
|
75
|
-
* @param {Uint8Array} Q EdDSA public point
|
|
76
|
-
* @param {Uint8Array} k EdDSA secret seed
|
|
77
|
-
* @returns {Promise<Boolean>} whether params are valid
|
|
78
|
-
* @async
|
|
79
|
-
*/
|
|
80
|
-
async function validateParams(oid, Q, k) {
|
|
81
|
-
// Check whether the given curve is supported
|
|
82
|
-
if (oid.getName() !== 'ed25519') {
|
|
83
|
-
return false;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Derive public point Q' = dG from private key
|
|
88
|
-
* and expect Q == Q'
|
|
89
|
-
*/
|
|
90
|
-
const { publicKey } = nacl.sign.keyPair.fromSeed(k);
|
|
91
|
-
const dG = new Uint8Array([0x40, ...publicKey]); // Add public key prefix
|
|
92
|
-
return util.equalsUint8Array(Q, dG);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Parses MPI params and returns them as byte arrays of fixed length
|
|
97
|
-
* @param {Array} params key parameters
|
|
98
|
-
* @returns {Object} parameters in the form
|
|
99
|
-
* { oid, seed: Uint8Array, Q: Uint8Array }
|
|
100
|
-
*/
|
|
101
|
-
function parseParams(params) {
|
|
102
|
-
if (params.length < 2 || params.length > 3) {
|
|
103
|
-
throw new Error('Unexpected number of parameters');
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const parsedParams = {
|
|
107
|
-
oid: params[0],
|
|
108
|
-
Q: params[1].toUint8Array('be', 33)
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
if (params.length === 3) {
|
|
112
|
-
parsedParams.seed = params[2].toUint8Array('be', 32);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return parsedParams;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
export default { sign, verify, validateParams, parseParams };
|
|
@@ -1,34 +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 Functions to access Elliptic Curve Cryptography
|
|
20
|
-
* @see module:crypto/public_key/elliptic/curve
|
|
21
|
-
* @see module:crypto/public_key/elliptic/ecdh
|
|
22
|
-
* @see module:crypto/public_key/elliptic/ecdsa
|
|
23
|
-
* @see module:crypto/public_key/elliptic/eddsa
|
|
24
|
-
* @module crypto/public_key/elliptic
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import Curve, { generate, getPreferredHashAlgo } from './curves';
|
|
28
|
-
import ecdsa from './ecdsa';
|
|
29
|
-
import eddsa from './eddsa';
|
|
30
|
-
import ecdh from './ecdh';
|
|
31
|
-
|
|
32
|
-
export default {
|
|
33
|
-
Curve, ecdh, ecdsa, eddsa, generate, getPreferredHashAlgo
|
|
34
|
-
};
|
|
@@ -1,85 +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 Wrapper for a KeyPair of an curve from indutny/elliptic library
|
|
20
|
-
* @requires enums
|
|
21
|
-
* @requires asn1.js
|
|
22
|
-
* @module crypto/public_key/elliptic/indutnyKey
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { loadScript, dl } from '../../../lightweight_helper';
|
|
26
|
-
import config from '../../../config';
|
|
27
|
-
import util from '../../../util';
|
|
28
|
-
|
|
29
|
-
export function keyFromPrivate(indutnyCurve, priv) {
|
|
30
|
-
const keyPair = indutnyCurve.keyPair({ priv: priv });
|
|
31
|
-
return keyPair;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function keyFromPublic(indutnyCurve, pub) {
|
|
35
|
-
const keyPair = indutnyCurve.keyPair({ pub: pub });
|
|
36
|
-
if (keyPair.validate().result !== true) {
|
|
37
|
-
throw new Error('Invalid elliptic public key');
|
|
38
|
-
}
|
|
39
|
-
return keyPair;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Load elliptic on demand to global.openpgp.elliptic
|
|
44
|
-
* @returns {Promise<elliptic>}
|
|
45
|
-
*/
|
|
46
|
-
async function loadEllipticPromise() {
|
|
47
|
-
const path = config.indutny_elliptic_path;
|
|
48
|
-
const options = config.indutny_elliptic_fetch_options;
|
|
49
|
-
const ellipticDlPromise = dl(path, options).catch(() => dl(path, options));
|
|
50
|
-
const ellipticContents = await ellipticDlPromise;
|
|
51
|
-
const mainUrl = URL.createObjectURL(new Blob([ellipticContents], { type: 'text/javascript' }));
|
|
52
|
-
await loadScript(mainUrl);
|
|
53
|
-
URL.revokeObjectURL(mainUrl);
|
|
54
|
-
if (!global.openpgp.elliptic) {
|
|
55
|
-
throw new Error('Elliptic library failed to load correctly');
|
|
56
|
-
}
|
|
57
|
-
return global.openpgp.elliptic;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let ellipticPromise;
|
|
61
|
-
|
|
62
|
-
function loadElliptic() {
|
|
63
|
-
if (!config.external_indutny_elliptic) {
|
|
64
|
-
return require('elliptic');
|
|
65
|
-
}
|
|
66
|
-
if (util.detectNode()) {
|
|
67
|
-
// eslint-disable-next-line
|
|
68
|
-
return require(config.indutny_elliptic_path);
|
|
69
|
-
}
|
|
70
|
-
if (!ellipticPromise) {
|
|
71
|
-
ellipticPromise = loadEllipticPromise().catch(e => {
|
|
72
|
-
ellipticPromise = undefined;
|
|
73
|
-
throw e;
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
return ellipticPromise;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export async function getIndutnyCurve(name) {
|
|
80
|
-
if (!config.use_indutny_elliptic) {
|
|
81
|
-
throw new Error('This curve is only supported in the full build of OpenPGP.js');
|
|
82
|
-
}
|
|
83
|
-
const elliptic = await loadElliptic();
|
|
84
|
-
return new elliptic.ec(name);
|
|
85
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Asymmetric cryptography functions
|
|
3
|
-
* @requires tweetnacl
|
|
4
|
-
* @requires crypto/public_key/dsa
|
|
5
|
-
* @requires crypto/public_key/elgamal
|
|
6
|
-
* @requires crypto/public_key/elliptic
|
|
7
|
-
* @requires crypto/public_key/rsa
|
|
8
|
-
* @module crypto/public_key
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import nacl from 'tweetnacl/nacl-fast-light.js';
|
|
12
|
-
import rsa from './rsa';
|
|
13
|
-
import elgamal from './elgamal';
|
|
14
|
-
import elliptic from './elliptic';
|
|
15
|
-
import dsa from './dsa';
|
|
16
|
-
|
|
17
|
-
export default {
|
|
18
|
-
/** @see module:crypto/public_key/rsa */
|
|
19
|
-
rsa: rsa,
|
|
20
|
-
/** @see module:crypto/public_key/elgamal */
|
|
21
|
-
elgamal: elgamal,
|
|
22
|
-
/** @see module:crypto/public_key/elliptic */
|
|
23
|
-
elliptic: elliptic,
|
|
24
|
-
/** @see module:crypto/public_key/dsa */
|
|
25
|
-
dsa: dsa,
|
|
26
|
-
/** @see tweetnacl */
|
|
27
|
-
nacl: nacl
|
|
28
|
-
};
|