예제 #1
0
 private IAsyncEnumerable <IFile> LoadLibraryItem(string itemName, string subFolder, string[] filters)
 {
     try
     {
         var compsLoc = m_Location.Combine(new Location("", "", new string[] { subFolder, itemName }));
         return(m_FileLoader.LoadFolder(compsLoc, filters));
     }
     catch (Exception ex)
     {
         throw new LibraryItemLoadException(itemName, subFolder, ex);
     }
 }
예제 #2
0
        private async Task <(IConfiguration Conf, IConfiguration EnvConf)> LoadConfigurationsFromLocation(ILocation loc)
        {
            var res = (Conf : (IConfiguration) new Configuration(), EnvConf : (IConfiguration) new Configuration());

            await foreach (var file in m_FileLoader.LoadFolder(loc, GetConfigurationFileFilters()))
            {
                if (string.Equals(file.Location.FileName, CONF_FILE_NAME, StringComparison.CurrentCultureIgnoreCase))
                {
                    res.Conf = ConfigurationFromFile(file);
                }
                else if (string.Equals(file.Location.FileName, m_EnvConfFileName, StringComparison.CurrentCultureIgnoreCase))
                {
                    res.EnvConf = ConfigurationFromFile(file);
                }
                else
                {
                    throw new Exception("Invalid configuration file");
                }
            }

            return(res);
        }
예제 #3
0
        private async IAsyncEnumerable <IFile> LoadAndValidateFiles(ILocation loc, SecureLibraryItemFile[] files, string[] filters)
        {
            await foreach (var file in m_FileLoader.LoadFolder(loc, filters))
            {
                var fileManifest = files.FirstOrDefault(f => file.Location.IsSame(f.Name));

                if (fileManifest != null)
                {
                    if (!m_Rsa.VerifyData(file.Content, fileManifest.Signature,
                                          HashAlgorithmName.SHA256, RSASignaturePadding.Pss))
                    {
                        throw new DigitalSignatureMismatchException(file.Location.ToId());
                    }

                    yield return(file);
                }
                else
                {
                    m_Logger.LogWarning($"'{file.Location.ToId()}' is not listed in the library manifest and skipped");
                }
            }
        }
예제 #4
0
        private async Task <SecureLibraryManifest> CreateManifest(ILocation libFolder, RSA rsaWrite, Version vers)
        {
            var components = new Dictionary <string, List <SecureLibraryItemFile> >(StringComparer.CurrentCultureIgnoreCase);
            var themes     = new Dictionary <string, List <SecureLibraryItemFile> >(StringComparer.CurrentCultureIgnoreCase);
            var plugins    = new Dictionary <string, List <SecureLibraryItemFile> >(StringComparer.CurrentCultureIgnoreCase);

            await foreach (var file in m_Loader.LoadFolder(libFolder, null))
            {
                if (file.Location.Segments.Count >= 2)
                {
                    var itemType = file.Location.Segments[0];
                    var itemName = file.Location.Segments[1];
                    Dictionary <string, List <SecureLibraryItemFile> > thisComp = null;

                    switch (itemType.ToLower())
                    {
                    case Location.Library.ComponentsFolderName:
                        thisComp = components;
                        break;

                    case Location.Library.ThemesFolderName:
                        thisComp = themes;
                        break;

                    case Location.Library.PluginsFolderName:
                        thisComp = plugins;
                        break;

                    default:
                        continue;
                    }

                    List <SecureLibraryItemFile> files;

                    if (!thisComp.TryGetValue(itemName, out files))
                    {
                        files = new List <SecureLibraryItemFile>();
                        thisComp.Add(itemName, files);
                    }

                    var signature = rsaWrite.SignData(file.Content, HashAlgorithmName.SHA256, RSASignaturePadding.Pss);

                    var fileManifest = new SecureLibraryItemFile()
                    {
                        Name      = file.Location.GetRelative(new Location("", "", new string[] { itemType, itemName })),
                        Signature = signature
                    };

                    files.Add(fileManifest);
                }
            }

            var manifest = new SecureLibraryManifest()
            {
                Version = vers,

                Components = components.Select(x => new SecureLibraryItem()
                {
                    Name  = x.Key,
                    Files = x.Value.ToArray()
                }).ToArray(),

                Themes = themes.Select(x => new SecureLibraryItem()
                {
                    Name  = x.Key,
                    Files = x.Value.ToArray()
                }).ToArray(),

                Plugins = plugins.Select(x => new SecureLibraryItem()
                {
                    Name  = x.Key,
                    Files = x.Value.ToArray()
                }).ToArray()
            };

            return(manifest);
        }
예제 #5
0
        public async IAsyncEnumerable <IFile> Load(ILocation[] locations)
        {
            var resFileIds = new List <string>();

            await m_PluginsManager.LoadPlugins(LoadPluginFiles(locations, resFileIds));

            foreach (var loc in locations)
            {
                m_Logger.LogInformation($"Loading project files from {loc.ToId()}");

                var filter = new List <string>();

                if (m_Filter != null)
                {
                    filter.AddRange(m_Filter);
                }

                var pluginExcludeFilter = LocationExtension.NEGATIVE_FILTER
                                          + Path.Combine(Location.Library.PluginsFolderName, LocationExtension.ANY_FILTER);

                filter.Add(pluginExcludeFilter);

                await foreach (var srcFile in m_FileLoader.LoadFolder(loc, filter.ToArray()))
                {
                    var args = new PreLoadFileArgs()
                    {
                        File     = srcFile,
                        SkipFile = false
                    };

                    await m_Ext.PreLoadFile(args);

                    if (!args.SkipFile)
                    {
                        var id = args.File.Location.ToId();

                        if (!resFileIds.Contains(id))
                        {
                            resFileIds.Add(id);
                            yield return(args.File);
                        }
                        else
                        {
                            throw new DuplicateFileException(id, loc.ToId());
                        }
                    }
                }
            }

            if (m_Config.Components?.Any() == true)
            {
                foreach (var compName in m_Config.Components)
                {
                    await foreach (var srcFile in ProcessLibraryItems(
                                       m_LibraryLoader.LoadComponentFiles(compName, m_Filter), resFileIds, false))
                    {
                        yield return(srcFile);
                    }
                }
            }

            if (m_Config.ThemesHierarchy?.Any() == true)
            {
                foreach (var theme in m_Config.ThemesHierarchy)
                {
                    foreach (var themeName in m_Config.ThemesHierarchy)
                    {
                        await foreach (var srcFile in ProcessLibraryItems(
                                           m_LibraryLoader.LoadThemeFiles(themeName, m_Filter), resFileIds, true))
                        {
                            yield return(srcFile);
                        }
                    }
                }
            }
        }