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

Deno panic on node:crypto createCipheriv with key provided as string #27807

Closed
jacobhaap opened this issue Jan 24, 2025 · 0 comments · Fixed by #27818
Closed

Deno panic on node:crypto createCipheriv with key provided as string #27807

jacobhaap opened this issue Jan 24, 2025 · 0 comments · Fixed by #27818
Labels
bug Something isn't working correctly crypto Related to node:crypto or WebCrypto

Comments

@jacobhaap
Copy link

jacobhaap commented Jan 24, 2025

Version: Deno 2.1.7

When using the createCipheriv function from node:crypto, deno panics when the key provided to the createCipheriv function with the aes-256-gcm algorithm is of type string (string provided for a key of type CipherKey, alias for BinaryLike/string).

This is reproducible in TypeScript via the following script:

import { randomBytes, createCipheriv } from "node:crypto";
import type { CipherGCMTypes, CipherKey, BinaryLike, CipherGCM } from "node:crypto";

const algorithm: CipherGCMTypes = "aes-256-gcm";
const key: CipherKey = randomBytes(32).toString('hex');
const iv: BinaryLike = randomBytes(16);

const text: string = "Greetings Fellow Humans";

const cypher: CipherGCM = createCipheriv(algorithm, key, iv);
let cyphertext: string = cypher.update(text, 'utf8', 'hex');
cyphertext += cypher.final('hex');

When the key is provided as Buffer (const key: CipherKey = randomBytes(32);), Deno does not panic and createCipheriv functions normally.

Deno panic:

Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: linux x86_64
Version: 2.1.7
Args: ["deno", "run", "-A", "cypher.ts"]

thread 'main' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/generic-array-0.14.7/src/lib.rs:572:9:
assertion `left == right` failed
  left: 64
 right: 32

Backtrace:

stack backtrace:
   0:     0x5f6644a4afaa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h304520fd6a30aa07
   1:     0x5f6644a7c9bb - core::fmt::write::hf5713710ce10ff22
   2:     0x5f6644a44763 - std::io::Write::write_fmt::hda708db57927dacf
   3:     0x5f6644a4c7b2 - std::panicking::default_hook::{{closure}}::he1ad87607d0c11c5
   4:     0x5f6644a4c41e - std::panicking::default_hook::h81c8cd2e7c59ee33
   5:     0x5f6645215c22 - deno::setup_panic_hook::{{closure}}::h38af1368884fd81b
   6:     0x5f6644a4d0e2 - std::panicking::rust_panic_with_hook::had2118629c312a4a
   7:     0x5f6644a4cd97 - std::panicking::begin_panic_handler::{{closure}}::h7fa5985d111bafa2
   8:     0x5f6644a4b489 - std::sys::backtrace::__rust_end_short_backtrace::h704d151dbefa09c5
   9:     0x5f6644a4ca24 - rust_begin_unwind
  10:     0x5f6644a79973 - core::panicking::panic_fmt::h3eea515d05f7a35e
  11:     0x5f6644a79cfe - core::panicking::assert_failed_inner::h11b1378688fb0090
  12:     0x5f6645d11771 - core::panicking::assert_failed::h5b3f205d09aaa48d
  13:     0x5f6645dd6e24 - deno_node::ops::crypto::cipher::CipherContext::new::hca31887f40562b81
  14:     0x5f6645e50a99 - deno_node::ops::crypto::op_node_create_cipheriv::op_node_create_cipheriv::slow_function_impl::h0ea494a10a5dd1ef
  15:     0x5f6645e50eb6 - deno_node::ops::crypto::op_node_create_cipheriv::op_node_create_cipheriv::v8_fn_ptr::h5cbec28e2183ee7e
  16:     0x5f65e480f1c6 - <unknown>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly crypto Related to node:crypto or WebCrypto
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants