Ejemplo n.º 1
0
        // Wrap calls to TarFileStream.MoveNext() to cache file names for HasFile().
        private bool MoveNext(TarFileStream stream)
        {
            var haveFile = stream.MoveNext();

            if (haveFile)
            {
                _DirectoryCache[stream.Current] = null;
            }

            return(haveFile);
        }
Ejemplo n.º 2
0
        // Open a file within the tar.
        protected TarFileStream OpenRead(string fileName)
        {
            var stream = new TarFileStream(PackageSourceFile);

            if (!stream.FindNextFile(fileName))
            {
                stream.Close();
                throw new FileNotFoundException(fileName);
            }

            return(stream);
        }
Ejemplo n.º 3
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);
                }
            }
        }
Ejemplo n.º 4
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();
                }
            }
        }
Ejemplo n.º 5
0
        // Wrap calls to TarFileStream.MoveNext() to cache file names for HasFile().
        private bool MoveNext(TarFileStream stream)
        {
            var haveFile = stream.MoveNext();

            if (haveFile)
                _DirectoryCache[stream.Current] = null;

            return haveFile;
        }
Ejemplo n.º 6
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();
                }
            }
        }
Ejemplo n.º 7
0
        // Open a file within the tar.
        protected TarFileStream OpenRead(string fileName)
        {
            var stream = new TarFileStream(PackageSourceFile);

            if (!stream.FindNextFile(fileName))
            {
                stream.Close();
                throw new FileNotFoundException(fileName);
            }

            return stream;
        }
Ejemplo n.º 8
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);
                }
            }
        }