Example #1
0
        public void RegisterPackageAndFormat(ExtPackage pkg)
        {
            var formats = pkg.SupportedFormats.Split(';');

            foreach (var f in formats)
            {
                _context.Formats.Add(new FormatTable
                {
                    Format   = f,
                    PluginId = pkg.PackageId
                });
            }

            _context.SaveChanges();
            RegisterPackage(pkg);
        }
Example #2
0
        public async Task <InstallResult> InstallPackageAsync(StorageFile package)
        {
            var folder = await CreateFolder();

            var workFolder = await folder.CreateFolderAsync(GenerateFolderName());

            if (await Decompressor.UnZipFile(package, workFolder))
            {
                // Find manifest.
                IStorageFile manifestFile;
                IStorageFile sigFile;
                if (NativeMethods.GetStorageFileFromPath(Path.Combine(workFolder.Path, "_signature"), out sigFile) != 0)
                {
                    return(InstallResult.FileError);
                }
                if (
                    NativeMethods.GetStorageFileFromPath(Path.Combine(workFolder.Path, "Manifest.json"),
                                                         out manifestFile) != 0)
                {
                    return(InstallResult.FileError);
                }
                else
                {
                    // Read manifest content.
                    var sigContent = await FileIO.ReadTextAsync(sigFile);

                    var manifestContent = await FileIO.ReadTextAsync(manifestFile);

                    // Verify security.
                    if (!await SecurityHelper.VerifyManifestSecurity(manifestContent, sigContent))
                    {
                        return(InstallResult.IntegrityFailure);
                    }

                    // Deserialize content.
                    if (!string.IsNullOrEmpty(manifestContent))
                    {
                        var m = JsonConvert.DeserializeObject <ManifestEntity>(manifestContent);
                        // Verify security
                        var verifyContentKvPairs =
                            m.SecurityInfo.Select(
                                i => new KeyValuePair <string, string>(Path.Combine(workFolder.Path, i.File), i.Hash));
                        if (!await SecurityHelper.VerifyHash(verifyContentKvPairs))
                        {
                            return(InstallResult.IntegrityFailure);
                        }

                        // Verify Architecture
#if WIN32
                        if (m.Arch != Arch.Win32 && m.Arch != Arch.Universal)
                        {
                            return(InstallResult.ArchitectureFailure);
                        }
#endif
#if ARM
                        if (m.Arch != Arch.WoA && m.Arch != Arch.Universal)
                        {
                            return(InstallResult.ArchitectureFailure);
                        }
#endif
                        // Register Package.
                        var extPkg = new ExtPackage
                        {
                            Arch             = m.Arch,
                            EntryPoint       = m.EntryPoint,
                            Name             = m.Name,
                            PackageId        = workFolder.Name,
                            SupportedFormats = SerializeFormats(m.SupportedFormats),
                            Version          = m.Version,
                            Type             = m.Type
                        };

                        _databaseWorker.RegisterPackage(extPkg);
                    }
                }

                return(InstallResult.Succeeded);
            }
            else
            {
                return(InstallResult.FileError);
            }
        }
Example #3
0
 public void RegisterPackage(ExtPackage pkg)
 {
     _context.Packages.Add(pkg);
     _context.SaveChanges();
 }