[1.0.0] New API REST
This commit is contained in:
Binary file not shown.
BIN
cryptea-tools-1.0.0.jar
Normal file
BIN
cryptea-tools-1.0.0.jar
Normal file
Binary file not shown.
@@ -33,17 +33,12 @@ import tools.cryptea.utils.Base64Helper;
|
||||
import tools.cryptea.utils.HexHelper;
|
||||
import tools.cryptea.utils.JsonHelper;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
import tools.jackson.databind.node.ObjectNode;
|
||||
|
||||
public class Certificate {
|
||||
|
||||
// Url base per verifica
|
||||
public static final String BASE_URL = "https://cryptea.web.francescomancuso.it";
|
||||
|
||||
// per Jackson v3
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
// per richieste HTTP
|
||||
private static final HttpClient CLIENT = HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(10))
|
||||
@@ -236,31 +231,32 @@ public class Certificate {
|
||||
String[] parts = cleaned.split("\\.");
|
||||
if (parts.length < 4)
|
||||
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
|
||||
* 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
|
||||
* @throws Exception Nella gestione della richiesta HTTP
|
||||
*/
|
||||
public static String[] certificateIsActive(String certId) throws Exception {
|
||||
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()
|
||||
.uri(new URI(BASE_URL + "/api/v2/verify"))
|
||||
.uri(new URI(BASE_URL + "/api/v2/cert/" + certId + "/verify"))
|
||||
.headers("Content-Type", "application/json")
|
||||
.timeout(Duration.ofSeconds(15))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(finalJson))
|
||||
.GET()
|
||||
.build();
|
||||
|
||||
try {
|
||||
@@ -270,10 +266,10 @@ public class Certificate {
|
||||
String status = jsonRes.get("status").asString();
|
||||
|
||||
if (status.equals("ok")) {
|
||||
ret[0] = jsonRes.get("isActive").asString();
|
||||
ret[0] = jsonRes.get("content").get("isActive").asString();
|
||||
} else {
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user