Exemple #1
0
        /// <summary>
        /// Processes VerifyIdentityRequest message from client.
        /// <para>It verifies the identity's public key against the signature of the challenge provided during the start of the conversation.
        /// If everything is OK, the status of the conversation is upgraded to Verified.</para>
        /// </summary>
        /// <param name="Client">Client that sent the request.</param>
        /// <param name="RequestMessage">Full request message.</param>
        /// <returns>Response message to be sent to the client.</returns>
        public ProxProtocolMessage ProcessMessageVerifyIdentityRequest(IncomingClient Client, ProxProtocolMessage RequestMessage)
        {
            log.Trace("()");

            ProxProtocolMessage res = null;

            if (!CheckSessionConditions(Client, RequestMessage, ServerRole.Client | ServerRole.Neighbor, ClientConversationStatus.ConversationStarted, out res))
            {
                log.Trace("(-):*.Response.Status={0}", res.Response.Status);
                return(res);
            }


            ProxMessageBuilder    messageBuilder        = Client.MessageBuilder;
            VerifyIdentityRequest verifyIdentityRequest = RequestMessage.Request.ConversationRequest.VerifyIdentity;

            byte[] challenge = verifyIdentityRequest.Challenge.ToByteArray();
            if (StructuralEqualityComparer <byte[]> .Default.Equals(challenge, Client.AuthenticationChallenge))
            {
                if (messageBuilder.VerifySignedConversationRequestBody(RequestMessage, verifyIdentityRequest, Client.PublicKey))
                {
                    log.Debug("Identity '{0}' successfully verified its public key.", Client.IdentityId.ToHex());
                    Client.ConversationStatus = ClientConversationStatus.Verified;
                    res = messageBuilder.CreateVerifyIdentityResponse(RequestMessage);
                }
                else
                {
                    log.Warn("Client's challenge signature is invalid.");
                    res = messageBuilder.CreateErrorInvalidSignatureResponse(RequestMessage);
                }
            }
            else
            {
                log.Warn("Challenge provided in the request does not match the challenge created by the proximity server.");
                res = messageBuilder.CreateErrorInvalidValueResponse(RequestMessage, "challenge");
            }

            log.Trace("(-):*.Response.Status={0}", res.Response.Status);
            return(res);
        }