Grizzly mit HTTPS

GENiALi

Mitglied
Hallo

Ich kommte eigentlich aus dem .NET Lager will aber aktuell ein Java Projekt machen. Dazu will ich einen self-hosted Webserver in betrieb nehmen. Das klappt auch wunderbar. Bis ich dann SSL ins spiel bringen will.

Folgendes Stück Code funktioniert perfekt.
Java:
private static void startWebserver(String port) {
    try {
        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(UriBuilder.fromUri("http://localhost/").port(Integer.valueOf(port)).build(),
                createBotApp());
        System.out.println(String.format("Application started.%nHit enter to stop it..."));
        System.in.read();
        server.shutdownNow();
    } catch (IOException ex) {
        System.out.println(ex.toString());
    }
}

public static ResourceConfig createBotApp() {
    return new ResourceConfig()
            .packages("ch.geniali.Webservices")
            .register(Webservice.class);
}

Sobald dann aber SSL ins spiel kommt gehts nicht mehr.
Java:
private static void startWebserver(String port) {
    try {
        SSLContextConfigurator sslContext = new SSLContextConfigurator();
        sslContext.setKeyStoreFile("./cert/keystore_server");
        sslContext.setKeyStorePass("PW");
        sslContext.setTrustStoreFile("./cert/truststore_server");
        sslContext.setTrustStorePass("PW");

        final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(UriBuilder.fromUri("https://localhost/").port(Integer.valueOf(port)).build(),
                createBotApp(), true, new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(true));
        System.out.println(String.format("Application started.%nHit enter to stop it..."));
        System.in.read();
        server.shutdownNow();
    } catch (IOException ex) {
        System.out.println(ex.toString());
    }
}

public static ResourceConfig createBotApp() {
    return new ResourceConfig()
            .packages("ch.geniali.Webservices")
            .register(Webservice.class);
}

Da das Projekt nie aus meiner Hand gehen wird habe ich ein Selfsignet Cert gemacht.

Generate client key and store it into keystore:
keytool -genkey -keystore ./keystore_client -alias clientKey -dname "CN=Client, OU=GENiALi, O=GENiALi, L=SWISS, ST=SWITZERLAND, C=CH"

Generate client certificate (this will generate self-signed certificate; if you have certification authority and want generate certificate request, use keytool -certreq):
keytool -export -alias clientKey -rfc -keystore ./keystore_client > ./client.cert

Import client certificate to servers truststore:
keytool -import -alias clientCert -file ./client.cert -keystore ./truststore_server

These steps are similar for server side:
keytool -genkey -keystore ./keystore_server -alias serverKey -dname "CN=localhost, OU=GENiALi, O=GENiALi, L=SWISS, ST=SWITZERLAND, C=CH"
keytool -export -alias serverKey -rfc -keystore ./keystore_server > ./server.cert
keytool -import -alias serverCert -file ./server.cert -keystore ./truststore_client

Die Frage: Sieht jemand was fehlt damit der Aufruf mit h**ps://localhost:<port>/ tut?
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
FrankenDerStein HTTP Https Server Bibliothek für Linux und Android gesucht. Netzwerkprogrammierung 7
JaXnPriVate Java HTTPS Server (Secure Sockets) Netzwerkprogrammierung 15
Thallius HTTP Kann man den Raw HTTPS Request irgendwie ausgeben lassen? Netzwerkprogrammierung 6
G localhost im Backend https vs. http Netzwerkprogrammierung 9
T HTTPS-Requests an Server: POST-Parameter kommen nicht an Netzwerkprogrammierung 5
M HTTPS Login & etwas posten Netzwerkprogrammierung 0
M Proxy und HTTPS Netzwerkprogrammierung 3
Thallius HTTP HTTPS unter Java 1.6 schlägt fehl Netzwerkprogrammierung 4
agent47 HTTPs Server Netzwerkprogrammierung 5
N Hintergrundlogin HTTPs Webform Netzwerkprogrammierung 5
E Gruppenchat: Über HTTPS oder nicht? Netzwerkprogrammierung 5
K HTTPS Zertifikat Netzwerkprogrammierung 3
F C/S über HTTPS Netzwerkprogrammierung 2
NoXiD Java mit HTTPS verbinden Netzwerkprogrammierung 6
T Up- und Download mit https Netzwerkprogrammierung 14
M HTTP HTTPS-Verbindung mittels Java und Javascript Netzwerkprogrammierung 2
T HTTPS einloggen Netzwerkprogrammierung 9
L Https Verbindung wird aus jar heraus nicht aufgebaut Netzwerkprogrammierung 12
E HTTPS Debuggen (verschlüsselte Daten anzeigen)? Netzwerkprogrammierung 12
Q HTTPS mit Apache HttpClient Netzwerkprogrammierung 4
M HTTPS Seiten runterladen Netzwerkprogrammierung 2
C HTTPS mit Apache HTTPClient Netzwerkprogrammierung 1
A HTTPS-Request via Proxy mit Konfigurationsskript Netzwerkprogrammierung 3
P HTTPS - öffentliches Zertifikat - ermitteln Netzwerkprogrammierung 5
G file download über https mit p12 Zertifikat Netzwerkprogrammierung 4

Ähnliche Java Themen

Neue Themen


Oben