oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.13k stars 2.67k forks source link

`ssh2` is not able to sign with private key #4487

Open jkbz64 opened 1 year ago

jkbz64 commented 1 year ago

What version of Bun is running?

0.8.1

What platform is your computer?

Linux 6.4.0-asahi-10-1-edge-ARCH aarch64 unknown

What steps can reproduce the bug?

import { readFileSync } from "node:fs";
import { Client } from "ssh2";

const connection = new Client();
connection
  .on("ready", () => {
    console.log("Client :: ready");
  })
  .connect({
    host: "<host>",
    port: 22,
    username: "<user>",
    privateKey: readFileSync("<path to pkey>"),
  });

What is the expected behavior?

Should output Client :: ready

What do you see instead?

8797 |   }
8798 | }), require_sign = __commonJS({
8799 |   "node_modules/browserify-sign/browser/sign.js"(exports, module) {
8800 |     var Buffer2 = require_safe_buffer().Buffer, createHmac = require_browser3(), crt = require_browserify_rsa(), EC = require_elliptic().ec, BN = require_bn3(), parseKeys = require_parse_asn1(), curves = require_curves2();
8801 | 
8802 |     function sign(hash, key, hashType, signType, tag) {
                                     ^
error: Error signing data with key: wrong private key type
      at sign (node:crypto:8802:34)
      at node:crypto:8944:74
      at sign (/tmp/ssh2/node_modules/ssh2/lib/protocol/keyParser.js:393:15)
      at /tmp/ssh2/node_modules/ssh2/lib/client.js:467:32
      at authPK (/tmp/ssh2/node_modules/ssh2/lib/protocol/Protocol.js:692:4)
      at USERAUTH_PK_OK (/tmp/ssh2/node_modules/ssh2/lib/client.js:466:12)
      at 60 (/tmp/ssh2/node_modules/ssh2/lib/protocol/handlers.misc.js:504:19)
      at onPayload (/tmp/ssh2/node_modules/ssh2/lib/protocol/Protocol.js:2052:9)
      at decrypt (/tmp/ssh2/node_modules/ssh2/lib/protocol/crypto.js:987:20)
      at parsePacket (/tmp/ssh2/node_modules/ssh2/lib/protocol/Protocol.js:2021:9)

Additional information

The same exact code works on node, tried to use Bun.file API instead of readFileSync, same result. Used standard ssh-keygen ssh-rsa key without password.

FrancescoMasaia commented 11 months ago

We replicated the same error in 1.0.4 version too

jawaad-juggle commented 10 months ago

Hey, I've run into this issue too. Did you managed to work a way around this?

FrancescoMasaia commented 10 months ago

Removed bun as dependency I’m not using bun anymore for that projectIl giorno 1 nov 2023, alle ore 11:58, jawaad-juggle @.***> ha scritto: Hey, I've run into this issue too. Did you managed to work a way around this?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

osbre commented 1 month ago

Duplicate of https://github.com/oven-sh/bun/issues/4290 ?

Tried to run this example:

❯❯❯ BUN_JSC_dumpModuleLoadingState=1 bun run app.js                                                        ✘ 134
Loader [fetch] bun:main
loader [parsing] bun:main
Loader [resolve] /Users/user/code/bun-ssh-project/app.js
Loader [fetch] /Users/user/code/bun-ssh-project/app.js
loader [parsing] /Users/user/code/bun-ssh-project/app.js
Loader [resolve] fs
Loader [resolve] ssh2
Loader [fetch] fs
Loader [fetch] /Users/user/code/bun-ssh-project/node_modules/ssh2/lib/index.js
loader [parsing] fs
loader [parsing] string_decoder
Loader [link] string_decoder
Loader [evaluate] string_decoder
loader [parsing] util/types
Loader [link] util/types
Loader [evaluate] util/types
loader [parsing] /Users/user/code/bun-ssh-project/node_modules/ssh2/lib/index.js
loader [parsing] buffer
Loader [link] buffer
Loader [evaluate] buffer
dyld[27404]: missing symbol called
fish: Job 1, 'BUN_JSC_dumpModuleLoadingState=…' terminated by signal SIGABRT (Abort)