From 4331d643201ee4d6ead1d4cbfa4013b9486fc3b0 Mon Sep 17 00:00:00 2001 From: fiereu Date: Sun, 24 Aug 2025 16:18:01 +0200 Subject: [PATCH] Changed wiki submodule from SSH to HTTPS --- .gitmodules | 2 +- docs | 1 + docs/Home.md | 1 - docs/jdk_version.md | 4 - docs/protocol/tls/index.md | 246 ------------------------------------- 5 files changed, 2 insertions(+), 252 deletions(-) create mode 160000 docs delete mode 100644 docs/Home.md delete mode 100644 docs/jdk_version.md delete mode 100644 docs/protocol/tls/index.md diff --git a/.gitmodules b/.gitmodules index 6961f44..4e2aad3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "docs"] path = docs - url = ssh://forge.fiereu.de/OpenMMO/OpenMMO.wiki + url = https://forge.fiereu.de/OpenMMO/OpenMMO.wiki diff --git a/docs b/docs new file mode 160000 index 0000000..3d86723 --- /dev/null +++ b/docs @@ -0,0 +1 @@ +Subproject commit 3d86723876590782060943e66d8adb3861381c02 diff --git a/docs/Home.md b/docs/Home.md deleted file mode 100644 index 4ed9ff0..0000000 --- a/docs/Home.md +++ /dev/null @@ -1 +0,0 @@ -Welcome to the wiki. \ No newline at end of file diff --git a/docs/jdk_version.md b/docs/jdk_version.md deleted file mode 100644 index a9a9a31..0000000 --- a/docs/jdk_version.md +++ /dev/null @@ -1,4 +0,0 @@ -# JDK Version - -The goal is to use the most recent JDK version that is compatible with the project. As of now, the project is tested and works with JDK 24. -This may change in the future, so please check `buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts` for the latest version used in the project. \ No newline at end of file diff --git a/docs/protocol/tls/index.md b/docs/protocol/tls/index.md deleted file mode 100644 index 98bbafc..0000000 --- a/docs/protocol/tls/index.md +++ /dev/null @@ -1,246 +0,0 @@ -# OpenMMO TLS Protocol Specification - -The OpenMMO TLS Protocol is a custom TLS-like implementation designed for secure communication between the PokeMMO client and server. This protocol establishes encrypted communication channels using ECDH key exchange. - -## Protocol Flow - -The TLS handshake follows a 3-packet exchange pattern: - -```mermaid -sequenceDiagram - participant Client - participant Server - - Note over Client,Server: TLS Handshake Phase - - Client->>Server: 1. ClientHello (0x00) - Note right of Client: Contains obfuscated timestamp - - Server->>Client: 2. ServerHello (0x01) - Note left of Server: Server public key + signature + checksum size - - Note over Client: Checks signature using known root public key
Derives shared secret via ECDH
Switches to secure mode - - Client->>Server: 3. ClientReady (0x02) - Note right of Client: Client public key - - Note over Server: Derives shared secret via ECDH
Switches to next protocol - - Note over Client,Server: Secure Communication Established
Switch to Application Protocol (e.g., Login) -``` - -## Packet Specifications - -### 1. ClientHello Packet (Opcode: 0x00) - -The ClientHello packet initiates the TLS handshake and contains an obfuscated timestamp for replay attack protection. - -```mermaid -packet - title ClientHello Packet Structure - 0-63: "Obfuscated Random Key (8 bytes)" - 64-127: "Obfuscated Timestamp (8 bytes)" -``` - -#### Field Details -- **Obfuscated Random Key**: Random value XOR'd with predefined key1 constant -- **Obfuscated Timestamp**: Client timestamp XOR'd with key2 and random key - -#### Obfuscation Algorithm -``` -randomKey = Random.nextLong() -xoredRandomKey = randomKey XOR key1 -xoredTimestamp = timestamp XOR key2 XOR randomKey -``` - -### 2. ServerHello Packet (Opcode: 0x01) - -The ServerHello packet contains the server's public key, authentication signature, and the checksum algorithm. - -```mermaid -packet - title ServerHello Packet Structure - 0-15: "Public Key Length (2 bytes, LE)" - 16-543: "Server Public Key (variable length, uncompressed point)" - 544-559: "Signature Length (2 bytes, LE)" - 560-1071: "ECDSA Signature (variable length)" - 1072-1079: "Checksum Size (1 byte)" -``` - -#### Field Details -- **Public Key Length**: Length of the public key data (typically 65 bytes) -- **Server Public Key**: ECDSA public key in uncompressed point format (0x04 + X + Y coordinates) -- **Signature Length**: Length of the ECDSA signature (typically 64 bytes) -- **ECDSA Signature**: Digital signature of the public key using server's root private key -- **Checksum Size**: Size of checksums to be used for subsequent packets (16 for HMAC-SHA256) - -### 3. ClientReady Packet (Opcode: 0x02) - -The ClientReady packet completes the handshake by providing the client's public key. - -```mermaid -packet - title ClientReady Packet Structure - 0-15: "Public Key Length (2 bytes, LE)" - 16-535: "Client Public Key (variable length, uncompressed point)" -``` - -#### Field Details -- **Public Key Length**: Length of the client's public key data (typically 65 bytes) -- **Client Public Key**: Client's ECDSA public key in uncompressed point format - -## Cryptographic Details - -### Elliptic Curve Parameters -- **Curve**: secp256r1 (P-256) -- **Key Size**: 256-bit -- **Public Key Format**: Uncompressed point (65 bytes: 0x04 + 32-byte X + 32-byte Y) -- **Signature Algorithm**: ECDSA with SHA-256 - -### Uncompressed Point De/Encoding - -``` -// Constants -UNCOMPRESSED_POINT_INDICATOR = 0x04 -CURVE = secp256r1 (P-256) -KEY_LENGTH = 32 // bytes for secp256r1 - -function encode_uncompressed_point(ecPublicKey): - point = ecPublicKey.getPoint() - x = point.getX().toByteArray() - y = point.getY().toByteArray() - - // Create output buffer: 1 byte indicator + 32 bytes X + 32 bytes Y - data = new ByteArray(1 + 2 * KEY_LENGTH) - offset = 0 - - // Set indicator - data[offset++] = UNCOMPRESSED_POINT_INDICATOR - - // Handle X coordinate (pad or trim to 32 bytes) - if x.length <= KEY_LENGTH: - // Right-pad with zeros if too short - copyBytes(x, 0, data, offset + KEY_LENGTH - x.length, x.length) - else if x.length == KEY_LENGTH + 1 AND x[0] == 0: - // Remove leading zero byte if present - copyBytes(x, 1, data, offset, KEY_LENGTH) - else: - throw "X coordinate too large" - - offset += KEY_LENGTH - - // Handle Y coordinate (same logic as X) - if y.length <= KEY_LENGTH: - copyBytes(y, 0, data, offset + KEY_LENGTH - y.length, y.length) - else if y.length == KEY_LENGTH + 1 AND y[0] == 0: - copyBytes(y, 1, data, offset, KEY_LENGTH) - else: - throw "Y coordinate too large" - - return data - -function decode_uncompressed_point(byteArray): - // Validate format - if byteArray[0] != UNCOMPRESSED_POINT_INDICATOR: - throw "Invalid uncompressed point indicator" - - if byteArray.length != 1 + 2 * KEY_LENGTH: - throw "Invalid data length" - - offset = 1 - - // Extract X coordinate (32 bytes) - x = bigIntegerFromBytes(byteArray[offset:offset + KEY_LENGTH]) - offset += KEY_LENGTH - - // Extract Y coordinate (32 bytes) - y = bigIntegerFromBytes(byteArray[offset:offset + KEY_LENGTH]) - - // Create EC point and public key - point = ECPoint(x, y) - return createECPublicKey(point, CURVE_SPEC) -``` - -### Key Derivation -After exchanging public keys, both client and server derive a shared secret using ECDH and generate symmetric encryption keys: - -``` -// ECDH Key Agreement -sharedSecret = ECDH(clientPrivateKey, serverPublicKey) // On client side -sharedSecret = ECDH(serverPrivateKey, clientPublicKey) // On server side - -// Key Derivation Constants -CLIENT_KEY_SALT = "KeySalt" + 0x01 -SERVER_KEY_SALT = "KeySalt" + 0x02 -COMMON_IV_SALT = "IVDERIV" - -function tripleHash(data, salt): - hasher = SHA-256() - hasher.update(salt) - hasher.update(data) - hasher.update(salt) - digest = hasher.finalize() - return digest[0:16] // First 16 bytes for 128-bit AES key - -// Derive Symmetric Keys (if shared secret >= 128 bits) -if sharedSecret.length * 8 >= 128: - clientSeed = tripleHash(sharedSecret, CLIENT_KEY_SALT) - serverSeed = tripleHash(sharedSecret, SERVER_KEY_SALT) -else: - // Fallback to default seeds - clientSeed = defaultClientSeed - serverSeed = defaultServerSeed - -// Create AES-CTR Ciphers -clientKey = AES_Key(clientSeed) -serverKey = AES_Key(serverSeed) -clientIV = tripleHash(clientSeed, COMMON_IV_SALT) -serverIV = tripleHash(serverSeed, COMMON_IV_SALT) - -// Initialize Ciphers -encryptionCipher = AES-CTR(serverKey, serverIV) // Server encrypts with server key -decryptionCipher = AES-CTR(clientKey, clientIV) // Server decrypts with client key -``` - -#### Key Usage -- **Client Seed**: Used for client-to-server encryption (server decrypts with this) -- **Server Seed**: Used for server-to-client encryption (server encrypts with this) -- **AES-CTR Mode**: Stream cipher mode enabling encryption/decryption of arbitrary length data -- **IV Derivation**: Initialization vectors derived using the same triple-hash with common salt -## Protocol State Machine - -```mermaid -stateDiagram-v2 - [*] --> Handshake: Connection Established
All packets are framed with length prefix - - state Handshake { - [*] --> WaitingClientHello - WaitingClientHello --> WaitingClientReady: Send ServerHello - WaitingClientReady --> HandshakeComplete: Receive ClientReady - } - - HandshakeComplete --> SecureCommunication: Switch to Application Protocol - - note right of SecureCommunication - All subsequent packets are: - - Framed with length prefix - - Checksummed (CRC16/HMAC-SHA256) - - Optionally encrypted - end note -``` - -## Implementation Notes - -### Packet Framing -- All packets are prefixed with a length field -- No encryption or checksum is applied during the handshake phase - -After the TLS handshake, all subsequent packets use the following format: -- Length prefix (variable encoding) -- Packet payload (encrypted if in secure mode) -- Checksum suffix (size determined by ServerHello) - -### Error Handling -- Invalid signatures result in connection termination -- Malformed packets trigger protocol violations -- Timestamp validation failures indicate potential replay attacks \ No newline at end of file