idz: Add type defs for common net comms context
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import setup from "./setup";
|
import setup from "./setup";
|
||||||
|
|
||||||
export { BLOCK_SIZE } from "./aes";
|
export { BLOCK_SIZE } from "./aes";
|
||||||
|
export { ClientHello } from "./setup";
|
||||||
export default setup;
|
export default setup;
|
||||||
|
|||||||
+14
-3
@@ -2,7 +2,7 @@ import { Socket } from "net";
|
|||||||
|
|
||||||
import AesEcbStream from "./aes";
|
import AesEcbStream from "./aes";
|
||||||
import { readBigInt, modPow, writeBigInt } from "./bigint";
|
import { readBigInt, modPow, writeBigInt } from "./bigint";
|
||||||
import IoByteStream from "../../util/stream";
|
import IoByteStream, { ByteStream } from "../../util/stream";
|
||||||
|
|
||||||
interface RsaKey {
|
interface RsaKey {
|
||||||
N: bigint;
|
N: bigint;
|
||||||
@@ -11,6 +11,17 @@ interface RsaKey {
|
|||||||
hashN: number;
|
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
|
// Proof-of-concept, so we only ever use one of the ten RSA key pairs
|
||||||
const rsaKey = {
|
const rsaKey = {
|
||||||
N: 4922323266120814292574970172377860734034664704992758249880018618131907367614177800329506877981986877921220485681998287752778495334541127048495486311792061n,
|
N: 4922323266120814292574970172377860734034664704992758249880018618131907367614177800329506877981986877921220485681998287752778495334541127048495486311792061n,
|
||||||
@@ -22,7 +33,7 @@ const rsaKey = {
|
|||||||
// Proof-of-concept, so we only use one fixed session key
|
// Proof-of-concept, so we only use one fixed session key
|
||||||
const aesKey = Buffer.from("ffddeeccbbaa99887766554433221100", "hex");
|
const aesKey = Buffer.from("ffddeeccbbaa99887766554433221100", "hex");
|
||||||
|
|
||||||
function writeServerHello(aesKey: Buffer, rsaKey: RsaKey) {
|
function writeServerHello(aesKey: Buffer, rsaKey: RsaKey): Buffer {
|
||||||
const M = readBigInt(aesKey);
|
const M = readBigInt(aesKey);
|
||||||
const keyEnc = modPow(M, rsaKey.e, rsaKey.N);
|
const keyEnc = modPow(M, rsaKey.e, rsaKey.N);
|
||||||
const result = Buffer.alloc(0x48);
|
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<IdzConnection> {
|
||||||
const tcpStream = new IoByteStream(socket);
|
const tcpStream = new IoByteStream(socket);
|
||||||
const serverHello = writeServerHello(aesKey, rsaKey);
|
const serverHello = writeServerHello(aesKey, rsaKey);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user