From 4fb5ec85170838f0a9a9f476776f7707453f7124 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 25 Sep 2020 19:52:46 +0200 Subject: [PATCH] Code polish. Added extra failure if registration data or public key data is null --- src/dorkbox/network/handshake/ClientHandshake.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/dorkbox/network/handshake/ClientHandshake.kt b/src/dorkbox/network/handshake/ClientHandshake.kt index 2555b559..92450de5 100644 --- a/src/dorkbox/network/handshake/ClientHandshake.kt +++ b/src/dorkbox/network/handshake/ClientHandshake.kt @@ -79,7 +79,6 @@ internal class ClientHandshake(private val crypto: Crypt return@FragmentAssembler } - if (this@ClientHandshake.sessionId != message.sessionId) { failed = ClientException("[$message.sessionId] ignored message intended for another client (mine is: " + "${this@ClientHandshake.sessionId})") @@ -87,17 +86,25 @@ internal class ClientHandshake(private val crypto: Crypt } // it must be the correct state + val registrationData = message.registrationData + when (message.state) { HandshakeMessage.HELLO_ACK -> { // The message was intended for this client. Try to parse it as one of the available message types. // this message is ENCRYPTED! - connectionHelloInfo = crypto.decrypt(message.registrationData, message.publicKey) + val serverPublicKeyBytes = message.publicKey + + if (registrationData != null && serverPublicKeyBytes != null) { + connectionHelloInfo = crypto.decrypt(registrationData, serverPublicKeyBytes) + } else { + failed = ClientException("[$message.sessionId] ignored message without registration and/or public key info") + } } HandshakeMessage.HELLO_ACK_IPC -> { // The message was intended for this client. Try to parse it as one of the available message types. // this message is ENCRYPTED! val cryptInput = crypto.cryptInput - cryptInput.buffer = message.registrationData + cryptInput.buffer = registrationData val sessId = cryptInput.readInt() val streamSubId = cryptInput.readInt()