mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2025-11-24 14:35:51 +00:00
Add workaround for WebCrypto X25519 key generation bug on WebKit Linux
Similar/same issue was already patched for Ed25519 . https://bugs.webkit.org/show_bug.cgi?id=279113
This commit is contained in:
parent
b9275642e1
commit
9703ab891e
@ -28,7 +28,15 @@ export async function generate(algo) {
|
|||||||
case enums.publicKey.x25519:
|
case enums.publicKey.x25519:
|
||||||
try {
|
try {
|
||||||
const webCrypto = util.getWebCrypto();
|
const webCrypto = util.getWebCrypto();
|
||||||
const webCryptoKey = await webCrypto.generateKey('X25519', true, ['deriveKey', 'deriveBits']);
|
const webCryptoKey = await webCrypto.generateKey('X25519', true, ['deriveKey', 'deriveBits'])
|
||||||
|
.catch(err => {
|
||||||
|
if (err.name === 'OperationError') { // Temporary (hopefully) fix for WebKit on Linux
|
||||||
|
const newErr = new Error('Unexpected key generation issue');
|
||||||
|
newErr.name = 'NotSupportedError';
|
||||||
|
throw newErr;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
const privateKey = await webCrypto.exportKey('jwk', webCryptoKey.privateKey);
|
const privateKey = await webCrypto.exportKey('jwk', webCryptoKey.privateKey);
|
||||||
const publicKey = await webCrypto.exportKey('jwk', webCryptoKey.publicKey);
|
const publicKey = await webCrypto.exportKey('jwk', webCryptoKey.publicKey);
|
||||||
@ -196,7 +204,15 @@ export async function generateEphemeralEncryptionMaterial(algo, recipientA) {
|
|||||||
case enums.publicKey.x25519:
|
case enums.publicKey.x25519:
|
||||||
try {
|
try {
|
||||||
const webCrypto = util.getWebCrypto();
|
const webCrypto = util.getWebCrypto();
|
||||||
const ephemeralKeyPair = await webCrypto.generateKey('X25519', true, ['deriveKey', 'deriveBits']);
|
const ephemeralKeyPair = await webCrypto.generateKey('X25519', true, ['deriveKey', 'deriveBits'])
|
||||||
|
.catch(err => {
|
||||||
|
if (err.name === 'OperationError') { // Temporary (hopefully) fix for WebKit on Linux
|
||||||
|
const newErr = new Error('Unexpected key generation issue');
|
||||||
|
newErr.name = 'NotSupportedError';
|
||||||
|
throw newErr;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
const ephemeralPublicKeyJwt = await webCrypto.exportKey('jwk', ephemeralKeyPair.publicKey);
|
const ephemeralPublicKeyJwt = await webCrypto.exportKey('jwk', ephemeralKeyPair.publicKey);
|
||||||
const ephemeralPrivateKeyJwt = await webCrypto.exportKey('jwk', ephemeralKeyPair.privateKey);
|
const ephemeralPrivateKeyJwt = await webCrypto.exportKey('jwk', ephemeralKeyPair.privateKey);
|
||||||
if (ephemeralPrivateKeyJwt.x !== ephemeralPublicKeyJwt.x) { // Weird issue with Webkit on Linux: https://bugs.webkit.org/show_bug.cgi?id=289693
|
if (ephemeralPrivateKeyJwt.x !== ephemeralPublicKeyJwt.x) { // Weird issue with Webkit on Linux: https://bugs.webkit.org/show_bug.cgi?id=289693
|
||||||
|
|||||||
@ -38,7 +38,15 @@ export async function generate(algo) {
|
|||||||
case enums.publicKey.ed25519:
|
case enums.publicKey.ed25519:
|
||||||
try {
|
try {
|
||||||
const webCrypto = util.getWebCrypto();
|
const webCrypto = util.getWebCrypto();
|
||||||
const webCryptoKey = await webCrypto.generateKey('Ed25519', true, ['sign', 'verify']);
|
const webCryptoKey = await webCrypto.generateKey('Ed25519', true, ['sign', 'verify'])
|
||||||
|
.catch(err => {
|
||||||
|
if (err.name === 'OperationError') { // Temporary (hopefully) fix for WebKit on Linux
|
||||||
|
const newErr = new Error('Unexpected key generation issue');
|
||||||
|
newErr.name = 'NotSupportedError';
|
||||||
|
throw newErr;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
const privateKey = await webCrypto.exportKey('jwk', webCryptoKey.privateKey);
|
const privateKey = await webCrypto.exportKey('jwk', webCryptoKey.privateKey);
|
||||||
const publicKey = await webCrypto.exportKey('jwk', webCryptoKey.publicKey);
|
const publicKey = await webCrypto.exportKey('jwk', webCryptoKey.publicKey);
|
||||||
@ -48,7 +56,7 @@ export async function generate(algo) {
|
|||||||
seed: b64ToUint8Array(privateKey.d, true)
|
seed: b64ToUint8Array(privateKey.d, true)
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.name !== 'NotSupportedError' && err.name !== 'OperationError') { // Temporary (hopefully) fix for WebKit on Linux
|
if (err.name !== 'NotSupportedError') {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
const seed = getRandomBytes(getPayloadSize(algo));
|
const seed = getRandomBytes(getPayloadSize(algo));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user