use of com.nukkitx.protocol.bedrock.packet.PlayStatusPacket in project ProxyPass by CloudburstMC.
the class UpstreamPacketHandler method handle.
@Override
public boolean handle(LoginPacket packet) {
int protocolVersion = packet.getProtocolVersion();
if (protocolVersion != ProxyPass.PROTOCOL_VERSION) {
PlayStatusPacket status = new PlayStatusPacket();
if (protocolVersion > ProxyPass.PROTOCOL_VERSION) {
status.setStatus(PlayStatusPacket.Status.LOGIN_FAILED_SERVER_OLD);
} else {
status.setStatus(PlayStatusPacket.Status.LOGIN_FAILED_CLIENT_OLD);
}
}
session.setPacketCodec(ProxyPass.CODEC);
JsonNode certData;
try {
certData = ProxyPass.JSON_MAPPER.readTree(packet.getChainData().toByteArray());
} catch (IOException e) {
throw new RuntimeException("Certificate JSON can not be read.");
}
JsonNode certChainData = certData.get("chain");
if (certChainData.getNodeType() != JsonNodeType.ARRAY) {
throw new RuntimeException("Certificate data is not valid");
}
chainData = (ArrayNode) certChainData;
boolean validChain;
try {
validChain = validateChainData(certChainData);
log.debug("Is player data valid? {}", validChain);
JWSObject jwt = JWSObject.parse(certChainData.get(certChainData.size() - 1).asText());
JsonNode payload = ProxyPass.JSON_MAPPER.readTree(jwt.getPayload().toBytes());
if (payload.get("extraData").getNodeType() != JsonNodeType.OBJECT) {
throw new RuntimeException("AuthData was not found!");
}
extraData = (JSONObject) jwt.getPayload().toJSONObject().get("extraData");
this.authData = new AuthData(extraData.getAsString("displayName"), UUID.fromString(extraData.getAsString("identity")), extraData.getAsString("XUID"));
if (payload.get("identityPublicKey").getNodeType() != JsonNodeType.STRING) {
throw new RuntimeException("Identity Public Key was not found!");
}
ECPublicKey identityPublicKey = EncryptionUtils.generateKey(payload.get("identityPublicKey").textValue());
JWSObject clientJwt = JWSObject.parse(packet.getSkinData().toString());
verifyJwt(clientJwt, identityPublicKey);
skinData = new JSONObject(clientJwt.getPayload().toJSONObject());
initializeProxySession();
} catch (Exception e) {
session.disconnect("disconnectionScreen.internalError.cantConnect");
throw new RuntimeException("Unable to complete login", e);
}
return true;
}
Aggregations