-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use AES-WRAP in Electron apps #40
Comments
I'm not having much luck with the Electron or BoringSSL teams. If I can't convince them to add/enable AES-KW, would you guys be open to a PR that uses a pure JS implementation of AES-KW when This would require adding a dependency on @stablelib/aes-kw or aes-kw, or forking one of them to embed the implementation in |
@gnarea I think the simplest way is creating and registering the new AES-KW provider with extra dependency for Electron. I don't think it's a good solution to import such dependencies to the package if they are required for Electron runtime only import { Crypto } from "@peculiar/webcrypto";
import * as core from "webcrypto-core";
class AesKwProvider extends core.AesKwProvider {
async onGenerateKey(algorithm, extractable, keyUsages) {
throw new Error("AES-KW: generateKey: Method not implemented");
}
async onExportKey(format, key) {
throw new Error("Method not implemented");
}
async onImportKey(format, keyData, algorithm, extractable, keyUsages) {
throw new Error("Method not implemented");
}
async onEncrypt(algorithm, key, data) {
throw new Error("Method not implemented");
}
async onDecrypt(algorithm, key, data) {
throw new Error("Method not implemented");
}
}
// Register the new AES-KW provider
const crypto = new Crypto();
crypto.subtle.providers.set(new AesKwProvider())
await crypto.subtle.generateKey({ name: "AES-KW", length: 128 }, false, ["wrapKey", "unwrapKey"]);
// Error: AES-KW: generateKey: Method not implemented But |
@microshine, thanks, that'd work for me. We could even just extend the I can put a PR together to make |
It's impossible.
it would be nice |
True, I didn't realise that class wasn't exported. Would you consider exporting it? Otherwise, I'd have to duplicate most of the code in |
|
Sorry, I don't understand why |
Actually, I don't think I'd need Then I could just proxy |
I see. Thanks @microshine! That's really helpful. I'll get back to this tomorrow or Monday, and I'll make the PR then. |
Coming back to this, what about a PR that only used the pure JS implementation of AES-KW if Node.js doesn't support this cipher? This is what I did in my project: export class AwalaCrypto extends Crypto {
constructor() {
super();
const doesNodejsSupportAesKw = getCiphers().includes('id-aes128-wrap');
if (!doesNodejsSupportAesKw) {
// This must be running on Electron, so let's use a pure JavaScript implementation of AES-KW:
// https://github.com/relaycorp/relaynet-core-js/issues/367
const providers = (this.subtle as SubtleCrypto).providers;
const nodejsAesKwProvider = providers.get('AES-KW') as AesKwProvider;
providers.set(new AwalaAesKwProvider(nodejsAesKwProvider));
}
}
} |
You'd get an error like this:
This is due to electron/electron#31874
This means that you can't use PKI.js with
EnvelopedData
and DH, for example.I don't think there's anything to change in this repo, but I wanted to create this issue to save some time to anyone that comes across this issue. Feel free to close it.
The text was updated successfully, but these errors were encountered: