/// <inheritdoc /> public Task HandleMessage(IPeerMessageContext <AuthenticationClientPayload> context, AuthLogonChallengeResponse payload) { AuthLogonProofRequest proof = null; //TODO: Change this console logging if (payload.Result != AuthenticationResult.Success) { Console.WriteLine($"Failed Auth: {payload.Result}"); } using (WoWSRP6ClientCryptoServiceProvider srpProvider = new WoWSRP6ClientCryptoServiceProvider(payload.Challenge.B.ToBigInteger(), payload.Challenge.N.ToBigInteger(), payload.Challenge.g.ToBigInteger())) { using (WoWSRP6PublicComponentHashServiceProvider hashingService = new WoWSRP6PublicComponentHashServiceProvider()) { //TODO: Remove hardcoded name/pass //Set the session key in the store for usage BigInteger unhashedKey = srpProvider.ComputeSessionKey("Glader".ToUpper(), "test", payload.Challenge.salt); Console.WriteLine($"SessionKey: {unhashedKey} KeySize: {unhashedKey.ToCleanByteArray().Length}"); proof = new AuthLogonProofRequest(srpProvider.A.ToCleanByteArray(), hashingService.ComputeSRP6M1(srpProvider.g, srpProvider.N, "Glader".ToUpper(), payload.Challenge.salt, srpProvider.A, srpProvider.B, unhashedKey)); //Set the session key as a hashed session key //SessionKeyStorage.SessionKey = hashingService.HashSessionKey(unhashedKey); } } Console.WriteLine("Sending Proof"); return(context.PayloadSendService.SendMessage(proof)); }
/// <inheritdoc /> public async Task HandleMessage(IPeerMessageContext <AuthenticationClientPayload> context, AuthLogonChallengeResponse payload) { AuthLogonProofRequest proof = null; if (payload.Result != AuthenticationResult.Success) { throw new InvalidOperationException($"The auth challenge failed. Returned: {payload.Result}."); } using (WoWSRP6CryptoServiceProvider srpProvider = new WoWSRP6CryptoServiceProvider(payload.Challenge.B.ToBigInteger(), payload.Challenge.N.ToBigInteger(), payload.Challenge.g.ToBigInteger())) { using (WoWSRP6PublicComponentHashServiceProvider hashingService = new WoWSRP6PublicComponentHashServiceProvider()) { //TODO: Remove hardcoded name/pass //Set the session key in the store for usage BigInteger unhashedKey = srpProvider.ComputeSessionKey("Glader".ToUpper(), "test", payload.Challenge.salt); proof = new AuthLogonProofRequest(srpProvider.A.ToCleanByteArray(), hashingService.ComputeSRP6M1(srpProvider.g, srpProvider.N, "Glader".ToUpper(), payload.Challenge.salt, srpProvider.A, srpProvider.B, unhashedKey)); //Set the session key as a hashed session key //SessionKeyStorage.SessionKey = hashingService.HashSessionKey(unhashedKey); } } await context.PayloadSendService.SendMessage(proof); }
public static void Test_SameBytes_As_WCELL(int value) { //arrange WCell.Core.Cryptography.BigInteger WcellBigInt = new WCell.Core.Cryptography.BigInteger(value); FreecraftCore.Crypto.BigInteger FreecraftBigInt = new FreecraftCore.Crypto.BigInteger(value); AssertBitIntEquivalence(WcellBigInt, FreecraftBigInt); }
public static void Test_N_Bytes_Equivalent() { //arrange string N = @"894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7"; WCell.Core.Cryptography.BigInteger WcellBigInt = new WCell.Core.Cryptography.BigInteger(@"894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7", 16); FreecraftCore.Crypto.BigInteger FreecraftBigInt = @"894B645E89E1535BBDAD5B8B290650530801B18EBFBF5E8FAB3C82872A3E9BB7".ToBigInteger(); AssertBitIntEquivalence(WcellBigInt, FreecraftBigInt); }
private static void AssertBitIntEquivalence(WCell.Core.Cryptography.BigInteger WcellBigInt, FreecraftCore.Crypto.BigInteger FreecraftBigInt) { //act byte[] wcellbytes = WcellBigInt.GetBytes(); byte[] freecraftbytes = FreecraftBigInt.ToCleanByteArray(); //assert Assert.AreEqual(wcellbytes.Length, freecraftbytes.Length, "BigInteger mismatched length between Wcell and FreecraftCore."); for (int i = 0; i < wcellbytes.Length; i++) { Assert.AreEqual(wcellbytes[i], freecraftbytes[i], $"Byte value mismatch at index: {i} Wcell: {wcellbytes[i]} Freecraft: {freecraftbytes[i]}"); } }