cubyz-node-client 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,91 @@
1
+ import { Buffer } from "node:buffer";
2
+ import type dgram from "node:dgram";
3
+ export declare function encodeMsbVarInt(value: number): Buffer;
4
+ interface FramedMessage {
5
+ protocolId: number;
6
+ payload: Buffer;
7
+ }
8
+ /**
9
+ * SecureChannelHandler drives a manual TLS 1.3 handshake over the Cubyz
10
+ * UDP channel 1 (SECURE).
11
+ *
12
+ * We implement TLS 1.3 ourselves because the Cubyz server generates a
13
+ * self-signed RSA-PSS certificate with an empty serialNumber (ASN.1
14
+ * INTEGER of length 0), which OpenSSL 3 rejects even with
15
+ * `rejectUnauthorized: false` — the error fires during record parsing,
16
+ * not during certificate verification.
17
+ *
18
+ * We only support TLS_AES_256_GCM_SHA384 with X25519 key exchange, which
19
+ * is what mbedTLS 3.x negotiates. We do not validate the server
20
+ * certificate at all (MITM is mitigated by the application-level
21
+ * signature exchange that follows).
22
+ *
23
+ * verificationData = all bytes received from the server on channel 1
24
+ * BEFORE `secureConnect` fires (i.e. every byte pushed via feedRawBytes
25
+ * before the handshake completes). This matches the Zig server's
26
+ * definition on the client side.
27
+ */
28
+ export declare class SecureChannelHandler {
29
+ private readonly udpSocket;
30
+ private readonly host;
31
+ private readonly port;
32
+ private readonly channelId;
33
+ private readonly mtu;
34
+ private sendSeq;
35
+ private state;
36
+ private readonly recordParser;
37
+ private readonly decoder;
38
+ private transcript;
39
+ private serverHandshakeKey;
40
+ private serverHandshakeIv;
41
+ private serverHandshakeSeq;
42
+ private clientHandshakeKey;
43
+ private clientHandshakeIv;
44
+ private clientHandshakeSeq;
45
+ private serverAppKey;
46
+ private serverAppIv;
47
+ private serverAppSeq;
48
+ private clientAppKey;
49
+ private clientAppIv;
50
+ private clientAppSeq;
51
+ private verificationDataBufs;
52
+ private collectingVerificationData;
53
+ private readonly clientX25519PrivKey;
54
+ private readonly clientX25519PubKeyBytes;
55
+ private readonly clientRandom;
56
+ onMessage: ((msg: FramedMessage) => void) | null;
57
+ onSecureConnect: ((verificationData: Buffer) => void) | null;
58
+ onError: ((err: Error) => void) | null;
59
+ verificationDataBuffer: Buffer | undefined;
60
+ constructor(options: {
61
+ socket: dgram.Socket;
62
+ host: string;
63
+ port: number;
64
+ channelId: number;
65
+ mtu: number;
66
+ initialSendSeq: number;
67
+ });
68
+ /**
69
+ * Trigger the TLS handshake. Must be called after the UDP init-ACK packet
70
+ * has been handed to the OS send queue so the server is guaranteed to be in
71
+ * the .connected state before it receives the TLS ClientHello.
72
+ */
73
+ startHandshake(): void;
74
+ feedRawBytes(data: Buffer): void;
75
+ private handleRecord;
76
+ private handlePlaintextHandshake;
77
+ private deriveHandshakeKeys;
78
+ private _handshakeSecret;
79
+ private _clientHsSecret;
80
+ private _serverHsSecret;
81
+ private deriveApplicationKeys;
82
+ private handleEncryptedRecord;
83
+ private handleDecryptedHandshakeMsg;
84
+ private processServerFinished;
85
+ private computeFinishedVerifyData;
86
+ private sendClientFinished;
87
+ sendMessage(protocolId: number, payload: Buffer): void;
88
+ private sendRawTlsRecord;
89
+ private fail;
90
+ }
91
+ export {};