Exemplo n.º 1
0
        public override Tuple <bool, ContactForm> AuthenticateContacnt(ClientToClientAuthForm authForm, CryptoFactoryBase factory, IPEndPoint endPoint,
                                                                       IEnumerable <ContactForm> publicForms,
                                                                       ResultOfOperation resultOfOperation)
        {
            var neededUsers = publicForms.Where(form => form.Login.Equals(authForm.Login)).ToArray();

            if (neededUsers.Length != 1)
            {
                resultOfOperation.ErrorMessage = "Пользователь с таким именем не зарегистрирован.";
                resultOfOperation.OperationWasFinishedSuccessful = true;
                return(new Tuple <bool, ContactForm>(resultOfOperation.OperationWasFinishedSuccessful, null));
            }

            var neededUser = neededUsers[0];

            if (!endPoint.Address.Equals(neededUser.Ip))
            {
                resultOfOperation.ErrorMessage = "Аутентификация не удалась.";
                resultOfOperation.OperationWasFinishedSuccessful = false;
                return(new Tuple <bool, ContactForm>(resultOfOperation.OperationWasFinishedSuccessful, null));
            }

            if (!authForm.ValidateSign(factory, neededUser.PublicKey))
            {
                resultOfOperation.ErrorMessage = "Аутентификация не удалась. Не удалось подтвердить подлинность подписи.";
                resultOfOperation.OperationWasFinishedSuccessful = false;
                return(new Tuple <bool, ContactForm>(resultOfOperation.OperationWasFinishedSuccessful, null));
            }

            resultOfOperation.OperationWasFinishedSuccessful = true;
            return(new Tuple <bool, ContactForm>(resultOfOperation.OperationWasFinishedSuccessful, neededUser));
        }
Exemplo n.º 2
0
 public abstract Tuple <bool, ContactForm> AuthenticateContacnt(ClientToClientAuthForm authForm, CryptoFactoryBase factory, IPEndPoint endPoint, IEnumerable <ContactForm> publicForms,
                                                                ResultOfOperation resultOfOperation);