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

ext/node: jwk public key export not implemented (PublicKeyObject) #18928

Closed
Tracked by #18455
Asguho opened this issue Apr 30, 2023 · 18 comments · Fixed by #25239
Closed
Tracked by #18455

ext/node: jwk public key export not implemented (PublicKeyObject) #18928

Asguho opened this issue Apr 30, 2023 · 18 comments · Fixed by #25239
Assignees
Labels
crypto Related to node:crypto or WebCrypto node API polyfill Related to various "node:*" modules APIs node compat

Comments

@Asguho
Copy link

Asguho commented Apr 30, 2023

Describe the bug

Using mineflayer from npm causes a "not implemented" error with the crypto module from the node compatibility layer

Steps to Reproduce

Running the code in this index.ts file

import mineflayer from 'npm:mineflayer'

const bot = mineflayer.createBot({
    username: 'use any value here',
    host: 'localhost',
    auth: 'microsoft'
})

bot.on('login', () => {
    console.log('Succesfully logged in!')
})

Results in this error

% deno run --allow-all index.ts
error: Uncaught Error: Not implemented: crypto.KeyObject.prototype.asymmetricKeyType
    at notImplemented (ext:deno_node/_utils.ts:7:11)
    at KeyObject.get asymmetricKeyType (ext:deno_node/internal/crypto/keys.ts:62:9)
    at keyToJWK (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/jose/4.14.4/dist/node/cjs/runtime/key_to_jwk.js:35:85)
    at exportJWK (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/jose/4.14.4/dist/node/cjs/key/export.js:16:40)
    at new XboxTokenManager (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/prismarine-auth/2.2.0/src/TokenManagers/XboxTokenManager.js:19:5)
    at MicrosoftAuthFlow.initTokenManagers (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/prismarine-auth/2.2.0/src/MicrosoftAuthFlow.js:72:16)
    at new MicrosoftAuthFlow (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/prismarine-auth/2.2.0/src/MicrosoftAuthFlow.js:35:10)
    at Object.authenticate (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.41.2/src/client/microsoftAuth.js:21:43)
    at Object.createClient (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/minecraft-protocol/1.41.2/src/createClient.js:50:25)
    at Object.createBot (file:///C:/Users/aske/AppData/Local/deno/npm/registry.npmjs.org/mineflayer/4.8.1/lib/loader.js:96:35)

Update (@kt3k): Now the error is:

error: Uncaught (in promise) Error: Not implemented: jwk public key export not implemented
    at notImplemented (ext:deno_node/_utils.ts:38:9)
    at PublicKeyObject.export (ext:deno_node/internal/crypto/keys.ts:714:7)
    at keyToJWK (file:///Users/kt3k/Library/Caches/deno/npm/registry.npmjs.org/jose/4.15.9/dist/node/cjs/runtime/key_to_jwk.js:38:32)
    ....

Expected behavior

% deno run --allow-all index.ts
Succesfully logged in!

Environment

OS: Windows 11
deno version: 1.31.1

@hironichu
Copy link
Contributor

This is an ongoing implementation you can track here #18455

@levex
Copy link
Contributor

levex commented May 2, 2023

Some of this work will land in a PR in the coming days :-)

@SgtPooki
Copy link

SgtPooki commented Aug 3, 2023

@levex it's been a few months since your comment. Any updates here?

@link-discord
Copy link

Any updates? This is still an issue.

@levex
Copy link
Contributor

levex commented Sep 10, 2023

Unfortunately, I no longer have time to spare on contributing to Deno - please raise this with the team. cc @bartlomieju you can probably assist in redirecting this ticket.

@Asguho
Copy link
Author

Asguho commented Oct 30, 2023

Is there any news on redirecting this issue?

@littledivy
Copy link
Member

KeyObject#asymmetricKeyType was added in #20981

We're tracking other node:crypto APIs in #18455 and private key APIs in #21124.

@foobarfighter
Copy link

foobarfighter commented Nov 14, 2023

@littledivy I'm still seeing this issue as of today.

[uncaught application error]: Error - connect: getConnection: Not implemented: crypto.KeyObject.prototype.asymmetricKeyType
    at SftpClient.fmtError (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2-sftp-client/9.1.0/src/index.js:82:22)
    at SftpClient.connect (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2-sftp-client/9.1.0/src/index.js:219:37)
    at eventLoopTick (ext:core/01_core.js:189:11)
    at async SFTPStorageClient.save (file:///Users/bob/workspace/bank-api/api/storage.ts:41:5)
    at async FileService.create (file:///Users/bob/workspace/bank-api/api/service.ts:37:5)
    at async file:///Users/bob/workspace/bank-api/api/main.ts:44:23
    at async dispatch (https://deno.land/x/oak@v12.6.1/middleware.ts:80:7)
    at async dispatch (https://deno.land/x/oak@v12.6.1/middleware.ts:80:7)
    at async dispatch (https://deno.land/x/oak@v12.6.1/middleware.ts:80:7)
    at async dispatch (https://deno.land/x/oak@v12.6.1/middleware.ts:80:7)
deno 1.38.1 (release, aarch64-apple-darwin)
v8 12.0.267.1
typescript 5.2.2

@bartlomieju bartlomieju reopened this Nov 14, 2023
@bartlomieju
Copy link
Member

@littledivy PTAL

@foobarfighter
Copy link

foobarfighter commented Nov 17, 2023

Here is some more information if it's helpful:

$ deno --version

deno 1.38.1 (release, aarch64-apple-darwin)
v8 12.0.267.1
typescript 5.2.2

Minimal test case. I'm trying to use the ssh2 npm module (in my previous comment I was using the ssh2-sftp-client npm module which uses ssh2 under the hood):

import { Client } from "npm:ssh2";

const client = new Client();
const p = client
  .on("ready", () => {
    console.log("ready");
  })
  .on("error", (e: Error) => {
    console.log(e);
  })
  .connect({ host: "127.0.0.1", port: 2022, username: "username", password: "*******" });

More informative stack trace:

Error: Not implemented: crypto.KeyObject.prototype.asymmetricKeyType
    at notImplemented (ext:deno_node/_utils.ts:9:9)
    at KeyObject.export (ext:deno_node/internal/crypto/keys.ts:79:5)
    at Curve25519Exchange.getPublicKey (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/protocol/kex.js:1268:46)
    at Curve25519Exchange.start (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/protocol/kex.js:996:29)
    at handleKexInit (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/protocol/kex.js:486:13)
    at Protocol.onKEXPayload (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/protocol/kex.js:1777:14)
    at NullDecipher.decrypt (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/protocol/crypto.js:612:26)
    at Protocol.parsePacket [as _parse] (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/protocol/Protocol.js:2021:25)
    at Protocol.parse (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/protocol/Protocol.js:306:16)
    at Socket.<anonymous> (file:///Users/bob/Library/Caches/deno/npm/registry.npmjs.org/ssh2/1.14.0/lib/client.js:775:21)

@foobarfighter
Copy link

I dug into this a little bit deeper. The error should reference crypto.KeyObject.prototype.export and not crypto.KeyObject.prototype.asymmetricKeyType. I believe there's a copy pasta bug there.

It also looks like this is unimplemented because in nodejs KeyObject.export is implemented in C++. How should node compatibility modules that have C++ bindings be implemented in deno? In this case, the nodejs C++ implementations have a dependency on openssl.

@bartlomieju bartlomieju added the node API polyfill Related to various "node:*" modules APIs label Mar 4, 2024
@ansarizafar
Copy link

I also have the same issue with Deno and libp2p. Is there any solution?

@AndreaGiulianini
Copy link

The same problem with packeage tunnel-ssh

@sntran
Copy link

sntran commented Apr 28, 2024

Would like to see this to get ssh2 to work in Deno as well. It's the only SSH2/SFTP solution that we could use at the moment.

littledivy added a commit that referenced this issue Apr 29, 2024
Initial support for exporting rsa public KeyObject.

Current assumption is that RSA keys are stored in pkcs1 der format in
key storage.

Ref #23471 
Ref #18928
Ref #21124
@birkskyum
Copy link
Contributor

birkskyum commented May 30, 2024

Hit a related:

ERROR Not implemented: crypto.PrivateKeyObject.prototype.export

in the

@lucacasonato lucacasonato added the crypto Related to node:crypto or WebCrypto label Jun 8, 2024
@kt3k
Copy link
Member

kt3k commented Aug 5, 2024

Looks like now the error is: TypeError: exporting ec is not implemented

thrown in:

`exporting ${this.asymmetricKeyType} is not implemented`,

@kt3k kt3k changed the title Not implemented: crypto.KeyObject.prototype.asymmetricKeyType error with mineflayer ext/node: TypeError: exporting ec is not implemented (PublicKeyObject) Aug 5, 2024
@birkskyum
Copy link
Contributor

birkskyum commented Aug 8, 2024

Using the latest canary (deno 1.45.5+507e5b7) i now get

error: Uncaught (in promise) Error: Not implemented: jwk public key export not implemented

Can't tell if the exporting ec is not implemented issue is resolved, or if this jwk issue appear before it. @kt3k , can you tell?

@kt3k
Copy link
Member

kt3k commented Aug 8, 2024

@birkskyum Thanks for checking! I confirmed the same error. Updated the title.

(I think the previous issue was resolved in #24463)

@kt3k kt3k changed the title ext/node: TypeError: exporting ec is not implemented (PublicKeyObject) ext/node: jwk public key export not implemented (PublicKeyObject) Aug 8, 2024
littledivy added a commit to littledivy/deno that referenced this issue Aug 27, 2024
lucacasonato pushed a commit that referenced this issue Aug 29, 2024
Fixes #18928

Signed-off-by: Divy Srivastava <dj.srivastava23@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Related to node:crypto or WebCrypto node API polyfill Related to various "node:*" modules APIs node compat
Projects
None yet
Development

Successfully merging a pull request may close this issue.