public async Task <ChannelVerificationResult> ValidateChannel(PackageGenerationInput input) { var result = new ChannelVerificationResult(); var connectionIdentifierHash = _contextAccessor.HttpContext.GetRemoteIPAddress().ToString().ToSha256(); //Run validation depending on the Entry Channel (Web, Application) switch (input.EntryChannel) { case EntryChannelEnum.Web: try { result.ChannelVerificationSucceeded = await HcaptchaValidationHelper.CheckHcaptchaResponseIsValid(input.Token, _configuration.GetSection("HcaptchaSecret").Value); } catch (InvalidSignatureException ise) { result.ChannelVerificationErrorMessage = ise.Message; } break; case EntryChannelEnum.Application: try { result.ChannelVerificationSucceeded = SafetyNetValidationHelper.CheckSafetyNetResponseIsValid(input.Token, _distributedCache, connectionIdentifierHash); } catch (InvalidSignatureException ise) { result.ChannelVerificationErrorMessage = ise.Message; } break; } return(result); }
public async Task <PackageGenerationResult> GeneratePackageAsync(PackageGenerationInput input) { var packageDetails = await _packageGenerationService.ProcessForPackageAsync(input.PackageName); var result = new PackageGenerationResult(); switch (packageDetails.Status) { case PackageCreationStatus.NotCreated: result.ServeStatus = PackageServeStatus.FileDoesNotExist; break; case PackageCreationStatus.Success: case PackageCreationStatus.AlreadyExists: { var downloadKey = $"{Guid.NewGuid():N}"; var connectionIdentifierHash = _contextAccessor.HttpContext.GetRemoteIPAddress().ToString().ToSha256(); var downloadContents = new DownloadContentsModel { FilePath = packageDetails.FileLocation, ConnectionIdentifierHash = connectionIdentifierHash }; //Result is stored for 1 hour, but once accessed it gets deleted await _distributedCache.SetTimedObjectAsync(downloadKey, downloadContents, 1); //Finalize setting up the result object result.ServeStatus = PackageServeStatus.Ready; result.DownloadUrl = _linkGenerator.GetPathByAction("GetTool", "Download", new { guid = downloadKey }); result.FileName = packageDetails.ApplicationName; break; } } return(result); }
public bool ParametersAreValid(PackageGenerationInput input) { return(!string.IsNullOrWhiteSpace(input.PackageName) && !string.IsNullOrWhiteSpace(input.Token)); }