@protontech/openpgp 5.9.1-1 → 5.11.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/dist/lightweight/argon2id.min.mjs +1 -1
- package/dist/lightweight/argon2id.mjs +1 -1
- package/dist/lightweight/bn.interface.min.mjs +1 -1
- package/dist/lightweight/bn.interface.mjs +1 -1
- package/dist/lightweight/bn.min.mjs +1 -1
- package/dist/lightweight/bn.mjs +1 -1
- package/dist/lightweight/elliptic.min.mjs +1 -1
- package/dist/lightweight/elliptic.mjs +1 -1
- package/dist/lightweight/openpgp.min.mjs +2 -2
- package/dist/lightweight/openpgp.min.mjs.map +1 -1
- package/dist/lightweight/openpgp.mjs +1870 -1288
- package/dist/lightweight/ponyfill.es6.min.mjs +1 -1
- package/dist/lightweight/ponyfill.es6.mjs +1 -1
- package/dist/lightweight/web-streams-adapter.min.mjs +1 -1
- package/dist/lightweight/web-streams-adapter.mjs +1 -1
- package/dist/node/openpgp.js +1346 -764
- package/dist/node/openpgp.min.js +3 -3
- package/dist/node/openpgp.min.js.map +1 -1
- package/dist/node/openpgp.min.mjs +3 -3
- package/dist/node/openpgp.min.mjs.map +1 -1
- package/dist/node/openpgp.mjs +1343 -761
- package/dist/openpgp.js +1346 -764
- package/dist/openpgp.min.js +3 -3
- package/dist/openpgp.min.js.map +1 -1
- package/dist/openpgp.min.mjs +3 -3
- package/dist/openpgp.min.mjs.map +1 -1
- package/dist/openpgp.mjs +1343 -761
- package/openpgp.d.ts +9 -2
- package/package.json +3 -3
package/dist/openpgp.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! OpenPGP.js v5.
|
|
1
|
+
/*! OpenPGP.js v5.11.0 - 2023-11-27 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
|
|
2
2
|
const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
3
3
|
|
|
4
4
|
const doneWritingPromise = Symbol('doneWritingPromise');
|
|
@@ -241,18 +241,17 @@ if (NodeReadableStream$1) {
|
|
|
241
241
|
this.push(null);
|
|
242
242
|
break;
|
|
243
243
|
}
|
|
244
|
-
if (!this.push(value)
|
|
245
|
-
this._reading = false;
|
|
244
|
+
if (!this.push(value)) {
|
|
246
245
|
break;
|
|
247
246
|
}
|
|
248
247
|
}
|
|
249
|
-
} catch(e) {
|
|
250
|
-
this.
|
|
248
|
+
} catch (e) {
|
|
249
|
+
this.destroy(e);
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
252
|
|
|
254
|
-
_destroy(
|
|
255
|
-
this._reader.cancel(
|
|
253
|
+
async _destroy(error, callback) {
|
|
254
|
+
this._reader.cancel(error).then(callback, callback);
|
|
256
255
|
}
|
|
257
256
|
}
|
|
258
257
|
|
|
@@ -287,7 +286,7 @@ function Reader(input) {
|
|
|
287
286
|
const reader = input.getReader();
|
|
288
287
|
this._read = reader.read.bind(reader);
|
|
289
288
|
this._releaseLock = () => {};
|
|
290
|
-
this._cancel = () => {};
|
|
289
|
+
this._cancel = async () => {};
|
|
291
290
|
return;
|
|
292
291
|
}
|
|
293
292
|
let streamType = isStream(input);
|
|
@@ -1507,6 +1506,533 @@ async function getBigInteger() {
|
|
|
1507
1506
|
}
|
|
1508
1507
|
}
|
|
1509
1508
|
|
|
1509
|
+
/**
|
|
1510
|
+
* @module enums
|
|
1511
|
+
*/
|
|
1512
|
+
|
|
1513
|
+
const byValue = Symbol('byValue');
|
|
1514
|
+
|
|
1515
|
+
var enums = {
|
|
1516
|
+
|
|
1517
|
+
/** Maps curve names under various standards to one
|
|
1518
|
+
* @see {@link https://wiki.gnupg.org/ECC|ECC - GnuPG wiki}
|
|
1519
|
+
* @enum {String}
|
|
1520
|
+
* @readonly
|
|
1521
|
+
*/
|
|
1522
|
+
curve: {
|
|
1523
|
+
/** NIST P-256 Curve */
|
|
1524
|
+
'p256': 'p256',
|
|
1525
|
+
'P-256': 'p256',
|
|
1526
|
+
'secp256r1': 'p256',
|
|
1527
|
+
'prime256v1': 'p256',
|
|
1528
|
+
'1.2.840.10045.3.1.7': 'p256',
|
|
1529
|
+
'2a8648ce3d030107': 'p256',
|
|
1530
|
+
'2A8648CE3D030107': 'p256',
|
|
1531
|
+
|
|
1532
|
+
/** NIST P-384 Curve */
|
|
1533
|
+
'p384': 'p384',
|
|
1534
|
+
'P-384': 'p384',
|
|
1535
|
+
'secp384r1': 'p384',
|
|
1536
|
+
'1.3.132.0.34': 'p384',
|
|
1537
|
+
'2b81040022': 'p384',
|
|
1538
|
+
'2B81040022': 'p384',
|
|
1539
|
+
|
|
1540
|
+
/** NIST P-521 Curve */
|
|
1541
|
+
'p521': 'p521',
|
|
1542
|
+
'P-521': 'p521',
|
|
1543
|
+
'secp521r1': 'p521',
|
|
1544
|
+
'1.3.132.0.35': 'p521',
|
|
1545
|
+
'2b81040023': 'p521',
|
|
1546
|
+
'2B81040023': 'p521',
|
|
1547
|
+
|
|
1548
|
+
/** SECG SECP256k1 Curve */
|
|
1549
|
+
'secp256k1': 'secp256k1',
|
|
1550
|
+
'1.3.132.0.10': 'secp256k1',
|
|
1551
|
+
'2b8104000a': 'secp256k1',
|
|
1552
|
+
'2B8104000A': 'secp256k1',
|
|
1553
|
+
|
|
1554
|
+
/** Ed25519 - deprecated by crypto-refresh (replaced by standaone Ed25519 algo) */
|
|
1555
|
+
'ed25519Legacy': 'ed25519',
|
|
1556
|
+
'ED25519': 'ed25519',
|
|
1557
|
+
/** @deprecated use `ed25519Legacy` instead */
|
|
1558
|
+
'ed25519': 'ed25519',
|
|
1559
|
+
'Ed25519': 'ed25519',
|
|
1560
|
+
'1.3.6.1.4.1.11591.15.1': 'ed25519',
|
|
1561
|
+
'2b06010401da470f01': 'ed25519',
|
|
1562
|
+
'2B06010401DA470F01': 'ed25519',
|
|
1563
|
+
|
|
1564
|
+
/** Curve25519 - deprecated by crypto-refresh (replaced by standaone X25519 algo) */
|
|
1565
|
+
'curve25519Legacy': 'curve25519',
|
|
1566
|
+
'X25519': 'curve25519',
|
|
1567
|
+
'cv25519': 'curve25519',
|
|
1568
|
+
/** @deprecated use `curve25519Legacy` instead */
|
|
1569
|
+
'curve25519': 'curve25519',
|
|
1570
|
+
'Curve25519': 'curve25519',
|
|
1571
|
+
'1.3.6.1.4.1.3029.1.5.1': 'curve25519',
|
|
1572
|
+
'2b060104019755010501': 'curve25519',
|
|
1573
|
+
'2B060104019755010501': 'curve25519',
|
|
1574
|
+
|
|
1575
|
+
/** BrainpoolP256r1 Curve */
|
|
1576
|
+
'brainpoolP256r1': 'brainpoolP256r1',
|
|
1577
|
+
'1.3.36.3.3.2.8.1.1.7': 'brainpoolP256r1',
|
|
1578
|
+
'2b2403030208010107': 'brainpoolP256r1',
|
|
1579
|
+
'2B2403030208010107': 'brainpoolP256r1',
|
|
1580
|
+
|
|
1581
|
+
/** BrainpoolP384r1 Curve */
|
|
1582
|
+
'brainpoolP384r1': 'brainpoolP384r1',
|
|
1583
|
+
'1.3.36.3.3.2.8.1.1.11': 'brainpoolP384r1',
|
|
1584
|
+
'2b240303020801010b': 'brainpoolP384r1',
|
|
1585
|
+
'2B240303020801010B': 'brainpoolP384r1',
|
|
1586
|
+
|
|
1587
|
+
/** BrainpoolP512r1 Curve */
|
|
1588
|
+
'brainpoolP512r1': 'brainpoolP512r1',
|
|
1589
|
+
'1.3.36.3.3.2.8.1.1.13': 'brainpoolP512r1',
|
|
1590
|
+
'2b240303020801010d': 'brainpoolP512r1',
|
|
1591
|
+
'2B240303020801010D': 'brainpoolP512r1'
|
|
1592
|
+
},
|
|
1593
|
+
|
|
1594
|
+
/** KDF parameters flags
|
|
1595
|
+
* Non-standard extensions (for now) to allow email forwarding
|
|
1596
|
+
* @enum {Integer}
|
|
1597
|
+
* @readonly
|
|
1598
|
+
*/
|
|
1599
|
+
kdfFlags: {
|
|
1600
|
+
/** Specify fingerprint to use instead of the recipient's */
|
|
1601
|
+
replace_fingerprint: 0x01,
|
|
1602
|
+
/** Specify custom parameters to use in the KDF digest computation */
|
|
1603
|
+
replace_kdf_params: 0x02
|
|
1604
|
+
},
|
|
1605
|
+
|
|
1606
|
+
/** A string to key specifier type
|
|
1607
|
+
* @enum {Integer}
|
|
1608
|
+
* @readonly
|
|
1609
|
+
*/
|
|
1610
|
+
s2k: {
|
|
1611
|
+
simple: 0,
|
|
1612
|
+
salted: 1,
|
|
1613
|
+
iterated: 3,
|
|
1614
|
+
argon2: 4,
|
|
1615
|
+
gnu: 101
|
|
1616
|
+
},
|
|
1617
|
+
|
|
1618
|
+
/** {@link https://tools.ietf.org/html/draft-ietf-openpgp-crypto-refresh-08.html#section-9.1|crypto-refresh RFC, section 9.1}
|
|
1619
|
+
* @enum {Integer}
|
|
1620
|
+
* @readonly
|
|
1621
|
+
*/
|
|
1622
|
+
publicKey: {
|
|
1623
|
+
/** RSA (Encrypt or Sign) [HAC] */
|
|
1624
|
+
rsaEncryptSign: 1,
|
|
1625
|
+
/** RSA (Encrypt only) [HAC] */
|
|
1626
|
+
rsaEncrypt: 2,
|
|
1627
|
+
/** RSA (Sign only) [HAC] */
|
|
1628
|
+
rsaSign: 3,
|
|
1629
|
+
/** Elgamal (Encrypt only) [ELGAMAL] [HAC] */
|
|
1630
|
+
elgamal: 16,
|
|
1631
|
+
/** DSA (Sign only) [FIPS186] [HAC] */
|
|
1632
|
+
dsa: 17,
|
|
1633
|
+
/** ECDH (Encrypt only) [RFC6637] */
|
|
1634
|
+
ecdh: 18,
|
|
1635
|
+
/** ECDSA (Sign only) [RFC6637] */
|
|
1636
|
+
ecdsa: 19,
|
|
1637
|
+
/** EdDSA (Sign only) - deprecated by crypto-refresh (replaced by `ed25519` identifier below)
|
|
1638
|
+
* [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
|
|
1639
|
+
eddsaLegacy: 22, // NB: this is declared before `eddsa` to translate 22 to 'eddsa' for backwards compatibility
|
|
1640
|
+
/** @deprecated use `eddsaLegacy` instead */
|
|
1641
|
+
ed25519Legacy: 22,
|
|
1642
|
+
/** @deprecated use `eddsaLegacy` instead */
|
|
1643
|
+
eddsa: 22,
|
|
1644
|
+
/** Reserved for AEDH */
|
|
1645
|
+
aedh: 23,
|
|
1646
|
+
/** Reserved for AEDSA */
|
|
1647
|
+
aedsa: 24,
|
|
1648
|
+
/** X25519 (Encrypt only) */
|
|
1649
|
+
x25519: 25,
|
|
1650
|
+
/** X448 (Encrypt only) */
|
|
1651
|
+
x448: 26,
|
|
1652
|
+
/** Ed25519 (Sign only) */
|
|
1653
|
+
ed25519: 27,
|
|
1654
|
+
/** Ed448 (Sign only) */
|
|
1655
|
+
ed448: 28,
|
|
1656
|
+
/** Symmetric authenticated encryption algorithms */
|
|
1657
|
+
aead: 100,
|
|
1658
|
+
/** Authentication using CMAC */
|
|
1659
|
+
hmac: 101
|
|
1660
|
+
},
|
|
1661
|
+
|
|
1662
|
+
/** {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC4880, section 9.2}
|
|
1663
|
+
* @enum {Integer}
|
|
1664
|
+
* @readonly
|
|
1665
|
+
*/
|
|
1666
|
+
symmetric: {
|
|
1667
|
+
plaintext: 0,
|
|
1668
|
+
/** Not implemented! */
|
|
1669
|
+
idea: 1,
|
|
1670
|
+
tripledes: 2,
|
|
1671
|
+
cast5: 3,
|
|
1672
|
+
blowfish: 4,
|
|
1673
|
+
aes128: 7,
|
|
1674
|
+
aes192: 8,
|
|
1675
|
+
aes256: 9,
|
|
1676
|
+
twofish: 10
|
|
1677
|
+
},
|
|
1678
|
+
|
|
1679
|
+
/** {@link https://tools.ietf.org/html/rfc4880#section-9.3|RFC4880, section 9.3}
|
|
1680
|
+
* @enum {Integer}
|
|
1681
|
+
* @readonly
|
|
1682
|
+
*/
|
|
1683
|
+
compression: {
|
|
1684
|
+
uncompressed: 0,
|
|
1685
|
+
/** RFC1951 */
|
|
1686
|
+
zip: 1,
|
|
1687
|
+
/** RFC1950 */
|
|
1688
|
+
zlib: 2,
|
|
1689
|
+
bzip2: 3
|
|
1690
|
+
},
|
|
1691
|
+
|
|
1692
|
+
/** {@link https://tools.ietf.org/html/rfc4880#section-9.4|RFC4880, section 9.4}
|
|
1693
|
+
* @enum {Integer}
|
|
1694
|
+
* @readonly
|
|
1695
|
+
*/
|
|
1696
|
+
hash: {
|
|
1697
|
+
md5: 1,
|
|
1698
|
+
sha1: 2,
|
|
1699
|
+
ripemd: 3,
|
|
1700
|
+
sha256: 8,
|
|
1701
|
+
sha384: 9,
|
|
1702
|
+
sha512: 10,
|
|
1703
|
+
sha224: 11
|
|
1704
|
+
},
|
|
1705
|
+
|
|
1706
|
+
/** A list of hash names as accepted by webCrypto functions.
|
|
1707
|
+
* {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest|Parameters, algo}
|
|
1708
|
+
* @enum {String}
|
|
1709
|
+
*/
|
|
1710
|
+
webHash: {
|
|
1711
|
+
'SHA-1': 2,
|
|
1712
|
+
'SHA-256': 8,
|
|
1713
|
+
'SHA-384': 9,
|
|
1714
|
+
'SHA-512': 10
|
|
1715
|
+
},
|
|
1716
|
+
|
|
1717
|
+
/** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-9.6|RFC4880bis-04, section 9.6}
|
|
1718
|
+
* @enum {Integer}
|
|
1719
|
+
* @readonly
|
|
1720
|
+
*/
|
|
1721
|
+
aead: {
|
|
1722
|
+
eax: 1,
|
|
1723
|
+
ocb: 2,
|
|
1724
|
+
experimentalGCM: 100 // Private algorithm
|
|
1725
|
+
},
|
|
1726
|
+
|
|
1727
|
+
/** A list of packet types and numeric tags associated with them.
|
|
1728
|
+
* @enum {Integer}
|
|
1729
|
+
* @readonly
|
|
1730
|
+
*/
|
|
1731
|
+
packet: {
|
|
1732
|
+
publicKeyEncryptedSessionKey: 1,
|
|
1733
|
+
signature: 2,
|
|
1734
|
+
symEncryptedSessionKey: 3,
|
|
1735
|
+
onePassSignature: 4,
|
|
1736
|
+
secretKey: 5,
|
|
1737
|
+
publicKey: 6,
|
|
1738
|
+
secretSubkey: 7,
|
|
1739
|
+
compressedData: 8,
|
|
1740
|
+
symmetricallyEncryptedData: 9,
|
|
1741
|
+
marker: 10,
|
|
1742
|
+
literalData: 11,
|
|
1743
|
+
trust: 12,
|
|
1744
|
+
userID: 13,
|
|
1745
|
+
publicSubkey: 14,
|
|
1746
|
+
userAttribute: 17,
|
|
1747
|
+
symEncryptedIntegrityProtectedData: 18,
|
|
1748
|
+
modificationDetectionCode: 19,
|
|
1749
|
+
aeadEncryptedData: 20 // see IETF draft: https://tools.ietf.org/html/draft-ford-openpgp-format-00#section-2.1
|
|
1750
|
+
},
|
|
1751
|
+
|
|
1752
|
+
/** Data types in the literal packet
|
|
1753
|
+
* @enum {Integer}
|
|
1754
|
+
* @readonly
|
|
1755
|
+
*/
|
|
1756
|
+
literal: {
|
|
1757
|
+
/** Binary data 'b' */
|
|
1758
|
+
binary: 'b'.charCodeAt(),
|
|
1759
|
+
/** Text data 't' */
|
|
1760
|
+
text: 't'.charCodeAt(),
|
|
1761
|
+
/** Utf8 data 'u' */
|
|
1762
|
+
utf8: 'u'.charCodeAt(),
|
|
1763
|
+
/** MIME message body part 'm' */
|
|
1764
|
+
mime: 'm'.charCodeAt()
|
|
1765
|
+
},
|
|
1766
|
+
|
|
1767
|
+
|
|
1768
|
+
/** One pass signature packet type
|
|
1769
|
+
* @enum {Integer}
|
|
1770
|
+
* @readonly
|
|
1771
|
+
*/
|
|
1772
|
+
signature: {
|
|
1773
|
+
/** 0x00: Signature of a binary document. */
|
|
1774
|
+
binary: 0,
|
|
1775
|
+
/** 0x01: Signature of a canonical text document.
|
|
1776
|
+
*
|
|
1777
|
+
* Canonicalyzing the document by converting line endings. */
|
|
1778
|
+
text: 1,
|
|
1779
|
+
/** 0x02: Standalone signature.
|
|
1780
|
+
*
|
|
1781
|
+
* This signature is a signature of only its own subpacket contents.
|
|
1782
|
+
* It is calculated identically to a signature over a zero-lengh
|
|
1783
|
+
* binary document. Note that it doesn't make sense to have a V3
|
|
1784
|
+
* standalone signature. */
|
|
1785
|
+
standalone: 2,
|
|
1786
|
+
/** 0x10: Generic certification of a User ID and Public-Key packet.
|
|
1787
|
+
*
|
|
1788
|
+
* The issuer of this certification does not make any particular
|
|
1789
|
+
* assertion as to how well the certifier has checked that the owner
|
|
1790
|
+
* of the key is in fact the person described by the User ID. */
|
|
1791
|
+
certGeneric: 16,
|
|
1792
|
+
/** 0x11: Persona certification of a User ID and Public-Key packet.
|
|
1793
|
+
*
|
|
1794
|
+
* The issuer of this certification has not done any verification of
|
|
1795
|
+
* the claim that the owner of this key is the User ID specified. */
|
|
1796
|
+
certPersona: 17,
|
|
1797
|
+
/** 0x12: Casual certification of a User ID and Public-Key packet.
|
|
1798
|
+
*
|
|
1799
|
+
* The issuer of this certification has done some casual
|
|
1800
|
+
* verification of the claim of identity. */
|
|
1801
|
+
certCasual: 18,
|
|
1802
|
+
/** 0x13: Positive certification of a User ID and Public-Key packet.
|
|
1803
|
+
*
|
|
1804
|
+
* The issuer of this certification has done substantial
|
|
1805
|
+
* verification of the claim of identity.
|
|
1806
|
+
*
|
|
1807
|
+
* Most OpenPGP implementations make their "key signatures" as 0x10
|
|
1808
|
+
* certifications. Some implementations can issue 0x11-0x13
|
|
1809
|
+
* certifications, but few differentiate between the types. */
|
|
1810
|
+
certPositive: 19,
|
|
1811
|
+
/** 0x30: Certification revocation signature
|
|
1812
|
+
*
|
|
1813
|
+
* This signature revokes an earlier User ID certification signature
|
|
1814
|
+
* (signature class 0x10 through 0x13) or direct-key signature
|
|
1815
|
+
* (0x1F). It should be issued by the same key that issued the
|
|
1816
|
+
* revoked signature or an authorized revocation key. The signature
|
|
1817
|
+
* is computed over the same data as the certificate that it
|
|
1818
|
+
* revokes, and should have a later creation date than that
|
|
1819
|
+
* certificate. */
|
|
1820
|
+
certRevocation: 48,
|
|
1821
|
+
/** 0x18: Subkey Binding Signature
|
|
1822
|
+
*
|
|
1823
|
+
* This signature is a statement by the top-level signing key that
|
|
1824
|
+
* indicates that it owns the subkey. This signature is calculated
|
|
1825
|
+
* directly on the primary key and subkey, and not on any User ID or
|
|
1826
|
+
* other packets. A signature that binds a signing subkey MUST have
|
|
1827
|
+
* an Embedded Signature subpacket in this binding signature that
|
|
1828
|
+
* contains a 0x19 signature made by the signing subkey on the
|
|
1829
|
+
* primary key and subkey. */
|
|
1830
|
+
subkeyBinding: 24,
|
|
1831
|
+
/** 0x19: Primary Key Binding Signature
|
|
1832
|
+
*
|
|
1833
|
+
* This signature is a statement by a signing subkey, indicating
|
|
1834
|
+
* that it is owned by the primary key and subkey. This signature
|
|
1835
|
+
* is calculated the same way as a 0x18 signature: directly on the
|
|
1836
|
+
* primary key and subkey, and not on any User ID or other packets.
|
|
1837
|
+
*
|
|
1838
|
+
* When a signature is made over a key, the hash data starts with the
|
|
1839
|
+
* octet 0x99, followed by a two-octet length of the key, and then body
|
|
1840
|
+
* of the key packet. (Note that this is an old-style packet header for
|
|
1841
|
+
* a key packet with two-octet length.) A subkey binding signature
|
|
1842
|
+
* (type 0x18) or primary key binding signature (type 0x19) then hashes
|
|
1843
|
+
* the subkey using the same format as the main key (also using 0x99 as
|
|
1844
|
+
* the first octet). */
|
|
1845
|
+
keyBinding: 25,
|
|
1846
|
+
/** 0x1F: Signature directly on a key
|
|
1847
|
+
*
|
|
1848
|
+
* This signature is calculated directly on a key. It binds the
|
|
1849
|
+
* information in the Signature subpackets to the key, and is
|
|
1850
|
+
* appropriate to be used for subpackets that provide information
|
|
1851
|
+
* about the key, such as the Revocation Key subpacket. It is also
|
|
1852
|
+
* appropriate for statements that non-self certifiers want to make
|
|
1853
|
+
* about the key itself, rather than the binding between a key and a
|
|
1854
|
+
* name. */
|
|
1855
|
+
key: 31,
|
|
1856
|
+
/** 0x20: Key revocation signature
|
|
1857
|
+
*
|
|
1858
|
+
* The signature is calculated directly on the key being revoked. A
|
|
1859
|
+
* revoked key is not to be used. Only revocation signatures by the
|
|
1860
|
+
* key being revoked, or by an authorized revocation key, should be
|
|
1861
|
+
* considered valid revocation signatures.a */
|
|
1862
|
+
keyRevocation: 32,
|
|
1863
|
+
/** 0x28: Subkey revocation signature
|
|
1864
|
+
*
|
|
1865
|
+
* The signature is calculated directly on the subkey being revoked.
|
|
1866
|
+
* A revoked subkey is not to be used. Only revocation signatures
|
|
1867
|
+
* by the top-level signature key that is bound to this subkey, or
|
|
1868
|
+
* by an authorized revocation key, should be considered valid
|
|
1869
|
+
* revocation signatures.
|
|
1870
|
+
*
|
|
1871
|
+
* Key revocation signatures (types 0x20 and 0x28)
|
|
1872
|
+
* hash only the key being revoked. */
|
|
1873
|
+
subkeyRevocation: 40,
|
|
1874
|
+
/** 0x40: Timestamp signature.
|
|
1875
|
+
* This signature is only meaningful for the timestamp contained in
|
|
1876
|
+
* it. */
|
|
1877
|
+
timestamp: 64,
|
|
1878
|
+
/** 0x50: Third-Party Confirmation signature.
|
|
1879
|
+
*
|
|
1880
|
+
* This signature is a signature over some other OpenPGP Signature
|
|
1881
|
+
* packet(s). It is analogous to a notary seal on the signed data.
|
|
1882
|
+
* A third-party signature SHOULD include Signature Target
|
|
1883
|
+
* subpacket(s) to give easy identification. Note that we really do
|
|
1884
|
+
* mean SHOULD. There are plausible uses for this (such as a blind
|
|
1885
|
+
* party that only sees the signature, not the key or source
|
|
1886
|
+
* document) that cannot include a target subpacket. */
|
|
1887
|
+
thirdParty: 80
|
|
1888
|
+
},
|
|
1889
|
+
|
|
1890
|
+
/** Signature subpacket type
|
|
1891
|
+
* @enum {Integer}
|
|
1892
|
+
* @readonly
|
|
1893
|
+
*/
|
|
1894
|
+
signatureSubpacket: {
|
|
1895
|
+
signatureCreationTime: 2,
|
|
1896
|
+
signatureExpirationTime: 3,
|
|
1897
|
+
exportableCertification: 4,
|
|
1898
|
+
trustSignature: 5,
|
|
1899
|
+
regularExpression: 6,
|
|
1900
|
+
revocable: 7,
|
|
1901
|
+
keyExpirationTime: 9,
|
|
1902
|
+
placeholderBackwardsCompatibility: 10,
|
|
1903
|
+
preferredSymmetricAlgorithms: 11,
|
|
1904
|
+
revocationKey: 12,
|
|
1905
|
+
issuer: 16,
|
|
1906
|
+
notationData: 20,
|
|
1907
|
+
preferredHashAlgorithms: 21,
|
|
1908
|
+
preferredCompressionAlgorithms: 22,
|
|
1909
|
+
keyServerPreferences: 23,
|
|
1910
|
+
preferredKeyServer: 24,
|
|
1911
|
+
primaryUserID: 25,
|
|
1912
|
+
policyURI: 26,
|
|
1913
|
+
keyFlags: 27,
|
|
1914
|
+
signersUserID: 28,
|
|
1915
|
+
reasonForRevocation: 29,
|
|
1916
|
+
features: 30,
|
|
1917
|
+
signatureTarget: 31,
|
|
1918
|
+
embeddedSignature: 32,
|
|
1919
|
+
issuerFingerprint: 33,
|
|
1920
|
+
preferredAEADAlgorithms: 34
|
|
1921
|
+
},
|
|
1922
|
+
|
|
1923
|
+
/** Key flags
|
|
1924
|
+
* @enum {Integer}
|
|
1925
|
+
* @readonly
|
|
1926
|
+
*/
|
|
1927
|
+
keyFlags: {
|
|
1928
|
+
/** 0x01 - This key may be used to certify other keys. */
|
|
1929
|
+
certifyKeys: 1,
|
|
1930
|
+
/** 0x02 - This key may be used to sign data. */
|
|
1931
|
+
signData: 2,
|
|
1932
|
+
/** 0x04 - This key may be used to encrypt communications. */
|
|
1933
|
+
encryptCommunication: 4,
|
|
1934
|
+
/** 0x08 - This key may be used to encrypt storage. */
|
|
1935
|
+
encryptStorage: 8,
|
|
1936
|
+
/** 0x10 - The private component of this key may have been split
|
|
1937
|
+
* by a secret-sharing mechanism. */
|
|
1938
|
+
splitPrivateKey: 16,
|
|
1939
|
+
/** 0x20 - This key may be used for authentication. */
|
|
1940
|
+
authentication: 32,
|
|
1941
|
+
/** This key may be used for forwarded communications */
|
|
1942
|
+
forwardedCommunication: 64,
|
|
1943
|
+
/** 0x80 - The private component of this key may be in the
|
|
1944
|
+
* possession of more than one person. */
|
|
1945
|
+
sharedPrivateKey: 128
|
|
1946
|
+
},
|
|
1947
|
+
|
|
1948
|
+
/** Armor type
|
|
1949
|
+
* @enum {Integer}
|
|
1950
|
+
* @readonly
|
|
1951
|
+
*/
|
|
1952
|
+
armor: {
|
|
1953
|
+
multipartSection: 0,
|
|
1954
|
+
multipartLast: 1,
|
|
1955
|
+
signed: 2,
|
|
1956
|
+
message: 3,
|
|
1957
|
+
publicKey: 4,
|
|
1958
|
+
privateKey: 5,
|
|
1959
|
+
signature: 6
|
|
1960
|
+
},
|
|
1961
|
+
|
|
1962
|
+
/** {@link https://tools.ietf.org/html/rfc4880#section-5.2.3.23|RFC4880, section 5.2.3.23}
|
|
1963
|
+
* @enum {Integer}
|
|
1964
|
+
* @readonly
|
|
1965
|
+
*/
|
|
1966
|
+
reasonForRevocation: {
|
|
1967
|
+
/** No reason specified (key revocations or cert revocations) */
|
|
1968
|
+
noReason: 0,
|
|
1969
|
+
/** Key is superseded (key revocations) */
|
|
1970
|
+
keySuperseded: 1,
|
|
1971
|
+
/** Key material has been compromised (key revocations) */
|
|
1972
|
+
keyCompromised: 2,
|
|
1973
|
+
/** Key is retired and no longer used (key revocations) */
|
|
1974
|
+
keyRetired: 3,
|
|
1975
|
+
/** User ID information is no longer valid (cert revocations) */
|
|
1976
|
+
userIDInvalid: 32
|
|
1977
|
+
},
|
|
1978
|
+
|
|
1979
|
+
/** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-5.2.3.25|RFC4880bis-04, section 5.2.3.25}
|
|
1980
|
+
* @enum {Integer}
|
|
1981
|
+
* @readonly
|
|
1982
|
+
*/
|
|
1983
|
+
features: {
|
|
1984
|
+
/** 0x01 - Modification Detection (packets 18 and 19) */
|
|
1985
|
+
modificationDetection: 1,
|
|
1986
|
+
/** 0x02 - AEAD Encrypted Data Packet (packet 20) and version 5
|
|
1987
|
+
* Symmetric-Key Encrypted Session Key Packets (packet 3) */
|
|
1988
|
+
aead: 2,
|
|
1989
|
+
/** 0x04 - Version 5 Public-Key Packet format and corresponding new
|
|
1990
|
+
* fingerprint format */
|
|
1991
|
+
v5Keys: 4
|
|
1992
|
+
},
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Asserts validity of given value and converts from string/integer to integer.
|
|
1996
|
+
* @param {Object} type target enum type
|
|
1997
|
+
* @param {String|Integer} e value to check and/or convert
|
|
1998
|
+
* @returns {Integer} enum value if it exists
|
|
1999
|
+
* @throws {Error} if the value is invalid
|
|
2000
|
+
*/
|
|
2001
|
+
write: function(type, e) {
|
|
2002
|
+
if (typeof e === 'number') {
|
|
2003
|
+
e = this.read(type, e);
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
if (type[e] !== undefined) {
|
|
2007
|
+
return type[e];
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
throw new Error('Invalid enum value.');
|
|
2011
|
+
},
|
|
2012
|
+
|
|
2013
|
+
/**
|
|
2014
|
+
* Converts enum integer value to the corresponding string, if it exists.
|
|
2015
|
+
* @param {Object} type target enum type
|
|
2016
|
+
* @param {Integer} e value to convert
|
|
2017
|
+
* @returns {String} name of enum value if it exists
|
|
2018
|
+
* @throws {Error} if the value is invalid
|
|
2019
|
+
*/
|
|
2020
|
+
read: function(type, e) {
|
|
2021
|
+
if (!type[byValue]) {
|
|
2022
|
+
type[byValue] = [];
|
|
2023
|
+
Object.entries(type).forEach(([key, value]) => {
|
|
2024
|
+
type[byValue][value] = key;
|
|
2025
|
+
});
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
if (type[byValue][e] !== undefined) {
|
|
2029
|
+
return type[byValue][e];
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
throw new Error('Invalid enum value.');
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
|
|
1510
2036
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
1511
2037
|
|
|
1512
2038
|
const debugMode = (() => {
|
|
@@ -2088,6 +2614,12 @@ const util = {
|
|
|
2088
2614
|
*/
|
|
2089
2615
|
selectUint8: function(cond, a, b) {
|
|
2090
2616
|
return (a & (256 - cond)) | (b & (255 + cond));
|
|
2617
|
+
},
|
|
2618
|
+
/**
|
|
2619
|
+
* @param {module:enums.symmetric} cipherAlgo
|
|
2620
|
+
*/
|
|
2621
|
+
isAES: function(cipherAlgo) {
|
|
2622
|
+
return cipherAlgo === enums.symmetric.aes128 || cipherAlgo === enums.symmetric.aes192 || cipherAlgo === enums.symmetric.aes256;
|
|
2091
2623
|
}
|
|
2092
2624
|
};
|
|
2093
2625
|
|
|
@@ -2202,517 +2734,6 @@ function uint8ArrayToB64(bytes, url) {
|
|
|
2202
2734
|
return encoded;
|
|
2203
2735
|
}
|
|
2204
2736
|
|
|
2205
|
-
/**
|
|
2206
|
-
* @module enums
|
|
2207
|
-
*/
|
|
2208
|
-
|
|
2209
|
-
const byValue = Symbol('byValue');
|
|
2210
|
-
|
|
2211
|
-
var enums = {
|
|
2212
|
-
|
|
2213
|
-
/** Maps curve names under various standards to one
|
|
2214
|
-
* @see {@link https://wiki.gnupg.org/ECC|ECC - GnuPG wiki}
|
|
2215
|
-
* @enum {String}
|
|
2216
|
-
* @readonly
|
|
2217
|
-
*/
|
|
2218
|
-
curve: {
|
|
2219
|
-
/** NIST P-256 Curve */
|
|
2220
|
-
'p256': 'p256',
|
|
2221
|
-
'P-256': 'p256',
|
|
2222
|
-
'secp256r1': 'p256',
|
|
2223
|
-
'prime256v1': 'p256',
|
|
2224
|
-
'1.2.840.10045.3.1.7': 'p256',
|
|
2225
|
-
'2a8648ce3d030107': 'p256',
|
|
2226
|
-
'2A8648CE3D030107': 'p256',
|
|
2227
|
-
|
|
2228
|
-
/** NIST P-384 Curve */
|
|
2229
|
-
'p384': 'p384',
|
|
2230
|
-
'P-384': 'p384',
|
|
2231
|
-
'secp384r1': 'p384',
|
|
2232
|
-
'1.3.132.0.34': 'p384',
|
|
2233
|
-
'2b81040022': 'p384',
|
|
2234
|
-
'2B81040022': 'p384',
|
|
2235
|
-
|
|
2236
|
-
/** NIST P-521 Curve */
|
|
2237
|
-
'p521': 'p521',
|
|
2238
|
-
'P-521': 'p521',
|
|
2239
|
-
'secp521r1': 'p521',
|
|
2240
|
-
'1.3.132.0.35': 'p521',
|
|
2241
|
-
'2b81040023': 'p521',
|
|
2242
|
-
'2B81040023': 'p521',
|
|
2243
|
-
|
|
2244
|
-
/** SECG SECP256k1 Curve */
|
|
2245
|
-
'secp256k1': 'secp256k1',
|
|
2246
|
-
'1.3.132.0.10': 'secp256k1',
|
|
2247
|
-
'2b8104000a': 'secp256k1',
|
|
2248
|
-
'2B8104000A': 'secp256k1',
|
|
2249
|
-
|
|
2250
|
-
/** Ed25519 */
|
|
2251
|
-
'ED25519': 'ed25519',
|
|
2252
|
-
'ed25519': 'ed25519',
|
|
2253
|
-
'Ed25519': 'ed25519',
|
|
2254
|
-
'1.3.6.1.4.1.11591.15.1': 'ed25519',
|
|
2255
|
-
'2b06010401da470f01': 'ed25519',
|
|
2256
|
-
'2B06010401DA470F01': 'ed25519',
|
|
2257
|
-
|
|
2258
|
-
/** Curve25519 */
|
|
2259
|
-
'X25519': 'curve25519',
|
|
2260
|
-
'cv25519': 'curve25519',
|
|
2261
|
-
'curve25519': 'curve25519',
|
|
2262
|
-
'Curve25519': 'curve25519',
|
|
2263
|
-
'1.3.6.1.4.1.3029.1.5.1': 'curve25519',
|
|
2264
|
-
'2b060104019755010501': 'curve25519',
|
|
2265
|
-
'2B060104019755010501': 'curve25519',
|
|
2266
|
-
|
|
2267
|
-
/** BrainpoolP256r1 Curve */
|
|
2268
|
-
'brainpoolP256r1': 'brainpoolP256r1',
|
|
2269
|
-
'1.3.36.3.3.2.8.1.1.7': 'brainpoolP256r1',
|
|
2270
|
-
'2b2403030208010107': 'brainpoolP256r1',
|
|
2271
|
-
'2B2403030208010107': 'brainpoolP256r1',
|
|
2272
|
-
|
|
2273
|
-
/** BrainpoolP384r1 Curve */
|
|
2274
|
-
'brainpoolP384r1': 'brainpoolP384r1',
|
|
2275
|
-
'1.3.36.3.3.2.8.1.1.11': 'brainpoolP384r1',
|
|
2276
|
-
'2b240303020801010b': 'brainpoolP384r1',
|
|
2277
|
-
'2B240303020801010B': 'brainpoolP384r1',
|
|
2278
|
-
|
|
2279
|
-
/** BrainpoolP512r1 Curve */
|
|
2280
|
-
'brainpoolP512r1': 'brainpoolP512r1',
|
|
2281
|
-
'1.3.36.3.3.2.8.1.1.13': 'brainpoolP512r1',
|
|
2282
|
-
'2b240303020801010d': 'brainpoolP512r1',
|
|
2283
|
-
'2B240303020801010D': 'brainpoolP512r1'
|
|
2284
|
-
},
|
|
2285
|
-
|
|
2286
|
-
/** KDF parameters flags
|
|
2287
|
-
* Non-standard extensions (for now) to allow email forwarding
|
|
2288
|
-
* @enum {Integer}
|
|
2289
|
-
* @readonly
|
|
2290
|
-
*/
|
|
2291
|
-
kdfFlags: {
|
|
2292
|
-
/** Specify fingerprint to use instead of the recipient's */
|
|
2293
|
-
replace_fingerprint: 0x01,
|
|
2294
|
-
/** Specify custom parameters to use in the KDF digest computation */
|
|
2295
|
-
replace_kdf_params: 0x02
|
|
2296
|
-
},
|
|
2297
|
-
|
|
2298
|
-
/** A string to key specifier type
|
|
2299
|
-
* @enum {Integer}
|
|
2300
|
-
* @readonly
|
|
2301
|
-
*/
|
|
2302
|
-
s2k: {
|
|
2303
|
-
simple: 0,
|
|
2304
|
-
salted: 1,
|
|
2305
|
-
iterated: 3,
|
|
2306
|
-
argon2: 4,
|
|
2307
|
-
gnu: 101
|
|
2308
|
-
},
|
|
2309
|
-
|
|
2310
|
-
/** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-9.1|RFC4880bis-04, section 9.1}
|
|
2311
|
-
* @enum {Integer}
|
|
2312
|
-
* @readonly
|
|
2313
|
-
*/
|
|
2314
|
-
publicKey: {
|
|
2315
|
-
/** RSA (Encrypt or Sign) [HAC] */
|
|
2316
|
-
rsaEncryptSign: 1,
|
|
2317
|
-
/** RSA (Encrypt only) [HAC] */
|
|
2318
|
-
rsaEncrypt: 2,
|
|
2319
|
-
/** RSA (Sign only) [HAC] */
|
|
2320
|
-
rsaSign: 3,
|
|
2321
|
-
/** Elgamal (Encrypt only) [ELGAMAL] [HAC] */
|
|
2322
|
-
elgamal: 16,
|
|
2323
|
-
/** DSA (Sign only) [FIPS186] [HAC] */
|
|
2324
|
-
dsa: 17,
|
|
2325
|
-
/** ECDH (Encrypt only) [RFC6637] */
|
|
2326
|
-
ecdh: 18,
|
|
2327
|
-
/** ECDSA (Sign only) [RFC6637] */
|
|
2328
|
-
ecdsa: 19,
|
|
2329
|
-
/** EdDSA (Sign only)
|
|
2330
|
-
* [{@link https://tools.ietf.org/html/draft-koch-eddsa-for-openpgp-04|Draft RFC}] */
|
|
2331
|
-
eddsa: 22,
|
|
2332
|
-
/** Reserved for AEDH */
|
|
2333
|
-
aedh: 23,
|
|
2334
|
-
/** Reserved for AEDSA */
|
|
2335
|
-
aedsa: 24,
|
|
2336
|
-
/** Symmetric authenticated encryption algorithms */
|
|
2337
|
-
aead: 100,
|
|
2338
|
-
/** Authentication using CMAC */
|
|
2339
|
-
hmac: 101
|
|
2340
|
-
},
|
|
2341
|
-
|
|
2342
|
-
/** {@link https://tools.ietf.org/html/rfc4880#section-9.2|RFC4880, section 9.2}
|
|
2343
|
-
* @enum {Integer}
|
|
2344
|
-
* @readonly
|
|
2345
|
-
*/
|
|
2346
|
-
symmetric: {
|
|
2347
|
-
plaintext: 0,
|
|
2348
|
-
/** Not implemented! */
|
|
2349
|
-
idea: 1,
|
|
2350
|
-
tripledes: 2,
|
|
2351
|
-
cast5: 3,
|
|
2352
|
-
blowfish: 4,
|
|
2353
|
-
aes128: 7,
|
|
2354
|
-
aes192: 8,
|
|
2355
|
-
aes256: 9,
|
|
2356
|
-
twofish: 10
|
|
2357
|
-
},
|
|
2358
|
-
|
|
2359
|
-
/** {@link https://tools.ietf.org/html/rfc4880#section-9.3|RFC4880, section 9.3}
|
|
2360
|
-
* @enum {Integer}
|
|
2361
|
-
* @readonly
|
|
2362
|
-
*/
|
|
2363
|
-
compression: {
|
|
2364
|
-
uncompressed: 0,
|
|
2365
|
-
/** RFC1951 */
|
|
2366
|
-
zip: 1,
|
|
2367
|
-
/** RFC1950 */
|
|
2368
|
-
zlib: 2,
|
|
2369
|
-
bzip2: 3
|
|
2370
|
-
},
|
|
2371
|
-
|
|
2372
|
-
/** {@link https://tools.ietf.org/html/rfc4880#section-9.4|RFC4880, section 9.4}
|
|
2373
|
-
* @enum {Integer}
|
|
2374
|
-
* @readonly
|
|
2375
|
-
*/
|
|
2376
|
-
hash: {
|
|
2377
|
-
md5: 1,
|
|
2378
|
-
sha1: 2,
|
|
2379
|
-
ripemd: 3,
|
|
2380
|
-
sha256: 8,
|
|
2381
|
-
sha384: 9,
|
|
2382
|
-
sha512: 10,
|
|
2383
|
-
sha224: 11
|
|
2384
|
-
},
|
|
2385
|
-
|
|
2386
|
-
/** A list of hash names as accepted by webCrypto functions.
|
|
2387
|
-
* {@link https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest|Parameters, algo}
|
|
2388
|
-
* @enum {String}
|
|
2389
|
-
*/
|
|
2390
|
-
webHash: {
|
|
2391
|
-
'SHA-1': 2,
|
|
2392
|
-
'SHA-256': 8,
|
|
2393
|
-
'SHA-384': 9,
|
|
2394
|
-
'SHA-512': 10
|
|
2395
|
-
},
|
|
2396
|
-
|
|
2397
|
-
/** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-9.6|RFC4880bis-04, section 9.6}
|
|
2398
|
-
* @enum {Integer}
|
|
2399
|
-
* @readonly
|
|
2400
|
-
*/
|
|
2401
|
-
aead: {
|
|
2402
|
-
eax: 1,
|
|
2403
|
-
ocb: 2,
|
|
2404
|
-
experimentalGCM: 100 // Private algorithm
|
|
2405
|
-
},
|
|
2406
|
-
|
|
2407
|
-
/** A list of packet types and numeric tags associated with them.
|
|
2408
|
-
* @enum {Integer}
|
|
2409
|
-
* @readonly
|
|
2410
|
-
*/
|
|
2411
|
-
packet: {
|
|
2412
|
-
publicKeyEncryptedSessionKey: 1,
|
|
2413
|
-
signature: 2,
|
|
2414
|
-
symEncryptedSessionKey: 3,
|
|
2415
|
-
onePassSignature: 4,
|
|
2416
|
-
secretKey: 5,
|
|
2417
|
-
publicKey: 6,
|
|
2418
|
-
secretSubkey: 7,
|
|
2419
|
-
compressedData: 8,
|
|
2420
|
-
symmetricallyEncryptedData: 9,
|
|
2421
|
-
marker: 10,
|
|
2422
|
-
literalData: 11,
|
|
2423
|
-
trust: 12,
|
|
2424
|
-
userID: 13,
|
|
2425
|
-
publicSubkey: 14,
|
|
2426
|
-
userAttribute: 17,
|
|
2427
|
-
symEncryptedIntegrityProtectedData: 18,
|
|
2428
|
-
modificationDetectionCode: 19,
|
|
2429
|
-
aeadEncryptedData: 20 // see IETF draft: https://tools.ietf.org/html/draft-ford-openpgp-format-00#section-2.1
|
|
2430
|
-
},
|
|
2431
|
-
|
|
2432
|
-
/** Data types in the literal packet
|
|
2433
|
-
* @enum {Integer}
|
|
2434
|
-
* @readonly
|
|
2435
|
-
*/
|
|
2436
|
-
literal: {
|
|
2437
|
-
/** Binary data 'b' */
|
|
2438
|
-
binary: 'b'.charCodeAt(),
|
|
2439
|
-
/** Text data 't' */
|
|
2440
|
-
text: 't'.charCodeAt(),
|
|
2441
|
-
/** Utf8 data 'u' */
|
|
2442
|
-
utf8: 'u'.charCodeAt(),
|
|
2443
|
-
/** MIME message body part 'm' */
|
|
2444
|
-
mime: 'm'.charCodeAt()
|
|
2445
|
-
},
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
/** One pass signature packet type
|
|
2449
|
-
* @enum {Integer}
|
|
2450
|
-
* @readonly
|
|
2451
|
-
*/
|
|
2452
|
-
signature: {
|
|
2453
|
-
/** 0x00: Signature of a binary document. */
|
|
2454
|
-
binary: 0,
|
|
2455
|
-
/** 0x01: Signature of a canonical text document.
|
|
2456
|
-
*
|
|
2457
|
-
* Canonicalyzing the document by converting line endings. */
|
|
2458
|
-
text: 1,
|
|
2459
|
-
/** 0x02: Standalone signature.
|
|
2460
|
-
*
|
|
2461
|
-
* This signature is a signature of only its own subpacket contents.
|
|
2462
|
-
* It is calculated identically to a signature over a zero-lengh
|
|
2463
|
-
* binary document. Note that it doesn't make sense to have a V3
|
|
2464
|
-
* standalone signature. */
|
|
2465
|
-
standalone: 2,
|
|
2466
|
-
/** 0x10: Generic certification of a User ID and Public-Key packet.
|
|
2467
|
-
*
|
|
2468
|
-
* The issuer of this certification does not make any particular
|
|
2469
|
-
* assertion as to how well the certifier has checked that the owner
|
|
2470
|
-
* of the key is in fact the person described by the User ID. */
|
|
2471
|
-
certGeneric: 16,
|
|
2472
|
-
/** 0x11: Persona certification of a User ID and Public-Key packet.
|
|
2473
|
-
*
|
|
2474
|
-
* The issuer of this certification has not done any verification of
|
|
2475
|
-
* the claim that the owner of this key is the User ID specified. */
|
|
2476
|
-
certPersona: 17,
|
|
2477
|
-
/** 0x12: Casual certification of a User ID and Public-Key packet.
|
|
2478
|
-
*
|
|
2479
|
-
* The issuer of this certification has done some casual
|
|
2480
|
-
* verification of the claim of identity. */
|
|
2481
|
-
certCasual: 18,
|
|
2482
|
-
/** 0x13: Positive certification of a User ID and Public-Key packet.
|
|
2483
|
-
*
|
|
2484
|
-
* The issuer of this certification has done substantial
|
|
2485
|
-
* verification of the claim of identity.
|
|
2486
|
-
*
|
|
2487
|
-
* Most OpenPGP implementations make their "key signatures" as 0x10
|
|
2488
|
-
* certifications. Some implementations can issue 0x11-0x13
|
|
2489
|
-
* certifications, but few differentiate between the types. */
|
|
2490
|
-
certPositive: 19,
|
|
2491
|
-
/** 0x30: Certification revocation signature
|
|
2492
|
-
*
|
|
2493
|
-
* This signature revokes an earlier User ID certification signature
|
|
2494
|
-
* (signature class 0x10 through 0x13) or direct-key signature
|
|
2495
|
-
* (0x1F). It should be issued by the same key that issued the
|
|
2496
|
-
* revoked signature or an authorized revocation key. The signature
|
|
2497
|
-
* is computed over the same data as the certificate that it
|
|
2498
|
-
* revokes, and should have a later creation date than that
|
|
2499
|
-
* certificate. */
|
|
2500
|
-
certRevocation: 48,
|
|
2501
|
-
/** 0x18: Subkey Binding Signature
|
|
2502
|
-
*
|
|
2503
|
-
* This signature is a statement by the top-level signing key that
|
|
2504
|
-
* indicates that it owns the subkey. This signature is calculated
|
|
2505
|
-
* directly on the primary key and subkey, and not on any User ID or
|
|
2506
|
-
* other packets. A signature that binds a signing subkey MUST have
|
|
2507
|
-
* an Embedded Signature subpacket in this binding signature that
|
|
2508
|
-
* contains a 0x19 signature made by the signing subkey on the
|
|
2509
|
-
* primary key and subkey. */
|
|
2510
|
-
subkeyBinding: 24,
|
|
2511
|
-
/** 0x19: Primary Key Binding Signature
|
|
2512
|
-
*
|
|
2513
|
-
* This signature is a statement by a signing subkey, indicating
|
|
2514
|
-
* that it is owned by the primary key and subkey. This signature
|
|
2515
|
-
* is calculated the same way as a 0x18 signature: directly on the
|
|
2516
|
-
* primary key and subkey, and not on any User ID or other packets.
|
|
2517
|
-
*
|
|
2518
|
-
* When a signature is made over a key, the hash data starts with the
|
|
2519
|
-
* octet 0x99, followed by a two-octet length of the key, and then body
|
|
2520
|
-
* of the key packet. (Note that this is an old-style packet header for
|
|
2521
|
-
* a key packet with two-octet length.) A subkey binding signature
|
|
2522
|
-
* (type 0x18) or primary key binding signature (type 0x19) then hashes
|
|
2523
|
-
* the subkey using the same format as the main key (also using 0x99 as
|
|
2524
|
-
* the first octet). */
|
|
2525
|
-
keyBinding: 25,
|
|
2526
|
-
/** 0x1F: Signature directly on a key
|
|
2527
|
-
*
|
|
2528
|
-
* This signature is calculated directly on a key. It binds the
|
|
2529
|
-
* information in the Signature subpackets to the key, and is
|
|
2530
|
-
* appropriate to be used for subpackets that provide information
|
|
2531
|
-
* about the key, such as the Revocation Key subpacket. It is also
|
|
2532
|
-
* appropriate for statements that non-self certifiers want to make
|
|
2533
|
-
* about the key itself, rather than the binding between a key and a
|
|
2534
|
-
* name. */
|
|
2535
|
-
key: 31,
|
|
2536
|
-
/** 0x20: Key revocation signature
|
|
2537
|
-
*
|
|
2538
|
-
* The signature is calculated directly on the key being revoked. A
|
|
2539
|
-
* revoked key is not to be used. Only revocation signatures by the
|
|
2540
|
-
* key being revoked, or by an authorized revocation key, should be
|
|
2541
|
-
* considered valid revocation signatures.a */
|
|
2542
|
-
keyRevocation: 32,
|
|
2543
|
-
/** 0x28: Subkey revocation signature
|
|
2544
|
-
*
|
|
2545
|
-
* The signature is calculated directly on the subkey being revoked.
|
|
2546
|
-
* A revoked subkey is not to be used. Only revocation signatures
|
|
2547
|
-
* by the top-level signature key that is bound to this subkey, or
|
|
2548
|
-
* by an authorized revocation key, should be considered valid
|
|
2549
|
-
* revocation signatures.
|
|
2550
|
-
*
|
|
2551
|
-
* Key revocation signatures (types 0x20 and 0x28)
|
|
2552
|
-
* hash only the key being revoked. */
|
|
2553
|
-
subkeyRevocation: 40,
|
|
2554
|
-
/** 0x40: Timestamp signature.
|
|
2555
|
-
* This signature is only meaningful for the timestamp contained in
|
|
2556
|
-
* it. */
|
|
2557
|
-
timestamp: 64,
|
|
2558
|
-
/** 0x50: Third-Party Confirmation signature.
|
|
2559
|
-
*
|
|
2560
|
-
* This signature is a signature over some other OpenPGP Signature
|
|
2561
|
-
* packet(s). It is analogous to a notary seal on the signed data.
|
|
2562
|
-
* A third-party signature SHOULD include Signature Target
|
|
2563
|
-
* subpacket(s) to give easy identification. Note that we really do
|
|
2564
|
-
* mean SHOULD. There are plausible uses for this (such as a blind
|
|
2565
|
-
* party that only sees the signature, not the key or source
|
|
2566
|
-
* document) that cannot include a target subpacket. */
|
|
2567
|
-
thirdParty: 80
|
|
2568
|
-
},
|
|
2569
|
-
|
|
2570
|
-
/** Signature subpacket type
|
|
2571
|
-
* @enum {Integer}
|
|
2572
|
-
* @readonly
|
|
2573
|
-
*/
|
|
2574
|
-
signatureSubpacket: {
|
|
2575
|
-
signatureCreationTime: 2,
|
|
2576
|
-
signatureExpirationTime: 3,
|
|
2577
|
-
exportableCertification: 4,
|
|
2578
|
-
trustSignature: 5,
|
|
2579
|
-
regularExpression: 6,
|
|
2580
|
-
revocable: 7,
|
|
2581
|
-
keyExpirationTime: 9,
|
|
2582
|
-
placeholderBackwardsCompatibility: 10,
|
|
2583
|
-
preferredSymmetricAlgorithms: 11,
|
|
2584
|
-
revocationKey: 12,
|
|
2585
|
-
issuer: 16,
|
|
2586
|
-
notationData: 20,
|
|
2587
|
-
preferredHashAlgorithms: 21,
|
|
2588
|
-
preferredCompressionAlgorithms: 22,
|
|
2589
|
-
keyServerPreferences: 23,
|
|
2590
|
-
preferredKeyServer: 24,
|
|
2591
|
-
primaryUserID: 25,
|
|
2592
|
-
policyURI: 26,
|
|
2593
|
-
keyFlags: 27,
|
|
2594
|
-
signersUserID: 28,
|
|
2595
|
-
reasonForRevocation: 29,
|
|
2596
|
-
features: 30,
|
|
2597
|
-
signatureTarget: 31,
|
|
2598
|
-
embeddedSignature: 32,
|
|
2599
|
-
issuerFingerprint: 33,
|
|
2600
|
-
preferredAEADAlgorithms: 34
|
|
2601
|
-
},
|
|
2602
|
-
|
|
2603
|
-
/** Key flags
|
|
2604
|
-
* @enum {Integer}
|
|
2605
|
-
* @readonly
|
|
2606
|
-
*/
|
|
2607
|
-
keyFlags: {
|
|
2608
|
-
/** 0x01 - This key may be used to certify other keys. */
|
|
2609
|
-
certifyKeys: 1,
|
|
2610
|
-
/** 0x02 - This key may be used to sign data. */
|
|
2611
|
-
signData: 2,
|
|
2612
|
-
/** 0x04 - This key may be used to encrypt communications. */
|
|
2613
|
-
encryptCommunication: 4,
|
|
2614
|
-
/** 0x08 - This key may be used to encrypt storage. */
|
|
2615
|
-
encryptStorage: 8,
|
|
2616
|
-
/** 0x10 - The private component of this key may have been split
|
|
2617
|
-
* by a secret-sharing mechanism. */
|
|
2618
|
-
splitPrivateKey: 16,
|
|
2619
|
-
/** 0x20 - This key may be used for authentication. */
|
|
2620
|
-
authentication: 32,
|
|
2621
|
-
/** This key may be used for forwarded communications */
|
|
2622
|
-
forwardedCommunication: 64,
|
|
2623
|
-
/** 0x80 - The private component of this key may be in the
|
|
2624
|
-
* possession of more than one person. */
|
|
2625
|
-
sharedPrivateKey: 128
|
|
2626
|
-
},
|
|
2627
|
-
|
|
2628
|
-
/** Armor type
|
|
2629
|
-
* @enum {Integer}
|
|
2630
|
-
* @readonly
|
|
2631
|
-
*/
|
|
2632
|
-
armor: {
|
|
2633
|
-
multipartSection: 0,
|
|
2634
|
-
multipartLast: 1,
|
|
2635
|
-
signed: 2,
|
|
2636
|
-
message: 3,
|
|
2637
|
-
publicKey: 4,
|
|
2638
|
-
privateKey: 5,
|
|
2639
|
-
signature: 6
|
|
2640
|
-
},
|
|
2641
|
-
|
|
2642
|
-
/** {@link https://tools.ietf.org/html/rfc4880#section-5.2.3.23|RFC4880, section 5.2.3.23}
|
|
2643
|
-
* @enum {Integer}
|
|
2644
|
-
* @readonly
|
|
2645
|
-
*/
|
|
2646
|
-
reasonForRevocation: {
|
|
2647
|
-
/** No reason specified (key revocations or cert revocations) */
|
|
2648
|
-
noReason: 0,
|
|
2649
|
-
/** Key is superseded (key revocations) */
|
|
2650
|
-
keySuperseded: 1,
|
|
2651
|
-
/** Key material has been compromised (key revocations) */
|
|
2652
|
-
keyCompromised: 2,
|
|
2653
|
-
/** Key is retired and no longer used (key revocations) */
|
|
2654
|
-
keyRetired: 3,
|
|
2655
|
-
/** User ID information is no longer valid (cert revocations) */
|
|
2656
|
-
userIDInvalid: 32
|
|
2657
|
-
},
|
|
2658
|
-
|
|
2659
|
-
/** {@link https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-04#section-5.2.3.25|RFC4880bis-04, section 5.2.3.25}
|
|
2660
|
-
* @enum {Integer}
|
|
2661
|
-
* @readonly
|
|
2662
|
-
*/
|
|
2663
|
-
features: {
|
|
2664
|
-
/** 0x01 - Modification Detection (packets 18 and 19) */
|
|
2665
|
-
modificationDetection: 1,
|
|
2666
|
-
/** 0x02 - AEAD Encrypted Data Packet (packet 20) and version 5
|
|
2667
|
-
* Symmetric-Key Encrypted Session Key Packets (packet 3) */
|
|
2668
|
-
aead: 2,
|
|
2669
|
-
/** 0x04 - Version 5 Public-Key Packet format and corresponding new
|
|
2670
|
-
* fingerprint format */
|
|
2671
|
-
v5Keys: 4
|
|
2672
|
-
},
|
|
2673
|
-
|
|
2674
|
-
/**
|
|
2675
|
-
* Asserts validity of given value and converts from string/integer to integer.
|
|
2676
|
-
* @param {Object} type target enum type
|
|
2677
|
-
* @param {String|Integer} e value to check and/or convert
|
|
2678
|
-
* @returns {Integer} enum value if it exists
|
|
2679
|
-
* @throws {Error} if the value is invalid
|
|
2680
|
-
*/
|
|
2681
|
-
write: function(type, e) {
|
|
2682
|
-
if (typeof e === 'number') {
|
|
2683
|
-
e = this.read(type, e);
|
|
2684
|
-
}
|
|
2685
|
-
|
|
2686
|
-
if (type[e] !== undefined) {
|
|
2687
|
-
return type[e];
|
|
2688
|
-
}
|
|
2689
|
-
|
|
2690
|
-
throw new Error('Invalid enum value.');
|
|
2691
|
-
},
|
|
2692
|
-
|
|
2693
|
-
/**
|
|
2694
|
-
* Converts enum integer value to the corresponding string, if it exists.
|
|
2695
|
-
* @param {Object} type target enum type
|
|
2696
|
-
* @param {Integer} e value to convert
|
|
2697
|
-
* @returns {String} name of enum value if it exists
|
|
2698
|
-
* @throws {Error} if the value is invalid
|
|
2699
|
-
*/
|
|
2700
|
-
read: function(type, e) {
|
|
2701
|
-
if (!type[byValue]) {
|
|
2702
|
-
type[byValue] = [];
|
|
2703
|
-
Object.entries(type).forEach(([key, value]) => {
|
|
2704
|
-
type[byValue][value] = key;
|
|
2705
|
-
});
|
|
2706
|
-
}
|
|
2707
|
-
|
|
2708
|
-
if (type[byValue][e] !== undefined) {
|
|
2709
|
-
return type[byValue][e];
|
|
2710
|
-
}
|
|
2711
|
-
|
|
2712
|
-
throw new Error('Invalid enum value.');
|
|
2713
|
-
}
|
|
2714
|
-
};
|
|
2715
|
-
|
|
2716
2737
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
2717
2738
|
|
|
2718
2739
|
var config = {
|
|
@@ -2929,7 +2950,7 @@ var config = {
|
|
|
2929
2950
|
* @memberof module:config
|
|
2930
2951
|
* @property {String} versionString A version string to be included in armored messages
|
|
2931
2952
|
*/
|
|
2932
|
-
versionString: 'OpenPGP.js 5.
|
|
2953
|
+
versionString: 'OpenPGP.js 5.11.0',
|
|
2933
2954
|
/**
|
|
2934
2955
|
* @memberof module:config
|
|
2935
2956
|
* @property {String} commentString A comment string to be included in armored messages
|
|
@@ -2980,7 +3001,14 @@ var config = {
|
|
|
2980
3001
|
* @memberof module:config
|
|
2981
3002
|
* @property {Set<String>} rejectCurves {@link module:enums.curve}
|
|
2982
3003
|
*/
|
|
2983
|
-
rejectCurves: new Set([enums.curve.secp256k1])
|
|
3004
|
+
rejectCurves: new Set([enums.curve.secp256k1]),
|
|
3005
|
+
/**
|
|
3006
|
+
* Whether to validate generated EdDSA signatures before returning them, to ensure they are not faulty signatures.
|
|
3007
|
+
* This check will make signing 2-3 times slower.
|
|
3008
|
+
* Faulty signatures may be generated (in principle) if random bitflips occur at specific points in the signature
|
|
3009
|
+
* computation, and could be used to recover the signer's secret key given a second signature over the same data.
|
|
3010
|
+
*/
|
|
3011
|
+
checkEdDSAFaultySignatures: true
|
|
2984
3012
|
};
|
|
2985
3013
|
|
|
2986
3014
|
/**
|
|
@@ -3421,6 +3449,7 @@ class KeyID {
|
|
|
3421
3449
|
*/
|
|
3422
3450
|
read(bytes) {
|
|
3423
3451
|
this.bytes = util.uint8ArrayToString(bytes.subarray(0, 8));
|
|
3452
|
+
return this.bytes.length;
|
|
3424
3453
|
}
|
|
3425
3454
|
|
|
3426
3455
|
/**
|
|
@@ -9967,7 +9996,7 @@ async function encrypt(algo, key, plaintext, iv, config) {
|
|
|
9967
9996
|
if (util.getNodeCrypto() && nodeAlgos[algoName]) { // Node crypto library.
|
|
9968
9997
|
return nodeEncrypt(algo, key, plaintext, iv);
|
|
9969
9998
|
}
|
|
9970
|
-
if (
|
|
9999
|
+
if (util.isAES(algo)) {
|
|
9971
10000
|
return aesEncrypt(algo, key, plaintext, iv, config);
|
|
9972
10001
|
}
|
|
9973
10002
|
|
|
@@ -10010,7 +10039,7 @@ async function decrypt(algo, key, ciphertext, iv) {
|
|
|
10010
10039
|
if (util.getNodeCrypto() && nodeAlgos[algoName]) { // Node crypto library.
|
|
10011
10040
|
return nodeDecrypt(algo, key, ciphertext, iv);
|
|
10012
10041
|
}
|
|
10013
|
-
if (
|
|
10042
|
+
if (util.isAES(algo)) {
|
|
10014
10043
|
return aesDecrypt(algo, key, ciphertext, iv);
|
|
10015
10044
|
}
|
|
10016
10045
|
|
|
@@ -10029,7 +10058,7 @@ async function decrypt(algo, key, ciphertext, iv) {
|
|
|
10029
10058
|
let j = 0;
|
|
10030
10059
|
while (chunk ? ct.length >= block_size : ct.length) {
|
|
10031
10060
|
const decblock = cipherfn.encrypt(blockp);
|
|
10032
|
-
blockp = ct;
|
|
10061
|
+
blockp = ct.subarray(0, block_size);
|
|
10033
10062
|
for (i = 0; i < block_size; i++) {
|
|
10034
10063
|
plaintext[j++] = blockp[i] ^ decblock[i];
|
|
10035
10064
|
}
|
|
@@ -10955,42 +10984,42 @@ async function GCM(cipher, key) {
|
|
|
10955
10984
|
throw new Error('GCM mode supports only AES cipher');
|
|
10956
10985
|
}
|
|
10957
10986
|
|
|
10958
|
-
if (util.
|
|
10959
|
-
const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
|
|
10960
|
-
|
|
10987
|
+
if (util.getNodeCrypto()) { // Node crypto library
|
|
10961
10988
|
return {
|
|
10962
10989
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
|
10963
|
-
|
|
10964
|
-
|
|
10965
|
-
|
|
10966
|
-
const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
|
|
10990
|
+
const en = new nodeCrypto$4.createCipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
|
|
10991
|
+
en.setAAD(adata);
|
|
10992
|
+
const ct = Buffer$2.concat([en.update(pt), en.final(), en.getAuthTag()]); // append auth tag to ciphertext
|
|
10967
10993
|
return new Uint8Array(ct);
|
|
10968
10994
|
},
|
|
10969
10995
|
|
|
10970
10996
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
|
10971
|
-
|
|
10972
|
-
|
|
10973
|
-
|
|
10974
|
-
const pt =
|
|
10997
|
+
const de = new nodeCrypto$4.createDecipheriv('aes-' + (key.length * 8) + '-gcm', key, iv);
|
|
10998
|
+
de.setAAD(adata);
|
|
10999
|
+
de.setAuthTag(ct.slice(ct.length - tagLength$2, ct.length)); // read auth tag at end of ciphertext
|
|
11000
|
+
const pt = Buffer$2.concat([de.update(ct.slice(0, ct.length - tagLength$2)), de.final()]);
|
|
10975
11001
|
return new Uint8Array(pt);
|
|
10976
11002
|
}
|
|
10977
11003
|
};
|
|
10978
11004
|
}
|
|
10979
11005
|
|
|
10980
|
-
if (util.
|
|
11006
|
+
if (util.getWebCrypto() && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
|
11007
|
+
const _key = await webCrypto$4.importKey('raw', key, { name: ALGO }, false, ['encrypt', 'decrypt']);
|
|
11008
|
+
|
|
10981
11009
|
return {
|
|
10982
11010
|
encrypt: async function(pt, iv, adata = new Uint8Array()) {
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
11011
|
+
if (!pt.length) { // iOS does not support GCM-en/decrypting empty messages
|
|
11012
|
+
return AES_GCM.encrypt(pt, key, iv, adata);
|
|
11013
|
+
}
|
|
11014
|
+
const ct = await webCrypto$4.encrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, pt);
|
|
10986
11015
|
return new Uint8Array(ct);
|
|
10987
11016
|
},
|
|
10988
11017
|
|
|
10989
11018
|
decrypt: async function(ct, iv, adata = new Uint8Array()) {
|
|
10990
|
-
|
|
10991
|
-
|
|
10992
|
-
|
|
10993
|
-
const pt =
|
|
11019
|
+
if (ct.length === tagLength$2) { // iOS does not support GCM-en/decrypting empty messages
|
|
11020
|
+
return AES_GCM.decrypt(ct, key, iv, adata);
|
|
11021
|
+
}
|
|
11022
|
+
const pt = await webCrypto$4.decrypt({ name: ALGO, iv, additionalData: adata, tagLength: tagLength$2 * 8 }, _key, ct);
|
|
10994
11023
|
return new Uint8Array(pt);
|
|
10995
11024
|
}
|
|
10996
11025
|
};
|
|
@@ -11993,11 +12022,11 @@ const nodeCrypto$5 = util.getNodeCrypto();
|
|
|
11993
12022
|
*/
|
|
11994
12023
|
function getRandomBytes(length) {
|
|
11995
12024
|
const buf = new Uint8Array(length);
|
|
11996
|
-
if (
|
|
11997
|
-
crypto.getRandomValues(buf);
|
|
11998
|
-
} else if (nodeCrypto$5) {
|
|
12025
|
+
if (nodeCrypto$5) {
|
|
11999
12026
|
const bytes = nodeCrypto$5.randomBytes(buf.length);
|
|
12000
12027
|
buf.set(bytes);
|
|
12028
|
+
} else if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
|
|
12029
|
+
crypto.getRandomValues(buf);
|
|
12001
12030
|
} else {
|
|
12002
12031
|
throw new Error('No secure random number generator available.');
|
|
12003
12032
|
}
|
|
@@ -13559,7 +13588,7 @@ const curves = {
|
|
|
13559
13588
|
},
|
|
13560
13589
|
ed25519: {
|
|
13561
13590
|
oid: [0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01],
|
|
13562
|
-
keyType: enums.publicKey.
|
|
13591
|
+
keyType: enums.publicKey.eddsaLegacy,
|
|
13563
13592
|
hash: enums.hash.sha512,
|
|
13564
13593
|
node: false, // nodeCurves.ed25519 TODO
|
|
13565
13594
|
payloadSize: 32
|
|
@@ -13598,7 +13627,7 @@ const curves = {
|
|
|
13598
13627
|
}
|
|
13599
13628
|
};
|
|
13600
13629
|
|
|
13601
|
-
class
|
|
13630
|
+
class CurveWithOID {
|
|
13602
13631
|
constructor(oidOrName, params) {
|
|
13603
13632
|
try {
|
|
13604
13633
|
if (util.isArray(oidOrName) ||
|
|
@@ -13675,7 +13704,7 @@ class Curve {
|
|
|
13675
13704
|
async function generate$1(curve) {
|
|
13676
13705
|
const BigInteger = await util.getBigInteger();
|
|
13677
13706
|
|
|
13678
|
-
curve = new
|
|
13707
|
+
curve = new CurveWithOID(curve);
|
|
13679
13708
|
const keyPair = await curve.genKeyPair();
|
|
13680
13709
|
const Q = new BigInteger(keyPair.publicKey).toUint8Array();
|
|
13681
13710
|
const secret = new BigInteger(keyPair.privateKey).toUint8Array('be', curve.payloadSize);
|
|
@@ -13866,7 +13895,7 @@ const nodeCrypto$8 = util.getNodeCrypto();
|
|
|
13866
13895
|
* @async
|
|
13867
13896
|
*/
|
|
13868
13897
|
async function sign$1(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
13869
|
-
const curve = new
|
|
13898
|
+
const curve = new CurveWithOID(oid);
|
|
13870
13899
|
if (message && !util.isStream(message)) {
|
|
13871
13900
|
const keyPair = { publicKey, privateKey };
|
|
13872
13901
|
switch (curve.type) {
|
|
@@ -13911,7 +13940,7 @@ async function sign$1(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
13911
13940
|
* @async
|
|
13912
13941
|
*/
|
|
13913
13942
|
async function verify$1(oid, hashAlgo, signature, message, publicKey, hashed) {
|
|
13914
|
-
const curve = new
|
|
13943
|
+
const curve = new CurveWithOID(oid);
|
|
13915
13944
|
if (message && !util.isStream(message)) {
|
|
13916
13945
|
switch (curve.type) {
|
|
13917
13946
|
case 'web':
|
|
@@ -13945,7 +13974,7 @@ async function verify$1(oid, hashAlgo, signature, message, publicKey, hashed) {
|
|
|
13945
13974
|
* @async
|
|
13946
13975
|
*/
|
|
13947
13976
|
async function validateParams$2(oid, Q, d) {
|
|
13948
|
-
const curve = new
|
|
13977
|
+
const curve = new CurveWithOID(oid);
|
|
13949
13978
|
// Reject curves x25519 and ed25519
|
|
13950
13979
|
if (curve.keyType !== enums.publicKey.ecdsa) {
|
|
13951
13980
|
return false;
|
|
@@ -14148,7 +14177,7 @@ var ecdsa = /*#__PURE__*/Object.freeze({
|
|
|
14148
14177
|
naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
|
|
14149
14178
|
|
|
14150
14179
|
/**
|
|
14151
|
-
* Sign a message using the provided key
|
|
14180
|
+
* Sign a message using the provided legacy EdDSA key
|
|
14152
14181
|
* @param {module:type/oid} oid - Elliptic curve object identifier
|
|
14153
14182
|
* @param {module:enums.hash} hashAlgo - Hash algorithm used to sign (must be sha256 or stronger)
|
|
14154
14183
|
* @param {Uint8Array} message - Message to sign
|
|
@@ -14164,10 +14193,24 @@ naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
|
|
|
14164
14193
|
async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
14165
14194
|
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
14166
14195
|
// see https://tools.ietf.org/id/draft-ietf-openpgp-rfc4880bis-10.html#section-15-7.2
|
|
14167
|
-
throw new Error('Hash algorithm too weak
|
|
14196
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14168
14197
|
}
|
|
14169
14198
|
const secretKey = util.concatUint8Array([privateKey, publicKey.subarray(1)]);
|
|
14170
14199
|
const signature = naclFastLight.sign.detached(hashed, secretKey);
|
|
14200
|
+
if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1))) {
|
|
14201
|
+
/**
|
|
14202
|
+
* Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
|
|
14203
|
+
* if two signatures over the same message are obtained.
|
|
14204
|
+
* See https://github.com/jedisct1/libsodium/issues/170.
|
|
14205
|
+
* If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
|
|
14206
|
+
* then the generated signature is always safe, and the verification step is skipped.
|
|
14207
|
+
* Otherwise, we need to verify the generated to ensure that no bitflip occured:
|
|
14208
|
+
* - in M between the computation of `r` and `h`.
|
|
14209
|
+
* - in the public key before computing `h`
|
|
14210
|
+
* The verification step is almost 2-3 times as slow as signing, but it's faster than re-signing + re-deriving the public key for separate checks.
|
|
14211
|
+
*/
|
|
14212
|
+
throw new Error('Transient signing failure');
|
|
14213
|
+
}
|
|
14171
14214
|
// EdDSA signature params are returned in little-endian format
|
|
14172
14215
|
return {
|
|
14173
14216
|
r: signature.subarray(0, 32),
|
|
@@ -14176,7 +14219,7 @@ async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
14176
14219
|
}
|
|
14177
14220
|
|
|
14178
14221
|
/**
|
|
14179
|
-
* Verifies if a signature is valid for a message
|
|
14222
|
+
* Verifies if a legacy EdDSA signature is valid for a message
|
|
14180
14223
|
* @param {module:type/oid} oid - Elliptic curve object identifier
|
|
14181
14224
|
* @param {module:enums.hash} hashAlgo - Hash algorithm used in the signature
|
|
14182
14225
|
* @param {{r: Uint8Array,
|
|
@@ -14188,11 +14231,14 @@ async function sign$2(oid, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
|
14188
14231
|
* @async
|
|
14189
14232
|
*/
|
|
14190
14233
|
async function verify$2(oid, hashAlgo, { r, s }, m, publicKey, hashed) {
|
|
14234
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(enums.hash.sha256)) {
|
|
14235
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14236
|
+
}
|
|
14191
14237
|
const signature = util.concatUint8Array([r, s]);
|
|
14192
14238
|
return naclFastLight.sign.detached.verify(hashed, signature, publicKey.subarray(1));
|
|
14193
14239
|
}
|
|
14194
14240
|
/**
|
|
14195
|
-
* Validate EdDSA parameters
|
|
14241
|
+
* Validate legacy EdDSA parameters
|
|
14196
14242
|
* @param {module:type/oid} oid - Elliptic curve object identifier
|
|
14197
14243
|
* @param {Uint8Array} Q - EdDSA public point
|
|
14198
14244
|
* @param {Uint8Array} k - EdDSA secret seed
|
|
@@ -14212,9 +14258,10 @@ async function validateParams$3(oid, Q, k) {
|
|
|
14212
14258
|
const { publicKey } = naclFastLight.sign.keyPair.fromSeed(k);
|
|
14213
14259
|
const dG = new Uint8Array([0x40, ...publicKey]); // Add public key prefix
|
|
14214
14260
|
return util.equalsUint8Array(Q, dG);
|
|
14261
|
+
|
|
14215
14262
|
}
|
|
14216
14263
|
|
|
14217
|
-
var
|
|
14264
|
+
var eddsa_legacy = /*#__PURE__*/Object.freeze({
|
|
14218
14265
|
__proto__: null,
|
|
14219
14266
|
sign: sign$2,
|
|
14220
14267
|
verify: verify$2,
|
|
@@ -14223,6 +14270,139 @@ var eddsa = /*#__PURE__*/Object.freeze({
|
|
|
14223
14270
|
|
|
14224
14271
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
14225
14272
|
|
|
14273
|
+
naclFastLight.hash = bytes => new Uint8Array(_512().update(bytes).digest());
|
|
14274
|
+
|
|
14275
|
+
/**
|
|
14276
|
+
* Generate (non-legacy) EdDSA key
|
|
14277
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
14278
|
+
* @returns {Promise<{ A: Uint8Array, seed: Uint8Array }>}
|
|
14279
|
+
*/
|
|
14280
|
+
async function generate$2(algo) {
|
|
14281
|
+
switch (algo) {
|
|
14282
|
+
case enums.publicKey.ed25519: {
|
|
14283
|
+
const seed = getRandomBytes(32);
|
|
14284
|
+
const { publicKey: A } = naclFastLight.sign.keyPair.fromSeed(seed);
|
|
14285
|
+
return { A, seed };
|
|
14286
|
+
}
|
|
14287
|
+
default:
|
|
14288
|
+
throw new Error('Unsupported EdDSA algorithm');
|
|
14289
|
+
}
|
|
14290
|
+
}
|
|
14291
|
+
|
|
14292
|
+
/**
|
|
14293
|
+
* Sign a message using the provided key
|
|
14294
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
14295
|
+
* @param {module:enums.hash} hashAlgo - Hash algorithm used to sign (must be sha256 or stronger)
|
|
14296
|
+
* @param {Uint8Array} message - Message to sign
|
|
14297
|
+
* @param {Uint8Array} publicKey - Public key
|
|
14298
|
+
* @param {Uint8Array} privateKey - Private key used to sign the message
|
|
14299
|
+
* @param {Uint8Array} hashed - The hashed message
|
|
14300
|
+
* @returns {Promise<{
|
|
14301
|
+
* RS: Uint8Array
|
|
14302
|
+
* }>} Signature of the message
|
|
14303
|
+
* @async
|
|
14304
|
+
*/
|
|
14305
|
+
async function sign$3(algo, hashAlgo, message, publicKey, privateKey, hashed) {
|
|
14306
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
|
|
14307
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14308
|
+
}
|
|
14309
|
+
switch (algo) {
|
|
14310
|
+
case enums.publicKey.ed25519: {
|
|
14311
|
+
const secretKey = util.concatUint8Array([privateKey, publicKey]);
|
|
14312
|
+
const signature = naclFastLight.sign.detached(hashed, secretKey);
|
|
14313
|
+
if (config.checkEdDSAFaultySignatures && !naclFastLight.sign.detached.verify(hashed, signature, publicKey)) {
|
|
14314
|
+
/**
|
|
14315
|
+
* Detect faulty signatures caused by random bitflips during `crypto_sign` which could lead to private key extraction
|
|
14316
|
+
* if two signatures over the same message are obtained.
|
|
14317
|
+
* See https://github.com/jedisct1/libsodium/issues/170.
|
|
14318
|
+
* If the input data is not deterministic, e.g. thanks to the random salt in v6 OpenPGP signatures (not yet implemented),
|
|
14319
|
+
* then the generated signature is always safe, and the verification step is skipped.
|
|
14320
|
+
* Otherwise, we need to verify the generated to ensure that no bitflip occured:
|
|
14321
|
+
* - in M between the computation of `r` and `h`.
|
|
14322
|
+
* - in the public key before computing `h`
|
|
14323
|
+
* The verification step is almost 2-3 times as slow as signing, but it's faster than re-signing + re-deriving the public key for separate checks.
|
|
14324
|
+
*/
|
|
14325
|
+
throw new Error('Transient signing failure');
|
|
14326
|
+
}
|
|
14327
|
+
return { RS: signature };
|
|
14328
|
+
}
|
|
14329
|
+
case enums.publicKey.ed448:
|
|
14330
|
+
default:
|
|
14331
|
+
throw new Error('Unsupported EdDSA algorithm');
|
|
14332
|
+
}
|
|
14333
|
+
|
|
14334
|
+
}
|
|
14335
|
+
|
|
14336
|
+
/**
|
|
14337
|
+
* Verifies if a signature is valid for a message
|
|
14338
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
14339
|
+
* @param {module:enums.hash} hashAlgo - Hash algorithm used in the signature
|
|
14340
|
+
* @param {{ RS: Uint8Array }} signature Signature to verify the message
|
|
14341
|
+
* @param {Uint8Array} m - Message to verify
|
|
14342
|
+
* @param {Uint8Array} publicKey - Public key used to verify the message
|
|
14343
|
+
* @param {Uint8Array} hashed - The hashed message
|
|
14344
|
+
* @returns {Boolean}
|
|
14345
|
+
* @async
|
|
14346
|
+
*/
|
|
14347
|
+
async function verify$3(algo, hashAlgo, { RS }, m, publicKey, hashed) {
|
|
14348
|
+
if (hash.getHashByteLength(hashAlgo) < hash.getHashByteLength(getPreferredHashAlgo$1(algo))) {
|
|
14349
|
+
throw new Error('Hash algorithm too weak for EdDSA.');
|
|
14350
|
+
}
|
|
14351
|
+
switch (algo) {
|
|
14352
|
+
case enums.publicKey.ed25519: {
|
|
14353
|
+
return naclFastLight.sign.detached.verify(hashed, RS, publicKey);
|
|
14354
|
+
}
|
|
14355
|
+
case enums.publicKey.ed448:
|
|
14356
|
+
default:
|
|
14357
|
+
throw new Error('Unsupported EdDSA algorithm');
|
|
14358
|
+
}
|
|
14359
|
+
}
|
|
14360
|
+
/**
|
|
14361
|
+
* Validate (non-legacy) EdDSA parameters
|
|
14362
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
14363
|
+
* @param {Uint8Array} A - EdDSA public point
|
|
14364
|
+
* @param {Uint8Array} seed - EdDSA secret seed
|
|
14365
|
+
* @param {Uint8Array} oid - (legacy only) EdDSA OID
|
|
14366
|
+
* @returns {Promise<Boolean>} Whether params are valid.
|
|
14367
|
+
* @async
|
|
14368
|
+
*/
|
|
14369
|
+
async function validateParams$4(algo, A, seed) {
|
|
14370
|
+
switch (algo) {
|
|
14371
|
+
case enums.publicKey.ed25519: {
|
|
14372
|
+
/**
|
|
14373
|
+
* Derive public point A' from private key
|
|
14374
|
+
* and expect A == A'
|
|
14375
|
+
*/
|
|
14376
|
+
const { publicKey } = naclFastLight.sign.keyPair.fromSeed(seed);
|
|
14377
|
+
return util.equalsUint8Array(A, publicKey);
|
|
14378
|
+
}
|
|
14379
|
+
|
|
14380
|
+
case enums.publicKey.ed448: // unsupported
|
|
14381
|
+
default:
|
|
14382
|
+
return false;
|
|
14383
|
+
}
|
|
14384
|
+
}
|
|
14385
|
+
|
|
14386
|
+
function getPreferredHashAlgo$1(algo) {
|
|
14387
|
+
switch (algo) {
|
|
14388
|
+
case enums.publicKey.ed25519:
|
|
14389
|
+
return enums.hash.sha256;
|
|
14390
|
+
default:
|
|
14391
|
+
throw new Error('Unknown EdDSA algo');
|
|
14392
|
+
}
|
|
14393
|
+
}
|
|
14394
|
+
|
|
14395
|
+
var eddsa = /*#__PURE__*/Object.freeze({
|
|
14396
|
+
__proto__: null,
|
|
14397
|
+
generate: generate$2,
|
|
14398
|
+
sign: sign$3,
|
|
14399
|
+
verify: verify$3,
|
|
14400
|
+
validateParams: validateParams$4,
|
|
14401
|
+
getPreferredHashAlgo: getPreferredHashAlgo$1
|
|
14402
|
+
});
|
|
14403
|
+
|
|
14404
|
+
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
14405
|
+
|
|
14226
14406
|
/**
|
|
14227
14407
|
* AES key wrap
|
|
14228
14408
|
* @function
|
|
@@ -14410,7 +14590,7 @@ const nodeCrypto$9 = util.getNodeCrypto();
|
|
|
14410
14590
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
14411
14591
|
* @async
|
|
14412
14592
|
*/
|
|
14413
|
-
async function validateParams$
|
|
14593
|
+
async function validateParams$5(oid, Q, d) {
|
|
14414
14594
|
return validateStandardParams(enums.publicKey.ecdh, oid, Q, d);
|
|
14415
14595
|
}
|
|
14416
14596
|
|
|
@@ -14452,7 +14632,7 @@ async function kdf(hashAlgo, X, length, param, stripLeading = false, stripTraili
|
|
|
14452
14632
|
/**
|
|
14453
14633
|
* Generate ECDHE ephemeral key and secret from public key
|
|
14454
14634
|
*
|
|
14455
|
-
* @param {
|
|
14635
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14456
14636
|
* @param {Uint8Array} Q - Recipient public key
|
|
14457
14637
|
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
|
|
14458
14638
|
* @async
|
|
@@ -14495,7 +14675,7 @@ async function genPublicEphemeralKey(curve, Q) {
|
|
|
14495
14675
|
async function encrypt$3(oid, kdfParams, data, Q, fingerprint) {
|
|
14496
14676
|
const m = encode$1(data);
|
|
14497
14677
|
|
|
14498
|
-
const curve = new
|
|
14678
|
+
const curve = new CurveWithOID(oid);
|
|
14499
14679
|
const { publicKey, sharedKey } = await genPublicEphemeralKey(curve, Q);
|
|
14500
14680
|
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
|
|
14501
14681
|
const { keySize } = getCipher(kdfParams.cipher);
|
|
@@ -14507,7 +14687,7 @@ async function encrypt$3(oid, kdfParams, data, Q, fingerprint) {
|
|
|
14507
14687
|
/**
|
|
14508
14688
|
* Generate ECDHE secret from private key and public part of ephemeral key
|
|
14509
14689
|
*
|
|
14510
|
-
* @param {
|
|
14690
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14511
14691
|
* @param {Uint8Array} V - Public part of ephemeral key
|
|
14512
14692
|
* @param {Uint8Array} Q - Recipient public key
|
|
14513
14693
|
* @param {Uint8Array} d - Recipient private key
|
|
@@ -14555,7 +14735,7 @@ async function genPrivateEphemeralKey(curve, V, Q, d) {
|
|
|
14555
14735
|
* @async
|
|
14556
14736
|
*/
|
|
14557
14737
|
async function decrypt$3(oid, kdfParams, V, C, Q, d, fingerprint) {
|
|
14558
|
-
const curve = new
|
|
14738
|
+
const curve = new CurveWithOID(oid);
|
|
14559
14739
|
const { sharedKey } = await genPrivateEphemeralKey(curve, V, Q, d);
|
|
14560
14740
|
const param = buildEcdhParam(enums.publicKey.ecdh, oid, kdfParams, fingerprint);
|
|
14561
14741
|
const { keySize } = getCipher(kdfParams.cipher);
|
|
@@ -14575,7 +14755,7 @@ async function decrypt$3(oid, kdfParams, V, C, Q, d, fingerprint) {
|
|
|
14575
14755
|
/**
|
|
14576
14756
|
* Generate ECDHE secret from private key and public part of ephemeral key using webCrypto
|
|
14577
14757
|
*
|
|
14578
|
-
* @param {
|
|
14758
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14579
14759
|
* @param {Uint8Array} V - Public part of ephemeral key
|
|
14580
14760
|
* @param {Uint8Array} Q - Recipient public key
|
|
14581
14761
|
* @param {Uint8Array} d - Recipient private key
|
|
@@ -14628,7 +14808,7 @@ async function webPrivateEphemeralKey(curve, V, Q, d) {
|
|
|
14628
14808
|
/**
|
|
14629
14809
|
* Generate ECDHE ephemeral key and secret from public key using webCrypto
|
|
14630
14810
|
*
|
|
14631
|
-
* @param {
|
|
14811
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14632
14812
|
* @param {Uint8Array} Q - Recipient public key
|
|
14633
14813
|
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
|
|
14634
14814
|
* @async
|
|
@@ -14676,7 +14856,7 @@ async function webPublicEphemeralKey(curve, Q) {
|
|
|
14676
14856
|
/**
|
|
14677
14857
|
* Generate ECDHE secret from private key and public part of ephemeral key using indutny/elliptic
|
|
14678
14858
|
*
|
|
14679
|
-
* @param {
|
|
14859
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14680
14860
|
* @param {Uint8Array} V - Public part of ephemeral key
|
|
14681
14861
|
* @param {Uint8Array} d - Recipient private key
|
|
14682
14862
|
* @returns {Promise<{secretKey: Uint8Array, sharedKey: Uint8Array}>}
|
|
@@ -14696,7 +14876,7 @@ async function ellipticPrivateEphemeralKey(curve, V, d) {
|
|
|
14696
14876
|
/**
|
|
14697
14877
|
* Generate ECDHE ephemeral key and secret from public key using indutny/elliptic
|
|
14698
14878
|
*
|
|
14699
|
-
* @param {
|
|
14879
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14700
14880
|
* @param {Uint8Array} Q - Recipient public key
|
|
14701
14881
|
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
|
|
14702
14882
|
* @async
|
|
@@ -14716,7 +14896,7 @@ async function ellipticPublicEphemeralKey(curve, Q) {
|
|
|
14716
14896
|
/**
|
|
14717
14897
|
* Generate ECDHE secret from private key and public part of ephemeral key using nodeCrypto
|
|
14718
14898
|
*
|
|
14719
|
-
* @param {
|
|
14899
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14720
14900
|
* @param {Uint8Array} V - Public part of ephemeral key
|
|
14721
14901
|
* @param {Uint8Array} d - Recipient private key
|
|
14722
14902
|
* @returns {Promise<{secretKey: Uint8Array, sharedKey: Uint8Array}>}
|
|
@@ -14733,7 +14913,7 @@ async function nodePrivateEphemeralKey(curve, V, d) {
|
|
|
14733
14913
|
/**
|
|
14734
14914
|
* Generate ECDHE ephemeral key and secret from public key using nodeCrypto
|
|
14735
14915
|
*
|
|
14736
|
-
* @param {
|
|
14916
|
+
* @param {CurveWithOID} curve - Elliptic curve object
|
|
14737
14917
|
* @param {Uint8Array} Q - Recipient public key
|
|
14738
14918
|
* @returns {Promise<{publicKey: Uint8Array, sharedKey: Uint8Array}>}
|
|
14739
14919
|
* @async
|
|
@@ -14748,18 +14928,202 @@ async function nodePublicEphemeralKey(curve, Q) {
|
|
|
14748
14928
|
|
|
14749
14929
|
var ecdh = /*#__PURE__*/Object.freeze({
|
|
14750
14930
|
__proto__: null,
|
|
14751
|
-
validateParams: validateParams$
|
|
14931
|
+
validateParams: validateParams$5,
|
|
14752
14932
|
encrypt: encrypt$3,
|
|
14753
14933
|
decrypt: decrypt$3
|
|
14754
14934
|
});
|
|
14755
14935
|
|
|
14936
|
+
/**
|
|
14937
|
+
* @fileoverview This module implements HKDF using either the WebCrypto API or Node.js' crypto API.
|
|
14938
|
+
* @module crypto/hkdf
|
|
14939
|
+
* @private
|
|
14940
|
+
*/
|
|
14941
|
+
|
|
14942
|
+
const webCrypto$9 = util.getWebCrypto();
|
|
14943
|
+
const nodeCrypto$a = util.getNodeCrypto();
|
|
14944
|
+
const nodeSubtleCrypto = nodeCrypto$a && nodeCrypto$a.webcrypto && nodeCrypto$a.webcrypto.subtle;
|
|
14945
|
+
|
|
14946
|
+
async function HKDF(hashAlgo, inputKey, salt, info, outLen) {
|
|
14947
|
+
const hash = enums.read(enums.webHash, hashAlgo);
|
|
14948
|
+
if (!hash) throw new Error('Hash algo not supported with HKDF');
|
|
14949
|
+
|
|
14950
|
+
if (webCrypto$9 || nodeSubtleCrypto) {
|
|
14951
|
+
const crypto = webCrypto$9 || nodeSubtleCrypto;
|
|
14952
|
+
const importedKey = await crypto.importKey('raw', inputKey, 'HKDF', false, ['deriveBits']);
|
|
14953
|
+
const bits = await crypto.deriveBits({ name: 'HKDF', hash, salt, info }, importedKey, outLen * 8);
|
|
14954
|
+
return new Uint8Array(bits);
|
|
14955
|
+
}
|
|
14956
|
+
|
|
14957
|
+
if (nodeCrypto$a) {
|
|
14958
|
+
const hashAlgoName = enums.read(enums.hash, hashAlgo);
|
|
14959
|
+
// Node-only HKDF implementation based on https://www.rfc-editor.org/rfc/rfc5869
|
|
14960
|
+
|
|
14961
|
+
const computeHMAC = (hmacKey, hmacMessage) => nodeCrypto$a.createHmac(hashAlgoName, hmacKey).update(hmacMessage).digest();
|
|
14962
|
+
// Step 1: Extract
|
|
14963
|
+
// PRK = HMAC-Hash(salt, IKM)
|
|
14964
|
+
const pseudoRandomKey = computeHMAC(salt, inputKey);
|
|
14965
|
+
|
|
14966
|
+
const hashLen = pseudoRandomKey.length;
|
|
14967
|
+
|
|
14968
|
+
// Step 2: Expand
|
|
14969
|
+
// HKDF-Expand(PRK, info, L) -> OKM
|
|
14970
|
+
const n = Math.ceil(outLen / hashLen);
|
|
14971
|
+
const outputKeyingMaterial = new Uint8Array(n * hashLen);
|
|
14972
|
+
|
|
14973
|
+
// HMAC input buffer updated at each iteration
|
|
14974
|
+
const roundInput = new Uint8Array(hashLen + info.length + 1);
|
|
14975
|
+
// T_i and last byte are updated at each iteration, but `info` remains constant
|
|
14976
|
+
roundInput.set(info, hashLen);
|
|
14977
|
+
|
|
14978
|
+
for (let i = 0; i < n; i++) {
|
|
14979
|
+
// T(0) = empty string (zero length)
|
|
14980
|
+
// T(i) = HMAC-Hash(PRK, T(i-1) | info | i)
|
|
14981
|
+
roundInput[roundInput.length - 1] = i + 1;
|
|
14982
|
+
// t = T(i+1)
|
|
14983
|
+
const t = computeHMAC(pseudoRandomKey, i > 0 ? roundInput : roundInput.subarray(hashLen));
|
|
14984
|
+
roundInput.set(t, 0);
|
|
14985
|
+
|
|
14986
|
+
outputKeyingMaterial.set(t, i * hashLen);
|
|
14987
|
+
}
|
|
14988
|
+
|
|
14989
|
+
return outputKeyingMaterial.subarray(0, outLen);
|
|
14990
|
+
}
|
|
14991
|
+
|
|
14992
|
+
throw new Error('No HKDF implementation available');
|
|
14993
|
+
}
|
|
14994
|
+
|
|
14995
|
+
/**
|
|
14996
|
+
* @fileoverview Key encryption and decryption for RFC 6637 ECDH
|
|
14997
|
+
* @module crypto/public_key/elliptic/ecdh
|
|
14998
|
+
* @private
|
|
14999
|
+
*/
|
|
15000
|
+
|
|
15001
|
+
const HKDF_INFO = {
|
|
15002
|
+
x25519: util.encodeUTF8('OpenPGP X25519')
|
|
15003
|
+
};
|
|
15004
|
+
|
|
15005
|
+
/**
|
|
15006
|
+
* Generate ECDH key for Montgomery curves
|
|
15007
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
15008
|
+
* @returns {Promise<{ A: Uint8Array, k: Uint8Array }>}
|
|
15009
|
+
*/
|
|
15010
|
+
async function generate$3(algo) {
|
|
15011
|
+
switch (algo) {
|
|
15012
|
+
case enums.publicKey.x25519: {
|
|
15013
|
+
// k stays in little-endian, unlike legacy ECDH over curve25519
|
|
15014
|
+
const k = getRandomBytes(32);
|
|
15015
|
+
const { publicKey: A } = naclFastLight.box.keyPair.fromSecretKey(k);
|
|
15016
|
+
return { A, k };
|
|
15017
|
+
}
|
|
15018
|
+
default:
|
|
15019
|
+
throw new Error('Unsupported ECDH algorithm');
|
|
15020
|
+
}
|
|
15021
|
+
}
|
|
15022
|
+
|
|
15023
|
+
/**
|
|
15024
|
+
* Validate ECDH parameters
|
|
15025
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
15026
|
+
* @param {Uint8Array} A - ECDH public point
|
|
15027
|
+
* @param {Uint8Array} k - ECDH secret scalar
|
|
15028
|
+
* @returns {Promise<Boolean>} Whether params are valid.
|
|
15029
|
+
* @async
|
|
15030
|
+
*/
|
|
15031
|
+
async function validateParams$6(algo, A, k) {
|
|
15032
|
+
switch (algo) {
|
|
15033
|
+
case enums.publicKey.x25519: {
|
|
15034
|
+
/**
|
|
15035
|
+
* Derive public point A' from private key
|
|
15036
|
+
* and expect A == A'
|
|
15037
|
+
*/
|
|
15038
|
+
const { publicKey } = naclFastLight.box.keyPair.fromSecretKey(k);
|
|
15039
|
+
return util.equalsUint8Array(A, publicKey);
|
|
15040
|
+
}
|
|
15041
|
+
|
|
15042
|
+
default:
|
|
15043
|
+
return false;
|
|
15044
|
+
}
|
|
15045
|
+
}
|
|
15046
|
+
|
|
15047
|
+
/**
|
|
15048
|
+
* Wrap and encrypt a session key
|
|
15049
|
+
*
|
|
15050
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
15051
|
+
* @param {Uint8Array} data - session key data to be encrypted
|
|
15052
|
+
* @param {Uint8Array} recipientA - Recipient public key (K_B)
|
|
15053
|
+
* @returns {Promise<{
|
|
15054
|
+
* ephemeralPublicKey: Uint8Array,
|
|
15055
|
+
* wrappedKey: Uint8Array
|
|
15056
|
+
* }>} ephemeral public key (K_A) and encrypted key
|
|
15057
|
+
* @async
|
|
15058
|
+
*/
|
|
15059
|
+
async function encrypt$4(algo, data, recipientA) {
|
|
15060
|
+
switch (algo) {
|
|
15061
|
+
case enums.publicKey.x25519: {
|
|
15062
|
+
const ephemeralSecretKey = getRandomBytes(32);
|
|
15063
|
+
const sharedSecret = naclFastLight.scalarMult(ephemeralSecretKey, recipientA);
|
|
15064
|
+
const { publicKey: ephemeralPublicKey } = naclFastLight.box.keyPair.fromSecretKey(ephemeralSecretKey);
|
|
15065
|
+
const hkdfInput = util.concatUint8Array([
|
|
15066
|
+
ephemeralPublicKey,
|
|
15067
|
+
recipientA,
|
|
15068
|
+
sharedSecret
|
|
15069
|
+
]);
|
|
15070
|
+
const { keySize } = getCipher(enums.symmetric.aes128);
|
|
15071
|
+
const encryptionKey = await HKDF(enums.hash.sha256, hkdfInput, new Uint8Array(), HKDF_INFO.x25519, keySize);
|
|
15072
|
+
const wrappedKey = wrap(encryptionKey, data);
|
|
15073
|
+
return { ephemeralPublicKey, wrappedKey };
|
|
15074
|
+
}
|
|
15075
|
+
|
|
15076
|
+
default:
|
|
15077
|
+
throw new Error('Unsupported ECDH algorithm');
|
|
15078
|
+
}
|
|
15079
|
+
}
|
|
15080
|
+
|
|
15081
|
+
/**
|
|
15082
|
+
* Decrypt and unwrap the session key
|
|
15083
|
+
*
|
|
15084
|
+
* @param {module:enums.publicKey} algo - Algorithm identifier
|
|
15085
|
+
* @param {Uint8Array} ephemeralPublicKey - (K_A)
|
|
15086
|
+
* @param {Uint8Array} wrappedKey,
|
|
15087
|
+
* @param {Uint8Array} A - Recipient public key (K_b), needed for KDF
|
|
15088
|
+
* @param {Uint8Array} k - Recipient secret key (b)
|
|
15089
|
+
* @returns {Promise<Uint8Array>} decrypted session key data
|
|
15090
|
+
* @async
|
|
15091
|
+
*/
|
|
15092
|
+
async function decrypt$4(algo, ephemeralPublicKey, wrappedKey, A, k) {
|
|
15093
|
+
switch (algo) {
|
|
15094
|
+
case enums.publicKey.x25519: {
|
|
15095
|
+
const sharedSecret = naclFastLight.scalarMult(k, ephemeralPublicKey);
|
|
15096
|
+
const hkdfInput = util.concatUint8Array([
|
|
15097
|
+
ephemeralPublicKey,
|
|
15098
|
+
A,
|
|
15099
|
+
sharedSecret
|
|
15100
|
+
]);
|
|
15101
|
+
const { keySize } = getCipher(enums.symmetric.aes128);
|
|
15102
|
+
const encryptionKey = await HKDF(enums.hash.sha256, hkdfInput, new Uint8Array(), HKDF_INFO.x25519, keySize);
|
|
15103
|
+
return unwrap(encryptionKey, wrappedKey);
|
|
15104
|
+
}
|
|
15105
|
+
default:
|
|
15106
|
+
throw new Error('Unsupported ECDH algorithm');
|
|
15107
|
+
}
|
|
15108
|
+
}
|
|
15109
|
+
|
|
15110
|
+
var ecdh_x = /*#__PURE__*/Object.freeze({
|
|
15111
|
+
__proto__: null,
|
|
15112
|
+
generate: generate$3,
|
|
15113
|
+
validateParams: validateParams$6,
|
|
15114
|
+
encrypt: encrypt$4,
|
|
15115
|
+
decrypt: decrypt$4
|
|
15116
|
+
});
|
|
15117
|
+
|
|
14756
15118
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
14757
15119
|
|
|
14758
15120
|
var elliptic = /*#__PURE__*/Object.freeze({
|
|
14759
15121
|
__proto__: null,
|
|
14760
|
-
|
|
15122
|
+
CurveWithOID: CurveWithOID,
|
|
14761
15123
|
ecdh: ecdh,
|
|
15124
|
+
ecdhX: ecdh_x,
|
|
14762
15125
|
ecdsa: ecdsa,
|
|
15126
|
+
eddsaLegacy: eddsa_legacy,
|
|
14763
15127
|
eddsa: eddsa,
|
|
14764
15128
|
generate: generate$1,
|
|
14765
15129
|
getPreferredHashAlgo: getPreferredHashAlgo
|
|
@@ -14784,7 +15148,7 @@ var elliptic = /*#__PURE__*/Object.freeze({
|
|
|
14784
15148
|
* @returns {Promise<{ r: Uint8Array, s: Uint8Array }>}
|
|
14785
15149
|
* @async
|
|
14786
15150
|
*/
|
|
14787
|
-
async function sign$
|
|
15151
|
+
async function sign$4(hashAlgo, hashed, g, p, q, x) {
|
|
14788
15152
|
const BigInteger = await util.getBigInteger();
|
|
14789
15153
|
const one = new BigInteger(1);
|
|
14790
15154
|
p = new BigInteger(p);
|
|
@@ -14843,7 +15207,7 @@ async function sign$3(hashAlgo, hashed, g, p, q, x) {
|
|
|
14843
15207
|
* @returns {boolean}
|
|
14844
15208
|
* @async
|
|
14845
15209
|
*/
|
|
14846
|
-
async function verify$
|
|
15210
|
+
async function verify$4(hashAlgo, r, s, hashed, g, p, q, y) {
|
|
14847
15211
|
const BigInteger = await util.getBigInteger();
|
|
14848
15212
|
const zero = new BigInteger(0);
|
|
14849
15213
|
r = new BigInteger(r);
|
|
@@ -14886,7 +15250,7 @@ async function verify$3(hashAlgo, r, s, hashed, g, p, q, y) {
|
|
|
14886
15250
|
* @returns {Promise<Boolean>} Whether params are valid.
|
|
14887
15251
|
* @async
|
|
14888
15252
|
*/
|
|
14889
|
-
async function validateParams$
|
|
15253
|
+
async function validateParams$7(p, q, g, y, x) {
|
|
14890
15254
|
const BigInteger = await util.getBigInteger();
|
|
14891
15255
|
p = new BigInteger(p);
|
|
14892
15256
|
q = new BigInteger(q);
|
|
@@ -14941,9 +15305,9 @@ async function validateParams$5(p, q, g, y, x) {
|
|
|
14941
15305
|
|
|
14942
15306
|
var dsa = /*#__PURE__*/Object.freeze({
|
|
14943
15307
|
__proto__: null,
|
|
14944
|
-
sign: sign$
|
|
14945
|
-
verify: verify$
|
|
14946
|
-
validateParams: validateParams$
|
|
15308
|
+
sign: sign$4,
|
|
15309
|
+
verify: verify$4,
|
|
15310
|
+
validateParams: validateParams$7
|
|
14947
15311
|
});
|
|
14948
15312
|
|
|
14949
15313
|
/**
|
|
@@ -15079,10 +15443,10 @@ function parseSignatureParams(algo, signature) {
|
|
|
15079
15443
|
const s = util.readMPI(signature.subarray(read));
|
|
15080
15444
|
return { r, s };
|
|
15081
15445
|
}
|
|
15082
|
-
// Algorithm-Specific Fields for EdDSA signatures:
|
|
15446
|
+
// Algorithm-Specific Fields for legacy EdDSA signatures:
|
|
15083
15447
|
// - MPI of an EC point r.
|
|
15084
15448
|
// - EdDSA value s, in MPI, in the little endian representation
|
|
15085
|
-
case enums.publicKey.
|
|
15449
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15086
15450
|
// When parsing little-endian MPI data, we always need to left-pad it, as done with big-endian values:
|
|
15087
15451
|
// https://www.ietf.org/archive/id/draft-ietf-openpgp-rfc4880bis-10.html#section-3.2-9
|
|
15088
15452
|
let r = util.readMPI(signature.subarray(read)); read += r.length + 2;
|
|
@@ -15091,7 +15455,12 @@ function parseSignatureParams(algo, signature) {
|
|
|
15091
15455
|
s = util.leftPad(s, 32);
|
|
15092
15456
|
return { r, s };
|
|
15093
15457
|
}
|
|
15094
|
-
|
|
15458
|
+
// Algorithm-Specific Fields for Ed25519 signatures:
|
|
15459
|
+
// - 64 octets of the native signature
|
|
15460
|
+
case enums.publicKey.ed25519: {
|
|
15461
|
+
const RS = signature.subarray(read, read + 64); read += RS.length;
|
|
15462
|
+
return { RS };
|
|
15463
|
+
}
|
|
15095
15464
|
case enums.publicKey.hmac: {
|
|
15096
15465
|
const mac = new ShortByteString(); mac.read(signature.subarray(read));
|
|
15097
15466
|
return { mac };
|
|
@@ -15116,7 +15485,7 @@ function parseSignatureParams(algo, signature) {
|
|
|
15116
15485
|
* @returns {Promise<Boolean>} True if signature is valid.
|
|
15117
15486
|
* @async
|
|
15118
15487
|
*/
|
|
15119
|
-
async function verify$
|
|
15488
|
+
async function verify$5(algo, hashAlgo, signature, publicParams, privateParams, data, hashed) {
|
|
15120
15489
|
switch (algo) {
|
|
15121
15490
|
case enums.publicKey.rsaEncryptSign:
|
|
15122
15491
|
case enums.publicKey.rsaEncrypt:
|
|
@@ -15132,16 +15501,20 @@ async function verify$4(algo, hashAlgo, signature, publicParams, privateParams,
|
|
|
15132
15501
|
}
|
|
15133
15502
|
case enums.publicKey.ecdsa: {
|
|
15134
15503
|
const { oid, Q } = publicParams;
|
|
15135
|
-
const curveSize = new publicKey.elliptic.
|
|
15504
|
+
const curveSize = new publicKey.elliptic.CurveWithOID(oid).payloadSize;
|
|
15136
15505
|
// padding needed for webcrypto
|
|
15137
15506
|
const r = util.leftPad(signature.r, curveSize);
|
|
15138
15507
|
const s = util.leftPad(signature.s, curveSize);
|
|
15139
15508
|
return publicKey.elliptic.ecdsa.verify(oid, hashAlgo, { r, s }, data, Q, hashed);
|
|
15140
15509
|
}
|
|
15141
|
-
case enums.publicKey.
|
|
15510
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15142
15511
|
const { oid, Q } = publicParams;
|
|
15143
15512
|
// signature already padded on parsing
|
|
15144
|
-
return publicKey.elliptic.
|
|
15513
|
+
return publicKey.elliptic.eddsaLegacy.verify(oid, hashAlgo, signature, data, Q, hashed);
|
|
15514
|
+
}
|
|
15515
|
+
case enums.publicKey.ed25519: {
|
|
15516
|
+
const { A } = publicParams;
|
|
15517
|
+
return publicKey.elliptic.eddsa.verify(algo, hashAlgo, signature, data, A, hashed);
|
|
15145
15518
|
}
|
|
15146
15519
|
case enums.publicKey.hmac: {
|
|
15147
15520
|
if (!privateParams) {
|
|
@@ -15171,7 +15544,7 @@ async function verify$4(algo, hashAlgo, signature, publicParams, privateParams,
|
|
|
15171
15544
|
* @returns {Promise<Object>} Signature Object containing named signature parameters.
|
|
15172
15545
|
* @async
|
|
15173
15546
|
*/
|
|
15174
|
-
async function sign$
|
|
15547
|
+
async function sign$5(algo, hashAlgo, publicKeyParams, privateKeyParams, data, hashed) {
|
|
15175
15548
|
if (!publicKeyParams || !privateKeyParams) {
|
|
15176
15549
|
throw new Error('Missing key parameters');
|
|
15177
15550
|
}
|
|
@@ -15197,10 +15570,15 @@ async function sign$4(algo, hashAlgo, publicKeyParams, privateKeyParams, data, h
|
|
|
15197
15570
|
const { d } = privateKeyParams;
|
|
15198
15571
|
return publicKey.elliptic.ecdsa.sign(oid, hashAlgo, data, Q, d, hashed);
|
|
15199
15572
|
}
|
|
15200
|
-
case enums.publicKey.
|
|
15573
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15201
15574
|
const { oid, Q } = publicKeyParams;
|
|
15202
15575
|
const { seed } = privateKeyParams;
|
|
15203
|
-
return publicKey.elliptic.
|
|
15576
|
+
return publicKey.elliptic.eddsaLegacy.sign(oid, hashAlgo, data, Q, seed, hashed);
|
|
15577
|
+
}
|
|
15578
|
+
case enums.publicKey.ed25519: {
|
|
15579
|
+
const { A } = publicKeyParams;
|
|
15580
|
+
const { seed } = privateKeyParams;
|
|
15581
|
+
return publicKey.elliptic.eddsa.sign(algo, hashAlgo, data, A, seed, hashed);
|
|
15204
15582
|
}
|
|
15205
15583
|
case enums.publicKey.hmac: {
|
|
15206
15584
|
const { cipher: algo } = publicKeyParams;
|
|
@@ -15216,34 +15594,31 @@ async function sign$4(algo, hashAlgo, publicKeyParams, privateKeyParams, data, h
|
|
|
15216
15594
|
var signature = /*#__PURE__*/Object.freeze({
|
|
15217
15595
|
__proto__: null,
|
|
15218
15596
|
parseSignatureParams: parseSignatureParams,
|
|
15219
|
-
verify: verify$
|
|
15220
|
-
sign: sign$
|
|
15597
|
+
verify: verify$5,
|
|
15598
|
+
sign: sign$5
|
|
15221
15599
|
});
|
|
15222
15600
|
|
|
15223
15601
|
// OpenPGP.js - An OpenPGP implementation in javascript
|
|
15224
15602
|
|
|
15225
15603
|
class ECDHSymmetricKey {
|
|
15226
15604
|
constructor(data) {
|
|
15227
|
-
if (
|
|
15228
|
-
data =
|
|
15229
|
-
} else if (util.isString(data)) {
|
|
15230
|
-
data = util.stringToUint8Array(data);
|
|
15231
|
-
} else {
|
|
15232
|
-
data = new Uint8Array(data);
|
|
15605
|
+
if (data) {
|
|
15606
|
+
this.data = data;
|
|
15233
15607
|
}
|
|
15234
|
-
this.data = data;
|
|
15235
15608
|
}
|
|
15236
15609
|
|
|
15237
15610
|
/**
|
|
15238
|
-
* Read an ECDHSymmetricKey from an Uint8Array
|
|
15239
|
-
*
|
|
15611
|
+
* Read an ECDHSymmetricKey from an Uint8Array:
|
|
15612
|
+
* - 1 octect for the length `l`
|
|
15613
|
+
* - `l` octects of encoded session key data
|
|
15614
|
+
* @param {Uint8Array} bytes
|
|
15240
15615
|
* @returns {Number} Number of read bytes.
|
|
15241
15616
|
*/
|
|
15242
|
-
read(
|
|
15243
|
-
if (
|
|
15244
|
-
const length =
|
|
15245
|
-
if (
|
|
15246
|
-
this.data =
|
|
15617
|
+
read(bytes) {
|
|
15618
|
+
if (bytes.length >= 1) {
|
|
15619
|
+
const length = bytes[0];
|
|
15620
|
+
if (bytes.length >= 1 + length) {
|
|
15621
|
+
this.data = bytes.subarray(1, 1 + length);
|
|
15247
15622
|
return 1 + this.data.length;
|
|
15248
15623
|
}
|
|
15249
15624
|
}
|
|
@@ -15252,7 +15627,7 @@ class ECDHSymmetricKey {
|
|
|
15252
15627
|
|
|
15253
15628
|
/**
|
|
15254
15629
|
* Write an ECDHSymmetricKey as an Uint8Array
|
|
15255
|
-
* @returns {Uint8Array}
|
|
15630
|
+
* @returns {Uint8Array} Serialised data
|
|
15256
15631
|
*/
|
|
15257
15632
|
write() {
|
|
15258
15633
|
return util.concatUint8Array([new Uint8Array([this.data.length]), this.data]);
|
|
@@ -15292,6 +15667,9 @@ class KDFParams {
|
|
|
15292
15667
|
* @returns {Number} Number of read bytes.
|
|
15293
15668
|
*/
|
|
15294
15669
|
read(input) {
|
|
15670
|
+
if (input.length < 4 || (input[1] !== 1 && input[1] !== VERSION_FORWARDING)) {
|
|
15671
|
+
throw new UnsupportedError('Cannot read KDFParams');
|
|
15672
|
+
}
|
|
15295
15673
|
const totalBytes = input[0];
|
|
15296
15674
|
this.version = input[1];
|
|
15297
15675
|
this.hash = input[2];
|
|
@@ -15379,12 +15757,57 @@ const AEADEnum = type_enum(enums.aead);
|
|
|
15379
15757
|
const SymAlgoEnum = type_enum(enums.symmetric);
|
|
15380
15758
|
const HashEnum = type_enum(enums.hash);
|
|
15381
15759
|
|
|
15760
|
+
/**
|
|
15761
|
+
* Encoded symmetric key for x25519 and x448
|
|
15762
|
+
* The payload format varies for v3 and v6 PKESK:
|
|
15763
|
+
* the former includes an algorithm byte preceeding the encrypted session key.
|
|
15764
|
+
*
|
|
15765
|
+
* @module type/x25519x448_symkey
|
|
15766
|
+
*/
|
|
15767
|
+
|
|
15768
|
+
class ECDHXSymmetricKey {
|
|
15769
|
+
static fromObject({ wrappedKey, algorithm }) {
|
|
15770
|
+
const instance = new ECDHXSymmetricKey();
|
|
15771
|
+
instance.wrappedKey = wrappedKey;
|
|
15772
|
+
instance.algorithm = algorithm;
|
|
15773
|
+
return instance;
|
|
15774
|
+
}
|
|
15775
|
+
|
|
15776
|
+
/**
|
|
15777
|
+
* - 1 octect for the length `l`
|
|
15778
|
+
* - `l` octects of encoded session key data (with optional leading algorithm byte)
|
|
15779
|
+
* @param {Uint8Array} bytes
|
|
15780
|
+
* @returns {Number} Number of read bytes.
|
|
15781
|
+
*/
|
|
15782
|
+
read(bytes) {
|
|
15783
|
+
let read = 0;
|
|
15784
|
+
let followLength = bytes[read++];
|
|
15785
|
+
this.algorithm = followLength % 2 ? bytes[read++] : null; // session key size is always even
|
|
15786
|
+
followLength -= followLength % 2;
|
|
15787
|
+
this.wrappedKey = bytes.subarray(read, read + followLength); read += followLength;
|
|
15788
|
+
}
|
|
15789
|
+
|
|
15790
|
+
/**
|
|
15791
|
+
* Write an MontgomerySymmetricKey as an Uint8Array
|
|
15792
|
+
* @returns {Uint8Array} Serialised data
|
|
15793
|
+
*/
|
|
15794
|
+
write() {
|
|
15795
|
+
return util.concatUint8Array([
|
|
15796
|
+
this.algorithm ?
|
|
15797
|
+
new Uint8Array([this.wrappedKey.length + 1, this.algorithm]) :
|
|
15798
|
+
new Uint8Array([this.wrappedKey.length]),
|
|
15799
|
+
this.wrappedKey
|
|
15800
|
+
]);
|
|
15801
|
+
}
|
|
15802
|
+
}
|
|
15803
|
+
|
|
15382
15804
|
// GPG4Browsers - An OpenPGP implementation in javascript
|
|
15383
15805
|
|
|
15384
15806
|
/**
|
|
15385
15807
|
* Encrypts data using specified algorithm and public key parameters.
|
|
15386
15808
|
* See {@link https://tools.ietf.org/html/rfc4880#section-9.1|RFC 4880 9.1} for public key algorithms.
|
|
15387
|
-
* @param {module:enums.publicKey}
|
|
15809
|
+
* @param {module:enums.publicKey} keyAlgo - Public key algorithm
|
|
15810
|
+
* @param {module:enums.symmetric} symmetricAlgo - Cipher algorithm
|
|
15388
15811
|
* @param {Object} publicParams - Algorithm-specific public key parameters
|
|
15389
15812
|
* @param {Object} privateParams - Algorithm-specific private key parameters
|
|
15390
15813
|
* @param {Uint8Array} data - Data to be encrypted
|
|
@@ -15392,8 +15815,8 @@ const HashEnum = type_enum(enums.hash);
|
|
|
15392
15815
|
* @returns {Promise<Object>} Encrypted session key parameters.
|
|
15393
15816
|
* @async
|
|
15394
15817
|
*/
|
|
15395
|
-
async function publicKeyEncrypt(
|
|
15396
|
-
switch (
|
|
15818
|
+
async function publicKeyEncrypt(keyAlgo, symmetricAlgo, publicParams, privateParams, data, fingerprint) {
|
|
15819
|
+
switch (keyAlgo) {
|
|
15397
15820
|
case enums.publicKey.rsaEncrypt:
|
|
15398
15821
|
case enums.publicKey.rsaEncryptSign: {
|
|
15399
15822
|
const { n, e } = publicParams;
|
|
@@ -15410,6 +15833,17 @@ async function publicKeyEncrypt(algo, publicParams, privateParams, data, fingerp
|
|
|
15410
15833
|
oid, kdfParams, data, Q, fingerprint);
|
|
15411
15834
|
return { V, C: new ECDHSymmetricKey(C) };
|
|
15412
15835
|
}
|
|
15836
|
+
case enums.publicKey.x25519: {
|
|
15837
|
+
if (!util.isAES(symmetricAlgo)) {
|
|
15838
|
+
// see https://gitlab.com/openpgp-wg/rfc4880bis/-/merge_requests/276
|
|
15839
|
+
throw new Error('X25519 keys can only encrypt AES session keys');
|
|
15840
|
+
}
|
|
15841
|
+
const { A } = publicParams;
|
|
15842
|
+
const { ephemeralPublicKey, wrappedKey } = await publicKey.elliptic.ecdhX.encrypt(
|
|
15843
|
+
keyAlgo, data, A);
|
|
15844
|
+
const C = ECDHXSymmetricKey.fromObject({ algorithm: symmetricAlgo, wrappedKey });
|
|
15845
|
+
return { ephemeralPublicKey, C };
|
|
15846
|
+
}
|
|
15413
15847
|
case enums.publicKey.aead: {
|
|
15414
15848
|
if (!privateParams) {
|
|
15415
15849
|
throw new Error('Cannot encrypt with symmetric key missing private parameters');
|
|
@@ -15466,6 +15900,16 @@ async function publicKeyDecrypt(algo, publicKeyParams, privateKeyParams, session
|
|
|
15466
15900
|
return publicKey.elliptic.ecdh.decrypt(
|
|
15467
15901
|
oid, kdfParams, V, C.data, Q, d, fingerprint);
|
|
15468
15902
|
}
|
|
15903
|
+
case enums.publicKey.x25519: {
|
|
15904
|
+
const { A } = publicKeyParams;
|
|
15905
|
+
const { k } = privateKeyParams;
|
|
15906
|
+
const { ephemeralPublicKey, C } = sessionKeyParams;
|
|
15907
|
+
if (!util.isAES(C.algorithm)) {
|
|
15908
|
+
throw new Error('AES session key expected');
|
|
15909
|
+
}
|
|
15910
|
+
return publicKey.elliptic.ecdhX.decrypt(
|
|
15911
|
+
algo, ephemeralPublicKey, C.wrappedKey, A, k);
|
|
15912
|
+
}
|
|
15469
15913
|
case enums.publicKey.aead: {
|
|
15470
15914
|
const { cipher: algo } = publicKeyParams;
|
|
15471
15915
|
const algoValue = algo.getValue();
|
|
@@ -15517,7 +15961,7 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
15517
15961
|
const Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
|
|
15518
15962
|
return { read: read, publicParams: { oid, Q } };
|
|
15519
15963
|
}
|
|
15520
|
-
case enums.publicKey.
|
|
15964
|
+
case enums.publicKey.eddsaLegacy: {
|
|
15521
15965
|
const oid = new OID(); read += oid.read(bytes);
|
|
15522
15966
|
checkSupportedCurve(oid);
|
|
15523
15967
|
let Q = util.readMPI(bytes.subarray(read)); read += Q.length + 2;
|
|
@@ -15531,6 +15975,11 @@ function parsePublicKeyParams(algo, bytes) {
|
|
|
15531
15975
|
const kdfParams = new KDFParams(); read += kdfParams.read(bytes.subarray(read));
|
|
15532
15976
|
return { read: read, publicParams: { oid, Q, kdfParams } };
|
|
15533
15977
|
}
|
|
15978
|
+
case enums.publicKey.ed25519:
|
|
15979
|
+
case enums.publicKey.x25519: {
|
|
15980
|
+
const A = bytes.subarray(read, read + 32); read += A.length;
|
|
15981
|
+
return { read, publicParams: { A } };
|
|
15982
|
+
}
|
|
15534
15983
|
case enums.publicKey.hmac:
|
|
15535
15984
|
case enums.publicKey.aead: {
|
|
15536
15985
|
const algo = new SymAlgoEnum(); read += algo.read(bytes);
|
|
@@ -15569,17 +16018,25 @@ function parsePrivateKeyParams(algo, bytes, publicParams) {
|
|
|
15569
16018
|
}
|
|
15570
16019
|
case enums.publicKey.ecdsa:
|
|
15571
16020
|
case enums.publicKey.ecdh: {
|
|
15572
|
-
const curve = new
|
|
16021
|
+
const curve = new CurveWithOID(publicParams.oid);
|
|
15573
16022
|
let d = util.readMPI(bytes.subarray(read)); read += d.length + 2;
|
|
15574
16023
|
d = util.leftPad(d, curve.payloadSize);
|
|
15575
16024
|
return { read, privateParams: { d } };
|
|
15576
16025
|
}
|
|
15577
|
-
case enums.publicKey.
|
|
15578
|
-
const curve = new
|
|
16026
|
+
case enums.publicKey.eddsaLegacy: {
|
|
16027
|
+
const curve = new CurveWithOID(publicParams.oid);
|
|
15579
16028
|
let seed = util.readMPI(bytes.subarray(read)); read += seed.length + 2;
|
|
15580
16029
|
seed = util.leftPad(seed, curve.payloadSize);
|
|
15581
16030
|
return { read, privateParams: { seed } };
|
|
15582
16031
|
}
|
|
16032
|
+
case enums.publicKey.ed25519: {
|
|
16033
|
+
const seed = bytes.subarray(read, read + 32); read += seed.length;
|
|
16034
|
+
return { read, privateParams: { seed } };
|
|
16035
|
+
}
|
|
16036
|
+
case enums.publicKey.x25519: {
|
|
16037
|
+
const k = bytes.subarray(read, read + 32); read += k.length;
|
|
16038
|
+
return { read, privateParams: { k } };
|
|
16039
|
+
}
|
|
15583
16040
|
case enums.publicKey.hmac: {
|
|
15584
16041
|
const { cipher: algo } = publicParams;
|
|
15585
16042
|
const keySize = hash.getHashByteLength(algo.getValue());
|
|
@@ -15631,6 +16088,16 @@ function parseEncSessionKeyParams(algo, bytes) {
|
|
|
15631
16088
|
const C = new ECDHSymmetricKey(); C.read(bytes.subarray(read));
|
|
15632
16089
|
return { V, C };
|
|
15633
16090
|
}
|
|
16091
|
+
// Algorithm-Specific Fields for X25519 encrypted session keys:
|
|
16092
|
+
// - 32 octets representing an ephemeral X25519 public key.
|
|
16093
|
+
// - A one-octet size of the following fields.
|
|
16094
|
+
// - The one-octet algorithm identifier, if it was passed (in the case of a v3 PKESK packet).
|
|
16095
|
+
// - The encrypted session key.
|
|
16096
|
+
case enums.publicKey.x25519: {
|
|
16097
|
+
const ephemeralPublicKey = bytes.subarray(read, read + 32); read += ephemeralPublicKey.length;
|
|
16098
|
+
const C = new ECDHXSymmetricKey(); C.read(bytes.subarray(read));
|
|
16099
|
+
return { ephemeralPublicKey, C };
|
|
16100
|
+
}
|
|
15634
16101
|
// Algorithm-Specific Fields for symmetric AEAD encryption:
|
|
15635
16102
|
// - AEAD algorithm
|
|
15636
16103
|
// - Starting initialization vector
|
|
@@ -15657,22 +16124,13 @@ function parseEncSessionKeyParams(algo, bytes) {
|
|
|
15657
16124
|
* @returns {Uint8Array} The array containing the MPIs.
|
|
15658
16125
|
*/
|
|
15659
16126
|
function serializeParams(algo, params) {
|
|
15660
|
-
|
|
15661
|
-
|
|
15662
|
-
|
|
15663
|
-
|
|
15664
|
-
|
|
15665
|
-
|
|
15666
|
-
|
|
15667
|
-
});
|
|
15668
|
-
break;
|
|
15669
|
-
}
|
|
15670
|
-
default:
|
|
15671
|
-
orderedParams = Object.keys(params).map(name => {
|
|
15672
|
-
const param = params[name];
|
|
15673
|
-
return util.isUint8Array(param) ? util.uint8ArrayToMPI(param) : param.write();
|
|
15674
|
-
});
|
|
15675
|
-
}
|
|
16127
|
+
// Some algorithms do not rely on MPIs to store the binary params
|
|
16128
|
+
const algosWithNativeRepresentation = new Set([enums.publicKey.ed25519, enums.publicKey.x25519, enums.publicKey.aead, enums.publicKey.hmac]);
|
|
16129
|
+
const orderedParams = Object.keys(params).map(name => {
|
|
16130
|
+
const param = params[name];
|
|
16131
|
+
if (!util.isUint8Array(param)) return param.write();
|
|
16132
|
+
return algosWithNativeRepresentation.has(algo) ? param : util.uint8ArrayToMPI(param);
|
|
16133
|
+
});
|
|
15676
16134
|
return util.concatUint8Array(orderedParams);
|
|
15677
16135
|
}
|
|
15678
16136
|
|
|
@@ -15700,7 +16158,7 @@ function generateParams(algo, bits, oid, symmetric) {
|
|
|
15700
16158
|
privateParams: { d: secret },
|
|
15701
16159
|
publicParams: { oid: new OID(oid), Q }
|
|
15702
16160
|
}));
|
|
15703
|
-
case enums.publicKey.
|
|
16161
|
+
case enums.publicKey.eddsaLegacy:
|
|
15704
16162
|
return publicKey.elliptic.generate(oid).then(({ oid, Q, secret }) => ({
|
|
15705
16163
|
privateParams: { seed: secret },
|
|
15706
16164
|
publicParams: { oid: new OID(oid), Q }
|
|
@@ -15714,6 +16172,16 @@ function generateParams(algo, bits, oid, symmetric) {
|
|
|
15714
16172
|
kdfParams: new KDFParams({ hash, cipher })
|
|
15715
16173
|
}
|
|
15716
16174
|
}));
|
|
16175
|
+
case enums.publicKey.ed25519:
|
|
16176
|
+
return publicKey.elliptic.eddsa.generate(algo).then(({ A, seed }) => ({
|
|
16177
|
+
privateParams: { seed },
|
|
16178
|
+
publicParams: { A }
|
|
16179
|
+
}));
|
|
16180
|
+
case enums.publicKey.x25519:
|
|
16181
|
+
return publicKey.elliptic.ecdhX.generate(algo).then(({ A, k }) => ({
|
|
16182
|
+
privateParams: { k },
|
|
16183
|
+
publicParams: { A }
|
|
16184
|
+
}));
|
|
15717
16185
|
case enums.publicKey.hmac: {
|
|
15718
16186
|
const symAlgo = enums.write(enums.hash, symmetric);
|
|
15719
16187
|
const keyMaterial = getRandomBytes(hash.getHashByteLength(symAlgo));
|
|
@@ -15755,7 +16223,7 @@ async function createSymmetricParams(key, algo) {
|
|
|
15755
16223
|
* @returns {Promise<Boolean>} Whether the parameters are valid.
|
|
15756
16224
|
* @async
|
|
15757
16225
|
*/
|
|
15758
|
-
async function validateParams$
|
|
16226
|
+
async function validateParams$8(algo, publicParams, privateParams) {
|
|
15759
16227
|
if (!publicParams || !privateParams) {
|
|
15760
16228
|
throw new Error('Missing key parameters');
|
|
15761
16229
|
}
|
|
@@ -15784,10 +16252,20 @@ async function validateParams$6(algo, publicParams, privateParams) {
|
|
|
15784
16252
|
const { d } = privateParams;
|
|
15785
16253
|
return algoModule.validateParams(oid, Q, d);
|
|
15786
16254
|
}
|
|
15787
|
-
case enums.publicKey.
|
|
15788
|
-
const {
|
|
16255
|
+
case enums.publicKey.eddsaLegacy: {
|
|
16256
|
+
const { Q, oid } = publicParams;
|
|
16257
|
+
const { seed } = privateParams;
|
|
16258
|
+
return publicKey.elliptic.eddsaLegacy.validateParams(oid, Q, seed);
|
|
16259
|
+
}
|
|
16260
|
+
case enums.publicKey.ed25519: {
|
|
16261
|
+
const { A } = publicParams;
|
|
15789
16262
|
const { seed } = privateParams;
|
|
15790
|
-
return publicKey.elliptic.eddsa.validateParams(
|
|
16263
|
+
return publicKey.elliptic.eddsa.validateParams(algo, A, seed);
|
|
16264
|
+
}
|
|
16265
|
+
case enums.publicKey.x25519: {
|
|
16266
|
+
const { A } = publicParams;
|
|
16267
|
+
const { k } = privateParams;
|
|
16268
|
+
return publicKey.elliptic.ecdhX.validateParams(algo, A, k);
|
|
15791
16269
|
}
|
|
15792
16270
|
case enums.publicKey.hmac: {
|
|
15793
16271
|
const { cipher: algo, digest } = publicParams;
|
|
@@ -15857,6 +16335,23 @@ function checkSupportedCurve(oid) {
|
|
|
15857
16335
|
}
|
|
15858
16336
|
}
|
|
15859
16337
|
|
|
16338
|
+
/**
|
|
16339
|
+
* Get preferred hash algo for a given elliptic algo
|
|
16340
|
+
* @param {module:enums.publicKey} algo - alrogithm identifier
|
|
16341
|
+
* @param {module:type/oid} [oid] - curve OID if needed by algo
|
|
16342
|
+
*/
|
|
16343
|
+
function getPreferredCurveHashAlgo(algo, oid) {
|
|
16344
|
+
switch (algo) {
|
|
16345
|
+
case enums.publicKey.ecdsa:
|
|
16346
|
+
case enums.publicKey.eddsaLegacy:
|
|
16347
|
+
return publicKey.elliptic.getPreferredHashAlgo(oid);
|
|
16348
|
+
case enums.publicKey.ed25519:
|
|
16349
|
+
return publicKey.elliptic.eddsa.getPreferredHashAlgo(algo);
|
|
16350
|
+
default:
|
|
16351
|
+
throw new Error('Unknown elliptic signing algo');
|
|
16352
|
+
}
|
|
16353
|
+
}
|
|
16354
|
+
|
|
15860
16355
|
var crypto$1 = /*#__PURE__*/Object.freeze({
|
|
15861
16356
|
__proto__: null,
|
|
15862
16357
|
publicKeyEncrypt: publicKeyEncrypt,
|
|
@@ -15866,11 +16361,12 @@ var crypto$1 = /*#__PURE__*/Object.freeze({
|
|
|
15866
16361
|
parseEncSessionKeyParams: parseEncSessionKeyParams,
|
|
15867
16362
|
serializeParams: serializeParams,
|
|
15868
16363
|
generateParams: generateParams,
|
|
15869
|
-
validateParams: validateParams$
|
|
16364
|
+
validateParams: validateParams$8,
|
|
15870
16365
|
getPrefixRandom: getPrefixRandom,
|
|
15871
16366
|
generateSessionKey: generateSessionKey,
|
|
15872
16367
|
getAEADMode: getAEADMode,
|
|
15873
|
-
getCipher: getCipher
|
|
16368
|
+
getCipher: getCipher,
|
|
16369
|
+
getPreferredCurveHashAlgo: getPreferredCurveHashAlgo
|
|
15874
16370
|
});
|
|
15875
16371
|
|
|
15876
16372
|
/**
|
|
@@ -16113,15 +16609,15 @@ class GenericS2K {
|
|
|
16113
16609
|
this.type = 'gnu-dummy';
|
|
16114
16610
|
// GnuPG extension mode 1001 -- don't write secret key at all
|
|
16115
16611
|
} else {
|
|
16116
|
-
throw new
|
|
16612
|
+
throw new UnsupportedError('Unknown s2k gnu protection mode.');
|
|
16117
16613
|
}
|
|
16118
16614
|
} else {
|
|
16119
|
-
throw new
|
|
16615
|
+
throw new UnsupportedError('Unknown s2k type.');
|
|
16120
16616
|
}
|
|
16121
16617
|
break;
|
|
16122
16618
|
|
|
16123
16619
|
default:
|
|
16124
|
-
throw new
|
|
16620
|
+
throw new UnsupportedError('Unknown s2k type.'); // unreachable
|
|
16125
16621
|
}
|
|
16126
16622
|
|
|
16127
16623
|
return i;
|
|
@@ -16225,7 +16721,7 @@ function newS2KFromType(type, config$1 = config) {
|
|
|
16225
16721
|
case enums.s2k.simple:
|
|
16226
16722
|
return new GenericS2K(type, config$1);
|
|
16227
16723
|
default:
|
|
16228
|
-
throw new
|
|
16724
|
+
throw new UnsupportedError(`Unsupported S2K type ${type}`);
|
|
16229
16725
|
}
|
|
16230
16726
|
}
|
|
16231
16727
|
|
|
@@ -24979,13 +25475,17 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
24979
25475
|
* @param {Uint8Array} bytes - Payload of a tag 1 packet
|
|
24980
25476
|
*/
|
|
24981
25477
|
read(bytes) {
|
|
24982
|
-
|
|
25478
|
+
let i = 0;
|
|
25479
|
+
this.version = bytes[i++];
|
|
24983
25480
|
if (this.version !== VERSION$3) {
|
|
24984
25481
|
throw new UnsupportedError(`Version ${this.version} of the PKESK packet is unsupported.`);
|
|
24985
25482
|
}
|
|
24986
|
-
this.publicKeyID.read(bytes.subarray(
|
|
24987
|
-
this.publicKeyAlgorithm = bytes[
|
|
24988
|
-
this.encrypted = mod.parseEncSessionKeyParams(this.publicKeyAlgorithm, bytes.subarray(
|
|
25483
|
+
i += this.publicKeyID.read(bytes.subarray(i));
|
|
25484
|
+
this.publicKeyAlgorithm = bytes[i++];
|
|
25485
|
+
this.encrypted = mod.parseEncSessionKeyParams(this.publicKeyAlgorithm, bytes.subarray(i), this.version);
|
|
25486
|
+
if (this.publicKeyAlgorithm === enums.publicKey.x25519) {
|
|
25487
|
+
this.sessionKeyAlgorithm = enums.write(enums.symmetric, this.encrypted.C.algorithm);
|
|
25488
|
+
}
|
|
24989
25489
|
}
|
|
24990
25490
|
|
|
24991
25491
|
/**
|
|
@@ -25011,15 +25511,11 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
25011
25511
|
* @async
|
|
25012
25512
|
*/
|
|
25013
25513
|
async encrypt(key) {
|
|
25014
|
-
const data = util.concatUint8Array([
|
|
25015
|
-
new Uint8Array([enums.write(enums.symmetric, this.sessionKeyAlgorithm)]),
|
|
25016
|
-
this.sessionKey,
|
|
25017
|
-
util.writeChecksum(this.sessionKey)
|
|
25018
|
-
]);
|
|
25019
25514
|
const algo = enums.write(enums.publicKey, this.publicKeyAlgorithm);
|
|
25515
|
+
const encoded = encodeSessionKey(this.version, algo, this.sessionKeyAlgorithm, this.sessionKey);
|
|
25020
25516
|
const privateParams = algo === enums.publicKey.aead ? key.privateParams : null;
|
|
25021
25517
|
this.encrypted = await mod.publicKeyEncrypt(
|
|
25022
|
-
algo, key.publicParams, privateParams,
|
|
25518
|
+
algo, this.sessionKeyAlgorithm, key.publicParams, privateParams, encoded, key.getFingerprintBytes());
|
|
25023
25519
|
}
|
|
25024
25520
|
|
|
25025
25521
|
/**
|
|
@@ -25036,34 +25532,86 @@ class PublicKeyEncryptedSessionKeyPacket {
|
|
|
25036
25532
|
throw new Error('Decryption error');
|
|
25037
25533
|
}
|
|
25038
25534
|
|
|
25039
|
-
const randomPayload = randomSessionKey ?
|
|
25040
|
-
|
|
25041
|
-
|
|
25042
|
-
|
|
25043
|
-
]) : null;
|
|
25044
|
-
const decoded = await mod.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, key.getFingerprintBytes(), randomPayload);
|
|
25045
|
-
const symmetricAlgoByte = decoded[0];
|
|
25046
|
-
const sessionKey = decoded.subarray(1, decoded.length - 2);
|
|
25047
|
-
const checksum = decoded.subarray(decoded.length - 2);
|
|
25048
|
-
const computedChecksum = util.writeChecksum(sessionKey);
|
|
25049
|
-
const isValidChecksum = computedChecksum[0] === checksum[0] & computedChecksum[1] === checksum[1];
|
|
25050
|
-
|
|
25051
|
-
if (randomSessionKey) {
|
|
25052
|
-
// We must not leak info about the validity of the decrypted checksum or cipher algo.
|
|
25053
|
-
// The decrypted session key must be of the same algo and size as the random session key, otherwise we discard it and use the random data.
|
|
25054
|
-
const isValidPayload = isValidChecksum & symmetricAlgoByte === randomSessionKey.sessionKeyAlgorithm & sessionKey.length === randomSessionKey.sessionKey.length;
|
|
25055
|
-
this.sessionKeyAlgorithm = util.selectUint8(isValidPayload, symmetricAlgoByte, randomSessionKey.sessionKeyAlgorithm);
|
|
25056
|
-
this.sessionKey = util.selectUint8Array(isValidPayload, sessionKey, randomSessionKey.sessionKey);
|
|
25535
|
+
const randomPayload = randomSessionKey ?
|
|
25536
|
+
encodeSessionKey(this.version, this.publicKeyAlgorithm, randomSessionKey.sessionKeyAlgorithm, randomSessionKey.sessionKey) :
|
|
25537
|
+
null;
|
|
25538
|
+
const decryptedData = await mod.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, key.getFingerprintBytes(), randomPayload);
|
|
25057
25539
|
|
|
25058
|
-
}
|
|
25059
|
-
|
|
25060
|
-
|
|
25061
|
-
|
|
25062
|
-
|
|
25540
|
+
const { sessionKey, sessionKeyAlgorithm } = decodeSessionKey(this.version, this.publicKeyAlgorithm, decryptedData, randomSessionKey);
|
|
25541
|
+
|
|
25542
|
+
// v3 Montgomery curves have cleartext cipher algo
|
|
25543
|
+
if (this.publicKeyAlgorithm !== enums.publicKey.x25519) {
|
|
25544
|
+
this.sessionKeyAlgorithm = sessionKeyAlgorithm;
|
|
25545
|
+
}
|
|
25546
|
+
this.sessionKey = sessionKey;
|
|
25547
|
+
}
|
|
25548
|
+
}
|
|
25549
|
+
|
|
25550
|
+
|
|
25551
|
+
function encodeSessionKey(version, keyAlgo, cipherAlgo, sessionKeyData) {
|
|
25552
|
+
switch (keyAlgo) {
|
|
25553
|
+
case enums.publicKey.rsaEncrypt:
|
|
25554
|
+
case enums.publicKey.rsaEncryptSign:
|
|
25555
|
+
case enums.publicKey.elgamal:
|
|
25556
|
+
case enums.publicKey.ecdh:
|
|
25557
|
+
case enums.publicKey.aead: {
|
|
25558
|
+
// add checksum
|
|
25559
|
+
return util.concatUint8Array([
|
|
25560
|
+
new Uint8Array([cipherAlgo]),
|
|
25561
|
+
sessionKeyData,
|
|
25562
|
+
util.writeChecksum(sessionKeyData.subarray(sessionKeyData.length % 8))
|
|
25563
|
+
]);
|
|
25564
|
+
}
|
|
25565
|
+
case enums.publicKey.x25519:
|
|
25566
|
+
return sessionKeyData;
|
|
25567
|
+
default:
|
|
25568
|
+
throw new Error('Unsupported public key algorithm');
|
|
25569
|
+
}
|
|
25570
|
+
}
|
|
25571
|
+
|
|
25572
|
+
|
|
25573
|
+
function decodeSessionKey(version, keyAlgo, decryptedData, randomSessionKey) {
|
|
25574
|
+
switch (keyAlgo) {
|
|
25575
|
+
case enums.publicKey.rsaEncrypt:
|
|
25576
|
+
case enums.publicKey.rsaEncryptSign:
|
|
25577
|
+
case enums.publicKey.elgamal:
|
|
25578
|
+
case enums.publicKey.ecdh:
|
|
25579
|
+
case enums.publicKey.aead: {
|
|
25580
|
+
// verify checksum in constant time
|
|
25581
|
+
const result = decryptedData.subarray(0, decryptedData.length - 2);
|
|
25582
|
+
const checksum = decryptedData.subarray(decryptedData.length - 2);
|
|
25583
|
+
const computedChecksum = util.writeChecksum(result.subarray(result.length % 8));
|
|
25584
|
+
const isValidChecksum = computedChecksum[0] === checksum[0] & computedChecksum[1] === checksum[1];
|
|
25585
|
+
const decryptedSessionKey = { sessionKeyAlgorithm: result[0], sessionKey: result.subarray(1) };
|
|
25586
|
+
if (randomSessionKey) {
|
|
25587
|
+
// We must not leak info about the validity of the decrypted checksum or cipher algo.
|
|
25588
|
+
// The decrypted session key must be of the same algo and size as the random session key, otherwise we discard it and use the random data.
|
|
25589
|
+
const isValidPayload = isValidChecksum &
|
|
25590
|
+
decryptedSessionKey.sessionKeyAlgorithm === randomSessionKey.sessionKeyAlgorithm &
|
|
25591
|
+
decryptedSessionKey.sessionKey.length === randomSessionKey.sessionKey.length;
|
|
25592
|
+
return {
|
|
25593
|
+
sessionKey: util.selectUint8Array(isValidPayload, decryptedSessionKey.sessionKey, randomSessionKey.sessionKey),
|
|
25594
|
+
sessionKeyAlgorithm: util.selectUint8(
|
|
25595
|
+
isValidPayload,
|
|
25596
|
+
decryptedSessionKey.sessionKeyAlgorithm,
|
|
25597
|
+
randomSessionKey.sessionKeyAlgorithm
|
|
25598
|
+
)
|
|
25599
|
+
};
|
|
25063
25600
|
} else {
|
|
25064
|
-
|
|
25601
|
+
const isValidPayload = isValidChecksum && enums.read(enums.symmetric, decryptedSessionKey.sessionKeyAlgorithm);
|
|
25602
|
+
if (isValidPayload) {
|
|
25603
|
+
return decryptedSessionKey;
|
|
25604
|
+
} else {
|
|
25605
|
+
throw new Error('Decryption error');
|
|
25606
|
+
}
|
|
25065
25607
|
}
|
|
25066
25608
|
}
|
|
25609
|
+
case enums.publicKey.x25519:
|
|
25610
|
+
return {
|
|
25611
|
+
sessionKey: decryptedData
|
|
25612
|
+
};
|
|
25613
|
+
default:
|
|
25614
|
+
throw new Error('Unsupported public key algorithm');
|
|
25067
25615
|
}
|
|
25068
25616
|
}
|
|
25069
25617
|
|
|
@@ -25494,7 +26042,7 @@ class PublicKeyPacket {
|
|
|
25494
26042
|
result.bits = util.uint8ArrayBitLength(modulo);
|
|
25495
26043
|
} else if (this.publicParams.oid) {
|
|
25496
26044
|
result.curve = this.publicParams.oid.getName();
|
|
25497
|
-
} else {
|
|
26045
|
+
} else if (this.publicParams.cipher) {
|
|
25498
26046
|
result.symmetric = this.publicParams.cipher.getName();
|
|
25499
26047
|
}
|
|
25500
26048
|
return result;
|
|
@@ -25826,6 +26374,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25826
26374
|
async read(bytes) {
|
|
25827
26375
|
// - A Public-Key or Public-Subkey packet, as described above.
|
|
25828
26376
|
let i = await this.readPublicKey(bytes);
|
|
26377
|
+
const startOfSecretKeyData = i;
|
|
25829
26378
|
|
|
25830
26379
|
// - One octet indicating string-to-key usage conventions. Zero
|
|
25831
26380
|
// indicates that the secret-key data is not encrypted. 255 or 254
|
|
@@ -25839,41 +26388,48 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25839
26388
|
i++;
|
|
25840
26389
|
}
|
|
25841
26390
|
|
|
25842
|
-
|
|
25843
|
-
|
|
25844
|
-
|
|
25845
|
-
this.
|
|
26391
|
+
try {
|
|
26392
|
+
// - [Optional] If string-to-key usage octet was 255, 254, or 253, a
|
|
26393
|
+
// one-octet symmetric encryption algorithm.
|
|
26394
|
+
if (this.s2kUsage === 255 || this.s2kUsage === 254 || this.s2kUsage === 253) {
|
|
26395
|
+
this.symmetric = bytes[i++];
|
|
25846
26396
|
|
|
25847
|
-
|
|
25848
|
-
|
|
25849
|
-
|
|
25850
|
-
|
|
25851
|
-
|
|
26397
|
+
// - [Optional] If string-to-key usage octet was 253, a one-octet
|
|
26398
|
+
// AEAD algorithm.
|
|
26399
|
+
if (this.s2kUsage === 253) {
|
|
26400
|
+
this.aead = bytes[i++];
|
|
26401
|
+
}
|
|
25852
26402
|
|
|
25853
|
-
|
|
25854
|
-
|
|
25855
|
-
|
|
25856
|
-
|
|
25857
|
-
|
|
25858
|
-
|
|
26403
|
+
// - [Optional] If string-to-key usage octet was 255, 254, or 253, a
|
|
26404
|
+
// string-to-key specifier. The length of the string-to-key
|
|
26405
|
+
// specifier is implied by its type, as described above.
|
|
26406
|
+
const s2kType = bytes[i++];
|
|
26407
|
+
this.s2k = newS2KFromType(s2kType);
|
|
26408
|
+
i += this.s2k.read(bytes.subarray(i, bytes.length));
|
|
25859
26409
|
|
|
25860
|
-
|
|
25861
|
-
|
|
26410
|
+
if (this.s2k.type === 'gnu-dummy') {
|
|
26411
|
+
return;
|
|
26412
|
+
}
|
|
26413
|
+
} else if (this.s2kUsage) {
|
|
26414
|
+
this.symmetric = this.s2kUsage;
|
|
25862
26415
|
}
|
|
25863
|
-
} else if (this.s2kUsage) {
|
|
25864
|
-
this.symmetric = this.s2kUsage;
|
|
25865
|
-
}
|
|
25866
26416
|
|
|
25867
|
-
|
|
25868
|
-
|
|
25869
|
-
|
|
25870
|
-
|
|
25871
|
-
|
|
25872
|
-
|
|
25873
|
-
|
|
25874
|
-
|
|
26417
|
+
// - [Optional] If secret data is encrypted (string-to-key usage octet
|
|
26418
|
+
// not zero), an Initial Vector (IV) of the same length as the
|
|
26419
|
+
// cipher's block size.
|
|
26420
|
+
if (this.s2kUsage) {
|
|
26421
|
+
this.iv = bytes.subarray(
|
|
26422
|
+
i,
|
|
26423
|
+
i + mod.getCipher(this.symmetric).blockSize
|
|
26424
|
+
);
|
|
25875
26425
|
|
|
25876
|
-
|
|
26426
|
+
i += this.iv.length;
|
|
26427
|
+
}
|
|
26428
|
+
} catch (e) {
|
|
26429
|
+
// if the s2k is unsupported, we still want to support encrypting and verifying with the given key
|
|
26430
|
+
if (!this.s2kUsage) throw e; // always throw for decrypted keys
|
|
26431
|
+
this.unparseableKeyMaterial = bytes.subarray(startOfSecretKeyData);
|
|
26432
|
+
this.isEncrypted = true;
|
|
25877
26433
|
}
|
|
25878
26434
|
|
|
25879
26435
|
// - Only for a version 5 packet, a four-octet scalar octet count for
|
|
@@ -25909,8 +26465,15 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25909
26465
|
* @returns {Uint8Array} A string of bytes containing the secret key OpenPGP packet.
|
|
25910
26466
|
*/
|
|
25911
26467
|
write() {
|
|
25912
|
-
const
|
|
26468
|
+
const serializedPublicKey = this.writePublicKey();
|
|
26469
|
+
if (this.unparseableKeyMaterial) {
|
|
26470
|
+
return util.concatUint8Array([
|
|
26471
|
+
serializedPublicKey,
|
|
26472
|
+
this.unparseableKeyMaterial
|
|
26473
|
+
]);
|
|
26474
|
+
}
|
|
25913
26475
|
|
|
26476
|
+
const arr = [serializedPublicKey];
|
|
25914
26477
|
arr.push(new Uint8Array([this.s2kUsage]));
|
|
25915
26478
|
|
|
25916
26479
|
const optionalFieldsArr = [];
|
|
@@ -25970,6 +26533,18 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25970
26533
|
return this.isEncrypted === false;
|
|
25971
26534
|
}
|
|
25972
26535
|
|
|
26536
|
+
/**
|
|
26537
|
+
* Check whether the key includes secret key material.
|
|
26538
|
+
* Some secret keys do not include it, and can thus only be used
|
|
26539
|
+
* for public-key operations (encryption and verification).
|
|
26540
|
+
* Such keys are:
|
|
26541
|
+
* - GNU-dummy keys, where the secret material has been stripped away
|
|
26542
|
+
* - encrypted keys with unsupported S2K or cipher
|
|
26543
|
+
*/
|
|
26544
|
+
isMissingSecretKeyMaterial() {
|
|
26545
|
+
return this.unparseableKeyMaterial !== undefined || this.isDummy();
|
|
26546
|
+
}
|
|
26547
|
+
|
|
25973
26548
|
/**
|
|
25974
26549
|
* Check whether this is a gnu-dummy key
|
|
25975
26550
|
* @returns {Boolean}
|
|
@@ -25990,6 +26565,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
25990
26565
|
if (this.isDecrypted()) {
|
|
25991
26566
|
this.clearPrivateParams();
|
|
25992
26567
|
}
|
|
26568
|
+
delete this.unparseableKeyMaterial;
|
|
25993
26569
|
this.isEncrypted = null;
|
|
25994
26570
|
this.keyMaterial = null;
|
|
25995
26571
|
this.s2k = newS2KFromType(enums.s2k.gnu, config$1);
|
|
@@ -26061,6 +26637,10 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
26061
26637
|
return false;
|
|
26062
26638
|
}
|
|
26063
26639
|
|
|
26640
|
+
if (this.unparseableKeyMaterial) {
|
|
26641
|
+
throw new Error('Key packet cannot be decrypted: unsupported S2K or cipher algo');
|
|
26642
|
+
}
|
|
26643
|
+
|
|
26064
26644
|
if (this.isDecrypted()) {
|
|
26065
26645
|
throw new Error('Key packet is already decrypted.');
|
|
26066
26646
|
}
|
|
@@ -26145,7 +26725,7 @@ class SecretKeyPacket extends PublicKeyPacket {
|
|
|
26145
26725
|
* Clear private key parameters
|
|
26146
26726
|
*/
|
|
26147
26727
|
clearPrivateParams() {
|
|
26148
|
-
if (this.
|
|
26728
|
+
if (this.isMissingSecretKeyMaterial()) {
|
|
26149
26729
|
return;
|
|
26150
26730
|
}
|
|
26151
26731
|
|
|
@@ -27544,25 +28124,22 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
27544
28124
|
const dataToSign = {};
|
|
27545
28125
|
dataToSign.key = primaryKey;
|
|
27546
28126
|
dataToSign.bind = subkey;
|
|
27547
|
-
const
|
|
27548
|
-
subkeySignaturePacket.signatureType = enums.signature.subkeyBinding;
|
|
27549
|
-
subkeySignaturePacket.publicKeyAlgorithm = primaryKey.algorithm;
|
|
27550
|
-
subkeySignaturePacket.hashAlgorithm = await getPreferredHashAlgo$1(null, subkey, undefined, undefined, config);
|
|
28127
|
+
const signatureProperties = { signatureType: enums.signature.subkeyBinding };
|
|
27551
28128
|
if (options.sign) {
|
|
27552
|
-
|
|
27553
|
-
|
|
28129
|
+
signatureProperties.keyFlags = [enums.keyFlags.signData];
|
|
28130
|
+
signatureProperties.embeddedSignature = await createSignaturePacket(dataToSign, null, subkey, {
|
|
27554
28131
|
signatureType: enums.signature.keyBinding
|
|
27555
28132
|
}, options.date, undefined, undefined, undefined, config);
|
|
27556
28133
|
} else {
|
|
27557
|
-
|
|
28134
|
+
signatureProperties.keyFlags = options.forwarding ?
|
|
27558
28135
|
[enums.keyFlags.forwardedCommunication] :
|
|
27559
28136
|
[enums.keyFlags.encryptCommunication | enums.keyFlags.encryptStorage];
|
|
27560
28137
|
}
|
|
27561
28138
|
if (options.keyExpirationTime > 0) {
|
|
27562
|
-
|
|
27563
|
-
|
|
28139
|
+
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
|
28140
|
+
signatureProperties.keyNeverExpires = false;
|
|
27564
28141
|
}
|
|
27565
|
-
await
|
|
28142
|
+
const subkeySignaturePacket = await createSignaturePacket(dataToSign, null, primaryKey, signatureProperties, options.date, undefined, undefined, undefined, config);
|
|
27566
28143
|
return subkeySignaturePacket;
|
|
27567
28144
|
}
|
|
27568
28145
|
|
|
@@ -27576,7 +28153,7 @@ async function createBindingSignature(subkey, primaryKey, options, config) {
|
|
|
27576
28153
|
* @returns {Promise<enums.hash>}
|
|
27577
28154
|
* @async
|
|
27578
28155
|
*/
|
|
27579
|
-
async function getPreferredHashAlgo$
|
|
28156
|
+
async function getPreferredHashAlgo$2(key, keyPacket, date = new Date(), userID = {}, config) {
|
|
27580
28157
|
let hashAlgo = config.preferredHashAlgorithm;
|
|
27581
28158
|
let prefAlgo = hashAlgo;
|
|
27582
28159
|
if (key) {
|
|
@@ -27587,17 +28164,11 @@ async function getPreferredHashAlgo$1(key, keyPacket, date = new Date(), userID
|
|
|
27587
28164
|
prefAlgo : hashAlgo;
|
|
27588
28165
|
}
|
|
27589
28166
|
}
|
|
27590
|
-
switch (
|
|
27591
|
-
case
|
|
27592
|
-
case
|
|
27593
|
-
case
|
|
27594
|
-
|
|
27595
|
-
switch (keyPacket.algorithm) {
|
|
27596
|
-
case enums.publicKey.ecdh:
|
|
27597
|
-
case enums.publicKey.ecdsa:
|
|
27598
|
-
case enums.publicKey.eddsa:
|
|
27599
|
-
prefAlgo = mod.publicKey.elliptic.getPreferredHashAlgo(keyPacket.publicParams.oid);
|
|
27600
|
-
}
|
|
28167
|
+
switch (keyPacket.algorithm) {
|
|
28168
|
+
case enums.publicKey.ecdsa:
|
|
28169
|
+
case enums.publicKey.eddsaLegacy:
|
|
28170
|
+
case enums.publicKey.ed25519:
|
|
28171
|
+
prefAlgo = mod.getPreferredCurveHashAlgo(keyPacket.algorithm, keyPacket.publicParams.oid);
|
|
27601
28172
|
}
|
|
27602
28173
|
return mod.hash.getHashByteLength(hashAlgo) <= mod.hash.getHashByteLength(prefAlgo) ?
|
|
27603
28174
|
prefAlgo : hashAlgo;
|
|
@@ -27665,7 +28236,7 @@ async function createSignaturePacket(dataToSign, privateKey, signingKeyPacket, s
|
|
|
27665
28236
|
const signaturePacket = new SignaturePacket();
|
|
27666
28237
|
Object.assign(signaturePacket, signatureProperties);
|
|
27667
28238
|
signaturePacket.publicKeyAlgorithm = signingKeyPacket.algorithm;
|
|
27668
|
-
signaturePacket.hashAlgorithm = await getPreferredHashAlgo$
|
|
28239
|
+
signaturePacket.hashAlgorithm = await getPreferredHashAlgo$2(privateKey, signingKeyPacket, date, userID, config);
|
|
27669
28240
|
signaturePacket.rawNotations = notations;
|
|
27670
28241
|
await signaturePacket.sign(signingKeyPacket, dataToSign, date, detached);
|
|
27671
28242
|
return signaturePacket;
|
|
@@ -27806,11 +28377,11 @@ function sanitizeKeyOptions(options, subkeyDefaults = {}) {
|
|
|
27806
28377
|
} catch (e) {
|
|
27807
28378
|
throw new Error('Unknown curve');
|
|
27808
28379
|
}
|
|
27809
|
-
if (options.curve === enums.curve.
|
|
27810
|
-
options.curve = options.sign ? enums.curve.
|
|
28380
|
+
if (options.curve === enums.curve.ed25519Legacy || options.curve === enums.curve.curve25519Legacy) {
|
|
28381
|
+
options.curve = options.sign ? enums.curve.ed25519Legacy : enums.curve.curve25519Legacy;
|
|
27811
28382
|
}
|
|
27812
28383
|
if (options.sign) {
|
|
27813
|
-
options.algorithm = options.curve === enums.curve.
|
|
28384
|
+
options.algorithm = options.curve === enums.curve.ed25519Legacy ? enums.publicKey.eddsaLegacy : enums.publicKey.ecdsa;
|
|
27814
28385
|
} else {
|
|
27815
28386
|
options.algorithm = enums.publicKey.ecdh;
|
|
27816
28387
|
}
|
|
@@ -27838,6 +28409,7 @@ function isValidSigningKeyPacket(keyPacket, signature) {
|
|
|
27838
28409
|
return keyAlgo !== enums.publicKey.rsaEncrypt &&
|
|
27839
28410
|
keyAlgo !== enums.publicKey.elgamal &&
|
|
27840
28411
|
keyAlgo !== enums.publicKey.ecdh &&
|
|
28412
|
+
keyAlgo !== enums.publicKey.x25519 &&
|
|
27841
28413
|
(!signature.keyFlags ||
|
|
27842
28414
|
(signature.keyFlags[0] & enums.keyFlags.signData) !== 0);
|
|
27843
28415
|
}
|
|
@@ -27847,7 +28419,8 @@ function isValidEncryptionKeyPacket(keyPacket, signature) {
|
|
|
27847
28419
|
return keyAlgo !== enums.publicKey.dsa &&
|
|
27848
28420
|
keyAlgo !== enums.publicKey.rsaSign &&
|
|
27849
28421
|
keyAlgo !== enums.publicKey.ecdsa &&
|
|
27850
|
-
keyAlgo !== enums.publicKey.
|
|
28422
|
+
keyAlgo !== enums.publicKey.eddsaLegacy &&
|
|
28423
|
+
keyAlgo !== enums.publicKey.ed25519 &&
|
|
27851
28424
|
(!signature.keyFlags ||
|
|
27852
28425
|
(signature.keyFlags[0] & enums.keyFlags.encryptCommunication) !== 0 ||
|
|
27853
28426
|
(signature.keyFlags[0] & enums.keyFlags.encryptStorage) !== 0);
|
|
@@ -27892,7 +28465,7 @@ function checkKeyRequirements(keyPacket, config) {
|
|
|
27892
28465
|
}
|
|
27893
28466
|
break;
|
|
27894
28467
|
case enums.publicKey.ecdsa:
|
|
27895
|
-
case enums.publicKey.
|
|
28468
|
+
case enums.publicKey.eddsaLegacy:
|
|
27896
28469
|
case enums.publicKey.ecdh:
|
|
27897
28470
|
if (config.rejectCurves.has(algoInfo.curve)) {
|
|
27898
28471
|
throw new Error(`Support for ${algoInfo.algorithm} keys using curve ${algoInfo.curve} is disabled.`);
|
|
@@ -29402,7 +29975,7 @@ function createKey(packetlist) {
|
|
|
29402
29975
|
* @static
|
|
29403
29976
|
* @private
|
|
29404
29977
|
*/
|
|
29405
|
-
async function generate$
|
|
29978
|
+
async function generate$4(options, config) {
|
|
29406
29979
|
options.sign = true; // primary key is always a signing key
|
|
29407
29980
|
options = sanitizeKeyOptions(options);
|
|
29408
29981
|
options.subkeys = options.subkeys.map((subkey, index) => sanitizeKeyOptions(options.subkeys[index], options));
|
|
@@ -29519,50 +30092,50 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options, conf
|
|
|
29519
30092
|
const dataToSign = {};
|
|
29520
30093
|
dataToSign.userID = userIDPacket;
|
|
29521
30094
|
dataToSign.key = secretKeyPacket;
|
|
29522
|
-
|
|
29523
|
-
|
|
29524
|
-
|
|
29525
|
-
|
|
29526
|
-
|
|
29527
|
-
signaturePacket.preferredSymmetricAlgorithms = createPreferredAlgos([
|
|
30095
|
+
|
|
30096
|
+
const signatureProperties = {};
|
|
30097
|
+
signatureProperties.signatureType = enums.signature.certGeneric;
|
|
30098
|
+
signatureProperties.keyFlags = [enums.keyFlags.certifyKeys | enums.keyFlags.signData];
|
|
30099
|
+
signatureProperties.preferredSymmetricAlgorithms = createPreferredAlgos([
|
|
29528
30100
|
// prefer aes256, aes128, then aes192 (no WebCrypto support: https://www.chromium.org/blink/webcrypto#TOC-AES-support)
|
|
29529
30101
|
enums.symmetric.aes256,
|
|
29530
30102
|
enums.symmetric.aes128,
|
|
29531
30103
|
enums.symmetric.aes192
|
|
29532
30104
|
], config.preferredSymmetricAlgorithm);
|
|
29533
30105
|
if (config.aeadProtect) {
|
|
29534
|
-
|
|
30106
|
+
signatureProperties.preferredAEADAlgorithms = createPreferredAlgos([
|
|
29535
30107
|
enums.aead.eax,
|
|
29536
30108
|
enums.aead.ocb
|
|
29537
30109
|
], config.preferredAEADAlgorithm);
|
|
29538
30110
|
}
|
|
29539
|
-
|
|
30111
|
+
signatureProperties.preferredHashAlgorithms = createPreferredAlgos([
|
|
29540
30112
|
// prefer fast asm.js implementations (SHA-256)
|
|
29541
30113
|
enums.hash.sha256,
|
|
29542
30114
|
enums.hash.sha512
|
|
29543
30115
|
], config.preferredHashAlgorithm);
|
|
29544
|
-
|
|
30116
|
+
signatureProperties.preferredCompressionAlgorithms = createPreferredAlgos([
|
|
29545
30117
|
enums.compression.zlib,
|
|
29546
30118
|
enums.compression.zip,
|
|
29547
30119
|
enums.compression.uncompressed
|
|
29548
30120
|
], config.preferredCompressionAlgorithm);
|
|
29549
30121
|
if (index === 0) {
|
|
29550
|
-
|
|
30122
|
+
signatureProperties.isPrimaryUserID = true;
|
|
29551
30123
|
}
|
|
29552
30124
|
// integrity protection always enabled
|
|
29553
|
-
|
|
29554
|
-
|
|
30125
|
+
signatureProperties.features = [0];
|
|
30126
|
+
signatureProperties.features[0] |= enums.features.modificationDetection;
|
|
29555
30127
|
if (config.aeadProtect) {
|
|
29556
|
-
|
|
30128
|
+
signatureProperties.features[0] |= enums.features.aead;
|
|
29557
30129
|
}
|
|
29558
30130
|
if (config.v5Keys) {
|
|
29559
|
-
|
|
30131
|
+
signatureProperties.features[0] |= enums.features.v5Keys;
|
|
29560
30132
|
}
|
|
29561
30133
|
if (options.keyExpirationTime > 0) {
|
|
29562
|
-
|
|
29563
|
-
|
|
30134
|
+
signatureProperties.keyExpirationTime = options.keyExpirationTime;
|
|
30135
|
+
signatureProperties.keyNeverExpires = false;
|
|
29564
30136
|
}
|
|
29565
|
-
|
|
30137
|
+
|
|
30138
|
+
const signaturePacket = await createSignaturePacket(dataToSign, null, secretKeyPacket, signatureProperties, options.date, undefined, undefined, undefined, config);
|
|
29566
30139
|
|
|
29567
30140
|
return { userIDPacket, signaturePacket };
|
|
29568
30141
|
})).then(list => {
|
|
@@ -30081,6 +30654,15 @@ class Message {
|
|
|
30081
30654
|
enums.read(enums.aead, await getPreferredAlgo('aead', encryptionKeys, date, userIDs, config$1)) :
|
|
30082
30655
|
undefined;
|
|
30083
30656
|
|
|
30657
|
+
await Promise.all(encryptionKeys.map(key => key.getEncryptionKey()
|
|
30658
|
+
.catch(() => null) // ignore key strength requirements
|
|
30659
|
+
.then(maybeKey => {
|
|
30660
|
+
if (maybeKey && (maybeKey.keyPacket.algorithm === enums.publicKey.x25519) && !util.isAES(algo)) {
|
|
30661
|
+
throw new Error('Could not generate a session key compatible with the given `encryptionKeys`: X22519 keys can only be used to encrypt AES session keys; change `config.preferredSymmetricAlgorithm` accordingly.');
|
|
30662
|
+
}
|
|
30663
|
+
})
|
|
30664
|
+
));
|
|
30665
|
+
|
|
30084
30666
|
const sessionKeyData = mod.generateSessionKey(algo);
|
|
30085
30667
|
return { data: sessionKeyData, algorithm: algorithmName, aeadAlgorithm: aeadAlgorithmName };
|
|
30086
30668
|
}
|
|
@@ -30255,7 +30837,7 @@ class Message {
|
|
|
30255
30837
|
const signingKey = await primaryKey.getSigningKey(signingKeyID, date, userIDs, config$1);
|
|
30256
30838
|
const onePassSig = new OnePassSignaturePacket();
|
|
30257
30839
|
onePassSig.signatureType = signatureType;
|
|
30258
|
-
onePassSig.hashAlgorithm = await getPreferredHashAlgo$
|
|
30840
|
+
onePassSig.hashAlgorithm = await getPreferredHashAlgo$2(primaryKey, signingKey.keyPacket, date, userIDs, config$1);
|
|
30259
30841
|
onePassSig.publicKeyAlgorithm = signingKey.keyPacket.algorithm;
|
|
30260
30842
|
onePassSig.issuerKeyID = signingKey.getKeyID();
|
|
30261
30843
|
if (i === signingKeys.length - 1) {
|
|
@@ -30388,7 +30970,7 @@ class Message {
|
|
|
30388
30970
|
if (literalDataList.length !== 1) {
|
|
30389
30971
|
throw new Error('Can only verify message with one literal data packet.');
|
|
30390
30972
|
}
|
|
30391
|
-
const signatureList = signature.packets;
|
|
30973
|
+
const signatureList = signature.packets.filterByTag(enums.packet.signature); // drop UnparsablePackets
|
|
30392
30974
|
return createVerificationObjects(signatureList, literalDataList, verificationKeys, date, true, config$1);
|
|
30393
30975
|
}
|
|
30394
30976
|
|
|
@@ -30735,7 +31317,7 @@ class CleartextMessage {
|
|
|
30735
31317
|
* @async
|
|
30736
31318
|
*/
|
|
30737
31319
|
verify(keys, date = new Date(), config$1 = config) {
|
|
30738
|
-
const signatureList = this.signature.packets;
|
|
31320
|
+
const signatureList = this.signature.packets.filterByTag(enums.packet.signature); // drop UnparsablePackets
|
|
30739
31321
|
const literalDataPacket = new LiteralDataPacket();
|
|
30740
31322
|
// we assume that cleartext signature is generated based on UTF8 cleartext
|
|
30741
31323
|
literalDataPacket.setText(this.text);
|
|
@@ -30820,7 +31402,7 @@ function verifyHeaders$1(headers, packetlist) {
|
|
|
30820
31402
|
let oneHeader = null;
|
|
30821
31403
|
let hashAlgos = [];
|
|
30822
31404
|
headers.forEach(function(header) {
|
|
30823
|
-
oneHeader = header.match(
|
|
31405
|
+
oneHeader = header.match(/^Hash: (.+)$/); // get header value
|
|
30824
31406
|
if (oneHeader) {
|
|
30825
31407
|
oneHeader = oneHeader[1].replace(/\s/g, ''); // remove whitespace
|
|
30826
31408
|
oneHeader = oneHeader.split(',');
|
|
@@ -30912,7 +31494,7 @@ async function generateKey({ userIDs = [], passphrase, type = 'ecc', rsaBits = 4
|
|
|
30912
31494
|
const options = { userIDs, passphrase, type, rsaBits, curve, keyExpirationTime, date, subkeys, symmetricHash, symmetricCipher };
|
|
30913
31495
|
|
|
30914
31496
|
try {
|
|
30915
|
-
const { key, revocationCertificate } = await generate$
|
|
31497
|
+
const { key, revocationCertificate } = await generate$4(options, config$1);
|
|
30916
31498
|
key.getKeys().forEach(({ keyPacket }) => checkKeyRequirements(keyPacket, config$1));
|
|
30917
31499
|
|
|
30918
31500
|
return {
|
|
@@ -31106,7 +31688,7 @@ async function encryptKey({ privateKey, passphrase, config: config$1, ...rest })
|
|
|
31106
31688
|
* @async
|
|
31107
31689
|
* @static
|
|
31108
31690
|
*/
|
|
31109
|
-
async function encrypt$
|
|
31691
|
+
async function encrypt$5({ message, encryptionKeys, signingKeys, passwords, sessionKey, format = 'armored', signature = null, wildcard = false, signingKeyIDs = [], encryptionKeyIDs = [], date = new Date(), signingUserIDs = [], encryptionUserIDs = [], signatureNotations = [], config: config$1, ...rest }) {
|
|
31110
31692
|
config$1 = { ...config, ...config$1 }; checkConfig(config$1);
|
|
31111
31693
|
checkMessage(message); checkOutputMessageFormat(format);
|
|
31112
31694
|
encryptionKeys = toArray$1(encryptionKeys); signingKeys = toArray$1(signingKeys); passwords = toArray$1(passwords);
|
|
@@ -31175,7 +31757,7 @@ async function encrypt$4({ message, encryptionKeys, signingKeys, passwords, sess
|
|
|
31175
31757
|
* @async
|
|
31176
31758
|
* @static
|
|
31177
31759
|
*/
|
|
31178
|
-
async function decrypt$
|
|
31760
|
+
async function decrypt$5({ message, decryptionKeys, passwords, sessionKeys, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config: config$1, ...rest }) {
|
|
31179
31761
|
config$1 = { ...config, ...config$1 }; checkConfig(config$1);
|
|
31180
31762
|
checkMessage(message); verificationKeys = toArray$1(verificationKeys); decryptionKeys = toArray$1(decryptionKeys); passwords = toArray$1(passwords); sessionKeys = toArray$1(sessionKeys);
|
|
31181
31763
|
if (rest.privateKeys) throw new Error('The `privateKeys` option has been removed from openpgp.decrypt, pass `decryptionKeys` instead');
|
|
@@ -31238,7 +31820,7 @@ async function decrypt$4({ message, decryptionKeys, passwords, sessionKeys, veri
|
|
|
31238
31820
|
* @async
|
|
31239
31821
|
* @static
|
|
31240
31822
|
*/
|
|
31241
|
-
async function sign$
|
|
31823
|
+
async function sign$6({ message, signingKeys, format = 'armored', detached = false, signingKeyIDs = [], date = new Date(), signingUserIDs = [], signatureNotations = [], config: config$1, ...rest }) {
|
|
31242
31824
|
config$1 = { ...config, ...config$1 }; checkConfig(config$1);
|
|
31243
31825
|
checkCleartextOrMessage(message); checkOutputMessageFormat(format);
|
|
31244
31826
|
signingKeys = toArray$1(signingKeys); signingKeyIDs = toArray$1(signingKeyIDs); signingUserIDs = toArray$1(signingUserIDs); signatureNotations = toArray$1(signatureNotations);
|
|
@@ -31307,7 +31889,7 @@ async function sign$5({ message, signingKeys, format = 'armored', detached = fal
|
|
|
31307
31889
|
* @async
|
|
31308
31890
|
* @static
|
|
31309
31891
|
*/
|
|
31310
|
-
async function verify$
|
|
31892
|
+
async function verify$6({ message, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config: config$1, ...rest }) {
|
|
31311
31893
|
config$1 = { ...config, ...config$1 }; checkConfig(config$1);
|
|
31312
31894
|
checkCleartextOrMessage(message); verificationKeys = toArray$1(verificationKeys);
|
|
31313
31895
|
if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.verify, pass `verificationKeys` instead');
|
|
@@ -44476,7 +45058,7 @@ function* makePRNG(wasmContext, pass, lane, slice, m_, totalPasses, segmentLengt
|
|
|
44476
45058
|
return [];
|
|
44477
45059
|
}
|
|
44478
45060
|
|
|
44479
|
-
function validateParams$
|
|
45061
|
+
function validateParams$9({ type, version, tagLength, password, salt, ad, secret, parallelism, memorySize, passes }) {
|
|
44480
45062
|
const assertLength = (name, value, min, max) => {
|
|
44481
45063
|
if (value < min || value > max) { throw new Error(`${name} size should be between ${min} and ${max} bytes`); }
|
|
44482
45064
|
};
|
|
@@ -44499,7 +45081,7 @@ const WASM_PAGE_SIZE = 64 * KB;
|
|
|
44499
45081
|
function argon2id(params, { memory, instance: wasmInstance }) {
|
|
44500
45082
|
if (!isLittleEndian$1) throw new Error('BigEndian system not supported'); // optmisations assume LE system
|
|
44501
45083
|
|
|
44502
|
-
const ctx = validateParams$
|
|
45084
|
+
const ctx = validateParams$9({ type: TYPE$2, version: VERSION$4, ...params });
|
|
44503
45085
|
|
|
44504
45086
|
const { G:wasmG, G2:wasmG2, xor:wasmXOR, getLZ:wasmLZ } = wasmInstance.exports;
|
|
44505
45087
|
const wasmRefs = {};
|
|
@@ -44773,4 +45355,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
44773
45355
|
'default': loadWasm
|
|
44774
45356
|
});
|
|
44775
45357
|
|
|
44776
|
-
export { AEADEncryptedDataPacket, CleartextMessage, CompressedDataPacket, KDFParams, LiteralDataPacket, MarkerPacket, Message, OnePassSignaturePacket, PacketList, PrivateKey, PublicKey, PublicKeyEncryptedSessionKeyPacket, PublicKeyPacket, PublicSubkeyPacket, SecretKeyPacket, SecretSubkeyPacket, Signature, SignaturePacket, Subkey, SymEncryptedIntegrityProtectedDataPacket, SymEncryptedSessionKeyPacket, SymmetricallyEncryptedDataPacket, TrustPacket, UnparseablePacket, UserAttributePacket, UserIDPacket, armor, config, createCleartextMessage, createMessage, decrypt$
|
|
45358
|
+
export { AEADEncryptedDataPacket, CleartextMessage, CompressedDataPacket, KDFParams, LiteralDataPacket, MarkerPacket, Message, OnePassSignaturePacket, PacketList, PrivateKey, PublicKey, PublicKeyEncryptedSessionKeyPacket, PublicKeyPacket, PublicSubkeyPacket, SecretKeyPacket, SecretSubkeyPacket, Signature, SignaturePacket, Subkey, SymEncryptedIntegrityProtectedDataPacket, SymEncryptedSessionKeyPacket, SymmetricallyEncryptedDataPacket, TrustPacket, UnparseablePacket, UserAttributePacket, UserIDPacket, armor, config, createCleartextMessage, createMessage, decrypt$5 as decrypt, decryptKey, decryptSessionKeys, encrypt$5 as encrypt, encryptKey, encryptSessionKey, enums, generateKey, generateSessionKey$1 as generateSessionKey, readCleartextMessage, readKey, readKeys, readMessage, readPrivateKey, readPrivateKeys, readSignature, reformatKey, revokeKey, sign$6 as sign, unarmor, verify$6 as verify };
|