Minecraft 1.19.1 support

This commit is contained in:
md_5
2022-07-28 04:00:00 +10:00
parent adc32d5a5c
commit 78ca16dfe3
14 changed files with 237 additions and 135 deletions

View File

@@ -3,6 +3,8 @@ package net.md_5.bungee;
import com.google.common.io.ByteStreams;
import com.google.common.primitives.Longs;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.Key;
@@ -17,6 +19,7 @@ import java.security.spec.X509EncodedKeySpec;
import java.util.Arrays;
import java.util.Base64;
import java.util.Random;
import java.util.UUID;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
@@ -73,12 +76,23 @@ public class EncryptionUtil
return new EncryptionRequest( hash, pubKey, verify );
}
public static boolean check(PlayerPublicKey publicKey) throws GeneralSecurityException
public static boolean check(PlayerPublicKey publicKey, UUID uuid) throws GeneralSecurityException
{
Signature signature = Signature.getInstance( "SHA1withRSA" );
signature.initVerify( MOJANG_KEY );
signature.update( ( publicKey.getExpiry() + "-----BEGIN RSA PUBLIC KEY-----\n" + MIME_ENCODER.encodeToString( getPubkey( publicKey.getKey() ).getEncoded() ) + "\n-----END RSA PUBLIC KEY-----\n" ).getBytes( StandardCharsets.US_ASCII ) );
byte[] check;
if ( uuid != null )
{
byte[] encoded = getPubkey( publicKey.getKey() ).getEncoded();
check = new byte[ 24 + encoded.length ];
ByteBuffer.wrap( check ).order( ByteOrder.BIG_ENDIAN ).putLong( uuid.getMostSignificantBits() ).putLong( uuid.getLeastSignificantBits() ).putLong( publicKey.getExpiry() ).put( encoded );
} else
{
check = ( publicKey.getExpiry() + "-----BEGIN RSA PUBLIC KEY-----\n" + MIME_ENCODER.encodeToString( getPubkey( publicKey.getKey() ).getEncoded() ) + "\n-----END RSA PUBLIC KEY-----\n" ).getBytes( StandardCharsets.US_ASCII );
}
signature.update( check );
return signature.verify( publicKey.getSignature() );
}

View File

@@ -123,7 +123,7 @@ public class ServerConnector extends PacketHandler
channel.write( copiedHandshake );
channel.setProtocol( Protocol.LOGIN );
channel.write( new LoginRequest( user.getName(), null ) );
channel.write( new LoginRequest( user.getName(), null, user.getUniqueId() ) );
}
@Override

View File

@@ -8,6 +8,7 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.MessageDigest;
import java.time.Instant;
import java.util.HashSet;
@@ -396,10 +397,13 @@ public class InitialHandler extends PacketHandler implements PendingConnection
return;
}
if ( !EncryptionUtil.check( publicKey ) )
if ( getVersion() < ProtocolConstants.MINECRAFT_1_19_1 )
{
disconnect( bungee.getTranslation( "secure_profile_invalid" ) );
return;
if ( !EncryptionUtil.check( publicKey, null ) )
{
disconnect( bungee.getTranslation( "secure_profile_invalid" ) );
return;
}
}
}
@@ -509,6 +513,32 @@ public class InitialHandler extends PacketHandler implements PendingConnection
private void finish()
{
offlineId = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) );
if ( uniqueId == null )
{
uniqueId = offlineId;
}
if ( BungeeCord.getInstance().config.isEnforceSecureProfile() )
{
if ( getVersion() >= ProtocolConstants.MINECRAFT_1_19_1 )
{
boolean secure = false;
try
{
secure = EncryptionUtil.check( loginRequest.getPublicKey(), uniqueId );
} catch ( GeneralSecurityException ex )
{
}
if ( !secure )
{
disconnect( bungee.getTranslation( "secure_profile_invalid" ) );
return;
}
}
}
if ( isOnlineMode() )
{
// Check for multiple connections
@@ -539,12 +569,6 @@ public class InitialHandler extends PacketHandler implements PendingConnection
}
offlineId = UUID.nameUUIDFromBytes( ( "OfflinePlayer:" + getName() ).getBytes( Charsets.UTF_8 ) );
if ( uniqueId == null )
{
uniqueId = offlineId;
}
Callback<LoginEvent> complete = new Callback<LoginEvent>()
{
@Override

View File

@@ -76,6 +76,8 @@ public abstract class EntityMap
return EntityMap_1_16_2.INSTANCE_1_18;
case ProtocolConstants.MINECRAFT_1_19:
return EntityMap_1_16_2.INSTANCE_1_19;
case ProtocolConstants.MINECRAFT_1_19_1:
return EntityMap_1_16_2.INSTANCE_1_19_1;
}
throw new RuntimeException( "Version " + version + " has no entity map" );
}

View File

@@ -18,7 +18,7 @@ class EntityMap_1_16_2 extends EntityMap
static final EntityMap_1_16_2 INSTANCE_1_17 = new EntityMap_1_16_2( 0x04, 0x2D );
static final EntityMap_1_16_2 INSTANCE_1_18 = new EntityMap_1_16_2( 0x04, 0x2D );
static final EntityMap_1_16_2 INSTANCE_1_19 = new EntityMap_1_16_2( 0x02, 0x2F );
static final EntityMap_1_16_2 INSTANCE_1_19_1 = new EntityMap_1_16_2( 0x02, 0x30 );
//
private final int spawnPlayerId;
private final int spectateId;