public static DataLineDto GetDataLineDto(this string line) { var fragments = line.Split(FragmentSeparator); var lineDto = new DataLineDto(); foreach (var fragment in fragments) { var fragmentDto = new FragmentDto(); if (decimal.TryParse(fragment, out decimal decimalFragment)) { fragmentDto.Type = NumberObjectType; } else { fragmentDto.Type = WordObjectType; } fragmentDto.Value = fragment; lineDto.Fragments.Add(fragmentDto); } return(lineDto); }
public async Task <FragmentDto> GetKey([FromRoute] string user, [FromRoute] string pub, [FromBody] IEnumerable <string> alphas) { var sharekey = (await GetAuth(user).ShareKeyAsync(alphas.Select(itm => TResponseRj.Parse(itm)))).ToString(); var dto = new FragmentDto { CvkFragment = Cryptide.Instance.Encrypt(sharekey, pub.DecodeBase64Url()), CvkPublic = _manager.GetAccount(user).pub }; return(dto); }
public TideResponse Login(AuthenticationModel model) { try { var usernameHash = model.Username.ConvertToUint64(); // Fetch the item from the cache, otherwise get it from the blockchain if (!_memoryCache.GetCacheObject(CacheKeys.Fragment, out Fragment fragment, usernameHash)) { fragment = GetTableRow <Fragment>(_settings.Account, _settings.FragmentsTable, usernameHash); if (fragment != null) { _memoryCache.SetCacheObject(CacheKeys.Fragment, fragment); } } if (fragment == null) { _logger.LogMsg("Invalid user gathering fragment", model); return(new TideResponse(false, null, "That fragment does not exist")); } // Process the request. Gather correct fragment if the password checks out, otherwise return junk data // Alternatively reject it if too many requests have been made var(success, result, minutes) = ProcessRequest(model, fragment); if (result == null) { _logger.LogMsg("TideUser hit throttle", model); return(new TideResponse(false, null, $"Too many requests. Try again in: {minutes} minutes.")); } // Convert to a transfer object var dto = new FragmentDto(fragment) { CvkFragment = Cryptide.Instance.Encrypt(result, model.PublicKey) }; _logger.LogMsg(success ? "Correct Fragment retrieved" : "Junk fragment retrieved", model); return(new TideResponse(true, new { vendorFragment = dto }, null)); } catch (Exception e) { _logger.LogMsg("Error gathering fragment", model, e); return(new TideResponse(false, null, "Unable to gather fragment")); } }
public async Task <IActionResult> GetSi([FromRoute] string user, [FromRoute] string beta, [FromRoute] string pub, [FromBody] IEnumerable <string> alphas) { /* * var (result, minutes) = _throttler.SlowDown(RemoteIp); * if (result) * { * _logger.LogInformation($"TideUser {user} hit throttle", RemoteIp); * return BadRequest(new TideResponse(false, null, $"Too many requests. Try again in: {minutes} minutes.")); * } * //*/ var shareSi = (await GetAuth(user).FinishMtA(beta.DecodeBase64Url(), alphas.Select(itm => TResponseAlpha.Parse(itm)))).ToString(); var dto = new FragmentDto { CvkFragment = Cryptide.Instance.Encrypt(shareSi, pub.DecodeBase64Url()), CvkPublic = _manager.GetAccount(user).pub }; _logger.LogInformation($"fragment sent to the user: {user}", RemoteIp); return(Ok(new TideResponse(true, new { vendorFragment = dto }, null))); }
public TideResponse Login(AuthenticationModel model) { try { // Fetch the item from the cache, otherwise get it from the blockchain var fragment = _repo.GetShare(model.Username.ConvertToUint64()); if (fragment == null) { _logger.LogMsg("Invalid user gathering fragment", model); return(new TideResponse(false, null, "That fragment does not exist")); } // Process the request. Gather correct fragment if the password checks out, otherwise return junk data // Alternatively reject it if too many requests have been made var(result, minutes) = Throttle(model.Ip); if (result) { _logger.LogMsg("TideUser hit throttle", model); return(new TideResponse(false, null, $"Too many requests. Try again in: {minutes} minutes.")); } var validationResult = ValidationManager.ValidatePass(model.PasswordHash, AesCrypto.Decrypt(fragment.PasswordHash, _settings.Password), AesCrypto.Decrypt(fragment.CvkFragment, _settings.Password), _settings.Key).Result; // Convert to a transfer object var dto = new FragmentDto(fragment) { CvkFragment = Cryptide.Instance.Encrypt(validationResult.Result, model.PublicKey) }; _logger.LogMsg(validationResult.Success ? "Correct Fragment retrieved" : "Junk fragment retrieved", model); return(new TideResponse(true, new { vendorFragment = dto }, null)); } catch (Exception e) { _logger.LogMsg("Error gathering fragment", model, e); return(new TideResponse(false, null, "Unable to gather fragment")); } }