0

I've been trying to convert a Client/Server model I made in Java using sockets to SSL. After generating my PKCS12 file containing the server's root and intermediate files, I used System.setProperty to change the trust and keystores in the client and server files to the PKCS file. I'm not really sure if that's what your meant to do. I also made the changes to my sockets, using an SSLSocketFactory to create the necessary sockets.

Here is the Code Below. Client:

`public class Client 
{
    private SSLSocket client_socket;
    private DataOutputStream output_stream;
    private FileReader reader;
    private BufferedReader buffer_reader;
public Client(String address, int port)
{
    System.setProperty("javax.net.ssl.keyStore", "wa.p12");
    System.setProperty("javax.net.ssl.keyStorePassword", "namihana");
    System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
    System.setProperty("javax.net.ssl.trustStore", "wa.p12");
    System.setProperty("javax.net.ssl.trustStorePassword", "namihana");
    System.setProperty("javax.net.ssl.TrustStoreType", "PKCS12");
//  System.setProperty("javax.net.ssl.trustStoreType", "PKCS12");
    Security.addProvider(new Provider());

    try
    {
    SSLSocketFactory ssf =  (SSLSocketFactory) SSLSocketFactory.getDefault();
    client_socket = (SSLSocket) ssf.createSocket("127.0.0.1", 8072);
    client_socket.startHandshake();

 public class Server
{
    public Socket socket_2;
    public SSLServerSocket server_socket;
    public InputStreamReader input_stream;
    private BufferedReader buffer_reader;
    private DataOutputStream output_sender;
    private PrintWriter output_writer; 
    private boolean result;
    private char[] multichoice_answers;

Server:

public Server(int port)
        {
            System.setProperty("javax.net.ssl.keyStore", "wa.p12");
            System.setProperty("javax.net.ssl.keyStorePassword", "namihana");
            System.setProperty("javax.net.ssl.keyStoreType", "PKCS12");
            System.setProperty("javax.net.ssl.trustStore", "wa.p12");
            System.setProperty("javax.net.ssl.trustStorePassword", "namihana");
            System.setProperty("javax.net.ssl.TrustStoreType", "PKCS12");
             multichoice_answers = new char[30];
             multichoice_answers[0] = 'A';
             multichoice_answers[1] = 'A';
             multichoice_answers[2] = 'D'; 
             multichoice_answers[3] = 'C';
             multichoice_answers[4] = 'C';
             multichoice_answers[5] = 'C';
             multichoice_answers[6] = 'D';
             multichoice_answers[7] = 'B';
             multichoice_answers[8] = 'D';
             multichoice_answers[9] = 'B';
             multichoice_answers[10] = 'C';
             multichoice_answers[11] = 'D';
             multichoice_answers[12] = 'A';
             multichoice_answers[13] = 'D';
             multichoice_answers[14] = 'C';

            try
        {
            SSLServerSocketFactory ssf =  (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
            SSLServerSocket server_socket =  (SSLServerSocket) ssf.createServerSocket(port); 
            System.out.println("Server_socket made");
            Security.addProvider(new Provider()); 
            //server_socket.setSoTimeout(100000); 
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
     }


    public void receive()
    {
        try
        {
             System.out.println("Server connected2");   
             socket_2 =   server_socket.accept();
  • You haven't really asked a question, nor completely explained what the problem is, nor given a complete example to illustrate it. It looks like you got 75% of the way to a good question but then gave up. Please edit your question to add the missing details. – President James K. Polk May 22 '18 at 18:01

1 Answers1

0

You have a local ServerSocket variable in your try block that is shadowing the class member.

user207421
  • 305,947
  • 44
  • 307
  • 483