use of com.nimbusds.jose.shaded.json.JSONObject in project Geyser by GeyserMC.
the class LoginEncryptionUtils method validateChainData.
private static boolean validateChainData(JsonNode data) throws Exception {
if (data.size() != 3) {
return false;
}
ECPublicKey lastKey = null;
boolean mojangSigned = false;
Iterator<JsonNode> iterator = data.iterator();
while (iterator.hasNext()) {
JsonNode node = iterator.next();
JWSObject jwt = JWSObject.parse(node.asText());
// x509 cert is expected in every claim
URI x5u = jwt.getHeader().getX509CertURL();
if (x5u == null) {
return false;
}
ECPublicKey expectedKey = EncryptionUtils.generateKey(jwt.getHeader().getX509CertURL().toString());
// First key is self-signed
if (lastKey == null) {
lastKey = expectedKey;
} else if (!lastKey.equals(expectedKey)) {
return false;
}
if (!EncryptionUtils.verifyJwt(jwt, lastKey)) {
return false;
}
if (mojangSigned) {
return !iterator.hasNext();
}
if (lastKey.equals(EncryptionUtils.getMojangPublicKey())) {
mojangSigned = true;
}
Object payload = JSONValue.parse(jwt.getPayload().toString());
Preconditions.checkArgument(payload instanceof JSONObject, "Payload is not an object");
Object identityPublicKey = ((JSONObject) payload).get("identityPublicKey");
Preconditions.checkArgument(identityPublicKey instanceof String, "identityPublicKey node is missing in chain");
lastKey = EncryptionUtils.generateKey((String) identityPublicKey);
}
return mojangSigned;
}
use of com.nimbusds.jose.shaded.json.JSONObject in project PowerNukkitX by BlocklyNukkit.
the class Skin method isValidResourcePatch.
private boolean isValidResourcePatch() {
if (skinResourcePatch == null || skinResourcePatch.length() > 1000) {
return false;
}
try {
JSONObject object = (JSONObject) JSONValue.parse(skinResourcePatch);
JSONObject geometry = (JSONObject) object.get("geometry");
return geometry.containsKey("default") && geometry.get("default") instanceof String;
} catch (ClassCastException | NullPointerException e) {
return false;
}
}
use of com.nimbusds.jose.shaded.json.JSONObject in project PowerNukkitX by BlocklyNukkit.
the class Metrics method submitData.
/**
* Collects the data and sends it afterwards.
*/
private void submitData() {
final JSONObject data = getServerData();
JSONArray pluginData = new JSONArray();
pluginData.add(getPluginData());
data.put("plugins", pluginData);
try {
// We are still in the Thread of the timer, so nothing get blocked :)
sendData(data);
} catch (Exception e) {
// Something went wrong! :(
if (logFailedRequests) {
log.warn("Could not submit stats of {}", name, e);
}
}
}
use of com.nimbusds.jose.shaded.json.JSONObject in project PowerNukkitX by BlocklyNukkit.
the class Metrics method getServerData.
/**
* Gets the server specific data.
*
* @return The server specific data.
*/
private JSONObject getServerData() {
// OS specific data
String osName = System.getProperty("os.name");
String osArch = System.getProperty("os.arch");
String osVersion = System.getProperty("os.version");
int coreCount = Runtime.getRuntime().availableProcessors();
JSONObject data = new JSONObject();
data.put("serverUUID", serverUUID);
data.put("osName", osName);
data.put("osArch", osArch);
data.put("osVersion", osVersion);
data.put("coreCount", coreCount);
return data;
}
use of com.nimbusds.jose.shaded.json.JSONObject in project PowerNukkitX by BlocklyNukkit.
the class Metrics method createAdvancedChartData.
private static JSONObject createAdvancedChartData(final Callable<Map<String, Integer>> callable) throws Exception {
JSONObject data = new JSONObject();
JSONObject values = new JSONObject();
Map<String, Integer> map = callable.call();
if (map == null || map.isEmpty()) {
// Null = skip the chart
return null;
}
boolean allSkipped = true;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
if (entry.getValue() == 0) {
// Skip this invalid
continue;
}
allSkipped = false;
values.put(entry.getKey(), entry.getValue());
}
if (allSkipped) {
// Null = skip the chart
return null;
}
data.put(VALUES, values);
return data;
}
Aggregations