Ejemplo n.º 1
0
        public override void VerifyManifest()
        {
            var manifest = new List <FileDigest>(Manifest);

            try
            {
                Open();

                // For a tar package, it is more efficient to iterate the files in the order within the archive.
                while (_archiveIterator.HasNext())
                {
                    var extension = Path.GetExtension(_archiveIterator.CurrentFileName());
                    if (string.Compare(extension, MANIFEST_EXT, true) == 0 ||
                        string.Compare(extension, CERTIFICATE_EXT, true) == 0)
                    {
                        continue;
                    }

                    var fileDigest = manifest.Find(fd => string.Compare(fd.Name, _archiveIterator.CurrentFileName(), true) == 0);

                    if (fileDigest == null)
                    {
                        log.ErrorFormat("File {0} contained in the appliance is not listed in the manifest.", _archiveIterator.CurrentFileName());
                        throw new Exception(Messages.SECURITY_FILE_MISSING_FROM_MANIFEST);
                    }

                    manifest.Remove(fileDigest);
                    if (!_archiveIterator.VerifyCurrentFileAgainstDigest(fileDigest.AlgorithmName, fileDigest.Digest))
                    {
                        throw new Exception(string.Format(Messages.SECURITY_SIGNATURE_FAILED, fileDigest.Name));
                    }
                }
            }
            finally
            {
                Close();
            }

            if (manifest.Count > 0)
            {
                log.ErrorFormat("The following files are listed in the manifest but missing from the appliance: {0}",
                                string.Join(", ", manifest.Select(fd => fd.Name)));
                throw new Exception(Messages.SECURITY_FILE_MISSING_FROM_PACKAGE);
            }
        }