I'm trying to create a secure TCP/IP connection between my android client and java server. Cryptography by far is not my strong point. I know I have to use the Bouncy Castle keystores, but I'm stuck.
I need to create a self signed cert that I can use with the server and the client. This is where I'm stuck.
InputStream clientTruststoreIs = getResources().openRawResource(R.raw.bks);
KeyStore trustStore = null;
trustStore = KeyStore.getInstance("BKS");
trustStore.load(clientTruststoreIs, "123456".toCharArray());
InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
sslSocket = (SSLSocket) sslsocketfactory.createSocket(serverAddr, 2222);
inputStream = sslSocket.getInputStream();
Log.d("TEST", "\n1 input");
It connects fine, it shows the connection on the server side, however the line inputStream = sslSocket.getInputStream() is completely locking/not returning. I'm not sure if I did any of the bouncy castle set up properly, or if the server is properly set up. Please help, I'm at my wits' end....
Edit: I modified the server so that it sends data upon connection and still nothing, and I changed the order of where I get my input and output streams, and then it locked where I was getting the output stream:
sslSocket = (SSLSocket) sslsocketfactory.createSocket(serverAddr, 9999);
outputStream = sslSocket.getOutputStream();
Log.d("test", "--**--- created socket 2.0 outputsreams"); // does not reach here
outputStreamWriter = new OutputStreamWriter(outputStream);
bufferedWriter = new BufferedWriter(outputStreamWriter);
inputStream = sslSocket.getInputStream();
inputStreamReader = new InputStreamReader(inputStream);
bufferedReader = new BufferedReader(inputStreamReader);
...
String line = bufferedReader.readLine(); // where I'd expect it to lock...
So still no luck, no timeout, no exception, it just waits there...