Example #1
0
 public void SetUp()
 {
     _password        = "******"; // original password
     _wrongPassword   = "******";
     _passwordHashMD5 =
         HashUtil.ComputeHash(_password, HashingAlgorithm.MD5, null);
     _passwordHashSha1 =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA1, null);
     _passwordHashSha256 =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA256, null);
     _passwordHashSha384 =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA384, null);
     _passwordHashSha512 =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA512, null);
     _passwordHashMD5WithSalt =
         HashUtil.ComputeHash(_password, HashingAlgorithm.MD5, SecurityUtil.RandomSalt(4));
     _passwordHashSha1WithSalt =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA1, SecurityUtil.RandomSalt(8));
     _passwordHashSha256WithSalt =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA256, SecurityUtil.RandomSalt(16));
     _passwordHashSha384WithSalt =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA384, SecurityUtil.RandomSalt(32));
     _passwordHashSha512WithSalt =
         HashUtil.ComputeHash(_password, HashingAlgorithm.SHA512, SecurityUtil.RandomSalt(64));
 }
Example #2
0
        public Task <PasswordGeneratedEventArgs> GeneratePasswordAsTask()
        {
            Trace.WriteLine("Ran");
            var tcs = RegisterAsTask <PasswordGeneratedEventArgs>(ref OnNewPasswordGenerated);

            var childTask = Task <PasswordGeneratedEventArgs> .Factory.StartNew(() =>
            {
                Provider.ServerMachine.Identity     = MachineIdentity.GetCurrentIdentity();
                Provider.ServerMachine.Password     = AlphaNumericGenerator.Generate(2, GeneratorOptions.Numeric);
                Provider.ServerMachine.PasswordHash = HashUtil.ComputeHash(Provider.ServerMachine.Password, HashType.SHA512);

                var newPasswordEventArgs = new PasswordGeneratedEventArgs {
                    NewPassword = Provider.ServerMachine.Password
                };

                if (OnNewPasswordGenerated != null)
                {
                    OnNewPasswordGenerated(this, newPasswordEventArgs);
                }

                return(newPasswordEventArgs);
            }, TaskCreationOptions.AttachedToParent);

            return(tcs.Task);
        }
Example #3
0
            public void Parameter_checks()
            {
                Stream stream = null;
                var    ane    = Assert.Throws <ArgumentNullException>(delegate { HashUtil.ComputeHash(stream); });

                Assert.That(ane.Message, Contains.Substring("stream"));
            }
Example #4
0
        /// <summary>
        /// Note: Does not check old password of oldpassword is set to null!
        /// </summary>
        public static void ChangePassword(this DragonContext ctx, string username, string oldpassword, string password)
        {
            if (!ctx.UserStore.HasUserByKey(SERVICE_ID, username))
            {
                throw new UserKeyDoesNotExistException();
            }
            else
            {
                var hashedSaltedSecret = HashUtil.ComputeHash(password);

                bool res;
                if (oldpassword == null)
                {
                    // do not verify oldpassword if set to null
                    ctx.UserStore.UpdateSecret(SERVICE_ID, username, hashedSaltedSecret);
                    res = true;
                }
                else
                {
                    res = ctx.UserStore.UpdateSecret(SERVICE_ID, username, (s) => HashUtil.VerifyHash(oldpassword, s), hashedSaltedSecret);
                }
                if (!res)
                {
                    throw new InvalidUserOrOldSecretException();
                }
            }
        }
Example #5
0
            public void Parameter_checks()
            {
                byte[] bytes = null;
                var    ane   = Assert.Throws <ArgumentNullException>(delegate { HashUtil.ComputeHash(bytes); });

                Assert.That(ane.Message, Contains.Substring("bytes"), "Test 1");

                bytes = new byte[0];
                Assert.DoesNotThrow(delegate { HashUtil.ComputeHash(bytes); }, "Test 2");
            }
Example #6
0
        public static void ChangePasswordForCurrentUser(this DragonContext ctx, string oldpassword, string password)
        {
            var hashedSaltedSecret = HashUtil.ComputeHash(password);

            var res = ctx.UserStore.UpdateSecret(ctx.CurrentUserID, (s) => HashUtil.VerifyHash(oldpassword, s), hashedSaltedSecret);

            if (!res)
            {
                throw new InvalidUserOrOldSecretException();
            }
        }
Example #7
0
            public void Validate_hash()
            {
                foreach (var algorithmType in this.algorithmTextAndHashes.Keys)
                {
                    var textsAndHashes = this.algorithmTextAndHashes[algorithmType];

                    foreach (var keyValuePair in textsAndHashes)
                    {
                        Assert.AreEqual(keyValuePair.Value, HashUtil.ComputeHash(keyValuePair.Key, algorithmType));
                    }
                }
            }
Example #8
0
 public static void RegisterUsernamePassword(this DragonContext ctx, string username, string password)
 {
     if (ctx.UserStore.HasUserByKey(SERVICE_ID, username))
     {
         throw new UserKeyAlreadyExistsForThisServiceException();
     }
     else
     {
         var hashedSaltedSecret = HashUtil.ComputeHash(password);
         ctx.UserStore.Register(SERVICE_ID, username, hashedSaltedSecret);
     }
 }
Example #9
0
            public void Parameter_checks()
            {
                string text = null;
                var    ane  = Assert.Throws <ArgumentNullException>(delegate { HashUtil.ComputeHash(text); });

                Assert.That(ane.Message, Contains.Substring("text"), "Test 1");

                text = string.Empty;
                Assert.DoesNotThrow(delegate { HashUtil.ComputeHash(text); }, "Test 2");

                text = "  ";
                Assert.DoesNotThrow(delegate { HashUtil.ComputeHash(text); }, "Test 3");
            }
Example #10
0
            public void Validate_hash()
            {
                foreach (var algorithmType in this.algorithmTextAndHashes.Keys)
                {
                    var textsAndHashes = this.algorithmTextAndHashes[algorithmType];

                    foreach (var keyValuePair in textsAndHashes)
                    {
                        byte[] bytes = Encoding.UTF8.GetBytes(keyValuePair.Key);
                        Assert.AreEqual(keyValuePair.Value, HashUtil.ComputeHash(bytes, algorithmType));
                    }
                }
            }
Example #11
0
            public void Validate_hash()
            {
                foreach (var algorithmType in this.algorithmTextAndHashes.Keys)
                {
                    var textsAndHashes = this.algorithmTextAndHashes[algorithmType];

                    foreach (var keyValuePair in textsAndHashes)
                    {
                        using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(keyValuePair.Key)))
                        {
                            Assert.AreEqual(keyValuePair.Value, HashUtil.ComputeHash(ms, algorithmType));
                        }
                    }
                }
            }
Example #12
0
        public static bool HandleReconnectProof(AuthConnection client, BinaryReader br)
        {
            var pkt = PacketHelper.Parse <C_AuthReconnectProof>(br);

            var serverProof = HashUtil.ComputeHash(
                Encoding.ASCII.GetBytes(client.LogonChallenge.Identifier),
                pkt.ProofData,
                client.ChallengeData,
                client.SRP.SessionKey.ToProperByteArray());

            if (!serverProof.SequenceEqual(pkt.ClientProof))
            {
                return(true); // Drop client here
            }
            client.SendPacket(AuthOpcodes.AuthReconnectProof, PacketHelper.Build(new S_AuthReconnectProof
            {
                Error = AuthResult.Success
            }));

            return(true);
        }
Example #13
0
        public ActionResult Edit([Bind(Include = "Id,Name,HashValue,IsMedical")] Usuario usuario)
        {
            if (ModelState.IsValid)
            {
                var previous = db.Usuarios.Where(x => x.Id == usuario.Id).FirstOrDefault();

                if (previous != null)
                {
                    previous.Name      = usuario.Name;
                    previous.IsMedical = usuario.IsMedical;

                    if (!string.IsNullOrEmpty(usuario.HashValue))
                    {
                        previous.HashValue = HashUtil.ComputeHash(usuario.HashValue, null);
                    }
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            return(View(usuario));
        }
Example #14
0
        // TODO: Redo this
        public Task <IntroducerIntroductionCompletedEventArgs> RequestIntroductionAsTask(string novaId, string password)
        {
            var tcs = RegisterAsTask <IntroducerIntroductionCompletedEventArgs>(ref OnIntroductionCompleted);

            var childTask = Task.Factory.StartNew(() =>
            {
                var clientMachine = new Machine {
                    Identity = MachineIdentity.GetCurrentIdentity(), PrivateEndPoint = Network.GetInternalEndPoint()
                };

                var serverMachine = new Machine {
                    NovaId = novaId, PasswordHash = HashUtil.ComputeHash(password, HashType.SHA512)
                };

                Network.SendUnconnectedMessage(new RequestIntroducerIntroductionMessage {
                    ClientMachine = clientMachine, ServerMachine = serverMachine
                },
                                               Config.GetIPEndPoint("IntroducerEndPoint"));
            }, TaskCreationOptions.AttachedToParent);

            return(tcs.Task);
        }
Example #15
0
        public ActionResult Create([Bind(Include = "Id,Name,HashValue,IsMedical")] Usuario usuario)
        {
            if (ModelState.IsValid)
            {
                var previous = db.Usuarios.Where(x => x.Name.ToUpper() == usuario.Name.ToUpper()).FirstOrDefault();

                if (previous == null)
                {
                    usuario.HashValue = HashUtil.ComputeHash(usuario.HashValue, null);
                    db.Usuarios.Add(usuario);
                    db.SaveChanges();
                }
                else
                {
                    ViewBag.Message    = "Usuário já existe!";
                    ViewBag.StyleClass = "alert alert-danger";
                    return(View("Index"));
                }
                return(RedirectToAction("Index"));
            }

            return(View(usuario));
        }
Example #16
0
        public static bool HandleAuthSession(GatewayConnection client, BinaryReader br)
        {
            var pkt = PacketHelper.Parse <CMSG_AUTH_SESSION>(br);

            // TODO: verify build

            client.Crypt = new AuthCrypt(LoginService.GetSessionKey(pkt.Account));

            var serverDigest = HashUtil.ComputeHash(Encoding.ASCII.GetBytes(pkt.Account),
                                                    new byte[] { 0, 0, 0, 0 },
                                                    BitConverter.GetBytes(pkt.ClientSeed),
                                                    BitConverter.GetBytes(client.Seed),
                                                    client.Crypt.SessionKey);

            if (!serverDigest.SequenceEqual(pkt.ClientDigest))
            {
                return(false);
            }

            // TODO: Move to LoginService?
            using (var db = new DBLogin())
            {
                var acc = db.Account.FirstOrDefault(a => a.Username == pkt.Account);
                client.AccountName = acc.Username;
                client.AccountID   = acc.AccountID;
            }

            client.SendPacket(WorldOpcodes.SMSG_AUTH_RESPONSE, PacketHelper.Build(new SMSG_AUTH_RESPONSE
            {
                Response             = (byte)ResponseCodes.AUTH_OK,
                BillingTimeRemaining = 0,
                BillingPlanFlags     = 0,
                BillingTimeRested    = 0
            }));

            return(true);
        }