Fixed SRP6a.cs for .NET 7 (BigInt);
Added Success logging; Small improvements
This commit is contained in:
parent
3cd92e4ac1
commit
2aecf414ef
@ -90,10 +90,10 @@ namespace DiIiS_NA.LoginServer.Crypthography
|
||||
this.b = GetRandomBytes(128).ToBigInteger(); // server's secret ephemeral value.
|
||||
var gModb = BigInteger.ModPow(g, b, N); // pow(g, b, N)
|
||||
var k = H.ComputeHash(new byte[0].Concat(N.ToArray()).Concat(g.ToArray()).ToArray()).ToBigInteger(); // Multiplier parameter (k = H(N, g) in SRP-6a
|
||||
this.B = BigInteger.Remainder((this.Account.PasswordVerifier.ToBigInteger() * k) + gModb, N); // B = (k * v + pow(g, b, N)) % N
|
||||
this.B = BigInteger.Remainder((BigInteger.Add(BigInteger.Multiply(this.Account.PasswordVerifier.ToBigInteger(), k), gModb)), N); // B = (k * v + pow(g, b, N)) % N
|
||||
|
||||
// cook the logon challenge message
|
||||
this.LogonChallenge = new byte[0]
|
||||
this.LogonChallenge = Array.Empty<byte>()
|
||||
.Concat(new byte[] { 0 }) // command = 0
|
||||
.Concat(this.IdentitySalt.ToByteArray()) // identity-salt - generated by hashing account email.
|
||||
.Concat(this.Account.Salt) // account-salt - generated on account creation.
|
||||
@ -119,7 +119,7 @@ namespace DiIiS_NA.LoginServer.Crypthography
|
||||
|
||||
var identitySalt = H.ComputeHash(Encoding.ASCII.GetBytes(email)).ToHexString();
|
||||
var pBytes = H.ComputeHash(Encoding.ASCII.GetBytes(identitySalt.ToUpper() + ":" + password.ToUpper())); // p (identitySalt + password)
|
||||
var x = H.ComputeHash(new byte[0].Concat(salt).Concat(pBytes).ToArray()).ToBigInteger(); // x = H(s, p)
|
||||
var x = H.ComputeHash(Array.Empty<byte>().Concat(salt).Concat(pBytes).ToArray()).ToBigInteger(); // x = H(s, p)
|
||||
|
||||
return BigInteger.ModPow(g, x, N).ToArray(128);
|
||||
}
|
||||
@ -130,7 +130,7 @@ namespace DiIiS_NA.LoginServer.Crypthography
|
||||
var A = A_bytes.ToBigInteger(); // client's public ephemeral
|
||||
var u = H.ComputeHash(new byte[0].Concat(A_bytes).Concat(B.ToArray(128)).ToArray()).ToBigInteger(); // Random scrambling parameter - u = H(A, B)
|
||||
|
||||
var S_s = BigInteger.ModPow(A * BigInteger.ModPow(this.Account.PasswordVerifier.ToBigInteger(), u, N), b, N); // calculate server session key - S = (Av^u) ^ b
|
||||
var S_s = BigInteger.ModPow(BigInteger.Multiply(A, BigInteger.ModPow(this.Account.PasswordVerifier.ToBigInteger(), u, N)), b, N); // calculate server session key - S = (Av^u) ^ b
|
||||
this.SessionKey = Calc_K(S_s.ToArray(128)); // K = H(S) - Shared, strong session key.
|
||||
byte[] K_s = this.SessionKey;
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ namespace DiIiS_NA.Core.Logging
|
||||
{
|
||||
MinimumLevel = minLevel;
|
||||
MaximumLevel = maxLevel;
|
||||
this.IncludeTimeStamps = includeTimeStamps;
|
||||
IncludeTimeStamps = includeTimeStamps;
|
||||
}
|
||||
|
||||
/// <param name="level">Log level.</param>
|
||||
@ -21,9 +21,9 @@ namespace DiIiS_NA.Core.Logging
|
||||
/// <param name="message">Log message.</param>
|
||||
public override void LogMessage(Logger.Level level, string logger, string message)
|
||||
{
|
||||
var timeStamp = this.IncludeTimeStamps ? "[" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] " : "";
|
||||
var timeStamp = IncludeTimeStamps ? "[" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] " : "";
|
||||
SetConsoleForegroundColor(level);
|
||||
Console.WriteLine($"{timeStamp}[{level.ToString(),5}] [{logger,20}]: {message}");
|
||||
Console.WriteLine($"{timeStamp}[{level.ToString(),8}] [{logger,20}]: {message}");
|
||||
}
|
||||
|
||||
/// <param name="level">Log level.</param>
|
||||
@ -32,7 +32,7 @@ namespace DiIiS_NA.Core.Logging
|
||||
/// <param name="exception">Exception to be included with log message.</param>
|
||||
public override void LogException(Logger.Level level, string logger, string message, Exception exception)
|
||||
{
|
||||
var timeStamp = this.IncludeTimeStamps ? "[" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] " : "";
|
||||
var timeStamp = IncludeTimeStamps ? "[" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] " : "";
|
||||
SetConsoleForegroundColor(level);
|
||||
Console.WriteLine(
|
||||
$"{timeStamp}[{level.ToString(),8}] [{logger,20}]: {message} - [Exception] {exception}");
|
||||
@ -55,6 +55,9 @@ namespace DiIiS_NA.Core.Logging
|
||||
case Logger.Level.Info:
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
break;
|
||||
case Logger.Level.Success:
|
||||
Console.ForegroundColor = ConsoleColor.DarkGreen;
|
||||
break;
|
||||
case Logger.Level.Warn:
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
break;
|
||||
|
||||
@ -49,6 +49,10 @@ namespace DiIiS_NA.Core.Logging
|
||||
/// </summary>
|
||||
Info,
|
||||
/// <summary>
|
||||
/// Success messages.
|
||||
/// </summary>
|
||||
Success,
|
||||
/// <summary>
|
||||
/// Warning messages.
|
||||
/// </summary>
|
||||
Warn,
|
||||
@ -110,6 +114,13 @@ namespace DiIiS_NA.Core.Logging
|
||||
/// <param name="args">Additional arguments.</param>
|
||||
public void Info(string message, params object[] args) => Log(Level.Info, message, args);
|
||||
|
||||
/// <param name="message">The log message.</param>
|
||||
public void Success(string message) => Log(Level.Success, message, null);
|
||||
|
||||
/// <param name="message">The log message.</param>
|
||||
/// <param name="args">Additional arguments.</param>
|
||||
public void Success(string message, params object[] args) => Log(Level.Success, message, args);
|
||||
|
||||
/// <param name="message">The log message.</param>
|
||||
public void Warn(string message) => Log(Level.Warn, message, null);
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ namespace DiIiS_NA.GameServer.CommandManager
|
||||
if (!_commands.ContainsKey(attribute))
|
||||
_commands.Add(attribute, method);
|
||||
else
|
||||
Logger.Warn("There exists an already registered command '{0}'.", attribute.Name);
|
||||
Logger.Error("Command '{0}' already exists.", attribute.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
user.block.title