コード例 #1
0
ファイル: Package.cs プロジェクト: heiden-deng/xenadmin
        // 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);
        }
コード例 #2
0
ファイル: Package.cs プロジェクト: heiden-deng/xenadmin
        // 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);
        }
コード例 #3
0
ファイル: Package.cs プロジェクト: heiden-deng/xenadmin
        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);
                }
            }
        }
コード例 #4
0
ファイル: Package.cs プロジェクト: heiden-deng/xenadmin
        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();
                }
            }
        }
コード例 #5
0
ファイル: Package.cs プロジェクト: ChrisH4rding/xenadmin
        // 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;
        }
コード例 #6
0
ファイル: Package.cs プロジェクト: ChrisH4rding/xenadmin
        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();
                }
            }
        }
コード例 #7
0
ファイル: Package.cs プロジェクト: ChrisH4rding/xenadmin
        // 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;
        }
コード例 #8
0
ファイル: Package.cs プロジェクト: ChrisH4rding/xenadmin
        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);
                }
            }
        }