Skip to content

Minecraft 26.4 - #1913

Open
WouterGritter wants to merge 24 commits into
dev/4.0.0from
minecraft-26.4
Open

WouterGritter wants to merge 24 commits into
dev/4.0.0from
minecraft-26.4

Conversation

@WouterGritter

@WouterGritter WouterGritter commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Adds support for 26.4.

Protocol changes

  • Compression: SetCompression now only announces the threshold. LoginSuccess carries a new options byte, and compression is switched on around LoginAcknowledged (the last uncompressed packet in both directions).
  • Encryption:
    • Enabled only after hasJoined: proxy sends new ApplyOptions, waits for OptionsApplied, then encrypts. Auth-failure disconnects go out in plaintext.
    • Key exchange is now X25519 + HKDF-SHA256 instead of RSA (new SessionKeyExchange, key pair per login unlike vanilla which reuses one and rotates it every 60 s by default (key-rotation-period-seconds)).
    • EncryptionRequest: salt + X25519 key, no verify token (server id "server" like vanilla)
    • EncryptionResponse: client key + 32-byte HMAC
    • Separate AES key and IV per direction (was shared secret as both, which had issues)
    • hasJoined server id is now a base32hex HMAC digest.
  • JoinGame/Respawn: partialHashedSeed and isDebug were removed.
  • Transfer: gained a Map<String, String> properties field. Backend-initiated transfers now pass it through to the client.
  • Handshake: the host limit was raised to 1024 for 26.4 clients, which can append query properties (host?_o=original:port&_id=...). These are stripped from the virtual host before the forced-host lookup.
  • minecraft:mod_list: 26.4 clients send this right after the brand, once per session. Forwarding it immediately hits ensureConnected() while the initial backend connection was still in flight, which kicked the player. It is now stored on the player, like the brand, and sent to every backend during configuration.
  • Play packets: a new add_entity_motion clientbound packet
  • Commands:
    • Argument-type ids: renumbered alphabetically. brigadier:* became minecraft:*. resource_key and resource_or_tag_key were removed, and pattern was added. string was split into greedy_string, quoted_string and word without properties.
    • Properties:
      • time sends optional min/max bounds instead of only a min.
      • vec2/vec3 gained a bool.
      • loot_table, loot_predicate, loot_modifier, context_float_provider, context_int_provider and slot_source gained a context key set id.
    • Suggestion providers: sent as a varint registry id instead of a string. New minecraft:literal provider carries its own list of suggestions. They now pass through from backend to client, and proxy commands send ask_server.

TODOs / needs deciding

Check all before merging!

  • ProtocolVersion.MINECRAFT_26_4(-1, ..., "26.4") // TODO
  • With a 26.4 backend and an older client, the debug-world flag is now always false. I think this is fine, but worth noting.
  • Properly test this with older clients/backends
  • Encryption
    • NATIVE ENCRYPTION! (JavaVelocityCipher#withIv -> VelocityCipherFactory + native implementations + rebuild natives)
    • Rebuild MacOS natives
    • Especially scrutinize 2e71237 and 9bd706c Native encryption support for 26.4+ with tests #1928, which refactor the encryption flow and update/clean up the natives accordingly
    • Encryption tests
    • serverIdHash (LoginEvent/GameProfileRequestEvent) is now the base32hex digest for 26.4 clients, not SHA-1 hex (document this?)
    • (from above) new SessionKeyExchange, key pair per login unlike vanilla which reuses one and rotates it every 60 s by default (key-rotation-period-seconds): do we mirror vanilla's behavior instead? -> No, costs nothing and this is more secure.
    • Possibly deprecate the insecure and old VelocityCipherFactory#for[Encryption|Decryption] that do not consume byte[] iv. They would be forever deprecated and in use though, as they are needed for pre-26.4 clients, and any other projects that make use of the velocity-natives module (e.g. @astei's krypton) would have to deal with that too. -> handled in ecd4d31
    • Cherrypick the native bits into a separate PR so it's available for projects using velocity-native.
    • Deal with merge/rebase conflicts once Native encryption support for 26.4+ with tests #1928 gets merged.

Not included

API surface, may be done in later PRs, maybe open issues after PR gets merged.

  • Mod list API: the mod list is stored but not exposed to plugins. Related to Implementing support for minecraft:mod_list #1893. Issue exists (Implementing support for minecraft:mod_list #1893 (comment))
  • Transfer and handshake query properties API: plugins can't set or read them yet (query properties are only stripped). Exposing them to plugins and/or forwarding them to backends would be nice. Paper has no API for this yet either. Issue opened (Transfer and handshake query properties API #1930)
  • contact field: the server list ping JSON gained an optional contact string, which ServerPing doesn't have yet. Issue opened (Server list ping contact field #1931)
  • pattern argument: passed through as-is, but not exposed as a real argument type for plugins.
  • Clients now also accept the commands packet during configuration. Velocity doesn't register it there, so a backend sending it in configuration would reach the client without the proxy's commands merged in. Vanilla only sends it in play, where it is still merged. Could cause problems later.
  • ClientConfigSessionHandler: any other client plugin message that arrives before the backend connection exists is now dropped with a warning. Previously this threw and disconnected the player. Queueing and flushing once the backend is connected would be friendlier to mods. Related: Route plugin messages to the in-flight connection while no server is connected #1907 does something similar for the play state.
  • Forced hosts on _o: 26.4 clients that resolved an SRV record send the SRV target as the host and the address the player typed in the _o query property. Forced hosts could match on _o instead of the SRV target.

@WouterGritter WouterGritter changed the title Minecraft 26.4-snapshot-5 Minecraft 26.4 Oct 23, 2026
@WouterGritter
WouterGritter force-pushed the minecraft-26.4 branch 2 times, most recently from bd2151c to f343a42 Compare October 28, 2026 09:44
@WouterGritter
WouterGritter force-pushed the minecraft-26.4 branch 3 times, most recently from 342bb57 to 685e3ec Compare November 25, 2026 12:59
@WouterGritter

Copy link
Copy Markdown
Member Author

I had claude rewrite the commit history, splitting each snapshot commit into multiple commits, split by feature/refactor/action. Each batch of snapshot commits results in the same code as before the commit history rewrite of course, but hopefully this will make it easier to review!

@electronicboy electronicboy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of the C changes in 9bd706c (source read only, not compiled or run).

The source looks correct in both backends: EVP_CipherInit and CCCryptorCreateWithMode get the key and IV in the right slots (CommonCrypto takes the IV first), ivLen is checked before the copy into the 16-byte buffer, and moving EVP_CIPHER_CTX_new() after the array copies fixes an existing leak of ctx when the key copy threw. Passing the key as the IV from NativeVelocityCipher keeps the pre-26.4 behaviour.

Before merge:

  • Linux binaries: the six velocity-cipher-*.so files in this commit will need to be rebuilt by a maintainer from the reviewed source rather than merged as-is. These handle every session key, so we can't take contributor-built blobs.
  • macOS dylib: removing it was the right call, since the JNI symbol name is unchanged while the argument list isn't, and a stale binary would treat the jboolean as an array reference and crash the JVM. macOS falls back to the Java cipher until it is rebuilt.

Minor, non-blocking, and predating this commit: jni_cipher_macos.c still reports "openssl initialize cipher" on the CommonCrypto path, and "cipher not 16 bytes" should say "key".

Comment thread native/src/main/c/jni_cipher_openssl.c Resolved
Comment thread native/src/main/c/jni_cipher_openssl.c Resolved
*
* @return the payload, or {@code null} if the client didn't send one
*/
byte @Nullable [] getClientModList() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name could clash with a future API PR that exposes this in a more useful format to plugins. But this method is internal so meh, we can always rename this then.

WouterGritter added a commit that referenced this pull request Nov 28, 2026
Addresses review feedback from #1913:

- Throw NullPointerException for a null key or IV instead of crashing
the JVM in GetArrayLength.
- Wipe the key and IV stack buffers before returning on every path
(OPENSSL_cleanse on OpenSSL, memset_s on CommonCrypto).
- Drop redundant (jbyte*) casts.
- Fix error messages: "cipher not 16 bytes" -> "key not 16 bytes", and
the CommonCrypto path no longer claims to be OpenSSL.
- Test the native argument checks directly.

TODO: Rebuild macOS natives.
astei pushed a commit that referenced this pull request Nov 28, 2026
* Native encryption support for 26.4+ with tests

Partial cherry-pick of the native/ changes from the minecraft-26.4 branch
(PR #1913), without the proxy-side 26.4 protocol changes:

- 2e71237 26.4-snapshot-9..10: Replace RSA login encryption with X25519 key exchange (JavaVelocityCipher only)
- 9bd706c Native encryption support for 26.4+ with tests (TODO: rebuild macos natives)
- 38b0266 Build natives for macOS
- 5b59096 Remove .gitkeep after macos natives have been rebuilt

* Harden native cipher init and rebuild Linux natives

Addresses review feedback from #1913:

- Throw NullPointerException for a null key or IV instead of crashing
the JVM in GetArrayLength.
- Wipe the key and IV stack buffers before returning on every path
(OPENSSL_cleanse on OpenSSL, memset_s on CommonCrypto).
- Drop redundant (jbyte*) casts.
- Fix error messages: "cipher not 16 bytes" -> "key not 16 bytes", and
the CommonCrypto path no longer claims to be OpenSSL.
- Test the native argument checks directly.

TODO: Rebuild macOS natives.

* Rebuild macOS cipher native from hardened source

Rebuilds velocity-cipher.dylib for macOS arm64 from the hardened
jni_cipher_macos.c (deployment target 27.0, matching the previous
dylib) and removes the placeholder .gitkeep.

* Rename IV-less cipher factory methods to *Insecure

Deprecate forEncryption(key) and forDecryption(key) in favor of
forEncryptionInsecure(key) and forDecryptionInsecure(key), which behave
identically but make the insecure key-as-IV mode explicit at every call
site. The two-argument methods no longer accept a null IV.

Velocity switches to the *Insecure methods, as Minecraft 26.3 and older
still require the key-as-IV mode.

---------

Co-authored-by: Shane Freeder <theboyetronic@gmail.com>
@WouterGritter
WouterGritter marked this pull request as ready for review November 29, 2026 12:45
private static final SecureRandom SECURE_RANDOM = new SecureRandom();
// the server id in the 26.4+ key packet, which is also side A's name in the key derivation
// (vanilla uses "server")
private static final String KEY_EXCHANGE_SERVER_ID = "server";

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client doesn't do anything with this except echoing whatever we send, it never exposes it anywhere.

Would it make sense to instead reply with "proxy" or maybe even "velocity"? The only tangible "benefit"/behavior change would be that a mod could then identify any velocity server as one, by reading this value.

@WouterGritter

Copy link
Copy Markdown
Member Author

Tested & confirmed working on 26.4-rc-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants