Esempio n. 1
0
        public int Step3(byte[] newPassword, string email)
        {
            if (CheckVendor.NotValidPassword(newPassword))
            {
                return(03_0007);
            }

            if (CheckVendor.NotValidEmail(email))
            {
                return(03_0005);
            }

            if (CheckVendor.NotValidResponse(_serverResponse))
            {
                return(02_0008);
            }

            _password = newPassword;
            var recoveryRequest = new RecoveryRequest();

            recoveryRequest.Email = email;

            recoveryRequest.Verifier = Srp6Vendor.Srp6Init(_username, _password, out var salt).ToByteArray();

            recoveryRequest.Salt = salt;

            recoveryRequest.GroupParam = Srp6Vendor.BitLength;

            recoveryRequest.OperationToken = _serverResponse.AuthToken;

            recoveryRequest.ReportTime = DateTime.Now;

            var result = ApiCall.AuthReset.Call(null, new MilvanethProtocol {
                Context = null, Data = recoveryRequest
            });

            if (!(result.Data is ServerResponse sr))
            {
                return(02_0007);
            }

            if (!CheckVendor.NotValidResponse(sr))
            {
                _serverResponse = sr;
            }

            return(sr.Message);
        }
Esempio n. 2
0
        public int Step2(byte[] password)
        {
            if (CheckVendor.NotValidPassword(password))
            {
                return(03_0010);
            }

            if (CheckVendor.NotValidResponse(_serverChallenge))
            {
                return(02_0008);
            }

            var clientResponse = new ClientResponse();

            clientResponse.SessionId = _serverChallenge.SessionId;

            clientResponse.ClientEvidence = Srp6Vendor.Srp6Response(_username, password, _serverChallenge.Salt,
                                                                    new BigInteger(_serverChallenge.ServerToken), out var token).ToByteArray();

            clientResponse.ClientToken = token.ToByteArray();

            clientResponse.ReportTime = DateTime.Now;

            var result = ApiCall.AuthFinish.Call(null, new MilvanethProtocol {
                Context = null, Data = clientResponse
            });

            if (!(result.Data is ServerResponse sr))
            {
                return(02_0007);
            }

            if (!CheckVendor.NotValidResponse(sr))
            {
                _serverResponse = sr;
            }

            return(sr.Message);
        }
Esempio n. 3
0
        public int Step1(LobbyServiceResult service, LobbyCharacterResult character, string username, string displayName, string email, byte[] password, long[] trace)
        {
            var registerForm = new RegisterForm();

            if (CheckVendor.NotValidService(service))
            {
                return(03_0000);
            }

            registerForm.Service = service;

            if (CheckVendor.NotValidCharacter(character))
            {
                return(03_0000);
            }

            registerForm.Character = character;

            if (CheckVendor.NotValidTrace(trace))
            {
                return(03_0008);
            }

            registerForm.Trace = trace;

            // 4-16个字符,可使用英文、数字和下划线,必须以字母开头
            if (CheckVendor.NotValidUsername(username))
            {
                return(03_0001);
            }

            registerForm.Username = username;

            // 2-12个字符,可使用中英文、数字和下划线
            if (CheckVendor.NotValidDisplayName(displayName))
            {
                return(03_0003);
            }

            registerForm.DisplayName = displayName;

            if (CheckVendor.NotValidEmail(email))
            {
                return(03_0005);
            }

            registerForm.Email = email;

            // 4个字符以上的中文或8个字符以上的数字和字母
            if (CheckVendor.NotValidPassword(password))
            {
                return(03_0007);
            }

            _username = username;
            _password = password;

            registerForm.Verifier = Srp6Vendor.Srp6Init(username, password, out var salt).ToByteArray();

            registerForm.Salt = salt;

            registerForm.GroupParam = Srp6Vendor.BitLength;

            registerForm.ReportTime = DateTime.Now;

            for (var i = 0; i < 3; i++)
            {
                var result = ApiCall.AccountCreate.Call(null, new MilvanethProtocol {
                    Context = null, Data = registerForm
                });

                if (!(result.Data is ServerChallenge sc))
                {
                    return(02_0007);
                }

                if (!CheckVendor.NotValidResponse(sc))
                {
                    _serverChallenge = sc;
                }

                if (sc.Message != 01_0003) // retry with pow
                {
                    return(sc.Message);
                }

                registerForm.SessionId = sc.SessionId;

                registerForm.ProofOfWork = ProofOfWorkVendor.CalculateProofOfWork(sc.ProofOfWork);
            }

            return(01_0002);
        }