mirror of
https://github.com/djhackersdev/minime.git
synced 2026-07-14 23:22:49 -05:00
idz: Add type defs for common net comms context
This commit is contained in:
parent
9889b58b71
commit
4f7c0145a1
|
|
@ -1,4 +1,5 @@
|
|||
import setup from "./setup";
|
||||
|
||||
export { BLOCK_SIZE } from "./aes";
|
||||
export { ClientHello } from "./setup";
|
||||
export default setup;
|
||||
|
|
|
|||
|
|
@ -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<IdzConnection> {
|
||||
const tcpStream = new IoByteStream(socket);
|
||||
const serverHello = writeServerHello(aesKey, rsaKey);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user