sanketbajoria / ssh2-promise

ssh with promise/async await and typescript support
https://www.npmjs.com/package/ssh2-promise
MIT License
148 stars 25 forks source link

Disable Error Handling #80

Closed asarkisian closed 2 years ago

asarkisian commented 2 years ago

I am running mocha/webdriverio and running some tests on a remote ssh server. I can connect successfully and execute commands successfully; however, if I try to execute a command that returns a failure such as "rm data.dat" (assuming it doesn't exist), it will literally fail the test case and throw the following error:

Error: the buffer [ 97 98 115 100 102 115 58 32 67 111 109 109 97 110 100 32 110 111 116 32 102 111 117 110 100 46 10 ] was thrown, throw an Error :)

This is not ideal.. Is there a way error handling can be turned off? All I want it to do is simply output the error without having it throw an exception internally and thus fail my test case.. Yes, I can put this in a try/catch block and ignore the error however it won't continue printing the rest of the output.. it will stop at the error. So in essence, the try/catch block still doesn't allow me to reach my goals of printing the full output.

sanketbajoria commented 2 years ago

@asarkisian Can you please try latest release... we are doing error handling in string instead of buffer... https://www.npmjs.com/package/ssh2-promise/v/1.0.3

asarkisian commented 2 years ago

Hi Sanket,

Thank you. Also, is there any way we can run an exec() command without returning a promise? In other words, having an async as well as a sync version of this so that sometimes we don't want to wait until the command finishes.

Thanks!

On Sat, Jun 18, 2022 at 6:30 PM Sanket Bajoria @.***> wrote:

@asarkisian https://github.com/asarkisian Can you please try latest release... we are doing error handling in string instead of buffer... https://www.npmjs.com/package/ssh2-promise/v/1.0.3

— Reply to this email directly, view it on GitHub https://github.com/sanketbajoria/ssh2-promise/issues/80#issuecomment-1159594858, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETCUNEGUFTBFR42IQSLB3DVPZZ37ANCNFSM5Y5PZH5A . You are receiving this because you were mentioned.Message ID: @.***>

sanketbajoria commented 2 years ago

@asarkisian promises are by default async... so if you don't want to handle any error and also don't want to wait... then you can use.. in below manner

ssh.exec('dummy req'). catch((e) => {//don't do anything})

or you can capture 'unhandledRejection' at process level

process.on('unhandledRejection', callback)

Currently ssh2-promise doesn't support silent execution of command.

asarkisian commented 2 years ago

That worked! Final question to you, when I try to connect to a Solaris 10 machine, everything works perfectly.. I can login with no issues. When I connect to Solaris 11 however, it throws an authentication error. I know that Solaris 11 has beefier security when it comes to ciphers/kex. When attempting to login into Sol11, I get the error "Error: All configured authentication methods failed".

Have you seen this before? How can I add additional switches so that I can perhaps alter the ciphers or kex? Or also, how can I add verbose mode so that I can see what settings/security settings I currently have right now. Kindly advise.

Thank you

ERROR:

 Error: All configured authentication methods failed
  at doNextAuth

(/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/client.js:803:21) at tryNextAuth (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/client.js:993:7) at USERAUTH_FAILURE (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/client.js:373:11) at 51 (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/handlers.misc.js:337:16) at Protocol.onPayload (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/Protocol.js:2025:10) at AESGCMDecipherBinding.decrypt (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/crypto.js:1086:26) at Protocol.parsePacket [as _parse] (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/Protocol.js:1994:25) at Protocol.parse (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/Protocol.js:293:16) at Channel. (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/client.js:713:21) at Channel.emit (node:events:390:28) at Channel.emit (node:domain:475:12) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at Channel.Readable.push (node:internal/streams/readable:228:10) at CHANNEL_DATA (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/client.js:525:23) at 94 (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/handlers.misc.js:859:16) at Protocol.onPayload (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/Protocol.js:2025:10) at GenericDecipherBinding.decrypt (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/crypto.js:1418:26) at Protocol.parsePacket [as _parse] (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/Protocol.js:1994:25) at Protocol.parse (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/protocol/Protocol.js:293:16) at Socket. (/Users/armonds/Development/JPL/qa-automation-wdio-js/node_modules/ssh2/lib/client.js:713:21) at Socket.emit (node:events:390:28) at Socket.emit (node:domain:475:12) at addChunk (node:internal/streams/readable:315:12) at readableAddChunk (node:internal/streams/readable:289:9) at Socket.Readable.push (node:internal/streams/readable:228:10) at TCP.onStreamRead (node:internal/stream_base_commons:199:23)

On Mon, Jun 20, 2022 at 6:37 PM Sanket Bajoria @.***> wrote:

@asarkisian https://github.com/asarkisian promises are by default async... so if you don't want to handle any error and also don't want to wait... then you can use.. in below manner

ssh.exec('dummy req'). catch((e) => {//don't do anything})

— Reply to this email directly, view it on GitHub https://github.com/sanketbajoria/ssh2-promise/issues/80#issuecomment-1161062002, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETCUNHGVF5B3WXPB7IBJQ3VQEMGDANCNFSM5Y5PZH5A . You are receiving this because you were mentioned.Message ID: @.***>

sanketbajoria commented 2 years ago

@asarkisian we do hve option to send cipher in configuration. Please check the algorithms section in readme

sanketbajoria commented 2 years ago

@asarkisian feel free to close this issue.. if it is resolved

asarkisian commented 2 years ago

Thank you!

On Fri, Jul 1, 2022 at 8:49 PM Sanket Bajoria @.***> wrote:

@asarkisian https://github.com/asarkisian feel free to close this issue.. if it is resolved

— Reply to this email directly, view it on GitHub https://github.com/sanketbajoria/ssh2-promise/issues/80#issuecomment-1172827004, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETCUNC7CADWMU77G2CT7C3VR633LANCNFSM5Y5PZH5A . You are receiving this because you were mentioned.Message ID: @.***>

asarkisian commented 2 years ago

Hi Sanket,

To add ciphers, kex and hmac's, does this look correct? When I add these and try to connect to a SOL11 machine, I get an error: "Error: All configured authentication methods failed"

There might be something I am missing where you can point out. Thanks for all your help!

const sshConfig = { host: host, port: port, username: username, password: password, algorithm: { kex: ['diffie-hellman-group1-sha1' , 'diffie-hellman-group14-sha1' , 'diffie-hellman-group14-sha256' , 'diffie-hellman-group16-sha512' , 'diffie-hellman-group18-sha512' , 'diffie-hellman-group-exchange-sha1' , 'diffie-hellman-group-exchange-sha256' , 'ecdh-sha2-nistp256' , 'ecdh-sha2-nistp384' , 'ecdh-sha2-nistp521' , 'curve25519-sha256' , ' @.', @.'], cipher: ['3des-cbc' ,'aes128-cbc' ,'aes192-cbc' ,'aes256-cbc' ,' @.' ,'aes128-ctr' ,'aes192-ctr' ,'aes256-ctr' ,' @.' @.',' @.'], serverHostKey: [], hmac: ['hmac-sha1' , 'hmac-sha1-96' , 'hmac-sha2-256' , 'hmac-sha2-512' , ' @.' , @.' , @.' , @.' , @.' , ' @.' , @.' , ' @.'], compress: [], } };

// establish ssh connection SSHPromise.conn = new SSH2Promise(sshConfig); // enable x11 forwarding try{ await SSHPromise.conn.x11('xeyes'); } catch(err){ } await SSHPromise.conn.connect().then(() => { console.log(Connected); }).catch((e) => { console.log(Failed ${e}); throw e; })

On Mon, Jun 20, 2022 at 6:37 PM Sanket Bajoria @.***> wrote:

@asarkisian https://github.com/asarkisian promises are by default async... so if you don't want to handle any error and also don't want to wait... then you can use.. in below manner

ssh.exec('dummy req'). catch((e) => {//don't do anything})

— Reply to this email directly, view it on GitHub https://github.com/sanketbajoria/ssh2-promise/issues/80#issuecomment-1161062002, or unsubscribe https://github.com/notifications/unsubscribe-auth/AETCUNHGVF5B3WXPB7IBJQ3VQEMGDANCNFSM5Y5PZH5A . You are receiving this because you were mentioned.Message ID: @.***>