Commit 6ad87fa6 authored by j.hoerdt's avatar j.hoerdt
Browse files

instead of challenge response, try out tls client cer auth

parent 7348bb4f
......@@ -158,11 +158,6 @@ public class Main {
Main.logger.fine("setting http_agent to: " + http_agent);
System.setProperty("http.agent", http_agent);
Main.logger.fine("creating pid registry session");
handle_registry_session_id = sensor2graph.handle.Session.create();
Main.logger.fine("initializing neo4j driver.");
initialize_driver();
......@@ -175,7 +170,6 @@ public class Main {
Main.logger.log(Level.SEVERE, "An unrecoverable exception occured, terminating...", e);
} finally {
driver.close();
sensor2graph.handle.Session.terminate(handle_registry_session_id);
}
}
......
package sensor2graph.handle;
// package sensor2graph.handle;
import java.io.*;
import java.net.*;
import java.net.http.HttpResponse;
import java.time.Duration;
import javax.net.ssl.*;
import java.security.*;
import java.security.cert.*;
import java.net.http.*;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class Session {
private static solve_challenge
private static TrustManager[] get_trust_managers() throws Exception {
var certificate = CertificateFactory.getInstance("X.509").generateCertificate(new FileInputStream("server_cert"));
var keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
keyStore.setCertificateEntry("vm13.pid.gwdg.de", certificate);
var trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
return trustManagerFactory.getTrustManagers();
}
public static void main(String[] args) throws Exception {
var sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, get_trust_managers(), null);
public static String create(URI registry_uri, ) {
private static HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(20)).build();
var client = HttpClient.newBuilder().sslContext(sslContext).connectTimeout(Duration.ofSeconds(20)).build();
var challenge_request = HttpRequest.newBuilder(registry_uri))
var challenge_request = HttpRequest.newBuilder(URI.create("https://vm13.pid.gwdg.de:8000/api/handles?prefix=21.11138"))
.header("Accept", "application/json")
.method("POST", BodyPublishers.noBody()).build();
var challenge = client.send(challenge_request, BodyHandlers.ofString());
if (challenge.statusCode() != 201) {
throw new Exception("server send status code " + challenge.statusCode() " instead of 201");
}
System.out.println(challenge.body() + challenge.statusCode());
// if (challenge.statusCode() != 201) {
// throw new Exception("server send status code " + challenge.statusCode() + " instead of 201");
// }
solve_challenge
new Gson().fromJson(response_body, JsonObject.class).get("epic-pid").getAsString();
return "";
}
public static void terminate(String session_id) {
}
// new Gson().fromJson(response_body, JsonObject.class).get("epic-pid").getAsString();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment