2
I wonder if this communication between the sockets is safe. From this code I can safely exchange information?
I am also doubtful to understand how the Sslcontext class works (it is not in this code).
Server
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;
public class MainClass extends Thread {
public static void main(String[] args) throws Exception {
ServerSocketFactory ssf = SSLServerSocketFactory.getDefault();
ServerSocket ss = ssf.createServerSocket(9096);
while (true) {
new SSLSimpleServer(ss.accept()).start();
}
}
private Socket sock;
public SSLSimpleServer(Socket s) {
sock = s;
}
public void run() {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
PrintWriter pw = new PrintWriter(sock.getOutputStream());
String data = br.readLine();
pw.println("What is she?");
pw.close();
sock.close();
} catch (IOException ioe) {
// Client disconnected
}
}
}
Client
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
public class MainClass {
public static void main(String[] args) throws Exception {
SocketFactory sf = SSLSocketFactory.getDefault();
Socket s = sf.createSocket(args[0], Integer.parseInt(args[1]));
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter pw = new PrintWriter(s.getOutputStream());
System.out.println("Who is Sylvia?");
pw.println("Who is Sylvia?");
pw.flush();
System.out.println(br.readLine());
s.close();
}
}
Yes, there are several variables. But one questions this communication as it is, the messages are being encrypted so?
– Skywalker