[1.0.0] New API REST

This commit is contained in:
2026-03-26 22:21:44 +01:00
parent 2b0a6ece58
commit c18f0ab970
3 changed files with 13 additions and 17 deletions

Binary file not shown.

BIN
cryptea-tools-1.0.0.jar Normal file

Binary file not shown.

View File

@@ -33,17 +33,12 @@ import tools.cryptea.utils.Base64Helper;
import tools.cryptea.utils.HexHelper; import tools.cryptea.utils.HexHelper;
import tools.cryptea.utils.JsonHelper; import tools.cryptea.utils.JsonHelper;
import tools.jackson.databind.JsonNode; import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;
import tools.jackson.databind.node.ObjectNode;
public class Certificate { public class Certificate {
// Url base per verifica // Url base per verifica
public static final String BASE_URL = "https://cryptea.web.francescomancuso.it"; public static final String BASE_URL = "https://cryptea.web.francescomancuso.it";
// per Jackson v3
private static final ObjectMapper mapper = new ObjectMapper();
// per richieste HTTP // per richieste HTTP
private static final HttpClient CLIENT = HttpClient.newBuilder() private static final HttpClient CLIENT = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10)) .connectTimeout(Duration.ofSeconds(10))
@@ -236,31 +231,32 @@ public class Certificate {
String[] parts = cleaned.split("\\."); String[] parts = cleaned.split("\\.");
if (parts.length < 4) if (parts.length < 4)
throw new IllegalArgumentException("Formato certificato incompleto"); throw new IllegalArgumentException("Formato certificato incompleto");
return Base64Helper.toString(parts[0]).split("\\|")[1];
String id = null;
try {
id = Base64Helper.toString(parts[0]).split("\\|")[1].split("\\=")[1];
} catch (Exception e) {
throw new IllegalArgumentException("Formato certificato errato");
}
return id;
} }
/** /**
* Controlla se il certificato è stato revocato, attraverso una verifica remota * Controlla se il certificato è stato revocato, attraverso una verifica remota
* OCSP (Online Certificate Status Protocol) * OCSP (Online Certificate Status Protocol)
* *
* @param mdex I metadati estratti dal certificato * @param certId L'ID del certificato estratto
* @return Un array, r[0] indica true/false, r[1] l'eventuale motivo di errore * @return Un array, r[0] indica true/false, r[1] l'eventuale motivo di errore
* @throws Exception Nella gestione della richiesta HTTP * @throws Exception Nella gestione della richiesta HTTP
*/ */
public static String[] certificateIsActive(String certId) throws Exception { public static String[] certificateIsActive(String certId) throws Exception {
String[] ret = new String[2]; String[] ret = new String[2];
ObjectNode json = mapper.createObjectNode();
json.put("action", "verify_cert");
json.put("certId", certId);
String finalJson = JsonHelper.nodeToJson(json);
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(new URI(BASE_URL + "/api/v2/verify")) .uri(new URI(BASE_URL + "/api/v2/cert/" + certId + "/verify"))
.headers("Content-Type", "application/json") .headers("Content-Type", "application/json")
.timeout(Duration.ofSeconds(15)) .timeout(Duration.ofSeconds(15))
.POST(HttpRequest.BodyPublishers.ofString(finalJson)) .GET()
.build(); .build();
try { try {
@@ -270,10 +266,10 @@ public class Certificate {
String status = jsonRes.get("status").asString(); String status = jsonRes.get("status").asString();
if (status.equals("ok")) { if (status.equals("ok")) {
ret[0] = jsonRes.get("isActive").asString(); ret[0] = jsonRes.get("content").get("isActive").asString();
} else { } else {
ret[0] = "null"; ret[0] = "null";
ret[1] = "Errore nel processo di verifica!"; ret[1] = jsonRes.get("content").get("reason").asString() + " - Codice di errore: " + jsonRes.get("code").asString();
} }
} catch (HttpTimeoutException e) { } catch (HttpTimeoutException e) {