glenak 2 Junior Poster in Training

Hi all,

So, I'm building an SSL server/client app, and I keep getting this exception:

javax.net.ssl.SSLHandshakeException: renegotiation is not allowed

Does anyone know how I can work around this?

Here are my codes:
SERVER:

//server.jks = keystore
		//ServerJKS = keystore password
		//SeverKey = certificate's password (certificate = server_full)
		if (args.length<3) {
			System.out.println("Usage:");
	        System.out.println("   java AdminApp keyStoreName keyStorePass certPass");
	        return;
		}
		
		String keyStoreName = args[0];
	    char[] keyStorePass = args[1].toCharArray();
	    char[] certPass = args[2].toCharArray();
	    System.setProperty("javax.net.ssl.trustStore", args[0]);
	    System.setProperty("javax.net.ssl.trustStorePassword", args[1]);
	    
	    try {
	    	KeyStore keystore = KeyStore.getInstance("JKS");
	        keystore.load(new FileInputStream(keyStoreName), keyStorePass);
	        
	        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
	        kmf.init(keystore, certPass);
	        
	        SSLContext context = SSLContext.getInstance("SSL");
	        context.init(kmf.getKeyManagers(), null, null);
	       
	        SSLServerSocketFactory factory = context.getServerSocketFactory();
	        SSLServerSocket server = (SSLServerSocket) factory.createServerSocket(8888);
	        server.setNeedClientAuth(true);
	        
	        //call method printServerSocketInfo
	        printServerSocketInfo(server);
	        
	        SSLSocket socket = (SSLSocket) server.accept();
	        
	        //call method printSocketInfo
	        printSocketInfo(socket);
	        
	        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
	        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
	        
	        String msg = "Welcome to SSL Reverse Echo Server."+ " Please type in some words.";
	        writer.write(msg,0,msg.length());
	        writer.newLine();
	        writer.flush();
	        while ((msg = reader.readLine())!= null) {
	        	if (msg.equals("."))
	        		break;
	            char[] a = msg.toCharArray();
	            int n = a.length;
	            for(int i = 0; i < n/2; i++) {
	            	char t = a[i];
	            	a[i] = a[n-1-i];
	            	a[n-i-1] = t;
	            }
	            writer.write(a,0,n);
	            writer.newLine();
	            writer.flush();
	         }
	         writer.close();
	         reader.close();
	         socket.close();
	         server.close();
	      } catch (Exception e) {
	         System.err.println(e.toString());
	      }

CLIENT

if (args.length<3) {
			System.out.println("Usage:");
			System.out.println("   java SslReverseEchoerRevised keyStoreName keyStorePass certPass");
			return;
		}
		
		String keyStoreName = args[0];
	    char[] keyStorePass = args[1].toCharArray();
	    char[] certPass = args[2].toCharArray();
	    System.setProperty("javax.net.ssl.trustStore", args[0]);
	    System.setProperty("javax.net.ssl.trustStorePassword", args[1]);
	    
	    //these two, to get messages out and in
	    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
	    PrintStream out = System.out;
	    
	    try {
	    	KeyStore keystore = KeyStore.getInstance("JKS");
	        keystore.load(new FileInputStream(keyStoreName), keyStorePass);
	        
	        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
	        kmf.init(keystore, certPass);
	        
	        SSLContext context = SSLContext.getInstance("SSL");
	        context.init(kmf.getKeyManagers(), null, null);
	        
	        SSLSocketFactory factory = context.getSocketFactory();
	        SSLSocket socket = (SSLSocket) factory.createSocket("localhost", 8888);
	        
	        //call printSocketInfo method
	        printSocketInfo(socket);
	        
	        //start handshake
	        //socket.startHandshake();
	        
	        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
	        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
	        
	        String msg = null;
	        while ((msg = reader.readLine())!= null) {
	        	out.println(msg);
	            msg = in.readLine();
	            writer.write(msg,0,msg.length());
	            writer.newLine();
	            writer.flush();
	        }
	        writer.close();
	        reader.close();
	        socket.close();
	    } catch (Exception e) {
	    	System.err.println(e.toString());
	    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.