Next file done. ClientHandshakeHandler.java
@@ -87,6 +87,11 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
}
}
+ /**
+ * Process the handshake verification, checking that both the server and client have attempted it. If successful marks the channel as Authenticated.
+ * @param handshakeVerification
+ * @param ctx Channel Handler Context.
+ */
private void processHandshakeVerification(NetData.HandshakeVerification handshakeVerification, ChannelHandlerContext ctx) {
logger.info("Received server verification");
if (serverHello == null || clientHello == null) {
@@ -108,6 +113,11 @@ private void processHandshakeVerification(NetData.HandshakeVerification handshak
channelAuthenticated(ctx);
}
+ /**
+ * Generates a new secret key for a user and then decrypts the certificate into a byte array. Storing the certificate to the user ID.
+ * @param provisionIdentity
+ * @param ctx Channel Handler Context.
+ */
private void processNewIdentity(NetData.ProvisionIdentity provisionIdentity, ChannelHandlerContext ctx) {
logger.info("Received identity from server");
if (!requestedCertificate) {
@@ -167,12 +177,21 @@ private void processNewIdentity(NetData.ProvisionIdentity provisionIdentity, Cha
}
}
+ /**
+ * Creates a new builder on the channel and sets join status.
+ * @param ctx Channel Handler Context.
+ */
private void channelAuthenticated(ChannelHandlerContext ctx) {
ctx.getChannel().write(NetData.NetMessage.newBuilder()
.setServerInfoRequest(NetData.ServerInfoRequest.newBuilder()).build());
joinStatus.setCurrentActivity("Requesting server info");
}
+ /**
+ * Client checks to see if it received the server hello message, if so it processes it into a random key and the certificate.
+ * @param helloMessage Message from server to client.
+ * @param ctx Channel Handler Context.
+ */
private void processServerHello(NetData.HandshakeHello helloMessage, ChannelHandlerContext ctx) {
if (serverHello == null) {
logger.info("Received Server Hello");
@@ -205,6 +224,11 @@ private void processServerHello(NetData.HandshakeHello helloMessage, ChannelHand
}
+ /**
+ * Generates a client hello from clientRandom file, time, and the public client certificate. Sends the clients hello and certificate back to the server via network channel.
+ * @param helloMessage Message from server to client.
+ * @param ctx Channel Handler Context.
+ */
private void sendCertificate(NetData.HandshakeHello helloMessage, ChannelHandlerContext ctx) {
logger.info("Sending client certificate");
PublicIdentityCertificate pubClientCert = identity.getPlayerPublicCertificate();
@@ -225,6 +249,10 @@ private void sendCertificate(NetData.HandshakeHello helloMessage, ChannelHandler
.build());
}
+ /**
+ * Requests a new identity for a client if one doesn't already exist. Generated from the master secret key and server certificate.
+ * @param ctx Channel Handler Context.
+ */
private void requestIdentity(ChannelHandlerContext ctx) {
logger.info("No existing identity, requesting one");
