java ssl Problem(-e)
lima-city → Forum → Programmiersprachen → Java
administrator
auto
blocken
code
fehler
import
jemand
message
nachricht
null
run
scanner
server
show
string
system
tag
treten
verzweifeln
wiedereinmal
-
Hallo,
ich bin wiedereinmal am verzweifeln. Ich versuche nun schon den ganzen Tag eine SSL verbindung aufzubauen. Mit diesem beispield das ich gefunden habe geht es:
/** * */ package de.tutorials; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLServerSocket; import javax.net.ssl.SSLServerSocketFactory; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; /** * @author Tom * */ public class SSLSocketExample { /** * @param args */ public static void main(String[] args) { Executors.newSingleThreadExecutor().execute(new Server()); Executors.newSingleThreadExecutor().execute(new Client()); } static class Server implements Runnable { public void run() { try { SSLServerSocket serverSocket = (SSLServerSocket) SSLServerSocketFactory .getDefault().createServerSocket(5678); System.out.println("Server ready..." + serverSocket); System.out .println("Supported Cipher Suites: " + Arrays .toString(((SSLServerSocketFactory) SSLServerSocketFactory .getDefault()) .getSupportedCipherSuites())); SSLSocket socket = (SSLSocket) serverSocket.accept(); SSLSession sslSession = socket.getSession(); String cipherSuite = sslSession.getCipherSuite(); System.out.println(cipherSuite); Scanner scanner = new Scanner(socket.getInputStream()); System.out.println("Reading..."); while (scanner.hasNextLine()) { System.out.println("Server received: " + scanner.nextLine()); } scanner.close(); socket.close(); serverSocket.close(); } catch (IOException e) { e.printStackTrace(); } } } static class Client implements Runnable { public void run() { try { SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault() .createSocket("localhost", 5678); PrintWriter printWriter = new PrintWriter(socket .getOutputStream()); System.out.println("Client -> sending..."); for (int i = 0; i < 100; i++) { String message = "Hallo: " + i; System.out.println("Client sent: " + message); printWriter.println(message); printWriter.flush(); TimeUnit.SECONDS.sleep(1); } socket.close(); } catch (Exception e) { e.printStackTrace(); } } } }
aber bei mir geht es nicht:
Client Socket erstellen
SSLSocket socket = null; do { try { System.out.println("connecting"); socket = (SSLSocket) SSLSocketFactory.getDefault() .createSocket("localhost", 5678); } catch (IOException e) { e.printStackTrace(); }// end try } while (socket == null); connection = new Connection(socket);// klasse für // String senden // und empfangen String version = Connection.send("test:-version");
Connection class:
private static SSLSocket socket; private static OutputStream outputStream; private static InputStream inputStream; public Connection(SSLSocket socket) { Connection.socket = socket; try { Connection.outputStream = Connection.socket.getOutputStream(); Connection.inputStream = Connection.socket.getInputStream(); } catch (IOException e) { JOptionPane.showMessageDialog( null, "An error occured. Please call your administrator\n" + "and show this message if it occures twice.\n" + "error;init.Connection.IOException\n" + e.toString(), "Error", JOptionPane.ERROR_MESSAGE); System.exit(0); } } public static String send(String data) { byte[] returnedData = null; String answerBuffer = ""; try { outputStream.write(data.getBytes());// nachricht schicken } catch (Exception e) { //<-----HIER TRITT DER FEHLER AUF e.printStackTrace(); System.exit(0); }
Der Fehler ist :
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
Server:
try { serverSocket = (SSLServerSocket) SSLServerSocketFactory .getDefault().createServerSocket(5678); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } new Thread() { public void run() { while (true) { SSLSocket client = null; System.out.println("fetching client"); try { client =(SSLSocket) serverSocket.accept(); SSLSession sslSession = client.getSession(); String cipherSuite = sslSession.getCipherSuite(); System.out.println(cipherSuite)
Falls mir jemand helfen könnte oder noch infos braucht kann er mich auch in Skype adden [den.ganzen.tag.lang] .
Danke schonmal im vorraus
-
Diskutiere mit und stelle Fragen: Jetzt kostenlos anmelden!
lima-city: Gratis werbefreier Webspace für deine eigene Homepage