Пример #1
0
        /// <summary>
        /// Verify package
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task OnGetVerifyAsync(int?id)
        {
            await OnGetAsync();

            if (id == null)
            {
                return;
            }

            if (Admin && id != null)
            {
                // Get full package
                var package = await _mediator.Send(new GetPackageCommand { DatabaseID = (int)id });

                if (package == null)
                {
                    return;
                }

                if (package.Timestamps.Count == 0)
                {
                    CommandResult = "Missing timestamp object";
                    return;
                }

                if (!_timestampProofValidator.Validate(package.Timestamps[0], out IList <string> errors))
                {
                    CommandResult = string.Join(", ", errors);
                }
                else
                {
                    CommandResult = $"Package {package.Id.ToHex()} is valid!";
                }
            }
        }
Пример #2
0
        private bool ValidatePackage(PackageInfo packageInfo, Package package)
        {
            if (package == null)
            {
                _logger.LogError($"Error wrong notitifiation returned from FatchPackageCommand");
                return(false);
            }

            if (package.Timestamps == null || package.Timestamps.Count == 0)
            {
                _logger.LogError($"Error no timestamps was found on package id {package.Id}");
                return(false);
            }

            // Verify package
            SchemaValidationResult validationResult = _packageSchemaValidator.Validate(package); //

            if (validationResult.ErrorsFound > 0)
            {
                _logger.LogError(validationResult.ToString());
                return(false);
            }

            if (!_timestampProofValidator.Validate(package.Timestamps[0], out IList <string> errors))
            {
                var msg = string.Join(", ", errors);
                _logger.LogError(msg);
                return(false);
            }

            if (!ByteComparer.EqualityComparer.Equals(packageInfo.Id, package.Id))
            {
                _logger.LogError($"Error PackageInfo id {packageInfo.Id} is not the same as package id {package.Id} from file {packageInfo.File}");
                return(false);
            }


            return(true);
        }