I have been scratching my head trying to come up with a TLS implementation across a client and server setup.
Notes and snippets I have written down about some of the basic setup:
SSLContext context = SSLContext.getInstance("TLS");
// key managers, trust managers
context.init(keyManagers, trustManagers, null);
// Server
SSLEngine engine = context.createSSLEngine();
engine.setClientMode(false);
engine.setNeedClientAuth(true);
// Client
SSLEngine engine = context.createSSLEngine("ip", port);
engine.setClientMode(true);
// Send and receive with networkBuffer
// Reading from
ByteBuffer actualBuffer = ...;
engine.unwrap(networkBuffer, actualBuffer);
// Writing to
ByteBuffer unsecureBuffer = ...;
engine.wrap(unsecureBuffer, networkBuffer);
// Closing
engine.closeInbound();
engine.closeOutbound();
What I believe I have to do to handle this:
Create a set of keys on the client, and then send the public key to the server, and somehow the server will be able to read and write the necessary data.
I understand that there are major gaps in my understanding of how to send the keys from the client to the server, and I would appreciate if someone with a little more experience about using the SSL classes in the standard Java packages could shed some light on how this is handled.