Esempio n. 1
0
        public override void VerifyManifest()
        {
            // Verify the presence of a manifest.
            var manifest = Manifest;

            int verifiedCount = 0;

            using (var stream = new TarFileStream(PackageSourceFile))
            {
                // For a tar package, it is more efficient to iterate the files in the order within the archive.
                while (MoveNext(stream))
                {
                    // Find the manifest entry for the current tar entry.
                    FileDigest fileDigest = manifest.Find(
                        delegate(FileDigest aFileDigest)
                    {
                        return(String.Compare(aFileDigest.Name, stream.Current, true) == 0);
                    });

                    if (fileDigest == null)
                    {
                        continue;
                    }

                    // The manifest entry was found.
                    // Verify its digest.
                    fileDigest.Verify(new MemoryStream(stream.ReadAllBytes()));

                    verifiedCount++;
                }

                foreach (var fileDigest in manifest)
                {
                    if (!fileDigest.WasVerified)
                    {
                        // A manifest entry was missing.
                        XenOvf.Utilities.Log.Error(string.Format(Messages.FILE_MISSING, fileDigest.Name));
                    }
                }

                if (verifiedCount != manifest.Count)
                {
                    // A manifest entry was missing.
                    throw new Exception(Messages.SECURITY_FILE_MISSING);
                }
            }
        }
Esempio n. 2
0
        private void Load()
        {
            using (var stream = new TarFileStream(PackageSourceFile))
            {
                while (MoveNext(stream))
                {
                    var extension = Path.GetExtension(stream.Current);

                    if ((_DescriptorFileName == null) && (String.Compare(extension, Properties.Settings.Default.ovfFileExtension, true) == 0))
                    {
                        // Use the first file name with an ovf extension.
                        _DescriptorFileName = stream.Current;
                    }
                    else if (String.Compare(extension, Properties.Settings.Default.manifestFileExtension, true) == 0)
                    {
                        // Skip a manifest file that does not have the base name as the descriptor.
                        if ((_DescriptorFileName != null) && (String.Compare(stream.Current, ManifestFileName, true) != 0))
                        {
                            continue;
                        }
                    }
                    else if (String.Compare(extension, Properties.Settings.Default.certificateFileExtension, true) == 0)
                    {
                        // Skip a certificate file that does not have the base name as the descriptor.
                        if ((_DescriptorFileName != null) && (String.Compare(stream.Current, CertificateFileName, true) != 0))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        // Stop loading because descriptor, manifest, and certificate files must precede all other files.
                        break;
                    }

                    // Load this file.
                    _DirectoryCache[stream.Current] = stream.ReadAllBytes();
                }
            }
        }
Esempio n. 3
0
        private void Load()
        {
            using (var stream = new TarFileStream(PackageSourceFile))
            {
                while (MoveNext(stream))
                {
                    var extension = Path.GetExtension(stream.Current);

                    if ((_DescriptorFileName == null) && (String.Compare(extension, Properties.Settings.Default.ovfFileExtension, true) == 0))
                    {
                        // Use the first file name with an ovf extension.
                        _DescriptorFileName = stream.Current;
                    }
                    else if (String.Compare(extension, Properties.Settings.Default.manifestFileExtension, true) == 0)
                    {
                        // Skip a manifest file that does not have the base name as the descriptor.
                        if ((_DescriptorFileName != null) && (String.Compare(stream.Current, ManifestFileName, true) != 0))
                            continue;
                    }
                    else if (String.Compare(extension, Properties.Settings.Default.certificateFileExtension, true) == 0)
                    {
                        // Skip a certificate file that does not have the base name as the descriptor.
                        if ((_DescriptorFileName != null) && (String.Compare(stream.Current, CertificateFileName, true) != 0))
                            continue;
                    }
                    else
                    {
                        // Stop loading because descriptor, manifest, and certificate files must precede all other files.
                        break;
                    }

                    // Load this file.
                    _DirectoryCache[stream.Current] = stream.ReadAllBytes();
                }
            }
        }
Esempio n. 4
0
        public override void VerifyManifest()
        {
            // Verify the presence of a manifest.
            var manifest = Manifest;

            int verifiedCount = 0;

            using (var stream = new TarFileStream(PackageSourceFile))
            {
                // For a tar package, it is more efficient to iterate the files in the order within the archive.
                while (MoveNext(stream))
                {
                    // Find the manifest entry for the current tar entry.
                    FileDigest fileDigest = manifest.Find(
                        delegate(FileDigest aFileDigest)
                        {
                            return (String.Compare(aFileDigest.Name, stream.Current, true) == 0);
                        });

                    if (fileDigest == null)
                        continue;

                    // The manifest entry was found.
                    // Verify its digest.
                    fileDigest.Verify(new MemoryStream(stream.ReadAllBytes()));

                    verifiedCount++;
                }

                foreach (var fileDigest in manifest)
                {
                    if (!fileDigest.WasVerified)
                    {
                        // A manifest entry was missing.
                        XenOvf.Utilities.Log.Error(string.Format(Messages.FILE_MISSING, fileDigest.Name));
                    }
                }

                if (verifiedCount != manifest.Count)
                {
                    // A manifest entry was missing.
                    throw new Exception(Messages.SECURITY_FILE_MISSING);
                }
            }
        }