Search in sources :

Example 11 with JSONObject

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;
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) JsonNode(com.fasterxml.jackson.databind.JsonNode) JWSObject(com.nimbusds.jose.JWSObject) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) JWSObject(com.nimbusds.jose.JWSObject) URI(java.net.URI)

Example 12 with JSONObject

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;
    }
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) ToString(lombok.ToString)

Example 13 with JSONObject

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);
        }
    }
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) IOException(java.io.IOException)

Example 14 with JSONObject

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;
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 15 with JSONObject

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;
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) Map(java.util.Map)

Aggregations

JSONObject (com.nimbusds.jose.shaded.json.JSONObject)52 lombok.val (lombok.val)22 Test (org.junit.jupiter.api.Test)21 Secret (io.kidsfirst.core.model.Secret)10 JSONArray (com.nimbusds.jose.shaded.json.JSONArray)9 Map (java.util.Map)5 Slf4j (lombok.extern.slf4j.Slf4j)5 JWSObject (com.nimbusds.jose.JWSObject)4 FenceService (io.kidsfirst.core.service.FenceService)4 SecretService (io.kidsfirst.core.service.SecretService)4 ResponseEntity (org.springframework.http.ResponseEntity)4 JwtAuthenticationToken (org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken)4 org.springframework.web.bind.annotation (org.springframework.web.bind.annotation)4 IOException (java.io.IOException)3 ECPublicKey (java.security.interfaces.ECPublicKey)3 Flux (reactor.core.publisher.Flux)3 Mono (reactor.core.publisher.Mono)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)2 URI (java.net.URI)2