Hello all! I am trying to create a server - client bundle that will let me send simple messages with ssl support. I am quite new at java and i can't figure out what my problem is. I am running the server and client programs at 2 computers at the same network and i can send messages. My problem is that when i capture the messages with wireshark the protocol is TCP and i can read the messages:(
About the certificates now,i have create all my certificates with openssl and i have convert them to .jks with keytool. Myca.jks is the certificate of an selfsigned ca, i have signed the server and the client with this certificate.
Thanks for any tip:)
import java.io.*;
import java.net.*;
import java.security.*;
import java.util.*;
import javax.net.ssl.*;
public class sslserver {
ObjectOutputStream out;
ObjectInputStream in;
String message;
sslserver(){}
void run() throws Exception
{
char[] passphrase = "123456".toCharArray();
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(new FileInputStream("/home/jimmysnn/JavaApplication4/src/keystore.jks"), passphrase);
KeyStore serverkeystore = KeyStore.getInstance("JKS");
serverkeystore.load(new FileInputStream("/home/jimmysnn/JavaApplication4/src/server.jks"), passphrase);
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(keystore, passphrase);
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(serverkeystore);
SSLContext context = SSLContext.getInstance("TLS");
TrustManager[] trustManagers = tmf.getTrustManagers();
KeyManager[] keyManagers = kmf.getKeyManagers();
context.init(keyManagers, trustManagers, null);
//1. creating a server socket
SSLServerSocketFactory ssf = context.getServerSocketFactory();
ServerSocket ss = ssf.createServerSocket(2004);
//2. Wait for connection
System.out.println("Waiting for connection");
Socket s = ss.accept();
System.out.println("Connection received from " + s.getInetAddress().getHostName());
//3. get Input and Output streams
out = new ObjectOutputStream(s.getOutputStream());
out.flush();
in = new ObjectInputStream(s.getInputStream());
sendMessage("Connection successful");
//4. The two parts communicate via the input and output streams
Scanner input = new Scanner( System.in );
do{
message = (String)in.readObject();
System.out.println("client>" + message);
if (message.equals("bye"))
sendMessage("bye");
}while(!message.equals("bye"));
//4: Closing connection
in.close();
out.close();
ss.close();
}
void sendMessage(String msg) throws Exception
{
out.writeObject(msg);
out.flush();
System.out.println("server>" + msg);
}
public static void main(String args[]) throws Exception
{
Server server = new Server();
while(true){
server.run();
}
}
}