Skip to content
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

[Bug]: crypto package is missing cipher AES-WRAP #31874

Closed
3 tasks done
gnarea opened this issue Nov 17, 2021 · 3 comments
Closed
3 tasks done

[Bug]: crypto package is missing cipher AES-WRAP #31874

gnarea opened this issue Nov 17, 2021 · 3 comments

Comments

@gnarea
Copy link

gnarea commented Nov 17, 2021

Preflight Checklist

Electron Version

16 (tested on 12, 13, 14 and 15 too)

What operating system are you using?

Ubuntu

Operating System Version

Linux relaybox 5.8.0-63-generic #71-Ubuntu SMP Tue Jul 13 15:59:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

AES with key wrap mode (aka AES-KW or AES-WRAP) to be supported.

Actual Behavior

It isn't supported:

const crypto = require("crypto");
crypto.createCipheriv('aes128-wrap', crypto.randomBytes(24), null);

results in:

Uncaught Error: Unknown cipher
    at Cipheriv.createCipherBase (node:internal/crypto/cipher:116)
    at Cipheriv.createCipherWithIV (node:internal/crypto/cipher:135)
    at new Cipheriv (node:internal/crypto/cipher:243)
    at Object.createCipheriv (node:crypto:138)
    at <anonymous>:1:8

crypto.getCiphers() returns the following:

[
    "aes-128-cbc",
    "aes-128-cfb",
    "aes-128-ctr",
    "aes-128-ecb",
    "aes-128-gcm",
    "aes-128-ofb",
    "aes-192-cbc",
    "aes-192-ctr",
    "aes-192-ecb",
    "aes-192-gcm",
    "aes-192-ofb",
    "aes-256-cbc",
    "aes-256-cfb",
    "aes-256-ctr",
    "aes-256-ecb",
    "aes-256-gcm",
    "aes-256-ofb",
    "des-cbc",
    "des-ecb",
    "des-ede",
    "des-ede-cbc",
    "des-ede3",
    "des-ede3-cbc",
    "rc2-cbc",
    "rc4"
]

Testcase Gist URL

No response

Additional Information

Node.js 12+ supports it:

$ node -e 'console.log(require("crypto").getCiphers().filter(s => s.includes("wrap")))'
[
  'aes128-wrap',
  'aes192-wrap',
  'aes256-wrap',
  'des3-wrap',
  'id-aes128-wrap',
  'id-aes128-wrap-pad',
  'id-aes192-wrap',
  'id-aes192-wrap-pad',
  'id-aes256-wrap',
  'id-aes256-wrap-pad',
  'id-smime-alg-CMS3DESwrap'
]
@codebytere
Copy link
Member

codebytere commented Nov 17, 2021

@gnarea This is due to the fact that Node.js uses OpenSSL to underpin its crypto module, and Chromium uses a fork of OpenSSL - BoringSSL. The version of Node.js that comes with Electron is thus forced to use BoringSSL for Node.js' own crypto, which has a smaller, more secure API surface.

You're more than welcome to open a crbug upstream to see if BoringSSL will add it, but this is unfortunately not something Electron itself is in a position to fix.

@gnarea
Copy link
Author

gnarea commented Nov 17, 2021

@codebytere, thanks for looking into this. I'm certainly happy to propose it upstream, but how is AES-WRAP any different from the other ciphers that have been enabled by the Electron team? You've patched boringssl to add support for des-ede3 (#30453) and AES-CFB (#16573).

Why couldn't we do that here? BoringSSL already supports this cipher.


Edit: I've just reported the issue upstream: https://bugs.chromium.org/p/boringssl/issues/detail?id=458

@microshine
Copy link

This information may be useful. Here are lists of mechanisms from NodeJS and Electron for comparison

NodeJS v16.13.0

crypto.getCiphers().filter(o => o.includes("wrap"));

// Log
[
  'aes128-wrap',
  'aes192-wrap',
  'aes256-wrap',
  'des3-wrap',
  'id-aes128-wrap',
  'id-aes128-wrap-pad',
  'id-aes192-wrap',
  'id-aes192-wrap-pad',
  'id-aes256-wrap',
  'id-aes256-wrap-pad',
  'id-smime-alg-CMS3DESwrap'
]

Electron v16.0.0

const crypto = require("crypto");
console.log(crypto.getCiphers().filter(o => o.includes("aes")));

// Log
[
  'aes-128-cbc', 'aes-128-cfb',
  'aes-128-ctr', 'aes-128-ecb',
  'aes-128-gcm', 'aes-128-ofb',
  'aes-192-cbc', 'aes-192-ctr',
  'aes-192-ecb', 'aes-192-gcm',
  'aes-192-ofb', 'aes-256-cbc',
  'aes-256-cfb', 'aes-256-ctr',
  'aes-256-ecb', 'aes-256-gcm',
  'aes-256-ofb'
]

Electron doesn't suggest any wrap mechanisms

const crypto = require("crypto");
console.log(crypto.getCiphers().filter(o => o.includes("wrap")))

// Log
[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants