From 4f7c0145a1fb991c1ed2cd15eca5f2e69fe7f8ff Mon Sep 17 00:00:00 2001 From: Tau Date: Sun, 27 Sep 2020 00:06:55 -0400 Subject: [PATCH] idz: Add type defs for common net comms context --- src/idz/common/index.ts | 1 + src/idz/common/setup.ts | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/idz/common/index.ts b/src/idz/common/index.ts index 35efa22..d64f774 100644 --- a/src/idz/common/index.ts +++ b/src/idz/common/index.ts @@ -1,4 +1,5 @@ import setup from "./setup"; export { BLOCK_SIZE } from "./aes"; +export { ClientHello } from "./setup"; export default setup; diff --git a/src/idz/common/setup.ts b/src/idz/common/setup.ts index 1bff9dd..0d02d3d 100644 --- a/src/idz/common/setup.ts +++ b/src/idz/common/setup.ts @@ -2,7 +2,7 @@ import { Socket } from "net"; import AesEcbStream from "./aes"; import { readBigInt, modPow, writeBigInt } from "./bigint"; -import IoByteStream from "../../util/stream"; +import IoByteStream, { ByteStream } from "../../util/stream"; interface RsaKey { N: bigint; @@ -11,6 +11,17 @@ interface RsaKey { hashN: number; } +export interface ClientHello { + pcbId: string; + protocol: string; + model: string; +} + +export interface IdzConnection { + aesStream: ByteStream; + clientHello: ClientHello; +} + // Proof-of-concept, so we only ever use one of the ten RSA key pairs const rsaKey = { N: 4922323266120814292574970172377860734034664704992758249880018618131907367614177800329506877981986877921220485681998287752778495334541127048495486311792061n, @@ -22,7 +33,7 @@ const rsaKey = { // Proof-of-concept, so we only use one fixed session key const aesKey = Buffer.from("ffddeeccbbaa99887766554433221100", "hex"); -function writeServerHello(aesKey: Buffer, rsaKey: RsaKey) { +function writeServerHello(aesKey: Buffer, rsaKey: RsaKey): Buffer { const M = readBigInt(aesKey); const keyEnc = modPow(M, rsaKey.e, rsaKey.N); const result = Buffer.alloc(0x48); @@ -50,7 +61,7 @@ function readClientHello(buf: Buffer) { }; } -export default async function setup(socket: Socket) { +export default async function setup(socket: Socket): Promise { const tcpStream = new IoByteStream(socket); const serverHello = writeServerHello(aesKey, rsaKey);