Skip to content

Commit

Permalink
Kex (mac & enc not yet working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Manaf941 committed May 10, 2024
1 parent 0dbdb37 commit cb6635d
Show file tree
Hide file tree
Showing 38 changed files with 4,124 additions and 30 deletions.
3 changes: 3 additions & 0 deletions __tests__/packets/KexDHInit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test("parse", () => {

})
58 changes: 58 additions & 0 deletions __tests__/packets/KexInit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// TODO: Jest does not allow ESM imports ? figure it out
import { SSHPacketType } from "../../src/constants";
import KexInit from "../../src/packets/KexInit";

test("Packet Type should be SSH_MSG_KEXINIT", () => {
expect(KexInit.type).toBe(SSHPacketType.SSH_MSG_KEXINIT)
})

const sample = Buffer.from(
"141356fc33611b65c6301d0c2fae1acdcd00000102637572766532353531392d7368613235362c637572766532353531392d736861323536406c69627373682e6f72672c656364682d736861322d6e697374703235362c656364682d736861322d6e697374703338342c656364682d736861322d6e697374703532312c6469666669652d68656c6c6d616e2d67726f75702d65786368616e67652d7368613235362c6469666669652d68656c6c6d616e2d67726f757031362d7368613531322c6469666669652d68656c6c6d616e2d67726f757031382d7368613531322c6469666669652d68656c6c6d616e2d67726f757031342d7368613235362c6469666669652d68656c6c6d616e2d67726f757031342d73686131000000417273612d736861322d3531322c7273612d736861322d3235362c7373682d7273612c65636473612d736861322d6e697374703235362c7373682d656432353531390000006c63686163686132302d706f6c7931333035406f70656e7373682e636f6d2c6165733132382d6374722c6165733139322d6374722c6165733235362d6374722c6165733132382d67636d406f70656e7373682e636f6d2c6165733235362d67636d406f70656e7373682e636f6d0000006c63686163686132302d706f6c7931333035406f70656e7373682e636f6d2c6165733132382d6374722c6165733139322d6374722c6165733235362d6374722c6165733132382d67636d406f70656e7373682e636f6d2c6165733235362d67636d406f70656e7373682e636f6d000000d5756d61632d36342d65746d406f70656e7373682e636f6d2c756d61632d3132382d65746d406f70656e7373682e636f6d2c686d61632d736861322d3235362d65746d406f70656e7373682e636f6d2c686d61632d736861322d3531322d65746d406f70656e7373682e636f6d2c686d61632d736861312d65746d406f70656e7373682e636f6d2c756d61632d3634406f70656e7373682e636f6d2c756d61632d313238406f70656e7373682e636f6d2c686d61632d736861322d3235362c686d61632d736861322d3531322c686d61632d73686131000000d5756d61632d36342d65746d406f70656e7373682e636f6d2c756d61632d3132382d65746d406f70656e7373682e636f6d2c686d61632d736861322d3235362d65746d406f70656e7373682e636f6d2c686d61632d736861322d3531322d65746d406f70656e7373682e636f6d2c686d61632d736861312d65746d406f70656e7373682e636f6d2c756d61632d3634406f70656e7373682e636f6d2c756d61632d313238406f70656e7373682e636f6d2c686d61632d736861322d3235362c686d61632d736861322d3531322c686d61632d73686131000000156e6f6e652c7a6c6962406f70656e7373682e636f6d000000156e6f6e652c7a6c6962406f70656e7373682e636f6d00000000000000000000000000",
"hex"
)
test("Should parse", () => {
const packet = KexInit.parse(sample)

expect(packet.data.cookie.toString("hex")).toBe("1356fc33611b65c6301d0c2fae1acdcd")

expect(packet.data.kex_algorithms).toEqual([
"curve25519-sha256", "[email protected]", "ecdh-sha2-nistp256",
"ecdh-sha2-nistp384", "ecdh-sha2-nistp521", "diffie-hellman-group-exchange-sha256",
"diffie-hellman-group16-sha512", "diffie-hellman-group18-sha512", "diffie-hellman-group14-sha256",
"diffie-hellman-group14-sha1"
])
expect(packet.data.server_host_key_algorithms).toEqual([
"rsa-sha2-512", "rsa-sha2-256", "ssh-rsa", "ecdsa-sha2-nistp256",
"ssh-ed25519"
])
expect(packet.data.encryption_algorithms_client_to_server).toEqual([
"[email protected]", "aes128-ctr",
"aes192-ctr", "aes256-ctr", "[email protected]", "[email protected]"
])
expect(packet.data.encryption_algorithms_server_to_client).toEqual([
"[email protected]", "aes128-ctr",
"aes192-ctr", "aes256-ctr", "[email protected]", "[email protected]"
])
expect(packet.data.mac_algorithms_client_to_server).toEqual([
"[email protected]", "[email protected]",
"[email protected]", "[email protected]", "[email protected]",
"[email protected]", "[email protected]", "hmac-sha2-256", "hmac-sha2-512", "hmac-sha1"
])
expect(packet.data.mac_algorithms_server_to_client).toEqual([
"[email protected]", "[email protected]",
"[email protected]", "[email protected]", "[email protected]",
"[email protected]", "[email protected]", "hmac-sha2-256", "hmac-sha2-512", "hmac-sha1"
])
expect(packet.data.compression_algorithms_client_to_server).toEqual([
"none", "[email protected]"
])
expect(packet.data.compression_algorithms_server_to_client).toEqual([
"none", "[email protected]"
])
})

test("Should serialize correctly", () => {
const packet = KexInit.parse(sample)
const serialized = packet.serialize()
expect(serialized).toEqual(sample)
})
13 changes: 11 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"name": "typescript-template",
"name": "modernssh",
"private": true,
"version": "1.0.0",
"description": "[CHANGE THIS BEFORE RELEASE] Template made for Typescript",
"main": "dist/index.js",
"scripts": {
"test": "bun test ./__tests__/*/*",
"build": "tsc",
"start": "node .",
"dev": "tsc --watch",
Expand All @@ -14,11 +16,18 @@
"author": "JeanOUINA",
"license": "UNLICENSED",
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/node": "^20.10.0",
"@typescript-eslint/eslint-plugin": "^6.12.0",
"@typescript-eslint/parser": "^6.12.0",
"eslint": "^8.54.0",
"jest": "^29.7.0",
"modernlog": "^1.1.0",
"typed-emitter": "^2.1.0",
"typescript": "^5.2.2"
},
"type": "module"
"type": "module",
"dependencies": {
"asn1js": "^3.0.5"
}
}
Loading

0 comments on commit cb6635d

Please sign in to comment.