private static void InitAuthentication(MooNetClient client, bnet.protocol.authentication.LogonRequest request) { client.LoginEmail = request.Email; var account = AccountManager.GetAccountByEmail(request.Email.ToLower()); // check if account exists. if (account == null) // we should be returning an error to client /raist. { client.AuthenticationErrorCode = AuthenticationErrorCodes.NoGameAccount; client.AuthenticationComplete(); return; } var thumbprintData = "f9513183031b3836103ac3a3bb606c0e06fd3b94ae4a6b6e405844085b794e901b0ebb1db650b85bac4b489a38a1ca9dcef2bbd13445d0cd85accfc62d84bc3a8d960b1a7a65cd8d3f72a172f41dca98459015ffbd25d766b02824a42dacb7c4cd64f4b3b9e316de23ec1dbb0153b73a4fa58ffb39c3f484b4b478a660dc8979e16e52f978a0ca2fc4184fa0f69844d73ef99f47e3ccb02cf6a636b4ae9513404eee7e0ad536dcef50cd1699e38195e6afdd3655a3a3529b4e52b33ac5d04f5fa2b15536a2c782c89c0acf133e14eac15af035abf5e44e9e1124a3397dac8f90a4ccb1717540698869fc1ba9037e099d68698ecf17ffdd36f07013176be24269fda1e5d221708181d95474fc1d74bb901062a9f6a3e24aef79e9d583d9126796d63c153a0f75f02da27ecc0971f39a46ec29087c3ae474e08fdf8f65d1445b293399bc495ff651b7d2d7a36216ba5e4400ea7bbc884dc4cf3ed27f14501b8bb7fc0f86b5089880e6889bcd851153e299a337d6c945f710559595e351995341cbef44abac379cf0f845b362d294eec390d50f1a50089d250eae1b1205cea1aff514de076516f467cd077a1fbb759b415dc6c0ea1617f31f7d764a0d60d5b67aa82b4202b2a9455eb9ca3683955ec45aaf56aba42a2f3ae9be5f3eed093a6601816d00e0569bfcb91fb7843945336c99757812d373d510d25744f9480b6cc87e8a".ToByteArray(); var srp6a = new SRP6a(account); // create srp6 handler to process the authentication. OngoingAuthentications.Add(client, srp6a); // request client to load thumbprint.dll for authentication. var moduleLoadRequest = bnet.protocol.authentication.ModuleLoadRequest.CreateBuilder() .SetModuleHandle(bnet.protocol.ContentHandle.CreateBuilder() .SetRegion(0x00005858) // XX .SetUsage(0x61757468) // auth - thumbprint.dll .SetHash(ByteString.CopyFrom(VersionInfo.MooNet.ThumbprintHashMap[client.Platform]))) .SetMessage(ByteString.CopyFrom(thumbprintData)) .Build(); client.ThumbprintReq = true; client.MakeRPC(() => bnet.protocol.authentication.AuthenticationClient.CreateStub(client).ModuleLoad(null, moduleLoadRequest, callback => { })); }
public static void CreateAccount(string[] args) { var email = Command.Read <string>(args, 0); var password = Command.Read <string>(args, 1); if (email != null && password != null) { var salt = new byte[0].GenerateRandomKey(0x20).ToHexString(); var result = DB.Auth.Any <Account>(a => a.Email == email); if (!result) { var srp = new SRP6a(salt); srp.CalculateX(email, password.ToUpper(), false); var account = new Account { Email = email, PasswordVerifier = srp.V.ToHexString(), Salt = salt, Region = Regions.XX, }; if (DB.Auth.Add(account)) { Log.Message(LogType.Normal, "Account {0} successfully created", email); } } else { Log.Message(LogType.Error, "Account {0} already in database", email); } } }
private static void InitAuthentication(MooNetClient client, bnet.protocol.authentication.LogonRequest request) { var account = AccountManager.GetAccountByEmail(request.Email); // check if account exists. if (account == null) // we should be returning an error to client /raist. { client.AuthenticationErrorCode = MooNetClient.AuthenticationErrorCodes.NoGameAccount; client.AuthenticationCompleteSignal.Set(); return; } var srp6a = new SRP6a(account); // create srp6 handler to process the authentication. OngoingAuthentications.Add(client, srp6a); // request client to load password.dll for authentication. var moduleLoadRequest = bnet.protocol.authentication.ModuleLoadRequest.CreateBuilder() .SetModuleHandle(bnet.protocol.ContentHandle.CreateBuilder() .SetRegion(0x00005553) // us .SetUsage(0x61757468) // auth - password.dll .SetHash(ByteString.CopyFrom(ModuleHash))) .SetMessage(ByteString.CopyFrom(srp6a.LogonChallenge)) .Build(); client.MakeRPCWithListenerId(request.ListenerId, () => bnet.protocol.authentication.AuthenticationClient.CreateStub(client).ModuleLoad(null, moduleLoadRequest, ModuleLoadResponse)); }
public static Account CreateAccount(string email, string password, string battleTag, Account.UserLevels userLevel = Account.UserLevels.User) { if (password.Length > 16) { password = password.Substring(0, 16); // make sure the password does not exceed 16 chars. } var hashCode = GetRandomHashCodeForBattleTag(); var salt = SRP6a.GetRandomBytes(32); var passwordVerifier = SRP6a.CalculatePasswordVerifierForAccount(email, password, salt); var newDBAccount = new DBAccount { Email = email, Salt = salt, PasswordVerifier = passwordVerifier, BattleTagName = battleTag, UserLevel = userLevel, HashCode = hashCode }; DBSessions.AccountSession.SaveOrUpdate(newDBAccount); DBSessions.AccountSession.Flush(); return(GetAccountByDBAccount(newDBAccount)); }
private static void InitAuthentication(MooNetClient client, bnet.protocol.authentication.LogonRequest request) { var account = AccountManager.GetAccountByEmail(request.Email.ToLower()); // check if account exists. if (account == null) // we should be returning an error to client /raist. { client.AuthenticationErrorCode = AuthenticationErrorCodes.NoGameAccount; client.AuthenticationCompleteSignal.Set(); return; } var srp6a = new SRP6a(account); // create srp6 handler to process the authentication. OngoingAuthentications.Add(client, srp6a); // request client to load password.dll for authentication. var moduleLoadRequest = bnet.protocol.authentication.ModuleLoadRequest.CreateBuilder() .SetModuleHandle(bnet.protocol.ContentHandle.CreateBuilder() .SetRegion(0x00005553) // us .SetUsage(0x61757468) // auth - password.dll .SetHash(ByteString.CopyFrom(VersionInfo.MooNet.AuthModuleHashMap[client.Platform]))) .SetMessage(ByteString.CopyFrom(srp6a.LogonChallenge)) .Build(); //client.MakeRPCWithListenerId(request.ListenerId, () => // bnet.protocol.authentication.AuthenticationClient.CreateStub(client).ModuleLoad(null, moduleLoadRequest, ModuleLoadResponse)); client.MakeRPC(() => bnet.protocol.authentication.AuthenticationClient.CreateStub(client).ModuleLoad(null, moduleLoadRequest, ModuleLoadResponse)); }
public Account(string email, string password, UserLevels userLevel) // Account with **newly generated** persistent ID : base() { if (password.Length > 16) { password = password.Substring(0, 16); // make sure the password does not exceed 16 chars. } var salt = SRP6a.GetRandomBytes(32); var passwordVerifier = SRP6a.CalculatePasswordVerifierForAccount(email, password, salt); this.SetFields(email, salt, passwordVerifier, userLevel); }
public Account(string email, string password, string battleTagName, int hashCode, UserLevels userLevel) // Account with **newly generated** persistent ID : base(StringHashHelper.HashIdentity(battleTagName + "#" + hashCode.ToString("D4"))) { if (password.Length > 16) { password = password.Substring(0, 16); // make sure the password does not exceed 16 chars. } var salt = SRP6a.GetRandomBytes(32); var passwordVerifier = SRP6a.CalculatePasswordVerifierForAccount(email, password, salt); this.SetFields(email, salt, passwordVerifier, battleTagName, hashCode, userLevel); }
public static bool UpdatePassword(this Account account, string newPassword) { account.PasswordVerifier = SRP6a.CalculatePasswordVerifierForAccount(account.Email, newPassword, account.Salt); try { SaveToDB(account); return(true); } catch (Exception e) { Logger.ErrorException(e, "UpdatePassword()"); return(false); } }
public bool VerifyPassword(string password) { if (string.IsNullOrEmpty(password)) { return(false); } if (password.Length < 8 || password.Length > 16) { return(false); } var calculatedVerifier = SRP6a.CalculatePasswordVerifierForAccount(this.Email, password, this.Salt); return(calculatedVerifier.SequenceEqual(this.PasswordVerifier)); }
public void UpdatePassword(string newPassword) { this.PasswordVerifier = SRP6a.CalculatePasswordVerifierForAccount(this.Email, newPassword, this.Salt); try { var query = string.Format("UPDATE accounts SET passwordVerifier=@passwordVerifier WHERE id={0}", this.PersistentID); using (var cmd = new SQLiteCommand(query, DBManager.Connection)) { cmd.Parameters.Add("@passwordVerifier", System.Data.DbType.Binary, 128).Value = this.PasswordVerifier; cmd.ExecuteNonQuery(); } } catch (Exception e) { Logger.ErrorException(e, "UpdatePassword()"); } }
public static void Create(string[] args) { var email = Command.Read <string>(args, 0); var password = Command.Read <string>(args, 1); if (email != null && password != null) { var salt = new byte[0].GenerateRandomKey(0x20).ToHexString(); var result = DB.Auth.Accounts.Any(a => a.Email.Equals(email)); if (!result) { var srp = new SRP6a(salt); srp.CalculateX(email, password.ToUpper(), false); var account = new Account { Email = email, PasswordVerifier = srp.V.ToHexString(), Salt = salt, Expansion = 5 }; if (DB.Auth.Add(account)) { // Default class/expansion data (sent in AuthResponse) var defaultAllowedClasses = new byte[, ] { { 1, 0 }, { 2, 0 }, { 3, 0 }, { 4, 0 }, { 5, 0 }, { 6, 2 }, { 7, 0 }, { 8, 0 }, { 9, 0 }, { 10, 4 }, { 11, 0 } }; // Default race/expansion data (sent in AuthResponse) var defaultAllowedRaces = new byte[, ] { { 1, 0 }, { 2, 0 }, { 3, 0 }, { 4, 0 }, { 5, 0 }, { 6, 0 }, { 7, 0 }, { 8, 0 }, { 9, 3 }, { 10, 1 }, { 11, 1 }, { 22, 3 }, { 24, 4 }, { 25, 4 }, { 26, 4 } }; for (int i = 0; i < defaultAllowedClasses.Length / 2; i++) { DB.Auth.Add(new AllowedClass { AccountId = account.Id, Class = defaultAllowedClasses[i, 0], Expansion = defaultAllowedClasses[i, 1] }); } for (int i = 0; i < defaultAllowedRaces.Length / 2; i++) { DB.Auth.Add(new AllowedRace { AccountId = account.Id, Race = defaultAllowedRaces[i, 0], Expansion = defaultAllowedRaces[i, 1] }); } Log.Message(LogType.Normal, "Account {0} successfully created", email); } } else { Log.Message(LogType.Error, "Account {0} already in database", email); } } }