Skip to content

Commit

Permalink
feat: Add ssh reading limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Aug 10, 2018
1 parent 1d88024 commit ea08fb8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
},
"homepage": "https://github.com/Teletunnel/teletunnel-protocols#readme",
"devDependencies": {
"aegir": "^15.1.0"
"aegir": "^15.1.0",
"teletunnel-core": "github:Teletunnel/teletunnel-core"
},
"dependencies": {
"mafmt": "^6.0.0",
"pull-stream-to-net-socket": "^1.0.0",
"sni": "^1.0.0",
"stream-to-pull-stream": "^1.7.2",
"teletunnel-core": "github:Teletunnel/teletunnel-core"
"stream-to-pull-stream": "^1.7.2"
},
"contributors": [
"Maciej Krüger <mkg20001@gmail.com>"
Expand Down
12 changes: 7 additions & 5 deletions src/tcp-protos/ssh.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ module.exports = {
}
},
detect: async (conn) => { // ssh client sends SSH-2.0<VERSION>\r\n
let version = String(await conn.read(7))

if (version !== 'SSH-2.0') {
if (String(await conn.read(8)) !== 'SSH-2.0-') {
return false
}

let version = ''
let next
while ((next = String(await conn.read(1))) !== '\r') { // TODO: add reading limit
version += next
while (version.length < 100) {
while ((next = String(await conn.read(1))) !== '\r') {
version += next
}
break
}

return {version}
Expand Down
2 changes: 1 addition & 1 deletion test/ssh.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ const assert = require('assert')

describe('ssh', () => {
it('ssh module detects ssh', async () => {
assert.deepStrictEqual(await ssh.detect(conn()), {version: 'SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4'})
assert.deepStrictEqual(await ssh.detect(conn()), {version: 'OpenSSH_7.2p2 Ubuntu-4ubuntu2.4'})
})
})

0 comments on commit ea08fb8

Please sign in to comment.