Skip to content

runtime: crypto.KeyObject.from() returns undefined for asymmetric CryptoKeys and unregistered-buffer secret keys #6302

Description

@proggeramlug

Summary

crypto.KeyObject.from() returns undefined — silently, with no throw — for two shapes Node handles:

  1. an asymmetric CryptoKey (public/private)
  2. a secret CryptoKey whose backing buffer is not runtime-registered (e.g. imported from Buffer.from(hex) rather than from secretKey.export())

Behaviour

input node 26 perry main
KeyObject.from(<asymmetric CryptoKey>) public undefined
KeyObject.from(<HMAC CryptoKey from Buffer.from(hex)>) secret undefined

Root cause

crates/perry-runtime/src/object/native_module_crypto_key_object.rs:20-28key_object_from requires kind == 1 and is_registered_buffer(addr); anything else falls through to invalid_key(value) and yields undefined instead of throwing or constructing a KeyObject.

The checked-in fixture test-parity/node-suite/crypto/key-object/keyobject-class-from.ts only passes because it imports from secret.export(), which is an already-registered buffer — so this gap is not covered.

Split out of #2565 (whose three headline deliverables did ship and are byte-identical to Node).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions