Fix small TOTP and `SessionIdentification.ChallengeAnswer` property issue.

Signed-off-by: Aliwoto <aminnimaj@gmail.com>
This commit is contained in:
Aliwoto 2021-10-03 19:39:11 +00:00
parent 70ef761e20
commit 039836d83f
No known key found for this signature in database
GPG Key ID: 646B4FE4205EC48C
3 changed files with 17 additions and 15 deletions

View File

@ -163,7 +163,7 @@ namespace Socialvoid.Client
/// next jsonrpc request.
/// <code> since: v0.0.0 </code>
/// </summary>
protected string _otp;
protected string _otp_answer;
/// <summary>
/// <code> since: v0.0.0 </code>
/// </summary>
@ -282,7 +282,7 @@ namespace Socialvoid.Client
if (!string.IsNullOrEmpty(jresp.Result.ChallengeSecret))
{
_should_otp = true;
_otp = GetChallengeAnswer(jresp.Result.ChallengeSecret);
_otp_answer = GetChallengeAnswer(jresp.Result.ChallengeSecret);
// set challenege secret to null to avoid sending it again.
// this will avoid future conflicts in using old challenge secret.
jresp.Result.ChallengeSecret = null;
@ -368,16 +368,17 @@ namespace Socialvoid.Client
if (IsOtpValid(otp))
{
args.Add(OtpKey, otp);
sessionID.ChallengeAnswer = otp;
//sessionID.ChallengeAnswer = otp;
}
else if (_should_otp && IsOtpValid(_otp))
if (_should_otp && IsOtpValid(_otp_answer))
{
// after adding otp answer to args, don't forget to set
// _should_otp to false (and _otp to null).
args.Add(OtpKey, _otp);
sessionID.ChallengeAnswer = _otp;
//args.Add(OtpKey, _challenge);
sessionID.ChallengeAnswer = _otp_answer;
_should_otp = false;
_otp = null;
_otp_answer = null;
}
var request = GetRpcRequest(AuthenticateUserMethod, args);

View File

@ -129,13 +129,14 @@ namespace Socialvoid.Security.Otp
internal static string GetSha1(string value)
{
var data = Encoding.ASCII.GetBytes(value);
var hashData = new SHA1Managed().ComputeHash(data);
var hash = string.Empty;
foreach (var b in hashData)
{
hash += b.ToString("X2");
}
return hash;
return Convert.ToHexString(new SHA1Managed().ComputeHash(data)).ToLower();
//var hashData = new SHA1Managed().ComputeHash(data);
//var hash = string.Empty;
//foreach (var b in hashData)
//{
// hash += b.ToString("X2");
//}
//return hash;
}
#endregion
//-------------------------------------------------

View File

@ -42,7 +42,7 @@ namespace Socialvoid.Security
/// <code> since: v0.0.0 </code>
/// </summary>
[JsonPropertyName("challenge_answer")]
public string ChallengeAnswer { get; internal set; }
public string ChallengeAnswer { get; set; }
#endregion
//-------------------------------------------------
#region static field's Region